Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test storage object OCC write behavior with empty and non empty versions #1088

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions server/core_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,77 @@ func TestStorageListNoRepeats(t *testing.T) {
assert.Equal(t, "", values.Cursor, "cursor was not nil")
}

func TestStorageOverrwriteEmptyAndNonEmptyVersions(t *testing.T) {
db := NewDB(t)
defer db.Close()

uid := uuid.Must(uuid.NewV4())
InsertUser(t, db, uid)
collection := GenerateString()

ops := StorageOpWrites{
&StorageOpWrite{
OwnerID: uid.String(),
Object: &api.WriteStorageObject{
Collection: collection,
Key: "7",
Value: `{"testKey":"testValue1"}`,
PermissionRead: &wrapperspb.Int32Value{Value: 2},
PermissionWrite: &wrapperspb.Int32Value{Value: 1},
Version: "",
},
},
}

acks, code, err := StorageWriteObjects(context.Background(), logger, db, metrics, storageIdx, false, ops)

assert.Nil(t, err, "err was not nil")
assert.Equal(t, codes.OK, code, "code was not OK")
assert.NotNil(t, acks, "acks was nil")

ops = StorageOpWrites{
&StorageOpWrite{
OwnerID: uid.String(),
Object: &api.WriteStorageObject{
Collection: collection,
Key: "7",
Value: `{"testKey":"testValue2"}`,
PermissionRead: &wrapperspb.Int32Value{Value: 2},
PermissionWrite: &wrapperspb.Int32Value{Value: 1},
Version: "",
},
},
}

acks, code, err = StorageWriteObjects(context.Background(), logger, db, metrics, storageIdx, false, ops)

assert.Nil(t, err, "err was not nil")
assert.Equal(t, codes.OK, code, "code was not OK")
assert.NotNil(t, acks, "acks was nil")
assert.Len(t, acks.Acks, 1, "acks length was not 1")

ops = StorageOpWrites{
&StorageOpWrite{
OwnerID: uid.String(),
Object: &api.WriteStorageObject{
Collection: collection,
Key: "7",
Value: `{"testKey":"testValue3"}`,
PermissionRead: &wrapperspb.Int32Value{Value: 2},
PermissionWrite: &wrapperspb.Int32Value{Value: 1},
Version: acks.Acks[0].Version,
},
},
}

acks, code, err = StorageWriteObjects(context.Background(), logger, db, metrics, storageIdx, false, ops)

assert.Nil(t, err, "err was not nil")
assert.Equal(t, codes.OK, code, "code was not OK")
assert.NotNil(t, acks, "acks was nil")
assert.Len(t, acks.Acks, 1, "acks length was not 1")
}

// DB State and expected outcome when performing write op
type writeTestDBState struct {
write int
Expand Down
Loading