Merge branch 'master' into ds-mongo-fix

This commit is contained in:
Looong Dai 2022-03-16 11:15:13 +08:00 committed by GitHub
commit d1d159b9e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 94 additions and 0 deletions

View File

@ -453,6 +453,100 @@ func ConformanceTests(t *testing.T, props map[string]string, statestore state.St
}
}
})
t.Run("transaction-order", func(t *testing.T) {
// Arrange
firstKey := "key1"
firstValue := "value1"
secondKey := "key2"
secondValue := "value2"
thirdKey := "key3"
thirdValue := "value3"
// for CosmosDB
partitionMetadata := map[string]string{
"partitionKey": "myPartition",
}
// prerequisite: key1 should be present
err := statestore.Set(&state.SetRequest{
Key: firstKey,
Value: firstValue,
Metadata: partitionMetadata,
})
assert.NoError(t, err, "set request should be successful")
// prerequisite: key2 should not be present
err = statestore.Delete(&state.DeleteRequest{
Key: secondKey,
Metadata: partitionMetadata,
})
assert.NoError(t, err, "delete request should be successful")
// prerequisite: key3 should not be present
err = statestore.Delete(&state.DeleteRequest{
Key: thirdKey,
Metadata: partitionMetadata,
})
assert.NoError(t, err, "delete request should be successful")
operations := []state.TransactionalStateOperation{
// delete an item that already exists
{
Operation: state.Delete,
Request: state.DeleteRequest{
Key: firstKey,
},
},
// upsert a new item
{
Operation: state.Upsert,
Request: state.SetRequest{
Key: secondKey,
Value: secondValue,
},
},
// delete the item that was just upserted
{
Operation: state.Delete,
Request: state.DeleteRequest{
Key: secondKey,
},
},
// upsert a new item
{
Operation: state.Upsert,
Request: state.SetRequest{
Key: thirdKey,
Value: thirdValue,
},
},
}
expected := map[string][]byte{
firstKey: []byte(nil),
secondKey: []byte(nil),
thirdKey: []byte(fmt.Sprintf("\"%s\"", thirdValue)),
}
// Act
transactionStore := statestore.(state.TransactionalStore)
err = transactionStore.Multi(&state.TransactionalStateRequest{
Operations: operations,
Metadata: partitionMetadata,
})
assert.Nil(t, err)
// Assert
for k, v := range expected {
res, err := statestore.Get(&state.GetRequest{
Key: k,
Metadata: partitionMetadata,
})
assert.Nil(t, err)
assert.Equal(t, v, res.Data)
}
})
} else {
// Check if transactional feature is NOT listed
features := statestore.Features()