test for serialization issues with transaction upsert (#71)

* bulk save test

* upsert test

* spelling
This commit is contained in:
Mark Chmarny 2020-09-10 08:54:56 -07:00 committed by GitHub
parent 433dbb87b1
commit 4ef06bf388
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 5 deletions

View File

@ -67,7 +67,7 @@ func TestSaveState(t *testing.T) {
// go test -timeout 30s ./client -count 1 -run ^TestStateTransactions$
func TestStateTransactions(t *testing.T) {
ctx := context.Background()
data := "test"
data := `{ "message": "test" }`
store := "test"
meta := map[string]string{}
keys := []string{"k1", "k2", "k3"}
@ -89,11 +89,34 @@ func TestStateTransactions(t *testing.T) {
assert.Nil(t, err)
})
t.Run("get all inserts", func(t *testing.T) {
t.Run("exec upserts", func(t *testing.T) {
items, err := testClient.GetBulkItems(ctx, store, keys, 10)
assert.Nil(t, err)
assert.NotNil(t, items)
assert.Len(t, items, len(keys))
upsers := make([]*StateOperation, 0)
for _, item := range items {
op := &StateOperation{
Type: StateOperationTypeUpsert,
Item: &SetStateItem{
Key: item.Key,
Etag: item.Etag,
Value: item.Value,
},
}
upsers = append(upsers, op)
}
err = testClient.ExecuteStateTransaction(ctx, store, meta, upsers)
assert.Nil(t, err)
})
t.Run("get and validate inserts", func(t *testing.T) {
items, err := testClient.GetBulkItems(ctx, store, keys, 10)
assert.Nil(t, err)
assert.NotNil(t, items)
assert.Len(t, items, len(keys))
assert.Equal(t, data, string(items[0].Value))
})
for _, op := range adds {

View File

@ -11,7 +11,8 @@ import (
func main() {
// just for this demo
ctx := context.Background()
data := []byte("ping")
json := `{ "message": "hello" }`
data := []byte(json)
store := "statestore"
// create the client
@ -28,6 +29,7 @@ func main() {
fmt.Println("data published")
// save state with the key key1
fmt.Printf("saving data: %s\n", string(data))
if err := client.SaveState(ctx, store, "key1", data); err != nil {
panic(err)
}
@ -38,7 +40,7 @@ func main() {
if err != nil {
panic(err)
}
fmt.Printf("data [key:%s etag:%s]: %s", item.Key, item.Etag, string(item.Value))
fmt.Printf("data retrieved [key:%s etag:%s]: %s\n", item.Key, item.Etag, string(item.Value))
// save state with options
item2 := &dapr.SetStateItem{
@ -67,7 +69,7 @@ func main() {
// invoke a method called EchoMethod on another dapr enabled service
content := &dapr.DataContent{
ContentType: "text/plain",
Data: []byte(data),
Data: []byte("hellow"),
}
resp, err := client.InvokeServiceWithContent(ctx, "serving", "echo", content)
if err != nil {