Patch cosmosdb first-write without etag state test (#1069)

Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
Co-authored-by: Dapr Bot <56698301+dapr-bot@users.noreply.github.com>
This commit is contained in:
Simon Leet 2021-08-17 15:47:28 -07:00 committed by GitHub
parent d62eee779d
commit ce0674fb48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 10 deletions

View File

@ -16,7 +16,7 @@ resource cosmosDb 'Microsoft.DocumentDB/databaseAccounts@2021-04-15' = {
tags: confTestTags
properties: {
consistencyPolicy: {
defaultConsistencyLevel: 'Session'
defaultConsistencyLevel: 'Strong' // Needed by conformance test state.go
}
locations: [
{

View File

@ -15,6 +15,7 @@ import (
"github.com/a8m/documentdb"
"github.com/agrea/ptr"
"github.com/google/uuid"
jsoniter "github.com/json-iterator/go"
"github.com/dapr/components-contrib/contenttype"
@ -241,10 +242,10 @@ func (c *StateStore) Set(req *state.SetRequest) error {
options := []documentdb.CallOption{documentdb.PartitionKey(partitionKey)}
if req.ETag != nil {
var etag string
if req.ETag != nil {
etag = *req.ETag
}
options = append(options, documentdb.IfMatch((*req.ETag)))
}
if req.Options.Concurrency == state.FirstWrite && (req.ETag == nil || *req.ETag == "") {
etag := uuid.NewString()
options = append(options, documentdb.IfMatch((etag)))
}
if req.Options.Consistency == state.Strong {
@ -295,11 +296,7 @@ func (c *StateStore) Delete(req *state.DeleteRequest) error {
}
if req.ETag != nil {
var etag string
if req.ETag != nil {
etag = *req.ETag
}
options = append(options, documentdb.IfMatch((etag)))
options = append(options, documentdb.IfMatch((*req.ETag)))
}
if req.Options.Consistency == state.Strong {
options = append(options, documentdb.ConsistencyLevel(documentdb.Strong))