feature: add context to state API
Signed-off-by: 1046102779 <seachen@tencent.com>
This commit is contained in:
parent
1ce80dcaa0
commit
203c6c7757
|
@ -64,7 +64,7 @@ func TestReadAndWrite(t *testing.T) {
|
|||
Value: "value of key",
|
||||
ETag: ptr.String("the etag"),
|
||||
}
|
||||
err := store.Set(context.TODO(), setReq)
|
||||
err := store.Set(context.Background(), setReq)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
|
@ -72,7 +72,7 @@ func TestReadAndWrite(t *testing.T) {
|
|||
getReq := &state.GetRequest{
|
||||
Key: "theFirstKey",
|
||||
}
|
||||
resp, err := store.Get(context.TODO(), getReq)
|
||||
resp, err := store.Get(context.Background(), getReq)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, resp)
|
||||
assert.Equal(t, "value of key", string(resp.Data))
|
||||
|
@ -84,7 +84,7 @@ func TestReadAndWrite(t *testing.T) {
|
|||
Value: "1234",
|
||||
ETag: ptr.String("the etag"),
|
||||
}
|
||||
err := store.Set(context.TODO(), setReq)
|
||||
err := store.Set(context.Background(), setReq)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
|
@ -92,14 +92,14 @@ func TestReadAndWrite(t *testing.T) {
|
|||
getReq := &state.GetRequest{
|
||||
Key: "theSecondKey",
|
||||
}
|
||||
resp, err := store.Get(context.TODO(), getReq)
|
||||
resp, err := store.Get(context.Background(), getReq)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, resp)
|
||||
assert.Equal(t, "1234", string(resp.Data))
|
||||
})
|
||||
|
||||
t.Run("test BulkSet", func(t *testing.T) {
|
||||
err := store.BulkSet(context.TODO(), []state.SetRequest{{
|
||||
err := store.BulkSet(context.Background(), []state.SetRequest{{
|
||||
Key: "theFirstKey",
|
||||
Value: "666",
|
||||
}, {
|
||||
|
@ -111,7 +111,7 @@ func TestReadAndWrite(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("test BulkGet", func(t *testing.T) {
|
||||
_, resp, err := store.BulkGet(context.TODO(), []state.GetRequest{{
|
||||
_, resp, err := store.BulkGet(context.Background(), []state.GetRequest{{
|
||||
Key: "theFirstKey",
|
||||
}, {
|
||||
Key: "theSecondKey",
|
||||
|
@ -127,12 +127,12 @@ func TestReadAndWrite(t *testing.T) {
|
|||
req := &state.DeleteRequest{
|
||||
Key: "theFirstKey",
|
||||
}
|
||||
err := store.Delete(context.TODO(), req)
|
||||
err := store.Delete(context.Background(), req)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
t.Run("test BulkGet2", func(t *testing.T) {
|
||||
_, resp, err := store.BulkGet(context.TODO(), []state.GetRequest{{
|
||||
_, resp, err := store.BulkGet(context.Background(), []state.GetRequest{{
|
||||
Key: "theFirstKey",
|
||||
}, {
|
||||
Key: "theSecondKey",
|
||||
|
|
|
@ -125,7 +125,7 @@ func TestGet(t *testing.T) {
|
|||
Consistency: "strong",
|
||||
},
|
||||
}
|
||||
out, err := ss.Get(context.TODO(), req)
|
||||
out, err := ss.Get(context.Background(), req)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, []byte("some value"), out.Data)
|
||||
assert.Equal(t, "1bdead4badc0ffee", *out.ETag)
|
||||
|
@ -161,7 +161,7 @@ func TestGet(t *testing.T) {
|
|||
Consistency: "strong",
|
||||
},
|
||||
}
|
||||
out, err := ss.Get(context.TODO(), req)
|
||||
out, err := ss.Get(context.Background(), req)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, []byte("some value"), out.Data)
|
||||
assert.Equal(t, "1bdead4badc0ffee", *out.ETag)
|
||||
|
@ -197,7 +197,7 @@ func TestGet(t *testing.T) {
|
|||
Consistency: "strong",
|
||||
},
|
||||
}
|
||||
out, err := ss.Get(context.TODO(), req)
|
||||
out, err := ss.Get(context.Background(), req)
|
||||
assert.Nil(t, err)
|
||||
assert.Nil(t, out.Data)
|
||||
assert.Nil(t, out.ETag)
|
||||
|
@ -217,7 +217,7 @@ func TestGet(t *testing.T) {
|
|||
Consistency: "strong",
|
||||
},
|
||||
}
|
||||
out, err := ss.Get(context.TODO(), req)
|
||||
out, err := ss.Get(context.Background(), req)
|
||||
assert.NotNil(t, err)
|
||||
assert.Nil(t, out)
|
||||
})
|
||||
|
@ -238,7 +238,7 @@ func TestGet(t *testing.T) {
|
|||
Consistency: "strong",
|
||||
},
|
||||
}
|
||||
out, err := ss.Get(context.TODO(), req)
|
||||
out, err := ss.Get(context.Background(), req)
|
||||
assert.Nil(t, err)
|
||||
assert.Nil(t, out.Data)
|
||||
assert.Nil(t, out.ETag)
|
||||
|
@ -264,7 +264,7 @@ func TestGet(t *testing.T) {
|
|||
Consistency: "strong",
|
||||
},
|
||||
}
|
||||
out, err := ss.Get(context.TODO(), req)
|
||||
out, err := ss.Get(context.Background(), req)
|
||||
assert.Nil(t, err)
|
||||
assert.Empty(t, out.Data)
|
||||
})
|
||||
|
@ -303,7 +303,7 @@ func TestSet(t *testing.T) {
|
|||
Value: "value",
|
||||
},
|
||||
}
|
||||
err := ss.Set(context.TODO(), req)
|
||||
err := ss.Set(context.Background(), req)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
|
@ -341,7 +341,7 @@ func TestSet(t *testing.T) {
|
|||
Value: "value",
|
||||
},
|
||||
}
|
||||
err := ss.Set(context.TODO(), req)
|
||||
err := ss.Set(context.Background(), req)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
|
@ -375,7 +375,7 @@ func TestSet(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
err := ss.Set(context.TODO(), req)
|
||||
err := ss.Set(context.Background(), req)
|
||||
assert.NotNil(t, err)
|
||||
switch tagErr := err.(type) {
|
||||
case *state.ETagError:
|
||||
|
@ -417,7 +417,7 @@ func TestSet(t *testing.T) {
|
|||
Concurrency: state.FirstWrite,
|
||||
},
|
||||
}
|
||||
err := ss.Set(context.TODO(), req)
|
||||
err := ss.Set(context.Background(), req)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
|
@ -448,7 +448,7 @@ func TestSet(t *testing.T) {
|
|||
Concurrency: state.FirstWrite,
|
||||
},
|
||||
}
|
||||
err := ss.Set(context.TODO(), req)
|
||||
err := ss.Set(context.Background(), req)
|
||||
assert.NotNil(t, err)
|
||||
switch err.(type) {
|
||||
case *state.ETagError:
|
||||
|
@ -489,7 +489,7 @@ func TestSet(t *testing.T) {
|
|||
"ttlInSeconds": "-1",
|
||||
},
|
||||
}
|
||||
err := ss.Set(context.TODO(), req)
|
||||
err := ss.Set(context.Background(), req)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
t.Run("Successfully set item with 'correct' ttl", func(t *testing.T) {
|
||||
|
@ -524,7 +524,7 @@ func TestSet(t *testing.T) {
|
|||
"ttlInSeconds": "180",
|
||||
},
|
||||
}
|
||||
err := ss.Set(context.TODO(), req)
|
||||
err := ss.Set(context.Background(), req)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
|
@ -542,7 +542,7 @@ func TestSet(t *testing.T) {
|
|||
Value: "value",
|
||||
},
|
||||
}
|
||||
err := ss.Set(context.TODO(), req)
|
||||
err := ss.Set(context.Background(), req)
|
||||
assert.NotNil(t, err)
|
||||
})
|
||||
t.Run("Successfully set item with correct ttl but without component metadata", func(t *testing.T) {
|
||||
|
@ -576,7 +576,7 @@ func TestSet(t *testing.T) {
|
|||
"ttlInSeconds": "180",
|
||||
},
|
||||
}
|
||||
err := ss.Set(context.TODO(), req)
|
||||
err := ss.Set(context.Background(), req)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
t.Run("Unsuccessfully set item with ttl (invalid value)", func(t *testing.T) {
|
||||
|
@ -615,7 +615,7 @@ func TestSet(t *testing.T) {
|
|||
"ttlInSeconds": "invalidvalue",
|
||||
},
|
||||
}
|
||||
err := ss.Set(context.TODO(), req)
|
||||
err := ss.Set(context.Background(), req)
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, "dynamodb error: failed to parse ttlInSeconds: strconv.ParseInt: parsing \"invalidvalue\": invalid syntax", err.Error())
|
||||
})
|
||||
|
@ -690,7 +690,7 @@ func TestBulkSet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
err := ss.BulkSet(context.TODO(), req)
|
||||
err := ss.BulkSet(context.Background(), req)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
t.Run("Successfully set items with ttl = -1", func(t *testing.T) {
|
||||
|
@ -763,7 +763,7 @@ func TestBulkSet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
err := ss.BulkSet(context.TODO(), req)
|
||||
err := ss.BulkSet(context.Background(), req)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
t.Run("Successfully set items with ttl", func(t *testing.T) {
|
||||
|
@ -838,7 +838,7 @@ func TestBulkSet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
err := ss.BulkSet(context.TODO(), req)
|
||||
err := ss.BulkSet(context.Background(), req)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
t.Run("Unsuccessfully set items", func(t *testing.T) {
|
||||
|
@ -863,7 +863,7 @@ func TestBulkSet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
err := ss.BulkSet(context.TODO(), req)
|
||||
err := ss.BulkSet(context.Background(), req)
|
||||
assert.NotNil(t, err)
|
||||
})
|
||||
}
|
||||
|
@ -887,7 +887,7 @@ func TestDelete(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
err := ss.Delete(context.TODO(), req)
|
||||
err := ss.Delete(context.Background(), req)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
|
@ -915,7 +915,7 @@ func TestDelete(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
err := ss.Delete(context.TODO(), req)
|
||||
err := ss.Delete(context.Background(), req)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
|
@ -944,7 +944,7 @@ func TestDelete(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
err := ss.Delete(context.TODO(), req)
|
||||
err := ss.Delete(context.Background(), req)
|
||||
assert.NotNil(t, err)
|
||||
switch tagErr := err.(type) {
|
||||
case *state.ETagError:
|
||||
|
@ -965,7 +965,7 @@ func TestDelete(t *testing.T) {
|
|||
req := &state.DeleteRequest{
|
||||
Key: "key",
|
||||
}
|
||||
err := ss.Delete(context.TODO(), req)
|
||||
err := ss.Delete(context.Background(), req)
|
||||
assert.NotNil(t, err)
|
||||
})
|
||||
}
|
||||
|
@ -1014,7 +1014,7 @@ func TestBulkDelete(t *testing.T) {
|
|||
Key: "key2",
|
||||
},
|
||||
}
|
||||
err := ss.BulkDelete(context.TODO(), req)
|
||||
err := ss.BulkDelete(context.Background(), req)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
t.Run("Unsuccessfully delete items", func(t *testing.T) {
|
||||
|
@ -1033,7 +1033,7 @@ func TestBulkDelete(t *testing.T) {
|
|||
Key: "key",
|
||||
},
|
||||
}
|
||||
err := ss.BulkDelete(context.TODO(), req)
|
||||
err := ss.BulkDelete(context.Background(), req)
|
||||
assert.NotNil(t, err)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -299,8 +299,10 @@ func (c *StateStore) Set(ctx context.Context, req *state.SetRequest) error {
|
|||
return err
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, defaultTimeout)
|
||||
pk := azcosmos.NewPartitionKeyString(partitionKey)
|
||||
_, err = c.client.UpsertItem(ctx, pk, marsh, &options)
|
||||
cancel()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -339,13 +339,15 @@ func isTableAlreadyExistsError(err error) bool {
|
|||
func (r *StateStore) deleteRow(ctx context.Context, req *state.DeleteRequest) error {
|
||||
pk, rk := getPartitionAndRowKey(req.Key, r.cosmosDBMode)
|
||||
|
||||
deleteContext, cancel := context.WithTimeout(ctx, timeout)
|
||||
cancel()
|
||||
if req.ETag != nil {
|
||||
azcoreETag := azcore.ETag(*req.ETag)
|
||||
_, err := r.client.DeleteEntity(ctx, pk, rk, &aztables.DeleteEntityOptions{IfMatch: &azcoreETag})
|
||||
_, err := r.client.DeleteEntity(deleteContext, pk, rk, &aztables.DeleteEntityOptions{IfMatch: &azcoreETag})
|
||||
return err
|
||||
}
|
||||
all := azcore.ETagAny
|
||||
_, err := r.client.DeleteEntity(ctx, pk, rk, &aztables.DeleteEntityOptions{IfMatch: &all})
|
||||
_, err := r.client.DeleteEntity(deleteContext, pk, rk, &aztables.DeleteEntityOptions{IfMatch: &all})
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ func TestMultiWithNoRequests(t *testing.T) {
|
|||
var operations []state.TransactionalStateOperation
|
||||
|
||||
// Act
|
||||
err := m.roachDba.ExecuteMulti(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.roachDba.ExecuteMulti(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -134,7 +134,7 @@ func TestInvalidMultiInvalidAction(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.roachDba.ExecuteMulti(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.roachDba.ExecuteMulti(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -159,7 +159,7 @@ func TestValidSetRequest(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.roachDba.ExecuteMulti(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.roachDba.ExecuteMulti(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -183,7 +183,7 @@ func TestInvalidMultiSetRequest(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.roachDba.ExecuteMulti(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.roachDba.ExecuteMulti(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -207,7 +207,7 @@ func TestInvalidMultiSetRequestNoKey(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.roachDba.ExecuteMulti(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.roachDba.ExecuteMulti(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -232,7 +232,7 @@ func TestValidMultiDeleteRequest(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.roachDba.ExecuteMulti(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.roachDba.ExecuteMulti(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -256,7 +256,7 @@ func TestInvalidMultiDeleteRequest(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.roachDba.ExecuteMulti(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.roachDba.ExecuteMulti(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -280,7 +280,7 @@ func TestInvalidMultiDeleteRequestNoKey(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.roachDba.ExecuteMulti(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.roachDba.ExecuteMulti(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -312,7 +312,7 @@ func TestMultiOperationOrder(t *testing.T) {
|
|||
)
|
||||
|
||||
// Act
|
||||
err := m.roachDba.ExecuteMulti(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.roachDba.ExecuteMulti(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -335,7 +335,7 @@ func TestInvalidBulkSetNoKey(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.roachDba.BulkSet(context.TODO(), sets)
|
||||
err := m.roachDba.BulkSet(context.Background(), sets)
|
||||
|
||||
// Assert
|
||||
assert.NotNil(t, err)
|
||||
|
@ -357,7 +357,7 @@ func TestInvalidBulkSetEmptyValue(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.roachDba.BulkSet(context.TODO(), sets)
|
||||
err := m.roachDba.BulkSet(context.Background(), sets)
|
||||
|
||||
// Assert
|
||||
assert.NotNil(t, err)
|
||||
|
@ -380,7 +380,7 @@ func TestValidBulkSet(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.roachDba.BulkSet(context.TODO(), sets)
|
||||
err := m.roachDba.BulkSet(context.Background(), sets)
|
||||
|
||||
// Assert
|
||||
assert.Nil(t, err)
|
||||
|
@ -401,7 +401,7 @@ func TestInvalidBulkDeleteNoKey(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.roachDba.BulkDelete(context.TODO(), deletes)
|
||||
err := m.roachDba.BulkDelete(context.Background(), deletes)
|
||||
|
||||
// Assert
|
||||
assert.NotNil(t, err)
|
||||
|
@ -423,7 +423,7 @@ func TestValidBulkDelete(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.roachDba.BulkDelete(context.TODO(), deletes)
|
||||
err := m.roachDba.BulkDelete(context.Background(), deletes)
|
||||
|
||||
// Assert
|
||||
assert.Nil(t, err)
|
||||
|
|
|
@ -212,7 +212,7 @@ func deleteItemThatDoesNotExist(t *testing.T, pgs *CockroachDB) {
|
|||
Consistency: "",
|
||||
},
|
||||
}
|
||||
err := pgs.Delete(context.TODO(), deleteReq)
|
||||
err := pgs.Delete(context.Background(), deleteReq)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
|
@ -240,7 +240,7 @@ func multiWithSetOnly(t *testing.T, pgs *CockroachDB) {
|
|||
})
|
||||
}
|
||||
|
||||
err := pgs.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := pgs.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
Metadata: nil,
|
||||
})
|
||||
|
@ -281,7 +281,7 @@ func multiWithDeleteOnly(t *testing.T, pgs *CockroachDB) {
|
|||
})
|
||||
}
|
||||
|
||||
err := pgs.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := pgs.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
Metadata: nil,
|
||||
})
|
||||
|
@ -342,7 +342,7 @@ func multiWithDeleteAndSet(t *testing.T, pgs *CockroachDB) {
|
|||
})
|
||||
}
|
||||
|
||||
err := pgs.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := pgs.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
Metadata: nil,
|
||||
})
|
||||
|
@ -377,7 +377,7 @@ func deleteWithInvalidEtagFails(t *testing.T, pgs *CockroachDB) {
|
|||
Consistency: "",
|
||||
},
|
||||
}
|
||||
err := pgs.Delete(context.TODO(), deleteReq)
|
||||
err := pgs.Delete(context.Background(), deleteReq)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
|
@ -393,7 +393,7 @@ func deleteWithNoKeyFails(t *testing.T, pgs *CockroachDB) {
|
|||
Consistency: "",
|
||||
},
|
||||
}
|
||||
err := pgs.Delete(context.TODO(), deleteReq)
|
||||
err := pgs.Delete(context.Background(), deleteReq)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
|
@ -416,7 +416,7 @@ func newItemWithEtagFails(t *testing.T, pgs *CockroachDB) {
|
|||
ContentType: nil,
|
||||
}
|
||||
|
||||
err := pgs.Set(context.TODO(), setReq)
|
||||
err := pgs.Set(context.Background(), setReq)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
|
@ -450,7 +450,7 @@ func updateWithOldEtagFails(t *testing.T, pgs *CockroachDB) {
|
|||
},
|
||||
ContentType: nil,
|
||||
}
|
||||
err := pgs.Set(context.TODO(), setReq)
|
||||
err := pgs.Set(context.Background(), setReq)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
|
@ -502,7 +502,7 @@ func getItemWithNoKey(t *testing.T, pgs *CockroachDB) {
|
|||
},
|
||||
}
|
||||
|
||||
response, getErr := pgs.Get(context.TODO(), getReq)
|
||||
response, getErr := pgs.Get(context.Background(), getReq)
|
||||
assert.NotNil(t, getErr)
|
||||
assert.Nil(t, response)
|
||||
}
|
||||
|
@ -545,7 +545,7 @@ func setItemWithNoKey(t *testing.T, pgs *CockroachDB) {
|
|||
ContentType: nil,
|
||||
}
|
||||
|
||||
err := pgs.Set(context.TODO(), setReq)
|
||||
err := pgs.Set(context.Background(), setReq)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
|
@ -564,7 +564,7 @@ func testBulkSetAndBulkDelete(t *testing.T, pgs *CockroachDB) {
|
|||
},
|
||||
}
|
||||
|
||||
err := pgs.BulkSet(context.TODO(), setReq)
|
||||
err := pgs.BulkSet(context.Background(), setReq)
|
||||
assert.Nil(t, err)
|
||||
assert.True(t, storeItemExists(t, setReq[0].Key))
|
||||
assert.True(t, storeItemExists(t, setReq[1].Key))
|
||||
|
@ -578,7 +578,7 @@ func testBulkSetAndBulkDelete(t *testing.T, pgs *CockroachDB) {
|
|||
},
|
||||
}
|
||||
|
||||
err = pgs.BulkDelete(context.TODO(), deleteReq)
|
||||
err = pgs.BulkDelete(context.Background(), deleteReq)
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, storeItemExists(t, setReq[0].Key))
|
||||
assert.False(t, storeItemExists(t, setReq[1].Key))
|
||||
|
@ -645,7 +645,7 @@ func setItem(t *testing.T, pgs *CockroachDB, key string, value interface{}, etag
|
|||
ContentType: nil,
|
||||
}
|
||||
|
||||
err := pgs.Set(context.TODO(), setReq)
|
||||
err := pgs.Set(context.Background(), setReq)
|
||||
assert.Nil(t, err)
|
||||
itemExists := storeItemExists(t, key)
|
||||
assert.True(t, itemExists)
|
||||
|
@ -662,7 +662,7 @@ func getItem(t *testing.T, pgs *CockroachDB, key string) (*state.GetResponse, *f
|
|||
Metadata: map[string]string{},
|
||||
}
|
||||
|
||||
response, getErr := pgs.Get(context.TODO(), getReq)
|
||||
response, getErr := pgs.Get(context.Background(), getReq)
|
||||
assert.Nil(t, getErr)
|
||||
assert.NotNil(t, response)
|
||||
outputObject := &fakeItem{
|
||||
|
@ -686,7 +686,7 @@ func deleteItem(t *testing.T, pgs *CockroachDB, key string, etag *string) {
|
|||
Metadata: map[string]string{},
|
||||
}
|
||||
|
||||
deleteErr := pgs.Delete(context.TODO(), deleteReq)
|
||||
deleteErr := pgs.Delete(context.Background(), deleteReq)
|
||||
assert.Nil(t, deleteErr)
|
||||
assert.False(t, storeItemExists(t, key))
|
||||
}
|
||||
|
|
|
@ -44,13 +44,13 @@ func TestReadAndWrite(t *testing.T) {
|
|||
Value: valueA,
|
||||
ETag: ptr.String("the etag"),
|
||||
}
|
||||
err := store.Set(context.TODO(), setReq)
|
||||
err := store.Set(context.Background(), setReq)
|
||||
assert.Nil(t, err)
|
||||
// get after set
|
||||
getReq := &state.GetRequest{
|
||||
Key: keyA,
|
||||
}
|
||||
resp, err := store.Get(context.TODO(), getReq)
|
||||
resp, err := store.Get(context.Background(), getReq)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, resp)
|
||||
assert.Equal(t, valueA, string(resp.Data))
|
||||
|
@ -63,7 +63,7 @@ func TestReadAndWrite(t *testing.T) {
|
|||
Value: valueA,
|
||||
Metadata: map[string]string{"ttlInSeconds": "1"},
|
||||
}
|
||||
err := store.Set(context.TODO(), setReq)
|
||||
err := store.Set(context.Background(), setReq)
|
||||
assert.Nil(t, err)
|
||||
// simulate expiration
|
||||
time.Sleep(2 * time.Second)
|
||||
|
@ -71,7 +71,7 @@ func TestReadAndWrite(t *testing.T) {
|
|||
getReq := &state.GetRequest{
|
||||
Key: keyA,
|
||||
}
|
||||
resp, err := store.Get(context.TODO(), getReq)
|
||||
resp, err := store.Get(context.Background(), getReq)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, resp)
|
||||
assert.Nil(t, resp.Data)
|
||||
|
@ -85,20 +85,20 @@ func TestReadAndWrite(t *testing.T) {
|
|||
Value: "1234",
|
||||
ETag: ptr.String("the etag"),
|
||||
}
|
||||
err := store.Set(context.TODO(), setReq)
|
||||
err := store.Set(context.Background(), setReq)
|
||||
assert.Nil(t, err)
|
||||
// get
|
||||
getReq := &state.GetRequest{
|
||||
Key: "theSecondKey",
|
||||
}
|
||||
resp, err := store.Get(context.TODO(), getReq)
|
||||
resp, err := store.Get(context.Background(), getReq)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, resp)
|
||||
assert.Equal(t, "1234", string(resp.Data))
|
||||
})
|
||||
|
||||
t.Run("BulkSet two keys", func(t *testing.T) {
|
||||
err := store.BulkSet(context.TODO(), []state.SetRequest{{
|
||||
err := store.BulkSet(context.Background(), []state.SetRequest{{
|
||||
Key: "theFirstKey",
|
||||
Value: "666",
|
||||
}, {
|
||||
|
@ -110,7 +110,7 @@ func TestReadAndWrite(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("BulkGet fails when not supported", func(t *testing.T) {
|
||||
supportBulk, _, err := store.BulkGet(context.TODO(), []state.GetRequest{{
|
||||
supportBulk, _, err := store.BulkGet(context.Background(), []state.GetRequest{{
|
||||
Key: "theFirstKey",
|
||||
}, {
|
||||
Key: "theSecondKey",
|
||||
|
@ -124,7 +124,7 @@ func TestReadAndWrite(t *testing.T) {
|
|||
req := &state.DeleteRequest{
|
||||
Key: "theFirstKey",
|
||||
}
|
||||
err := store.Delete(context.TODO(), req)
|
||||
err := store.Delete(context.Background(), req)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ func TestSetGetAndDelete(t *testing.T) {
|
|||
"dkey": "dvalue",
|
||||
}
|
||||
|
||||
err = store.Set(context.TODO(), &state.SetRequest{
|
||||
err = store.Set(context.Background(), &state.SetRequest{
|
||||
Key: tkey,
|
||||
Value: tData,
|
||||
})
|
||||
|
@ -122,7 +122,7 @@ func TestSetGetAndDelete(t *testing.T) {
|
|||
return
|
||||
}
|
||||
|
||||
resp, err := store.Get(context.TODO(), &state.GetRequest{
|
||||
resp, err := store.Get(context.Background(), &state.GetRequest{
|
||||
Key: tkey,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -135,7 +135,7 @@ func TestSetGetAndDelete(t *testing.T) {
|
|||
t.Fatal("Response data does not match written data\n")
|
||||
}
|
||||
|
||||
err = store.Delete(context.TODO(), &state.DeleteRequest{
|
||||
err = store.Delete(context.Background(), &state.DeleteRequest{
|
||||
Key: tkey,
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -143,7 +143,7 @@ func TestSetGetAndDelete(t *testing.T) {
|
|||
return
|
||||
}
|
||||
|
||||
_, err = store.Get(context.TODO(), &state.GetRequest{
|
||||
_, err = store.Get(context.Background(), &state.GetRequest{
|
||||
Key: tkey,
|
||||
})
|
||||
if err == nil {
|
||||
|
|
|
@ -206,7 +206,7 @@ func TestMySQLIntegration(t *testing.T) {
|
|||
Key: "",
|
||||
}
|
||||
|
||||
response, getErr := mys.Get(context.TODO(), getReq)
|
||||
response, getErr := mys.Get(context.Background(), getReq)
|
||||
assert.NotNil(t, getErr)
|
||||
assert.Nil(t, response)
|
||||
})
|
||||
|
@ -243,7 +243,7 @@ func TestMySQLIntegration(t *testing.T) {
|
|||
Key: "",
|
||||
}
|
||||
|
||||
err := mys.Set(context.TODO(), setReq)
|
||||
err := mys.Set(context.Background(), setReq)
|
||||
assert.NotNil(t, err, "Error was not nil when setting item with no key.")
|
||||
})
|
||||
|
||||
|
@ -303,7 +303,7 @@ func TestMySQLIntegration(t *testing.T) {
|
|||
Value: newValue,
|
||||
}
|
||||
|
||||
err := mys.Set(context.TODO(), setReq)
|
||||
err := mys.Set(context.Background(), setReq)
|
||||
assert.NotNil(t, err, "Error was not thrown using old eTag")
|
||||
})
|
||||
|
||||
|
@ -319,7 +319,7 @@ func TestMySQLIntegration(t *testing.T) {
|
|||
Value: value,
|
||||
}
|
||||
|
||||
err := mys.Set(context.TODO(), setReq)
|
||||
err := mys.Set(context.Background(), setReq)
|
||||
assert.NotNil(t, err)
|
||||
})
|
||||
|
||||
|
@ -339,7 +339,7 @@ func TestMySQLIntegration(t *testing.T) {
|
|||
ETag: &eTag,
|
||||
}
|
||||
|
||||
err := mys.Delete(context.TODO(), deleteReq)
|
||||
err := mys.Delete(context.Background(), deleteReq)
|
||||
assert.NotNil(t, err)
|
||||
})
|
||||
|
||||
|
@ -350,7 +350,7 @@ func TestMySQLIntegration(t *testing.T) {
|
|||
Key: "",
|
||||
}
|
||||
|
||||
err := mys.Delete(context.TODO(), deleteReq)
|
||||
err := mys.Delete(context.Background(), deleteReq)
|
||||
assert.NotNil(t, err)
|
||||
})
|
||||
|
||||
|
@ -362,7 +362,7 @@ func TestMySQLIntegration(t *testing.T) {
|
|||
Key: randomKey(),
|
||||
}
|
||||
|
||||
err := mys.Delete(context.TODO(), deleteReq)
|
||||
err := mys.Delete(context.Background(), deleteReq)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
|
@ -379,7 +379,7 @@ func TestMySQLIntegration(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
err := mys.Set(context.TODO(), setReq)
|
||||
err := mys.Set(context.Background(), setReq)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Get the etag
|
||||
|
@ -397,7 +397,7 @@ func TestMySQLIntegration(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
err = mys.Set(context.TODO(), setReq)
|
||||
err = mys.Set(context.Background(), setReq)
|
||||
assert.ErrorContains(t, err, "Duplicate entry")
|
||||
|
||||
// Insert with invalid etag should fail on existing keys
|
||||
|
@ -410,7 +410,7 @@ func TestMySQLIntegration(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
err = mys.Set(context.TODO(), setReq)
|
||||
err = mys.Set(context.Background(), setReq)
|
||||
assert.ErrorContains(t, err, "possible etag mismatch")
|
||||
|
||||
// Insert with valid etag should succeed on existing keys
|
||||
|
@ -423,7 +423,7 @@ func TestMySQLIntegration(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
err = mys.Set(context.TODO(), setReq)
|
||||
err = mys.Set(context.Background(), setReq)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Insert with an etag should fail on new keys
|
||||
|
@ -436,7 +436,7 @@ func TestMySQLIntegration(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
err = mys.Set(context.TODO(), setReq)
|
||||
err = mys.Set(context.Background(), setReq)
|
||||
assert.ErrorContains(t, err, "possible etag mismatch")
|
||||
})
|
||||
|
||||
|
@ -475,7 +475,7 @@ func TestMySQLIntegration(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
err := mys.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := mys.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
@ -511,7 +511,7 @@ func TestMySQLIntegration(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
err := mys.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := mys.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
@ -538,7 +538,7 @@ func TestMySQLIntegration(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
err := mys.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := mys.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
@ -563,7 +563,7 @@ func testBulkSetAndBulkDelete(t *testing.T, mys *MySQL) {
|
|||
},
|
||||
}
|
||||
|
||||
err := mys.BulkSet(context.TODO(), setReq)
|
||||
err := mys.BulkSet(context.Background(), setReq)
|
||||
assert.Nil(t, err)
|
||||
assert.True(t, storeItemExists(t, setReq[0].Key))
|
||||
assert.True(t, storeItemExists(t, setReq[1].Key))
|
||||
|
@ -577,7 +577,7 @@ func testBulkSetAndBulkDelete(t *testing.T, mys *MySQL) {
|
|||
},
|
||||
}
|
||||
|
||||
err = mys.BulkDelete(context.TODO(), deleteReq)
|
||||
err = mys.BulkDelete(context.Background(), deleteReq)
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, storeItemExists(t, setReq[0].Key))
|
||||
assert.False(t, storeItemExists(t, setReq[1].Key))
|
||||
|
@ -597,7 +597,7 @@ func setItem(t *testing.T, mys *MySQL, key string, value interface{}, eTag *stri
|
|||
Value: value,
|
||||
}
|
||||
|
||||
err := mys.Set(context.TODO(), setReq)
|
||||
err := mys.Set(context.Background(), setReq)
|
||||
assert.Nil(t, err, "Error setting an item")
|
||||
itemExists := storeItemExists(t, key)
|
||||
assert.True(t, itemExists, "Item does not exist after being set")
|
||||
|
@ -609,7 +609,7 @@ func getItem(t *testing.T, mys *MySQL, key string) (*state.GetResponse, *fakeIte
|
|||
Options: state.GetStateOption{},
|
||||
}
|
||||
|
||||
response, getErr := mys.Get(context.TODO(), getReq)
|
||||
response, getErr := mys.Get(context.Background(), getReq)
|
||||
assert.Nil(t, getErr)
|
||||
assert.NotNil(t, response)
|
||||
outputObject := &fakeItem{}
|
||||
|
@ -625,7 +625,7 @@ func deleteItem(t *testing.T, mys *MySQL, key string, eTag *string) {
|
|||
Options: state.DeleteStateOption{},
|
||||
}
|
||||
|
||||
deleteErr := mys.Delete(context.TODO(), deleteReq)
|
||||
deleteErr := mys.Delete(context.Background(), deleteReq)
|
||||
assert.Nil(t, deleteErr, "There was an error deleting a record")
|
||||
assert.False(t, storeItemExists(t, key), "Item still exists after delete")
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ func TestExecuteMultiCannotBeginTransaction(t *testing.T) {
|
|||
m.mock1.ExpectBegin().WillReturnError(fmt.Errorf("beginError"))
|
||||
|
||||
// Act
|
||||
err := m.mySQL.Multi(context.TODO(), nil)
|
||||
err := m.mySQL.Multi(context.Background(), nil)
|
||||
|
||||
// Assert
|
||||
assert.NotNil(t, err, "no error returned")
|
||||
|
@ -181,7 +181,7 @@ func TestMySQLBulkDeleteRollbackDeletes(t *testing.T) {
|
|||
deletes := []state.DeleteRequest{createDeleteRequest()}
|
||||
|
||||
// Act
|
||||
err := m.mySQL.BulkDelete(context.TODO(), deletes)
|
||||
err := m.mySQL.BulkDelete(context.Background(), deletes)
|
||||
|
||||
// Assert
|
||||
assert.NotNil(t, err, "no error returned")
|
||||
|
@ -200,7 +200,7 @@ func TestMySQLBulkSetRollbackSets(t *testing.T) {
|
|||
sets := []state.SetRequest{createSetRequest()}
|
||||
|
||||
// Act
|
||||
err := m.mySQL.BulkSet(context.TODO(), sets)
|
||||
err := m.mySQL.BulkSet(context.Background(), sets)
|
||||
|
||||
// Assert
|
||||
assert.NotNil(t, err, "no error returned")
|
||||
|
@ -233,7 +233,7 @@ func TestExecuteMultiCommitSetsAndDeletes(t *testing.T) {
|
|||
}
|
||||
|
||||
// Act
|
||||
err := m.mySQL.Multi(context.TODO(), &request)
|
||||
err := m.mySQL.Multi(context.Background(), &request)
|
||||
|
||||
// Assert
|
||||
assert.Nil(t, err, "error returned")
|
||||
|
@ -249,7 +249,7 @@ func TestSetHandlesOptionsError(t *testing.T) {
|
|||
request.Options.Consistency = "Invalid"
|
||||
|
||||
// Act
|
||||
err := m.mySQL.setValue(context.TODO(), &request)
|
||||
err := m.mySQL.setValue(context.Background(), &request)
|
||||
|
||||
// Assert
|
||||
assert.NotNil(t, err)
|
||||
|
@ -264,7 +264,7 @@ func TestSetHandlesNoKey(t *testing.T) {
|
|||
request.Key = ""
|
||||
|
||||
// Act
|
||||
err := m.mySQL.Set(context.TODO(), &request)
|
||||
err := m.mySQL.Set(context.Background(), &request)
|
||||
|
||||
// Assert
|
||||
assert.NotNil(t, err)
|
||||
|
@ -284,7 +284,7 @@ func TestSetHandlesUpdate(t *testing.T) {
|
|||
request.ETag = &eTag
|
||||
|
||||
// Act
|
||||
err := m.mySQL.setValue(context.TODO(), &request)
|
||||
err := m.mySQL.setValue(context.Background(), &request)
|
||||
|
||||
// Assert
|
||||
assert.Nil(t, err)
|
||||
|
@ -303,7 +303,7 @@ func TestSetHandlesErr(t *testing.T) {
|
|||
request.ETag = &eTag
|
||||
|
||||
// Act
|
||||
err := m.mySQL.setValue(context.TODO(), &request)
|
||||
err := m.mySQL.setValue(context.Background(), &request)
|
||||
|
||||
// Assert
|
||||
assert.NotNil(t, err)
|
||||
|
@ -316,7 +316,7 @@ func TestSetHandlesErr(t *testing.T) {
|
|||
request := createSetRequest()
|
||||
|
||||
// Act
|
||||
err := m.mySQL.setValue(context.TODO(), &request)
|
||||
err := m.mySQL.setValue(context.Background(), &request)
|
||||
|
||||
// Assert
|
||||
assert.NotNil(t, err)
|
||||
|
@ -328,7 +328,7 @@ func TestSetHandlesErr(t *testing.T) {
|
|||
request := createSetRequest()
|
||||
|
||||
// Act
|
||||
err := m.mySQL.setValue(context.TODO(), &request)
|
||||
err := m.mySQL.setValue(context.Background(), &request)
|
||||
|
||||
// Assert
|
||||
assert.Nil(t, err)
|
||||
|
@ -339,7 +339,7 @@ func TestSetHandlesErr(t *testing.T) {
|
|||
request := createSetRequest()
|
||||
|
||||
// Act
|
||||
err := m.mySQL.setValue(context.TODO(), &request)
|
||||
err := m.mySQL.setValue(context.Background(), &request)
|
||||
|
||||
// Assert
|
||||
assert.NotNil(t, err)
|
||||
|
@ -353,7 +353,7 @@ func TestSetHandlesErr(t *testing.T) {
|
|||
request.ETag = &eTag
|
||||
|
||||
// Act
|
||||
err := m.mySQL.setValue(context.TODO(), &request)
|
||||
err := m.mySQL.setValue(context.Background(), &request)
|
||||
|
||||
// Assert
|
||||
assert.NotNil(t, err)
|
||||
|
@ -370,7 +370,7 @@ func TestMySQLDeleteHandlesNoKey(t *testing.T) {
|
|||
request.Key = ""
|
||||
|
||||
// Act
|
||||
err := m.mySQL.Delete(context.TODO(), &request)
|
||||
err := m.mySQL.Delete(context.Background(), &request)
|
||||
|
||||
// Asset
|
||||
assert.NotNil(t, err)
|
||||
|
@ -389,7 +389,7 @@ func TestDeleteWithETag(t *testing.T) {
|
|||
request.ETag = &eTag
|
||||
|
||||
// Act
|
||||
err := m.mySQL.deleteValue(context.TODO(), &request)
|
||||
err := m.mySQL.deleteValue(context.Background(), &request)
|
||||
|
||||
// Assert
|
||||
assert.Nil(t, err)
|
||||
|
@ -406,7 +406,7 @@ func TestDeleteWithErr(t *testing.T) {
|
|||
request := createDeleteRequest()
|
||||
|
||||
// Act
|
||||
err := m.mySQL.deleteValue(context.TODO(), &request)
|
||||
err := m.mySQL.deleteValue(context.Background(), &request)
|
||||
|
||||
// Assert
|
||||
assert.NotNil(t, err)
|
||||
|
@ -421,7 +421,7 @@ func TestDeleteWithErr(t *testing.T) {
|
|||
request.ETag = &eTag
|
||||
|
||||
// Act
|
||||
err := m.mySQL.deleteValue(context.TODO(), &request)
|
||||
err := m.mySQL.deleteValue(context.Background(), &request)
|
||||
|
||||
// Assert
|
||||
assert.NotNil(t, err)
|
||||
|
@ -442,7 +442,7 @@ func TestGetHandlesNoRows(t *testing.T) {
|
|||
}
|
||||
|
||||
// Act
|
||||
response, err := m.mySQL.Get(context.TODO(), request)
|
||||
response, err := m.mySQL.Get(context.Background(), request)
|
||||
|
||||
// Assert
|
||||
assert.Nil(t, err, "returned error")
|
||||
|
@ -459,7 +459,7 @@ func TestGetHandlesNoKey(t *testing.T) {
|
|||
}
|
||||
|
||||
// Act
|
||||
response, err := m.mySQL.Get(context.TODO(), request)
|
||||
response, err := m.mySQL.Get(context.Background(), request)
|
||||
|
||||
// Assert
|
||||
assert.NotNil(t, err, "returned error")
|
||||
|
@ -479,7 +479,7 @@ func TestGetHandlesGenericError(t *testing.T) {
|
|||
}
|
||||
|
||||
// Act
|
||||
response, err := m.mySQL.Get(context.TODO(), request)
|
||||
response, err := m.mySQL.Get(context.Background(), request)
|
||||
|
||||
// Assert
|
||||
assert.NotNil(t, err)
|
||||
|
@ -500,7 +500,7 @@ func TestGetSucceeds(t *testing.T) {
|
|||
}
|
||||
|
||||
// Act
|
||||
response, err := m.mySQL.Get(context.TODO(), request)
|
||||
response, err := m.mySQL.Get(context.Background(), request)
|
||||
|
||||
// Assert
|
||||
assert.Nil(t, err)
|
||||
|
@ -518,7 +518,7 @@ func TestGetSucceeds(t *testing.T) {
|
|||
}
|
||||
|
||||
// Act
|
||||
response, err := m.mySQL.Get(context.TODO(), request)
|
||||
response, err := m.mySQL.Get(context.Background(), request)
|
||||
|
||||
// Assert
|
||||
assert.Nil(t, err)
|
||||
|
@ -712,7 +712,7 @@ func TestBulkGetReturnsNil(t *testing.T) {
|
|||
m, _ := mockDatabase(t)
|
||||
|
||||
// Act
|
||||
supported, response, err := m.mySQL.BulkGet(context.TODO(), nil)
|
||||
supported, response, err := m.mySQL.BulkGet(context.Background(), nil)
|
||||
|
||||
// Assert
|
||||
assert.Nil(t, err, `returned err`)
|
||||
|
@ -731,7 +731,7 @@ func TestMultiWithNoRequestsDoesNothing(t *testing.T) {
|
|||
m.mock1.ExpectCommit()
|
||||
|
||||
// Act
|
||||
err := m.mySQL.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.mySQL.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: ops,
|
||||
})
|
||||
|
||||
|
@ -751,7 +751,7 @@ func TestInvalidMultiAction(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.mySQL.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.mySQL.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: ops,
|
||||
})
|
||||
|
||||
|
@ -790,7 +790,7 @@ func TestValidSetRequest(t *testing.T) {
|
|||
m.mock1.ExpectCommit()
|
||||
|
||||
// Act
|
||||
err := m.mySQL.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.mySQL.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: ops,
|
||||
})
|
||||
|
||||
|
@ -811,7 +811,7 @@ func TestInvalidMultiSetRequest(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.mySQL.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.mySQL.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: ops,
|
||||
})
|
||||
|
||||
|
@ -835,7 +835,7 @@ func TestInvalidMultiSetRequestNoKey(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.mySQL.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.mySQL.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: ops,
|
||||
})
|
||||
|
||||
|
@ -859,7 +859,7 @@ func TestValidMultiDeleteRequest(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.mySQL.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.mySQL.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: ops,
|
||||
})
|
||||
|
||||
|
@ -880,7 +880,7 @@ func TestInvalidMultiDeleteRequest(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.mySQL.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.mySQL.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: ops,
|
||||
})
|
||||
|
||||
|
@ -903,7 +903,7 @@ func TestInvalidMultiDeleteRequestNoKey(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.mySQL.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.mySQL.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: ops,
|
||||
})
|
||||
|
||||
|
@ -942,7 +942,7 @@ func TestMultiOperationOrder(t *testing.T) {
|
|||
m.mock1.ExpectCommit()
|
||||
|
||||
// Act
|
||||
err := m.mySQL.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.mySQL.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: ops,
|
||||
})
|
||||
|
||||
|
|
|
@ -89,16 +89,16 @@ func testGet(t *testing.T, ociProperties map[string]string) {
|
|||
t.Run("Get an non-existing key", func(t *testing.T) {
|
||||
err := statestore.Init(meta)
|
||||
assert.Nil(t, err)
|
||||
getResponse, err := statestore.Get(context.TODO(), &state.GetRequest{Key: "xyzq"})
|
||||
getResponse, err := statestore.Get(context.Background(), &state.GetRequest{Key: "xyzq"})
|
||||
assert.Equal(t, &state.GetResponse{}, getResponse, "Response must be empty")
|
||||
assert.NoError(t, err, "Non-existing key must not be treated as error")
|
||||
})
|
||||
t.Run("Get an existing key", func(t *testing.T) {
|
||||
err := statestore.Init(meta)
|
||||
assert.Nil(t, err)
|
||||
err = statestore.Set(context.TODO(), &state.SetRequest{Key: "test-key", Value: []byte("test-value")})
|
||||
err = statestore.Set(context.Background(), &state.SetRequest{Key: "test-key", Value: []byte("test-value")})
|
||||
assert.Nil(t, err)
|
||||
getResponse, err := statestore.Get(context.TODO(), &state.GetRequest{Key: "test-key"})
|
||||
getResponse, err := statestore.Get(context.Background(), &state.GetRequest{Key: "test-key"})
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "test-value", string(getResponse.Data), "Value retrieved should be equal to value set")
|
||||
assert.NotNil(t, *getResponse.ETag, "ETag should be set")
|
||||
|
@ -106,9 +106,9 @@ func testGet(t *testing.T, ociProperties map[string]string) {
|
|||
t.Run("Get an existing composed key", func(t *testing.T) {
|
||||
err := statestore.Init(meta)
|
||||
assert.Nil(t, err)
|
||||
err = statestore.Set(context.TODO(), &state.SetRequest{Key: "test-app||test-key", Value: []byte("test-value")})
|
||||
err = statestore.Set(context.Background(), &state.SetRequest{Key: "test-app||test-key", Value: []byte("test-value")})
|
||||
assert.Nil(t, err)
|
||||
getResponse, err := statestore.Get(context.TODO(), &state.GetRequest{Key: "test-app||test-key"})
|
||||
getResponse, err := statestore.Get(context.Background(), &state.GetRequest{Key: "test-app||test-key"})
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "test-value", string(getResponse.Data), "Value retrieved should be equal to value set")
|
||||
})
|
||||
|
@ -116,11 +116,11 @@ func testGet(t *testing.T, ociProperties map[string]string) {
|
|||
testKey := "unexpired-ttl-test-key"
|
||||
err := statestore.Init(meta)
|
||||
assert.Nil(t, err)
|
||||
err = statestore.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("test-value"), Metadata: (map[string]string{
|
||||
err = statestore.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("test-value"), Metadata: (map[string]string{
|
||||
"ttlInSeconds": "100",
|
||||
})})
|
||||
assert.Nil(t, err)
|
||||
getResponse, err := statestore.Get(context.TODO(), &state.GetRequest{Key: testKey})
|
||||
getResponse, err := statestore.Get(context.Background(), &state.GetRequest{Key: testKey})
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "test-value", string(getResponse.Data), "Value retrieved should be equal to value set despite TTL setting")
|
||||
})
|
||||
|
@ -128,23 +128,23 @@ func testGet(t *testing.T, ociProperties map[string]string) {
|
|||
testKey := "never-expiring-ttl-test-key"
|
||||
err := statestore.Init(meta)
|
||||
assert.Nil(t, err)
|
||||
err = statestore.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("test-value"), Metadata: (map[string]string{
|
||||
err = statestore.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("test-value"), Metadata: (map[string]string{
|
||||
"ttlInSeconds": "-1",
|
||||
})})
|
||||
assert.Nil(t, err)
|
||||
getResponse, err := statestore.Get(context.TODO(), &state.GetRequest{Key: testKey})
|
||||
getResponse, err := statestore.Get(context.Background(), &state.GetRequest{Key: testKey})
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "test-value", string(getResponse.Data), "Value retrieved should be equal (TTL setting of -1 means never expire)")
|
||||
})
|
||||
t.Run("Get an expired (TTL in the past) state element", func(t *testing.T) {
|
||||
err := statestore.Init(meta)
|
||||
assert.Nil(t, err)
|
||||
err = statestore.Set(context.TODO(), &state.SetRequest{Key: "ttl-test-key", Value: []byte("test-value"), Metadata: (map[string]string{
|
||||
err = statestore.Set(context.Background(), &state.SetRequest{Key: "ttl-test-key", Value: []byte("test-value"), Metadata: (map[string]string{
|
||||
"ttlInSeconds": "1",
|
||||
})})
|
||||
assert.Nil(t, err)
|
||||
time.Sleep(time.Second * 2)
|
||||
getResponse, err := statestore.Get(context.TODO(), &state.GetRequest{Key: "ttl-test-key"})
|
||||
getResponse, err := statestore.Get(context.Background(), &state.GetRequest{Key: "ttl-test-key"})
|
||||
assert.Equal(t, &state.GetResponse{}, getResponse, "Response must be empty")
|
||||
assert.NoError(t, err, "Expired element must not be treated as error")
|
||||
})
|
||||
|
@ -157,7 +157,7 @@ func testSet(t *testing.T, ociProperties map[string]string) {
|
|||
t.Run("Set without a key", func(t *testing.T) {
|
||||
err := statestore.Init(meta)
|
||||
assert.Nil(t, err)
|
||||
err = statestore.Set(context.TODO(), &state.SetRequest{Value: []byte("test-value")})
|
||||
err = statestore.Set(context.Background(), &state.SetRequest{Value: []byte("test-value")})
|
||||
assert.Equal(t, err, fmt.Errorf("key for value to set was missing from request"), "Lacking Key results in error")
|
||||
})
|
||||
t.Run("Regular Set Operation", func(t *testing.T) {
|
||||
|
@ -165,9 +165,9 @@ func testSet(t *testing.T, ociProperties map[string]string) {
|
|||
err := statestore.Init(meta)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = statestore.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("test-value")})
|
||||
err = statestore.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("test-value")})
|
||||
assert.Nil(t, err, "Setting a value with a proper key should be errorfree")
|
||||
getResponse, err := statestore.Get(context.TODO(), &state.GetRequest{Key: testKey})
|
||||
getResponse, err := statestore.Get(context.Background(), &state.GetRequest{Key: testKey})
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "test-value", string(getResponse.Data), "Value retrieved should be equal to value set")
|
||||
assert.NotNil(t, *getResponse.ETag, "ETag should be set")
|
||||
|
@ -177,20 +177,20 @@ func testSet(t *testing.T, ociProperties map[string]string) {
|
|||
err := statestore.Init(meta)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = statestore.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("test-value")})
|
||||
err = statestore.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("test-value")})
|
||||
assert.Nil(t, err, "Setting a value with a proper composite key should be errorfree")
|
||||
getResponse, err := statestore.Get(context.TODO(), &state.GetRequest{Key: testKey})
|
||||
getResponse, err := statestore.Get(context.Background(), &state.GetRequest{Key: testKey})
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "test-value", string(getResponse.Data), "Value retrieved should be equal to value set")
|
||||
assert.NotNil(t, *getResponse.ETag, "ETag should be set")
|
||||
})
|
||||
t.Run("Regular Set Operation with TTL", func(t *testing.T) {
|
||||
testKey := "test-key-with-ttl"
|
||||
err := statestore.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("test-value"), Metadata: (map[string]string{
|
||||
err := statestore.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("test-value"), Metadata: (map[string]string{
|
||||
"ttlInSeconds": "500",
|
||||
})})
|
||||
assert.Nil(t, err, "Setting a value with a proper key and a correct TTL value should be errorfree")
|
||||
err = statestore.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("test-value"), Metadata: (map[string]string{
|
||||
err = statestore.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("test-value"), Metadata: (map[string]string{
|
||||
"ttlInSeconds": "XXX",
|
||||
})})
|
||||
assert.NotNil(t, err, "Setting a value with a proper key and a incorrect TTL value should be produce an error")
|
||||
|
@ -201,25 +201,25 @@ func testSet(t *testing.T, ociProperties map[string]string) {
|
|||
err := statestore.Init(meta)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = statestore.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("test-value")})
|
||||
err = statestore.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("test-value")})
|
||||
assert.Nil(t, err, "Setting a value with a proper key should be errorfree")
|
||||
getResponse, _ := statestore.Get(context.TODO(), &state.GetRequest{Key: testKey})
|
||||
getResponse, _ := statestore.Get(context.Background(), &state.GetRequest{Key: testKey})
|
||||
etag := getResponse.ETag
|
||||
err = statestore.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("overwritten-value"), ETag: etag, Options: state.SetStateOption{
|
||||
err = statestore.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("overwritten-value"), ETag: etag, Options: state.SetStateOption{
|
||||
Concurrency: state.FirstWrite,
|
||||
}})
|
||||
assert.Nil(t, err, "Updating value with proper etag should go fine")
|
||||
|
||||
err = statestore.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("more-overwritten-value"), ETag: etag, Options: state.SetStateOption{
|
||||
err = statestore.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("more-overwritten-value"), ETag: etag, Options: state.SetStateOption{
|
||||
Concurrency: state.FirstWrite,
|
||||
}})
|
||||
assert.NotNil(t, err, "Updating value with the old etag should be refused")
|
||||
|
||||
// retrieve the latest etag - assigned by the previous set operation.
|
||||
getResponse, _ = statestore.Get(context.TODO(), &state.GetRequest{Key: testKey})
|
||||
getResponse, _ = statestore.Get(context.Background(), &state.GetRequest{Key: testKey})
|
||||
assert.NotNil(t, *getResponse.ETag, "ETag should be set")
|
||||
etag = getResponse.ETag
|
||||
err = statestore.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("more-overwritten-value"), ETag: etag, Options: state.SetStateOption{
|
||||
err = statestore.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("more-overwritten-value"), ETag: etag, Options: state.SetStateOption{
|
||||
Concurrency: state.FirstWrite,
|
||||
}})
|
||||
assert.Nil(t, err, "Updating value with the latest etag should be accepted")
|
||||
|
@ -233,7 +233,7 @@ func testDelete(t *testing.T, ociProperties map[string]string) {
|
|||
t.Run("Delete without a key", func(t *testing.T) {
|
||||
err := s.Init(m)
|
||||
assert.Nil(t, err)
|
||||
err = s.Delete(context.TODO(), &state.DeleteRequest{})
|
||||
err = s.Delete(context.Background(), &state.DeleteRequest{})
|
||||
assert.Equal(t, err, fmt.Errorf("key for value to delete was missing from request"), "Lacking Key results in error")
|
||||
})
|
||||
t.Run("Regular Delete Operation", func(t *testing.T) {
|
||||
|
@ -241,9 +241,9 @@ func testDelete(t *testing.T, ociProperties map[string]string) {
|
|||
err := s.Init(m)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = s.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("test-value")})
|
||||
err = s.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("test-value")})
|
||||
assert.Nil(t, err, "Setting a value with a proper key should be errorfree")
|
||||
err = s.Delete(context.TODO(), &state.DeleteRequest{Key: testKey})
|
||||
err = s.Delete(context.Background(), &state.DeleteRequest{Key: testKey})
|
||||
assert.Nil(t, err, "Deleting an existing value with a proper key should be errorfree")
|
||||
})
|
||||
t.Run("Regular Delete Operation for composite key", func(t *testing.T) {
|
||||
|
@ -251,13 +251,13 @@ func testDelete(t *testing.T, ociProperties map[string]string) {
|
|||
err := s.Init(m)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = s.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("test-value")})
|
||||
err = s.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("test-value")})
|
||||
assert.Nil(t, err, "Setting a value with a proper composite key should be errorfree")
|
||||
err = s.Delete(context.TODO(), &state.DeleteRequest{Key: testKey})
|
||||
err = s.Delete(context.Background(), &state.DeleteRequest{Key: testKey})
|
||||
assert.Nil(t, err, "Deleting an existing value with a proper composite key should be errorfree")
|
||||
})
|
||||
t.Run("Delete with an unknown key", func(t *testing.T) {
|
||||
err := s.Delete(context.TODO(), &state.DeleteRequest{Key: "unknownKey"})
|
||||
err := s.Delete(context.Background(), &state.DeleteRequest{Key: "unknownKey"})
|
||||
assert.Contains(t, err.Error(), "404", "Unknown Key results in error: http status code 404, object not found")
|
||||
})
|
||||
|
||||
|
@ -266,18 +266,18 @@ func testDelete(t *testing.T, ociProperties map[string]string) {
|
|||
err := s.Init(m)
|
||||
assert.Nil(t, err)
|
||||
// create document.
|
||||
err = s.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("test-value")})
|
||||
err = s.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("test-value")})
|
||||
assert.Nil(t, err, "Setting a value with a proper key should be errorfree")
|
||||
getResponse, _ := s.Get(context.TODO(), &state.GetRequest{Key: testKey})
|
||||
getResponse, _ := s.Get(context.Background(), &state.GetRequest{Key: testKey})
|
||||
etag := getResponse.ETag
|
||||
|
||||
incorrectETag := "someRandomETag"
|
||||
err = s.Delete(context.TODO(), &state.DeleteRequest{Key: testKey, ETag: &incorrectETag, Options: state.DeleteStateOption{
|
||||
err = s.Delete(context.Background(), &state.DeleteRequest{Key: testKey, ETag: &incorrectETag, Options: state.DeleteStateOption{
|
||||
Concurrency: state.FirstWrite,
|
||||
}})
|
||||
assert.NotNil(t, err, "Deleting value with an incorrect etag should be prevented")
|
||||
|
||||
err = s.Delete(context.TODO(), &state.DeleteRequest{Key: testKey, ETag: etag, Options: state.DeleteStateOption{
|
||||
err = s.Delete(context.Background(), &state.DeleteRequest{Key: testKey, ETag: etag, Options: state.DeleteStateOption{
|
||||
Concurrency: state.FirstWrite,
|
||||
}})
|
||||
assert.Nil(t, err, "Deleting value with proper etag should go fine")
|
||||
|
|
|
@ -236,24 +236,24 @@ func TestGetWithMockClient(t *testing.T) {
|
|||
s.client = mockClient
|
||||
t.Parallel()
|
||||
t.Run("Test regular Get", func(t *testing.T) {
|
||||
getResponse, err := s.Get(context.TODO(), &state.GetRequest{Key: "test-key"})
|
||||
getResponse, err := s.Get(context.Background(), &state.GetRequest{Key: "test-key"})
|
||||
assert.True(t, mockClient.getIsCalled, "function Get should be invoked on the mockClient")
|
||||
assert.Equal(t, "Hello World", string(getResponse.Data), "Value retrieved should be equal to value set")
|
||||
assert.NotNil(t, *getResponse.ETag, "ETag should be set")
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
t.Run("Test Get with composite key", func(t *testing.T) {
|
||||
getResponse, err := s.Get(context.TODO(), &state.GetRequest{Key: "test-app||test-key"})
|
||||
getResponse, err := s.Get(context.Background(), &state.GetRequest{Key: "test-app||test-key"})
|
||||
assert.Equal(t, "Hello Continent", string(getResponse.Data), "Value retrieved should be equal to value set")
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
t.Run("Test Get with an unknown key", func(t *testing.T) {
|
||||
getResponse, err := s.Get(context.TODO(), &state.GetRequest{Key: "unknownKey"})
|
||||
getResponse, err := s.Get(context.Background(), &state.GetRequest{Key: "unknownKey"})
|
||||
assert.Nil(t, getResponse.Data, "No value should be retrieved for an unknown key")
|
||||
assert.Nil(t, err, "404", "Not finding an object because of unknown key should not result in an error")
|
||||
})
|
||||
t.Run("Test expired element (because of TTL) ", func(t *testing.T) {
|
||||
getResponse, err := s.Get(context.TODO(), &state.GetRequest{Key: "test-expired-ttl-key"})
|
||||
getResponse, err := s.Get(context.Background(), &state.GetRequest{Key: "test-expired-ttl-key"})
|
||||
assert.Nil(t, getResponse.Data, "No value should be retrieved for an expired state element")
|
||||
assert.Nil(t, err, "Not returning an object because of expiration should not result in an error")
|
||||
})
|
||||
|
@ -289,28 +289,28 @@ func TestSetWithMockClient(t *testing.T) {
|
|||
mockClient := &mockedObjectStoreClient{}
|
||||
statestore.client = mockClient
|
||||
t.Run("Set without a key", func(t *testing.T) {
|
||||
err := statestore.Set(context.TODO(), &state.SetRequest{Value: []byte("test-value")})
|
||||
err := statestore.Set(context.Background(), &state.SetRequest{Value: []byte("test-value")})
|
||||
assert.Equal(t, err, fmt.Errorf("key for value to set was missing from request"), "Lacking Key results in error")
|
||||
})
|
||||
t.Run("Regular Set Operation", func(t *testing.T) {
|
||||
testKey := "test-key"
|
||||
err := statestore.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("test-value")})
|
||||
err := statestore.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("test-value")})
|
||||
assert.Nil(t, err, "Setting a value with a proper key should be errorfree")
|
||||
assert.True(t, mockClient.putIsCalled, "function put should be invoked on the mockClient")
|
||||
})
|
||||
t.Run("Regular Set Operation with TTL", func(t *testing.T) {
|
||||
testKey := "test-key"
|
||||
err := statestore.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("test-value"), Metadata: (map[string]string{
|
||||
err := statestore.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("test-value"), Metadata: (map[string]string{
|
||||
"ttlInSeconds": "5",
|
||||
})})
|
||||
assert.Nil(t, err, "Setting a value with a proper key and a correct TTL value should be errorfree")
|
||||
|
||||
err = statestore.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("test-value"), Metadata: (map[string]string{
|
||||
err = statestore.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("test-value"), Metadata: (map[string]string{
|
||||
"ttlInSeconds": "XXX",
|
||||
})})
|
||||
assert.NotNil(t, err, "Setting a value with a proper key and a incorrect TTL value should be produce an error")
|
||||
|
||||
err = statestore.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("test-value"), Metadata: (map[string]string{
|
||||
err = statestore.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("test-value"), Metadata: (map[string]string{
|
||||
"ttlInSeconds": "1",
|
||||
})})
|
||||
assert.Nil(t, err, "Setting a value with a proper key and a correct TTL value should be errorfree")
|
||||
|
@ -320,22 +320,22 @@ func TestSetWithMockClient(t *testing.T) {
|
|||
incorrectETag := "notTheCorrectETag"
|
||||
etag := "correctETag"
|
||||
|
||||
err := statestore.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("overwritten-value"), ETag: &incorrectETag, Options: state.SetStateOption{
|
||||
err := statestore.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("overwritten-value"), ETag: &incorrectETag, Options: state.SetStateOption{
|
||||
Concurrency: state.FirstWrite,
|
||||
}})
|
||||
assert.NotNil(t, err, "Updating value with wrong etag should fail")
|
||||
|
||||
err = statestore.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("overwritten-value"), ETag: nil, Options: state.SetStateOption{
|
||||
err = statestore.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("overwritten-value"), ETag: nil, Options: state.SetStateOption{
|
||||
Concurrency: state.FirstWrite,
|
||||
}})
|
||||
assert.NotNil(t, err, "Asking for FirstWrite concurrency policy without ETag should fail")
|
||||
|
||||
err = statestore.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("overwritten-value"), ETag: &etag, Options: state.SetStateOption{
|
||||
err = statestore.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("overwritten-value"), ETag: &etag, Options: state.SetStateOption{
|
||||
Concurrency: state.FirstWrite,
|
||||
}})
|
||||
assert.Nil(t, err, "Updating value with proper etag should go fine")
|
||||
|
||||
err = statestore.Set(context.TODO(), &state.SetRequest{Key: testKey, Value: []byte("overwritten-value"), ETag: nil, Options: state.SetStateOption{
|
||||
err = statestore.Set(context.Background(), &state.SetRequest{Key: testKey, Value: []byte("overwritten-value"), ETag: nil, Options: state.SetStateOption{
|
||||
Concurrency: state.FirstWrite,
|
||||
}})
|
||||
assert.NotNil(t, err, "Updating value with concurrency policy at FirstWrite should fail when ETag is missing")
|
||||
|
@ -348,34 +348,34 @@ func TestDeleteWithMockClient(t *testing.T) {
|
|||
mockClient := &mockedObjectStoreClient{}
|
||||
s.client = mockClient
|
||||
t.Run("Delete without a key", func(t *testing.T) {
|
||||
err := s.Delete(context.TODO(), &state.DeleteRequest{})
|
||||
err := s.Delete(context.Background(), &state.DeleteRequest{})
|
||||
assert.Equal(t, err, fmt.Errorf("key for value to delete was missing from request"), "Lacking Key results in error")
|
||||
})
|
||||
t.Run("Delete with an unknown key", func(t *testing.T) {
|
||||
err := s.Delete(context.TODO(), &state.DeleteRequest{Key: "unknownKey"})
|
||||
err := s.Delete(context.Background(), &state.DeleteRequest{Key: "unknownKey"})
|
||||
assert.Contains(t, err.Error(), "404", "Unknown Key results in error: http status code 404, object not found")
|
||||
})
|
||||
t.Run("Regular Delete Operation", func(t *testing.T) {
|
||||
testKey := "test-key"
|
||||
err := s.Delete(context.TODO(), &state.DeleteRequest{Key: testKey})
|
||||
err := s.Delete(context.Background(), &state.DeleteRequest{Key: testKey})
|
||||
assert.Nil(t, err, "Deleting an existing value with a proper key should be errorfree")
|
||||
assert.True(t, mockClient.deleteIsCalled, "function delete should be invoked on the mockClient")
|
||||
})
|
||||
t.Run("Testing Delete & Concurrency (ETags)", func(t *testing.T) {
|
||||
testKey := "etag-test-delete-key"
|
||||
incorrectETag := "notTheCorrectETag"
|
||||
err := s.Delete(context.TODO(), &state.DeleteRequest{Key: testKey, ETag: &incorrectETag, Options: state.DeleteStateOption{
|
||||
err := s.Delete(context.Background(), &state.DeleteRequest{Key: testKey, ETag: &incorrectETag, Options: state.DeleteStateOption{
|
||||
Concurrency: state.FirstWrite,
|
||||
}})
|
||||
assert.NotNil(t, err, "Deleting value with an incorrect etag should be prevented")
|
||||
|
||||
etag := "correctETag"
|
||||
err = s.Delete(context.TODO(), &state.DeleteRequest{Key: testKey, ETag: &etag, Options: state.DeleteStateOption{
|
||||
err = s.Delete(context.Background(), &state.DeleteRequest{Key: testKey, ETag: &etag, Options: state.DeleteStateOption{
|
||||
Concurrency: state.FirstWrite,
|
||||
}})
|
||||
assert.Nil(t, err, "Deleting value with proper etag should go fine")
|
||||
|
||||
err = s.Delete(context.TODO(), &state.DeleteRequest{Key: testKey, ETag: nil, Options: state.DeleteStateOption{
|
||||
err = s.Delete(context.Background(), &state.DeleteRequest{Key: testKey, ETag: nil, Options: state.DeleteStateOption{
|
||||
Concurrency: state.FirstWrite,
|
||||
}})
|
||||
assert.NotNil(t, err, "Asking for FirstWrite concurrency policy without ETag should fail")
|
||||
|
|
|
@ -224,7 +224,7 @@ func deleteItemThatDoesNotExist(t *testing.T, ods *OracleDatabase) {
|
|||
deleteReq := &state.DeleteRequest{
|
||||
Key: randomKey(),
|
||||
}
|
||||
err := ods.Delete(context.TODO(), deleteReq)
|
||||
err := ods.Delete(context.Background(), deleteReq)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
|
@ -243,7 +243,7 @@ func multiWithSetOnly(t *testing.T, ods *OracleDatabase) {
|
|||
})
|
||||
}
|
||||
|
||||
err := ods.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := ods.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
@ -273,7 +273,7 @@ func multiWithDeleteOnly(t *testing.T, ods *OracleDatabase) {
|
|||
})
|
||||
}
|
||||
|
||||
err := ods.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := ods.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
@ -316,7 +316,7 @@ func multiWithDeleteAndSet(t *testing.T, ods *OracleDatabase) {
|
|||
})
|
||||
}
|
||||
|
||||
err := ods.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := ods.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
@ -346,7 +346,7 @@ func deleteWithInvalidEtagFails(t *testing.T, ods *OracleDatabase) {
|
|||
Concurrency: state.FirstWrite,
|
||||
},
|
||||
}
|
||||
err := ods.Delete(context.TODO(), deleteReq)
|
||||
err := ods.Delete(context.Background(), deleteReq)
|
||||
assert.NotNil(t, err, "Deleting an item with the wrong etag while enforcing FirstWrite policy should fail")
|
||||
}
|
||||
|
||||
|
@ -354,7 +354,7 @@ func deleteWithNoKeyFails(t *testing.T, ods *OracleDatabase) {
|
|||
deleteReq := &state.DeleteRequest{
|
||||
Key: "",
|
||||
}
|
||||
err := ods.Delete(context.TODO(), deleteReq)
|
||||
err := ods.Delete(context.Background(), deleteReq)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
|
@ -372,7 +372,7 @@ func newItemWithEtagFails(t *testing.T, ods *OracleDatabase) {
|
|||
},
|
||||
}
|
||||
|
||||
err := ods.Set(context.TODO(), setReq)
|
||||
err := ods.Set(context.Background(), setReq)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
|
@ -402,7 +402,7 @@ func updateWithOldEtagFails(t *testing.T, ods *OracleDatabase) {
|
|||
Concurrency: state.FirstWrite,
|
||||
},
|
||||
}
|
||||
err := ods.Set(context.TODO(), setReq)
|
||||
err := ods.Set(context.Background(), setReq)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
|
@ -424,7 +424,7 @@ func updateAndDeleteWithEtagSucceeds(t *testing.T, ods *OracleDatabase) {
|
|||
Concurrency: state.FirstWrite,
|
||||
},
|
||||
}
|
||||
err := ods.Set(context.TODO(), setReq)
|
||||
err := ods.Set(context.Background(), setReq)
|
||||
assert.Nil(t, err, "Setting the item should be successful")
|
||||
updateResponse, updatedItem := getItem(t, ods, key)
|
||||
assert.Equal(t, value, updatedItem)
|
||||
|
@ -440,7 +440,7 @@ func updateAndDeleteWithEtagSucceeds(t *testing.T, ods *OracleDatabase) {
|
|||
Concurrency: state.FirstWrite,
|
||||
},
|
||||
}
|
||||
err = ods.Delete(context.TODO(), deleteReq)
|
||||
err = ods.Delete(context.Background(), deleteReq)
|
||||
assert.Nil(t, err, "Deleting an item with the right etag while enforcing FirstWrite policy should succeed")
|
||||
|
||||
// Item is not in the data store.
|
||||
|
@ -466,7 +466,7 @@ func updateAndDeleteWithWrongEtagAndNoFirstWriteSucceeds(t *testing.T, ods *Orac
|
|||
Concurrency: state.LastWrite,
|
||||
},
|
||||
}
|
||||
err := ods.Set(context.TODO(), setReq)
|
||||
err := ods.Set(context.Background(), setReq)
|
||||
assert.Nil(t, err, "Setting the item should be successful")
|
||||
_, updatedItem := getItem(t, ods, key)
|
||||
assert.Equal(t, value, updatedItem)
|
||||
|
@ -479,7 +479,7 @@ func updateAndDeleteWithWrongEtagAndNoFirstWriteSucceeds(t *testing.T, ods *Orac
|
|||
Concurrency: state.LastWrite,
|
||||
},
|
||||
}
|
||||
err = ods.Delete(context.TODO(), deleteReq)
|
||||
err = ods.Delete(context.Background(), deleteReq)
|
||||
assert.Nil(t, err, "Deleting an item with the wrong etag but not enforcing FirstWrite policy should succeed")
|
||||
|
||||
// Item is not in the data store.
|
||||
|
@ -501,7 +501,7 @@ func getItemWithNoKey(t *testing.T, ods *OracleDatabase) {
|
|||
Key: "",
|
||||
}
|
||||
|
||||
response, getErr := ods.Get(context.TODO(), getReq)
|
||||
response, getErr := ods.Get(context.Background(), getReq)
|
||||
assert.NotNil(t, getErr)
|
||||
assert.Nil(t, response)
|
||||
}
|
||||
|
@ -549,7 +549,7 @@ func setTTLUpdatesExpiry(t *testing.T, ods *OracleDatabase) {
|
|||
},
|
||||
}
|
||||
|
||||
err := ods.Set(context.TODO(), setReq)
|
||||
err := ods.Set(context.Background(), setReq)
|
||||
assert.Nil(t, err)
|
||||
connectionString := getConnectionString()
|
||||
if getWalletLocation() != "" {
|
||||
|
@ -581,10 +581,10 @@ func setNoTTLUpdatesExpiry(t *testing.T, ods *OracleDatabase) {
|
|||
"ttlInSeconds": "1000",
|
||||
},
|
||||
}
|
||||
err := ods.Set(context.TODO(), setReq)
|
||||
err := ods.Set(context.Background(), setReq)
|
||||
assert.Nil(t, err)
|
||||
delete(setReq.Metadata, "ttlInSeconds")
|
||||
err = ods.Set(context.TODO(), setReq)
|
||||
err = ods.Set(context.Background(), setReq)
|
||||
assert.Nil(t, err)
|
||||
connectionString := getConnectionString()
|
||||
if getWalletLocation() != "" {
|
||||
|
@ -615,11 +615,11 @@ func expiredStateCannotBeRead(t *testing.T, ods *OracleDatabase) {
|
|||
"ttlInSeconds": "1",
|
||||
},
|
||||
}
|
||||
err := ods.Set(context.TODO(), setReq)
|
||||
err := ods.Set(context.Background(), setReq)
|
||||
assert.Nil(t, err)
|
||||
|
||||
time.Sleep(time.Second * time.Duration(2))
|
||||
getResponse, err := ods.Get(context.TODO(), &state.GetRequest{Key: key})
|
||||
getResponse, err := ods.Get(context.Background(), &state.GetRequest{Key: key})
|
||||
assert.Equal(t, &state.GetResponse{}, getResponse, "Response must be empty")
|
||||
assert.NoError(t, err, "Expired element must not be treated as error")
|
||||
|
||||
|
@ -640,7 +640,7 @@ func unexpiredStateCanBeRead(t *testing.T, ods *OracleDatabase) {
|
|||
"ttlInSeconds": "10000",
|
||||
},
|
||||
}
|
||||
err := ods.Set(context.TODO(), setReq)
|
||||
err := ods.Set(context.Background(), setReq)
|
||||
assert.Nil(t, err)
|
||||
_, getValue := getItem(t, ods, key)
|
||||
assert.Equal(t, value.Color, getValue.Color, "Response must be as set")
|
||||
|
@ -654,7 +654,7 @@ func setItemWithNoKey(t *testing.T, ods *OracleDatabase) {
|
|||
Key: "",
|
||||
}
|
||||
|
||||
err := ods.Set(context.TODO(), setReq)
|
||||
err := ods.Set(context.Background(), setReq)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
|
@ -703,7 +703,7 @@ func testSetItemWithInvalidTTL(t *testing.T, ods *OracleDatabase) {
|
|||
"ttlInSeconds": "XX",
|
||||
}),
|
||||
}
|
||||
err := ods.Set(context.TODO(), setReq)
|
||||
err := ods.Set(context.Background(), setReq)
|
||||
assert.NotNil(t, err, "Setting a value with a proper key and a incorrect TTL value should be produce an error")
|
||||
}
|
||||
|
||||
|
@ -715,7 +715,7 @@ func testSetItemWithNegativeTTL(t *testing.T, ods *OracleDatabase) {
|
|||
"ttlInSeconds": "-10",
|
||||
}),
|
||||
}
|
||||
err := ods.Set(context.TODO(), setReq)
|
||||
err := ods.Set(context.Background(), setReq)
|
||||
assert.NotNil(t, err, "Setting a value with a proper key and a negative (other than -1) TTL value should be produce an error")
|
||||
}
|
||||
|
||||
|
@ -732,7 +732,7 @@ func testBulkSetAndBulkDelete(t *testing.T, ods *OracleDatabase) {
|
|||
},
|
||||
}
|
||||
|
||||
err := ods.BulkSet(context.TODO(), setReq)
|
||||
err := ods.BulkSet(context.Background(), setReq)
|
||||
assert.Nil(t, err)
|
||||
assert.True(t, storeItemExists(t, setReq[0].Key))
|
||||
assert.True(t, storeItemExists(t, setReq[1].Key))
|
||||
|
@ -746,7 +746,7 @@ func testBulkSetAndBulkDelete(t *testing.T, ods *OracleDatabase) {
|
|||
},
|
||||
}
|
||||
|
||||
err = ods.BulkDelete(context.TODO(), deleteReq)
|
||||
err = ods.BulkDelete(context.Background(), deleteReq)
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, storeItemExists(t, setReq[0].Key))
|
||||
assert.False(t, storeItemExists(t, setReq[1].Key))
|
||||
|
@ -813,7 +813,7 @@ func setItem(t *testing.T, ods *OracleDatabase, key string, value interface{}, e
|
|||
Options: setOptions,
|
||||
}
|
||||
|
||||
err := ods.Set(context.TODO(), setReq)
|
||||
err := ods.Set(context.Background(), setReq)
|
||||
assert.Nil(t, err)
|
||||
itemExists := storeItemExists(t, key)
|
||||
assert.True(t, itemExists, "Item should exist after set has been executed ")
|
||||
|
@ -825,7 +825,7 @@ func getItem(t *testing.T, ods *OracleDatabase, key string) (*state.GetResponse,
|
|||
Options: state.GetStateOption{},
|
||||
}
|
||||
|
||||
response, getErr := ods.Get(context.TODO(), getReq)
|
||||
response, getErr := ods.Get(context.Background(), getReq)
|
||||
assert.Nil(t, getErr)
|
||||
assert.NotNil(t, response)
|
||||
outputObject := &fakeItem{}
|
||||
|
@ -841,7 +841,7 @@ func deleteItem(t *testing.T, ods *OracleDatabase, key string, etag *string) {
|
|||
Options: state.DeleteStateOption{},
|
||||
}
|
||||
|
||||
deleteErr := ods.Delete(context.TODO(), deleteReq)
|
||||
deleteErr := ods.Delete(context.Background(), deleteReq)
|
||||
assert.Nil(t, deleteErr)
|
||||
assert.False(t, storeItemExists(t, key), "item should no longer exist after delete has been performed")
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ func TestMultiWithNoRequestsReturnsNil(t *testing.T) {
|
|||
t.Parallel()
|
||||
var operations []state.TransactionalStateOperation
|
||||
ods := createOracleDatabase(t)
|
||||
err := ods.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := ods.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
@ -101,7 +101,7 @@ func TestInvalidMultiAction(t *testing.T) {
|
|||
})
|
||||
|
||||
ods := createOracleDatabase(t)
|
||||
err := ods.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := ods.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
assert.NotNil(t, err)
|
||||
|
@ -117,7 +117,7 @@ func TestValidSetRequest(t *testing.T) {
|
|||
})
|
||||
|
||||
ods := createOracleDatabase(t)
|
||||
err := ods.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := ods.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
@ -133,7 +133,7 @@ func TestInvalidMultiSetRequest(t *testing.T) {
|
|||
})
|
||||
|
||||
ods := createOracleDatabase(t)
|
||||
err := ods.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := ods.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
assert.NotNil(t, err)
|
||||
|
@ -149,7 +149,7 @@ func TestValidMultiDeleteRequest(t *testing.T) {
|
|||
})
|
||||
|
||||
ods := createOracleDatabase(t)
|
||||
err := ods.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := ods.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
@ -165,7 +165,7 @@ func TestInvalidMultiDeleteRequest(t *testing.T) {
|
|||
})
|
||||
|
||||
ods := createOracleDatabase(t)
|
||||
err := ods.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := ods.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
assert.NotNil(t, err)
|
||||
|
|
|
@ -111,7 +111,7 @@ func TestMultiWithNoRequests(t *testing.T) {
|
|||
var operations []state.TransactionalStateOperation
|
||||
|
||||
// Act
|
||||
err := m.pgDba.ExecuteMulti(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.pgDba.ExecuteMulti(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -135,7 +135,7 @@ func TestInvalidMultiInvalidAction(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.pgDba.ExecuteMulti(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.pgDba.ExecuteMulti(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -160,7 +160,7 @@ func TestValidSetRequest(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.pgDba.ExecuteMulti(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.pgDba.ExecuteMulti(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -184,7 +184,7 @@ func TestInvalidMultiSetRequest(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.pgDba.ExecuteMulti(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.pgDba.ExecuteMulti(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -208,7 +208,7 @@ func TestInvalidMultiSetRequestNoKey(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.pgDba.ExecuteMulti(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.pgDba.ExecuteMulti(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -233,7 +233,7 @@ func TestValidMultiDeleteRequest(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.pgDba.ExecuteMulti(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.pgDba.ExecuteMulti(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -257,7 +257,7 @@ func TestInvalidMultiDeleteRequest(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.pgDba.ExecuteMulti(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.pgDba.ExecuteMulti(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -281,7 +281,7 @@ func TestInvalidMultiDeleteRequestNoKey(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.pgDba.ExecuteMulti(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.pgDba.ExecuteMulti(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -313,7 +313,7 @@ func TestMultiOperationOrder(t *testing.T) {
|
|||
)
|
||||
|
||||
// Act
|
||||
err := m.pgDba.ExecuteMulti(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := m.pgDba.ExecuteMulti(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
|
||||
|
@ -336,7 +336,7 @@ func TestInvalidBulkSetNoKey(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.pgDba.BulkSet(context.TODO(), sets)
|
||||
err := m.pgDba.BulkSet(context.Background(), sets)
|
||||
|
||||
// Assert
|
||||
assert.NotNil(t, err)
|
||||
|
@ -358,7 +358,7 @@ func TestInvalidBulkSetEmptyValue(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.pgDba.BulkSet(context.TODO(), sets)
|
||||
err := m.pgDba.BulkSet(context.Background(), sets)
|
||||
|
||||
// Assert
|
||||
assert.NotNil(t, err)
|
||||
|
@ -381,7 +381,7 @@ func TestValidBulkSet(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.pgDba.BulkSet(context.TODO(), sets)
|
||||
err := m.pgDba.BulkSet(context.Background(), sets)
|
||||
|
||||
// Assert
|
||||
assert.Nil(t, err)
|
||||
|
@ -402,7 +402,7 @@ func TestInvalidBulkDeleteNoKey(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.pgDba.BulkDelete(context.TODO(), deletes)
|
||||
err := m.pgDba.BulkDelete(context.Background(), deletes)
|
||||
|
||||
// Assert
|
||||
assert.NotNil(t, err)
|
||||
|
@ -424,7 +424,7 @@ func TestValidBulkDelete(t *testing.T) {
|
|||
})
|
||||
|
||||
// Act
|
||||
err := m.pgDba.BulkDelete(context.TODO(), deletes)
|
||||
err := m.pgDba.BulkDelete(context.Background(), deletes)
|
||||
|
||||
// Assert
|
||||
assert.Nil(t, err)
|
||||
|
|
|
@ -193,7 +193,7 @@ func deleteItemThatDoesNotExist(t *testing.T, pgs *PostgreSQL) {
|
|||
deleteReq := &state.DeleteRequest{
|
||||
Key: randomKey(),
|
||||
}
|
||||
err := pgs.Delete(context.TODO(), deleteReq)
|
||||
err := pgs.Delete(context.Background(), deleteReq)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
|
@ -212,7 +212,7 @@ func multiWithSetOnly(t *testing.T, pgs *PostgreSQL) {
|
|||
})
|
||||
}
|
||||
|
||||
err := pgs.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := pgs.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
@ -242,7 +242,7 @@ func multiWithDeleteOnly(t *testing.T, pgs *PostgreSQL) {
|
|||
})
|
||||
}
|
||||
|
||||
err := pgs.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := pgs.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
@ -285,7 +285,7 @@ func multiWithDeleteAndSet(t *testing.T, pgs *PostgreSQL) {
|
|||
})
|
||||
}
|
||||
|
||||
err := pgs.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := pgs.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: operations,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
|
@ -312,7 +312,7 @@ func deleteWithInvalidEtagFails(t *testing.T, pgs *PostgreSQL) {
|
|||
Key: key,
|
||||
ETag: &etag,
|
||||
}
|
||||
err := pgs.Delete(context.TODO(), deleteReq)
|
||||
err := pgs.Delete(context.Background(), deleteReq)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
|
@ -320,7 +320,7 @@ func deleteWithNoKeyFails(t *testing.T, pgs *PostgreSQL) {
|
|||
deleteReq := &state.DeleteRequest{
|
||||
Key: "",
|
||||
}
|
||||
err := pgs.Delete(context.TODO(), deleteReq)
|
||||
err := pgs.Delete(context.Background(), deleteReq)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
|
@ -335,7 +335,7 @@ func newItemWithEtagFails(t *testing.T, pgs *PostgreSQL) {
|
|||
Value: value,
|
||||
}
|
||||
|
||||
err := pgs.Set(context.TODO(), setReq)
|
||||
err := pgs.Set(context.Background(), setReq)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
|
@ -361,7 +361,7 @@ func updateWithOldEtagFails(t *testing.T, pgs *PostgreSQL) {
|
|||
ETag: originalEtag,
|
||||
Value: newValue,
|
||||
}
|
||||
err := pgs.Set(context.TODO(), setReq)
|
||||
err := pgs.Set(context.Background(), setReq)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
|
@ -403,7 +403,7 @@ func getItemWithNoKey(t *testing.T, pgs *PostgreSQL) {
|
|||
Key: "",
|
||||
}
|
||||
|
||||
response, getErr := pgs.Get(context.TODO(), getReq)
|
||||
response, getErr := pgs.Get(context.Background(), getReq)
|
||||
assert.NotNil(t, getErr)
|
||||
assert.Nil(t, response)
|
||||
}
|
||||
|
@ -434,7 +434,7 @@ func setItemWithNoKey(t *testing.T, pgs *PostgreSQL) {
|
|||
Key: "",
|
||||
}
|
||||
|
||||
err := pgs.Set(context.TODO(), setReq)
|
||||
err := pgs.Set(context.Background(), setReq)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
|
@ -451,7 +451,7 @@ func testBulkSetAndBulkDelete(t *testing.T, pgs *PostgreSQL) {
|
|||
},
|
||||
}
|
||||
|
||||
err := pgs.BulkSet(context.TODO(), setReq)
|
||||
err := pgs.BulkSet(context.Background(), setReq)
|
||||
assert.Nil(t, err)
|
||||
assert.True(t, storeItemExists(t, setReq[0].Key))
|
||||
assert.True(t, storeItemExists(t, setReq[1].Key))
|
||||
|
@ -465,7 +465,7 @@ func testBulkSetAndBulkDelete(t *testing.T, pgs *PostgreSQL) {
|
|||
},
|
||||
}
|
||||
|
||||
err = pgs.BulkDelete(context.TODO(), deleteReq)
|
||||
err = pgs.BulkDelete(context.Background(), deleteReq)
|
||||
assert.Nil(t, err)
|
||||
assert.False(t, storeItemExists(t, setReq[0].Key))
|
||||
assert.False(t, storeItemExists(t, setReq[1].Key))
|
||||
|
@ -522,7 +522,7 @@ func setItem(t *testing.T, pgs *PostgreSQL, key string, value interface{}, etag
|
|||
Value: value,
|
||||
}
|
||||
|
||||
err := pgs.Set(context.TODO(), setReq)
|
||||
err := pgs.Set(context.Background(), setReq)
|
||||
assert.Nil(t, err)
|
||||
itemExists := storeItemExists(t, key)
|
||||
assert.True(t, itemExists)
|
||||
|
@ -534,7 +534,7 @@ func getItem(t *testing.T, pgs *PostgreSQL, key string) (*state.GetResponse, *fa
|
|||
Options: state.GetStateOption{},
|
||||
}
|
||||
|
||||
response, getErr := pgs.Get(context.TODO(), getReq)
|
||||
response, getErr := pgs.Get(context.Background(), getReq)
|
||||
assert.Nil(t, getErr)
|
||||
assert.NotNil(t, response)
|
||||
outputObject := &fakeItem{}
|
||||
|
@ -550,7 +550,7 @@ func deleteItem(t *testing.T, pgs *PostgreSQL, key string, etag *string) {
|
|||
Options: state.DeleteStateOption{},
|
||||
}
|
||||
|
||||
deleteErr := pgs.Delete(context.TODO(), deleteReq)
|
||||
deleteErr := pgs.Delete(context.Background(), deleteReq)
|
||||
assert.Nil(t, deleteErr)
|
||||
assert.False(t, storeItemExists(t, key))
|
||||
}
|
||||
|
|
|
@ -206,7 +206,7 @@ func TestTransactionalUpsert(t *testing.T) {
|
|||
}
|
||||
ss.ctx, ss.cancel = context.WithCancel(context.Background())
|
||||
|
||||
err := ss.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := ss.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: []state.TransactionalStateOperation{
|
||||
{
|
||||
Operation: state.Upsert,
|
||||
|
@ -273,13 +273,13 @@ func TestTransactionalDelete(t *testing.T) {
|
|||
ss.ctx, ss.cancel = context.WithCancel(context.Background())
|
||||
|
||||
// Insert a record first.
|
||||
ss.Set(context.TODO(), &state.SetRequest{
|
||||
ss.Set(context.Background(), &state.SetRequest{
|
||||
Key: "weapon",
|
||||
Value: "deathstar",
|
||||
})
|
||||
|
||||
etag := "1"
|
||||
err := ss.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := ss.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: []state.TransactionalStateOperation{{
|
||||
Operation: state.Delete,
|
||||
Request: state.DeleteRequest{
|
||||
|
@ -331,7 +331,7 @@ func TestRequestsWithGlobalTTL(t *testing.T) {
|
|||
ss.ctx, ss.cancel = context.WithCancel(context.Background())
|
||||
|
||||
t.Run("TTL: Only global specified", func(t *testing.T) {
|
||||
ss.Set(context.TODO(), &state.SetRequest{
|
||||
ss.Set(context.Background(), &state.SetRequest{
|
||||
Key: "weapon100",
|
||||
Value: "deathstar100",
|
||||
})
|
||||
|
@ -342,7 +342,7 @@ func TestRequestsWithGlobalTTL(t *testing.T) {
|
|||
|
||||
t.Run("TTL: Global and Request specified", func(t *testing.T) {
|
||||
requestTTL := 200
|
||||
ss.Set(context.TODO(), &state.SetRequest{
|
||||
ss.Set(context.Background(), &state.SetRequest{
|
||||
Key: "weapon100",
|
||||
Value: "deathstar100",
|
||||
Metadata: map[string]string{
|
||||
|
@ -355,7 +355,7 @@ func TestRequestsWithGlobalTTL(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("TTL: Global and Request specified", func(t *testing.T) {
|
||||
err := ss.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := ss.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: []state.TransactionalStateOperation{
|
||||
{
|
||||
Operation: state.Upsert,
|
||||
|
@ -424,7 +424,7 @@ func TestSetRequestWithTTL(t *testing.T) {
|
|||
|
||||
t.Run("TTL specified", func(t *testing.T) {
|
||||
ttlInSeconds := 100
|
||||
ss.Set(context.TODO(), &state.SetRequest{
|
||||
ss.Set(context.Background(), &state.SetRequest{
|
||||
Key: "weapon100",
|
||||
Value: "deathstar100",
|
||||
Metadata: map[string]string{
|
||||
|
@ -438,7 +438,7 @@ func TestSetRequestWithTTL(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("TTL not specified", func(t *testing.T) {
|
||||
ss.Set(context.TODO(), &state.SetRequest{
|
||||
ss.Set(context.Background(), &state.SetRequest{
|
||||
Key: "weapon200",
|
||||
Value: "deathstar200",
|
||||
})
|
||||
|
@ -449,7 +449,7 @@ func TestSetRequestWithTTL(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("TTL Changed for Existing Key", func(t *testing.T) {
|
||||
ss.Set(context.TODO(), &state.SetRequest{
|
||||
ss.Set(context.Background(), &state.SetRequest{
|
||||
Key: "weapon300",
|
||||
Value: "deathstar300",
|
||||
})
|
||||
|
@ -458,7 +458,7 @@ func TestSetRequestWithTTL(t *testing.T) {
|
|||
|
||||
// make the key no longer persistent
|
||||
ttlInSeconds := 123
|
||||
ss.Set(context.TODO(), &state.SetRequest{
|
||||
ss.Set(context.Background(), &state.SetRequest{
|
||||
Key: "weapon300",
|
||||
Value: "deathstar300",
|
||||
Metadata: map[string]string{
|
||||
|
@ -469,7 +469,7 @@ func TestSetRequestWithTTL(t *testing.T) {
|
|||
assert.Equal(t, time.Duration(ttlInSeconds)*time.Second, ttl)
|
||||
|
||||
// make the key persistent again
|
||||
ss.Set(context.TODO(), &state.SetRequest{
|
||||
ss.Set(context.Background(), &state.SetRequest{
|
||||
Key: "weapon300",
|
||||
Value: "deathstar301",
|
||||
Metadata: map[string]string{
|
||||
|
@ -493,12 +493,12 @@ func TestTransactionalDeleteNoEtag(t *testing.T) {
|
|||
ss.ctx, ss.cancel = context.WithCancel(context.Background())
|
||||
|
||||
// Insert a record first.
|
||||
ss.Set(context.TODO(), &state.SetRequest{
|
||||
ss.Set(context.Background(), &state.SetRequest{
|
||||
Key: "weapon100",
|
||||
Value: "deathstar100",
|
||||
})
|
||||
|
||||
err := ss.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := ss.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: []state.TransactionalStateOperation{{
|
||||
Operation: state.Delete,
|
||||
Request: state.DeleteRequest{
|
||||
|
|
|
@ -24,7 +24,7 @@ import (
|
|||
func TestSetRequestWithOptions(t *testing.T) {
|
||||
t.Run("set with default options", func(t *testing.T) {
|
||||
counter := 0
|
||||
SetWithOptions(context.TODO(), func(ctx context.Context, req *SetRequest) error {
|
||||
SetWithOptions(context.Background(), func(ctx context.Context, req *SetRequest) error {
|
||||
counter++
|
||||
|
||||
return nil
|
||||
|
@ -34,7 +34,7 @@ func TestSetRequestWithOptions(t *testing.T) {
|
|||
|
||||
t.Run("set with no explicit options", func(t *testing.T) {
|
||||
counter := 0
|
||||
SetWithOptions(context.TODO(), func(ctx context.Context, req *SetRequest) error {
|
||||
SetWithOptions(context.Background(), func(ctx context.Context, req *SetRequest) error {
|
||||
counter++
|
||||
|
||||
return nil
|
||||
|
|
|
@ -87,12 +87,12 @@ func TestRethinkDBStateStore(t *testing.T) {
|
|||
d := &testObj{F1: "test", F2: 1, F3: time.Now().UTC()}
|
||||
k := fmt.Sprintf("ids-%d", time.Now().UnixNano())
|
||||
|
||||
if err := db.Set(context.TODO(), &state.SetRequest{Key: k, Value: d}); err != nil {
|
||||
if err := db.Set(context.Background(), &state.SetRequest{Key: k, Value: d}); err != nil {
|
||||
t.Fatalf("error setting data to db: %v", err)
|
||||
}
|
||||
|
||||
// get set data and compare
|
||||
resp, err := db.Get(context.TODO(), &state.GetRequest{Key: k})
|
||||
resp, err := db.Get(context.Background(), &state.GetRequest{Key: k})
|
||||
assert.Nil(t, err)
|
||||
d2 := testGetTestObj(t, resp)
|
||||
assert.NotNil(t, d2)
|
||||
|
@ -104,12 +104,12 @@ func TestRethinkDBStateStore(t *testing.T) {
|
|||
d2.F2 = 2
|
||||
d2.F3 = time.Now().UTC()
|
||||
tag := fmt.Sprintf("hash-%d", time.Now().UnixNano())
|
||||
if err = db.Set(context.TODO(), &state.SetRequest{Key: k, Value: d2, ETag: &tag}); err != nil {
|
||||
if err = db.Set(context.Background(), &state.SetRequest{Key: k, Value: d2, ETag: &tag}); err != nil {
|
||||
t.Fatalf("error setting data to db: %v", err)
|
||||
}
|
||||
|
||||
// get updated data and compare
|
||||
resp2, err := db.Get(context.TODO(), &state.GetRequest{Key: k})
|
||||
resp2, err := db.Get(context.Background(), &state.GetRequest{Key: k})
|
||||
assert.Nil(t, err)
|
||||
d3 := testGetTestObj(t, resp2)
|
||||
assert.NotNil(t, d3)
|
||||
|
@ -118,7 +118,7 @@ func TestRethinkDBStateStore(t *testing.T) {
|
|||
assert.Equal(t, d2.F3.Format(time.RFC3339), d3.F3.Format(time.RFC3339))
|
||||
|
||||
// delete data
|
||||
if err := db.Delete(context.TODO(), &state.DeleteRequest{Key: k}); err != nil {
|
||||
if err := db.Delete(context.Background(), &state.DeleteRequest{Key: k}); err != nil {
|
||||
t.Fatalf("error on data deletion: %v", err)
|
||||
}
|
||||
})
|
||||
|
@ -128,19 +128,19 @@ func TestRethinkDBStateStore(t *testing.T) {
|
|||
d := []byte("test")
|
||||
k := fmt.Sprintf("idb-%d", time.Now().UnixNano())
|
||||
|
||||
if err := db.Set(context.TODO(), &state.SetRequest{Key: k, Value: d}); err != nil {
|
||||
if err := db.Set(context.Background(), &state.SetRequest{Key: k, Value: d}); err != nil {
|
||||
t.Fatalf("error setting data to db: %v", err)
|
||||
}
|
||||
|
||||
// get set data and compare
|
||||
resp, err := db.Get(context.TODO(), &state.GetRequest{Key: k})
|
||||
resp, err := db.Get(context.Background(), &state.GetRequest{Key: k})
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, resp)
|
||||
assert.NotNil(t, resp.Data)
|
||||
assert.Equal(t, string(d), string(resp.Data))
|
||||
|
||||
// delete data
|
||||
if err := db.Delete(context.TODO(), &state.DeleteRequest{Key: k}); err != nil {
|
||||
if err := db.Delete(context.Background(), &state.DeleteRequest{Key: k}); err != nil {
|
||||
t.Fatalf("error on data deletion: %v", err)
|
||||
}
|
||||
})
|
||||
|
@ -178,26 +178,26 @@ func testBulk(t *testing.T, db *RethinkDB, i int) {
|
|||
}
|
||||
|
||||
// bulk set it
|
||||
if err := db.BulkSet(context.TODO(), setList); err != nil {
|
||||
if err := db.BulkSet(context.Background(), setList); err != nil {
|
||||
t.Fatalf("error setting data to db: %v -- run %d", err, i)
|
||||
}
|
||||
|
||||
// check for the data
|
||||
for _, v := range deleteList {
|
||||
resp, err := db.Get(context.TODO(), &state.GetRequest{Key: v.Key})
|
||||
resp, err := db.Get(context.Background(), &state.GetRequest{Key: v.Key})
|
||||
assert.Nilf(t, err, " -- run %d", i)
|
||||
assert.NotNil(t, resp)
|
||||
assert.NotNil(t, resp.Data)
|
||||
}
|
||||
|
||||
// delete data
|
||||
if err := db.BulkDelete(context.TODO(), deleteList); err != nil {
|
||||
if err := db.BulkDelete(context.Background(), deleteList); err != nil {
|
||||
t.Fatalf("error on data deletion: %v -- run %d", err, i)
|
||||
}
|
||||
|
||||
// check for the data NOT being there
|
||||
for _, v := range deleteList {
|
||||
resp, err := db.Get(context.TODO(), &state.GetRequest{Key: v.Key})
|
||||
resp, err := db.Get(context.Background(), &state.GetRequest{Key: v.Key})
|
||||
assert.Nilf(t, err, " -- run %d", i)
|
||||
assert.NotNil(t, resp)
|
||||
assert.Nil(t, resp.Data)
|
||||
|
@ -225,7 +225,7 @@ func TestRethinkDBStateStoreMulti(t *testing.T) {
|
|||
for i := 0; i < numOfRecords; i++ {
|
||||
list[i] = state.SetRequest{Key: fmt.Sprintf(recordIDFormat, i), Value: d}
|
||||
}
|
||||
if err := db.BulkSet(context.TODO(), list); err != nil {
|
||||
if err := db.BulkSet(context.Background(), list); err != nil {
|
||||
t.Fatalf("error setting multi to db: %v", err)
|
||||
}
|
||||
|
||||
|
@ -259,19 +259,19 @@ func TestRethinkDBStateStoreMulti(t *testing.T) {
|
|||
}
|
||||
|
||||
// execute multi
|
||||
if err := db.Multi(context.TODO(), req); err != nil {
|
||||
if err := db.Multi(context.Background(), req); err != nil {
|
||||
t.Fatalf("error setting multi to db: %v", err)
|
||||
}
|
||||
|
||||
// the one not deleted should be still there
|
||||
m1, err := db.Get(context.TODO(), &state.GetRequest{Key: fmt.Sprintf(recordIDFormat, 1)})
|
||||
m1, err := db.Get(context.Background(), &state.GetRequest{Key: fmt.Sprintf(recordIDFormat, 1)})
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, m1)
|
||||
assert.NotNil(t, m1.Data)
|
||||
assert.Equal(t, string(d2), string(m1.Data))
|
||||
|
||||
// the one deleted should not
|
||||
m2, err := db.Get(context.TODO(), &state.GetRequest{Key: fmt.Sprintf(recordIDFormat, 3)})
|
||||
m2, err := db.Get(context.Background(), &state.GetRequest{Key: fmt.Sprintf(recordIDFormat, 3)})
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, m2)
|
||||
assert.Nil(t, m2.Data)
|
||||
|
|
|
@ -131,7 +131,7 @@ func getTestStoreWithKeyType(t *testing.T, kt KeyType, indexedProperties string)
|
|||
}
|
||||
|
||||
func assertUserExists(t *testing.T, store *SQLServer, key string) (user, string) {
|
||||
getRes, err := store.Get(context.TODO(), &state.GetRequest{Key: key})
|
||||
getRes, err := store.Get(context.Background(), &state.GetRequest{Key: key})
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, getRes)
|
||||
assert.NotNil(t, getRes.Data, "No data was returned")
|
||||
|
@ -154,7 +154,7 @@ func assertLoadedUserIsEqual(t *testing.T, store *SQLServer, key string, expecte
|
|||
}
|
||||
|
||||
func assertUserDoesNotExist(t *testing.T, store *SQLServer, key string) {
|
||||
_, err := store.Get(context.TODO(), &state.GetRequest{Key: key})
|
||||
_, err := store.Get(context.Background(), &state.GetRequest{Key: key})
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
|
@ -225,14 +225,14 @@ func testSingleOperations(t *testing.T) {
|
|||
assertUserDoesNotExist(t, store, john.ID)
|
||||
|
||||
// Save and read
|
||||
err := store.Set(context.TODO(), &state.SetRequest{Key: john.ID, Value: john})
|
||||
err := store.Set(context.Background(), &state.SetRequest{Key: john.ID, Value: john})
|
||||
assert.Nil(t, err)
|
||||
johnV1, etagFromInsert := assertLoadedUserIsEqual(t, store, john.ID, john)
|
||||
|
||||
// Update with ETAG
|
||||
waterJohn := johnV1
|
||||
waterJohn.FavoriteBeverage = "Water"
|
||||
err = store.Set(context.TODO(), &state.SetRequest{Key: waterJohn.ID, Value: waterJohn, ETag: &etagFromInsert})
|
||||
err = store.Set(context.Background(), &state.SetRequest{Key: waterJohn.ID, Value: waterJohn, ETag: &etagFromInsert})
|
||||
assert.Nil(t, err)
|
||||
|
||||
// Get updated
|
||||
|
@ -241,7 +241,7 @@ func testSingleOperations(t *testing.T) {
|
|||
// Update without ETAG
|
||||
noEtagJohn := johnV2
|
||||
noEtagJohn.FavoriteBeverage = "No Etag John"
|
||||
err = store.Set(context.TODO(), &state.SetRequest{Key: noEtagJohn.ID, Value: noEtagJohn})
|
||||
err = store.Set(context.Background(), &state.SetRequest{Key: noEtagJohn.ID, Value: noEtagJohn})
|
||||
assert.Nil(t, err)
|
||||
|
||||
// 7. Get updated
|
||||
|
@ -250,17 +250,17 @@ func testSingleOperations(t *testing.T) {
|
|||
// 8. Update with invalid ETAG should fail
|
||||
failedJohn := johnV3
|
||||
failedJohn.FavoriteBeverage = "Will not work"
|
||||
err = store.Set(context.TODO(), &state.SetRequest{Key: failedJohn.ID, Value: failedJohn, ETag: &etagFromInsert})
|
||||
err = store.Set(context.Background(), &state.SetRequest{Key: failedJohn.ID, Value: failedJohn, ETag: &etagFromInsert})
|
||||
assert.NotNil(t, err)
|
||||
_, etag := assertLoadedUserIsEqual(t, store, johnV3.ID, johnV3)
|
||||
|
||||
// 9. Delete with invalid ETAG should fail
|
||||
err = store.Delete(context.TODO(), &state.DeleteRequest{Key: johnV3.ID, ETag: &invEtag})
|
||||
err = store.Delete(context.Background(), &state.DeleteRequest{Key: johnV3.ID, ETag: &invEtag})
|
||||
assert.NotNil(t, err)
|
||||
assertLoadedUserIsEqual(t, store, johnV3.ID, johnV3)
|
||||
|
||||
// 10. Delete with valid ETAG
|
||||
err = store.Delete(context.TODO(), &state.DeleteRequest{Key: johnV2.ID, ETag: &etag})
|
||||
err = store.Delete(context.Background(), &state.DeleteRequest{Key: johnV2.ID, ETag: &etag})
|
||||
assert.Nil(t, err)
|
||||
|
||||
assertUserDoesNotExist(t, store, johnV2.ID)
|
||||
|
@ -274,7 +274,7 @@ func testSetNewRecordWithInvalidEtagShouldFail(t *testing.T) {
|
|||
u := user{uuid.New().String(), "John", "Coffee"}
|
||||
|
||||
invEtag := invalidEtag
|
||||
err := store.Set(context.TODO(), &state.SetRequest{Key: u.ID, Value: u, ETag: &invEtag})
|
||||
err := store.Set(context.Background(), &state.SetRequest{Key: u.ID, Value: u, ETag: &invEtag})
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
|
@ -282,7 +282,7 @@ func testSetNewRecordWithInvalidEtagShouldFail(t *testing.T) {
|
|||
func testIndexedProperties(t *testing.T) {
|
||||
store := getTestStore(t, `[{ "column":"FavoriteBeverage", "property":"FavoriteBeverage", "type":"nvarchar(100)"}, { "column":"PetsCount", "property":"PetsCount", "type": "INTEGER"}]`)
|
||||
|
||||
err := store.BulkSet(context.TODO(), []state.SetRequest{
|
||||
err := store.BulkSet(context.Background(), []state.SetRequest{
|
||||
{Key: "1", Value: userWithPets{user{"1", "John", "Coffee"}, 3}},
|
||||
{Key: "2", Value: userWithPets{user{"2", "Laura", "Water"}, 1}},
|
||||
{Key: "3", Value: userWithPets{user{"3", "Carl", "Beer"}, 0}},
|
||||
|
@ -344,7 +344,7 @@ func testMultiOperations(t *testing.T) {
|
|||
bulkSet[i] = state.SetRequest{Key: u.ID, Value: u}
|
||||
}
|
||||
|
||||
err := store.BulkSet(context.TODO(), bulkSet)
|
||||
err := store.BulkSet(context.Background(), bulkSet)
|
||||
assert.Nil(t, err)
|
||||
assertUserCountIsEqualTo(t, store, len(initialUsers))
|
||||
|
||||
|
@ -364,7 +364,7 @@ func testMultiOperations(t *testing.T) {
|
|||
modified := original.user
|
||||
modified.FavoriteBeverage = beverageTea
|
||||
|
||||
localErr := store.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
localErr := store.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: []state.TransactionalStateOperation{
|
||||
{Operation: state.Delete, Request: state.DeleteRequest{Key: toDelete.ID}},
|
||||
{Operation: state.Upsert, Request: state.SetRequest{Key: modified.ID, Value: modified}},
|
||||
|
@ -387,7 +387,7 @@ func testMultiOperations(t *testing.T) {
|
|||
modified := toModify.user
|
||||
modified.FavoriteBeverage = beverageTea
|
||||
|
||||
err = store.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err = store.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: []state.TransactionalStateOperation{
|
||||
{Operation: state.Delete, Request: state.DeleteRequest{Key: toDelete.ID, ETag: &toDelete.etag}},
|
||||
{Operation: state.Upsert, Request: state.SetRequest{Key: modified.ID, Value: modified, ETag: &toModify.etag}},
|
||||
|
@ -411,7 +411,7 @@ func testMultiOperations(t *testing.T) {
|
|||
modified := toModify.user
|
||||
modified.FavoriteBeverage = beverageTea
|
||||
|
||||
err = store.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err = store.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: []state.TransactionalStateOperation{
|
||||
{Operation: state.Delete, Request: state.DeleteRequest{Key: toDelete.ID, ETag: &toDelete.etag}},
|
||||
{Operation: state.Upsert, Request: state.SetRequest{Key: modified.ID, Value: modified, ETag: &toModify.etag}},
|
||||
|
@ -432,7 +432,7 @@ func testMultiOperations(t *testing.T) {
|
|||
toInsert := user{keyGen.NextKey(), "Wont-be-inserted", "Beer"}
|
||||
|
||||
invEtag := invalidEtag
|
||||
err = store.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err = store.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: []state.TransactionalStateOperation{
|
||||
{Operation: state.Delete, Request: state.DeleteRequest{Key: toDelete.ID, ETag: &invEtag}},
|
||||
{Operation: state.Upsert, Request: state.SetRequest{Key: toInsert.ID, Value: toInsert}},
|
||||
|
@ -453,7 +453,7 @@ func testMultiOperations(t *testing.T) {
|
|||
modified.FavoriteBeverage = beverageTea
|
||||
|
||||
invEtag := invalidEtag
|
||||
err = store.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err = store.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: []state.TransactionalStateOperation{
|
||||
{Operation: state.Delete, Request: state.DeleteRequest{Key: toDelete.ID, ETag: &invEtag}},
|
||||
{Operation: state.Upsert, Request: state.SetRequest{Key: modified.ID, Value: modified}},
|
||||
|
@ -473,7 +473,7 @@ func testMultiOperations(t *testing.T) {
|
|||
modified.FavoriteBeverage = beverageTea
|
||||
|
||||
invEtag := invalidEtag
|
||||
err = store.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err = store.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: []state.TransactionalStateOperation{
|
||||
{Operation: state.Delete, Request: state.DeleteRequest{Key: toDelete.ID}},
|
||||
{Operation: state.Upsert, Request: state.SetRequest{Key: modified.ID, Value: modified, ETag: &invEtag}},
|
||||
|
@ -521,7 +521,7 @@ func testBulkSet(t *testing.T) {
|
|||
sets[i] = state.SetRequest{Key: u.ID, Value: u}
|
||||
}
|
||||
|
||||
err := store.BulkSet(context.TODO(), sets)
|
||||
err := store.BulkSet(context.Background(), sets)
|
||||
assert.Nil(t, err)
|
||||
totalUsers = len(sets)
|
||||
assertUserCountIsEqualTo(t, store, totalUsers)
|
||||
|
@ -533,7 +533,7 @@ func testBulkSet(t *testing.T) {
|
|||
modified.FavoriteBeverage = beverageTea
|
||||
toInsert := user{keyGen.NextKey(), "Maria", "Wine"}
|
||||
|
||||
err := store.BulkSet(context.TODO(), []state.SetRequest{
|
||||
err := store.BulkSet(context.Background(), []state.SetRequest{
|
||||
{Key: modified.ID, Value: modified, ETag: &toModifyETag},
|
||||
{Key: toInsert.ID, Value: toInsert},
|
||||
})
|
||||
|
@ -552,7 +552,7 @@ func testBulkSet(t *testing.T) {
|
|||
modified.FavoriteBeverage = beverageTea
|
||||
toInsert := user{keyGen.NextKey(), "Tony", "Milk"}
|
||||
|
||||
err := store.BulkSet(context.TODO(), []state.SetRequest{
|
||||
err := store.BulkSet(context.Background(), []state.SetRequest{
|
||||
{Key: modified.ID, Value: modified},
|
||||
{Key: toInsert.ID, Value: toInsert},
|
||||
})
|
||||
|
@ -579,7 +579,7 @@ func testBulkSet(t *testing.T) {
|
|||
{Key: modified.ID, Value: modified, ETag: &invEtag},
|
||||
}
|
||||
|
||||
err := store.BulkSet(context.TODO(), sets)
|
||||
err := store.BulkSet(context.Background(), sets)
|
||||
assert.NotNil(t, err)
|
||||
assertUserCountIsEqualTo(t, store, totalUsers)
|
||||
assertUserDoesNotExist(t, store, toInsert1.ID)
|
||||
|
@ -622,7 +622,7 @@ func testBulkDelete(t *testing.T) {
|
|||
for i, u := range initialUsers {
|
||||
sets[i] = state.SetRequest{Key: u.ID, Value: u}
|
||||
}
|
||||
err := store.BulkSet(context.TODO(), sets)
|
||||
err := store.BulkSet(context.Background(), sets)
|
||||
assert.Nil(t, err)
|
||||
totalUsers := len(initialUsers)
|
||||
assertUserCountIsEqualTo(t, store, totalUsers)
|
||||
|
@ -632,7 +632,7 @@ func testBulkDelete(t *testing.T) {
|
|||
t.Run("Delete 2 items without etag should work", func(t *testing.T) {
|
||||
deleted1 := initialUsers[userIndex].ID
|
||||
deleted2 := initialUsers[userIndex+1].ID
|
||||
err := store.BulkDelete(context.TODO(), []state.DeleteRequest{
|
||||
err := store.BulkDelete(context.Background(), []state.DeleteRequest{
|
||||
{Key: deleted1},
|
||||
{Key: deleted2},
|
||||
})
|
||||
|
@ -649,7 +649,7 @@ func testBulkDelete(t *testing.T) {
|
|||
deleted1, deleted1Etag := assertUserExists(t, store, initialUsers[userIndex].ID)
|
||||
deleted2, deleted2Etag := assertUserExists(t, store, initialUsers[userIndex+1].ID)
|
||||
|
||||
err := store.BulkDelete(context.TODO(), []state.DeleteRequest{
|
||||
err := store.BulkDelete(context.Background(), []state.DeleteRequest{
|
||||
{Key: deleted1.ID, ETag: &deleted1Etag},
|
||||
{Key: deleted2.ID, ETag: &deleted2Etag},
|
||||
})
|
||||
|
@ -666,7 +666,7 @@ func testBulkDelete(t *testing.T) {
|
|||
deleted1, deleted1Etag := assertUserExists(t, store, initialUsers[userIndex].ID)
|
||||
deleted2 := initialUsers[userIndex+1]
|
||||
|
||||
err := store.BulkDelete(context.TODO(), []state.DeleteRequest{
|
||||
err := store.BulkDelete(context.Background(), []state.DeleteRequest{
|
||||
{Key: deleted1.ID, ETag: &deleted1Etag},
|
||||
{Key: deleted2.ID},
|
||||
})
|
||||
|
@ -684,7 +684,7 @@ func testBulkDelete(t *testing.T) {
|
|||
deleted2 := initialUsers[userIndex+1]
|
||||
|
||||
invEtag := invalidEtag
|
||||
err := store.BulkDelete(context.TODO(), []state.DeleteRequest{
|
||||
err := store.BulkDelete(context.Background(), []state.DeleteRequest{
|
||||
{Key: deleted1.ID, ETag: &deleted1Etag},
|
||||
{Key: deleted2.ID, ETag: &invEtag},
|
||||
})
|
||||
|
@ -704,7 +704,7 @@ func testInsertAndUpdateSetRecordDates(t *testing.T) {
|
|||
store := getTestStore(t, "")
|
||||
|
||||
u := user{"1", "John", "Coffee"}
|
||||
err := store.Set(context.TODO(), &state.SetRequest{Key: u.ID, Value: u})
|
||||
err := store.Set(context.Background(), &state.SetRequest{Key: u.ID, Value: u})
|
||||
assert.Nil(t, err)
|
||||
|
||||
var originalInsertTime time.Time
|
||||
|
@ -726,7 +726,7 @@ func testInsertAndUpdateSetRecordDates(t *testing.T) {
|
|||
|
||||
modified := u
|
||||
modified.FavoriteBeverage = beverageTea
|
||||
err = store.Set(context.TODO(), &state.SetRequest{Key: modified.ID, Value: modified})
|
||||
err = store.Set(context.Background(), &state.SetRequest{Key: modified.ID, Value: modified})
|
||||
assert.Nil(t, err)
|
||||
assertDBQuery(t, store, getUserTsql, func(t *testing.T, rows *sql.Rows) {
|
||||
assert.True(t, rows.Next())
|
||||
|
@ -750,7 +750,7 @@ func testConcurrentSets(t *testing.T) {
|
|||
store := getTestStore(t, "")
|
||||
|
||||
u := user{"1", "John", "Coffee"}
|
||||
err := store.Set(context.TODO(), &state.SetRequest{Key: u.ID, Value: u})
|
||||
err := store.Set(context.Background(), &state.SetRequest{Key: u.ID, Value: u})
|
||||
assert.Nil(t, err)
|
||||
|
||||
_, etag := assertLoadedUserIsEqual(t, store, u.ID, u)
|
||||
|
@ -767,7 +767,7 @@ func testConcurrentSets(t *testing.T) {
|
|||
defer wc.Done()
|
||||
|
||||
modified := user{"1", "John", beverageTea}
|
||||
err := store.Set(context.TODO(), &state.SetRequest{Key: id, Value: modified, ETag: &etag})
|
||||
err := store.Set(context.Background(), &state.SetRequest{Key: id, Value: modified, ETag: &etag})
|
||||
if err != nil {
|
||||
atomic.AddInt32(&totalErrors, 1)
|
||||
} else {
|
||||
|
|
|
@ -27,22 +27,22 @@ func TestStore_withDefaultBulkImpl(t *testing.T) {
|
|||
require.Equal(t, s.count, 0)
|
||||
require.Equal(t, s.bulkCount, 0)
|
||||
|
||||
store.Get(context.TODO(), &GetRequest{})
|
||||
store.Set(context.TODO(), &SetRequest{})
|
||||
store.Delete(context.TODO(), &DeleteRequest{})
|
||||
store.Get(context.Background(), &GetRequest{})
|
||||
store.Set(context.Background(), &SetRequest{})
|
||||
store.Delete(context.Background(), &DeleteRequest{})
|
||||
require.Equal(t, 3, s.count)
|
||||
require.Equal(t, 0, s.bulkCount)
|
||||
|
||||
bulkGet, responses, err := store.BulkGet(context.TODO(), []GetRequest{{}, {}, {}})
|
||||
bulkGet, responses, err := store.BulkGet(context.Background(), []GetRequest{{}, {}, {}})
|
||||
require.Equal(t, false, bulkGet)
|
||||
require.Equal(t, 0, len(responses))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 3, s.count)
|
||||
require.Equal(t, 0, s.bulkCount)
|
||||
store.BulkSet(context.TODO(), []SetRequest{{}, {}, {}, {}})
|
||||
store.BulkSet(context.Background(), []SetRequest{{}, {}, {}, {}})
|
||||
require.Equal(t, 3+4, s.count)
|
||||
require.Equal(t, 0, s.bulkCount)
|
||||
store.BulkDelete(context.TODO(), []DeleteRequest{{}, {}, {}, {}, {}})
|
||||
store.BulkDelete(context.Background(), []DeleteRequest{{}, {}, {}, {}, {}})
|
||||
require.Equal(t, 3+4+5, s.count)
|
||||
require.Equal(t, 0, s.bulkCount)
|
||||
}
|
||||
|
@ -53,20 +53,20 @@ func TestStore_withCustomisedBulkImpl_notSupportBulkGet(t *testing.T) {
|
|||
require.Equal(t, s.count, 0)
|
||||
require.Equal(t, s.bulkCount, 0)
|
||||
|
||||
store.Get(context.TODO(), &GetRequest{})
|
||||
store.Set(context.TODO(), &SetRequest{})
|
||||
store.Delete(context.TODO(), &DeleteRequest{})
|
||||
store.Get(context.Background(), &GetRequest{})
|
||||
store.Set(context.Background(), &SetRequest{})
|
||||
store.Delete(context.Background(), &DeleteRequest{})
|
||||
require.Equal(t, 3, s.count)
|
||||
require.Equal(t, 0, s.bulkCount)
|
||||
|
||||
bulkGet, _, _ := store.BulkGet(context.TODO(), []GetRequest{{}, {}, {}})
|
||||
bulkGet, _, _ := store.BulkGet(context.Background(), []GetRequest{{}, {}, {}})
|
||||
require.Equal(t, false, bulkGet)
|
||||
require.Equal(t, 6, s.count)
|
||||
require.Equal(t, 0, s.bulkCount)
|
||||
store.BulkSet(context.TODO(), []SetRequest{{}, {}, {}, {}})
|
||||
store.BulkSet(context.Background(), []SetRequest{{}, {}, {}, {}})
|
||||
require.Equal(t, 6, s.count)
|
||||
require.Equal(t, 1, s.bulkCount)
|
||||
store.BulkDelete(context.TODO(), []DeleteRequest{{}, {}, {}, {}, {}})
|
||||
store.BulkDelete(context.Background(), []DeleteRequest{{}, {}, {}, {}, {}})
|
||||
require.Equal(t, 6, s.count)
|
||||
require.Equal(t, 2, s.bulkCount)
|
||||
}
|
||||
|
@ -77,20 +77,20 @@ func TestStore_withCustomisedBulkImpl_supportBulkGet(t *testing.T) {
|
|||
require.Equal(t, s.count, 0)
|
||||
require.Equal(t, s.bulkCount, 0)
|
||||
|
||||
store.Get(context.TODO(), &GetRequest{})
|
||||
store.Set(context.TODO(), &SetRequest{})
|
||||
store.Delete(context.TODO(), &DeleteRequest{})
|
||||
store.Get(context.Background(), &GetRequest{})
|
||||
store.Set(context.Background(), &SetRequest{})
|
||||
store.Delete(context.Background(), &DeleteRequest{})
|
||||
require.Equal(t, 3, s.count)
|
||||
require.Equal(t, 0, s.bulkCount)
|
||||
|
||||
bulkGet, _, _ := store.BulkGet(context.TODO(), []GetRequest{{}, {}, {}})
|
||||
bulkGet, _, _ := store.BulkGet(context.Background(), []GetRequest{{}, {}, {}})
|
||||
require.Equal(t, true, bulkGet)
|
||||
require.Equal(t, 3, s.count)
|
||||
require.Equal(t, 1, s.bulkCount)
|
||||
store.BulkSet(context.TODO(), []SetRequest{{}, {}, {}, {}})
|
||||
store.BulkSet(context.Background(), []SetRequest{{}, {}, {}, {}})
|
||||
require.Equal(t, 3, s.count)
|
||||
require.Equal(t, 2, s.bulkCount)
|
||||
store.BulkDelete(context.TODO(), []DeleteRequest{{}, {}, {}, {}, {}})
|
||||
store.BulkDelete(context.Background(), []DeleteRequest{{}, {}, {}, {}, {}})
|
||||
require.Equal(t, 3, s.count)
|
||||
require.Equal(t, 3, s.bulkCount)
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ func TestGet(t *testing.T) {
|
|||
t.Run("With key exists", func(t *testing.T) {
|
||||
conn.EXPECT().Get("foo").Return([]byte("bar"), &zk.Stat{Version: 123}, nil).Times(1)
|
||||
|
||||
res, err := s.Get(context.TODO(), &state.GetRequest{Key: "foo"})
|
||||
res, err := s.Get(context.Background(), &state.GetRequest{Key: "foo"})
|
||||
assert.NotNil(t, res, "Key must be exists")
|
||||
assert.Equal(t, "bar", string(res.Data), "Value must be equals")
|
||||
assert.Equal(t, ptr.String("123"), res.ETag, "ETag must be equals")
|
||||
|
@ -91,7 +91,7 @@ func TestGet(t *testing.T) {
|
|||
t.Run("With key non-exists", func(t *testing.T) {
|
||||
conn.EXPECT().Get("foo").Return(nil, nil, zk.ErrNoNode).Times(1)
|
||||
|
||||
res, err := s.Get(context.TODO(), &state.GetRequest{Key: "foo"})
|
||||
res, err := s.Get(context.Background(), &state.GetRequest{Key: "foo"})
|
||||
assert.Equal(t, &state.GetResponse{}, res, "Response must be empty")
|
||||
assert.NoError(t, err, "Non-existent key must not be treated as error")
|
||||
})
|
||||
|
@ -109,21 +109,21 @@ func TestDelete(t *testing.T) {
|
|||
t.Run("With key", func(t *testing.T) {
|
||||
conn.EXPECT().Delete("foo", int32(anyVersion)).Return(nil).Times(1)
|
||||
|
||||
err := s.Delete(context.TODO(), &state.DeleteRequest{Key: "foo"})
|
||||
err := s.Delete(context.Background(), &state.DeleteRequest{Key: "foo"})
|
||||
assert.NoError(t, err, "Key must be exists")
|
||||
})
|
||||
|
||||
t.Run("With key and version", func(t *testing.T) {
|
||||
conn.EXPECT().Delete("foo", int32(123)).Return(nil).Times(1)
|
||||
|
||||
err := s.Delete(context.TODO(), &state.DeleteRequest{Key: "foo", ETag: &etag})
|
||||
err := s.Delete(context.Background(), &state.DeleteRequest{Key: "foo", ETag: &etag})
|
||||
assert.NoError(t, err, "Key must be exists")
|
||||
})
|
||||
|
||||
t.Run("With key and concurrency", func(t *testing.T) {
|
||||
conn.EXPECT().Delete("foo", int32(anyVersion)).Return(nil).Times(1)
|
||||
|
||||
err := s.Delete(context.TODO(), &state.DeleteRequest{
|
||||
err := s.Delete(context.Background(), &state.DeleteRequest{
|
||||
Key: "foo",
|
||||
ETag: &etag,
|
||||
Options: state.DeleteStateOption{Concurrency: state.LastWrite},
|
||||
|
@ -134,14 +134,14 @@ func TestDelete(t *testing.T) {
|
|||
t.Run("With delete error", func(t *testing.T) {
|
||||
conn.EXPECT().Delete("foo", int32(anyVersion)).Return(zk.ErrUnknown).Times(1)
|
||||
|
||||
err := s.Delete(context.TODO(), &state.DeleteRequest{Key: "foo"})
|
||||
err := s.Delete(context.Background(), &state.DeleteRequest{Key: "foo"})
|
||||
assert.EqualError(t, err, "zk: unknown error")
|
||||
})
|
||||
|
||||
t.Run("With delete and ignore NoNode error", func(t *testing.T) {
|
||||
conn.EXPECT().Delete("foo", int32(anyVersion)).Return(zk.ErrNoNode).Times(1)
|
||||
|
||||
err := s.Delete(context.TODO(), &state.DeleteRequest{Key: "foo"})
|
||||
err := s.Delete(context.Background(), &state.DeleteRequest{Key: "foo"})
|
||||
assert.NoError(t, err, "Delete must be successful")
|
||||
})
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ func TestBulkDelete(t *testing.T) {
|
|||
&zk.DeleteRequest{Path: "bar", Version: int32(anyVersion)},
|
||||
}).Return([]zk.MultiResponse{{}, {}}, nil).Times(1)
|
||||
|
||||
err := s.BulkDelete(context.TODO(), []state.DeleteRequest{{Key: "foo"}, {Key: "bar"}})
|
||||
err := s.BulkDelete(context.Background(), []state.DeleteRequest{{Key: "foo"}, {Key: "bar"}})
|
||||
assert.NoError(t, err, "Key must be exists")
|
||||
})
|
||||
|
||||
|
@ -172,7 +172,7 @@ func TestBulkDelete(t *testing.T) {
|
|||
{Error: zk.ErrUnknown}, {Error: zk.ErrNoAuth},
|
||||
}, nil).Times(1)
|
||||
|
||||
err := s.BulkDelete(context.TODO(), []state.DeleteRequest{{Key: "foo"}, {Key: "bar"}})
|
||||
err := s.BulkDelete(context.Background(), []state.DeleteRequest{{Key: "foo"}, {Key: "bar"}})
|
||||
assert.Equal(t, err.(*multierror.Error).Errors, []error{zk.ErrUnknown, zk.ErrNoAuth})
|
||||
})
|
||||
t.Run("With keys and ignore NoNode error", func(t *testing.T) {
|
||||
|
@ -183,7 +183,7 @@ func TestBulkDelete(t *testing.T) {
|
|||
{Error: zk.ErrNoNode}, {},
|
||||
}, nil).Times(1)
|
||||
|
||||
err := s.BulkDelete(context.TODO(), []state.DeleteRequest{{Key: "foo"}, {Key: "bar"}})
|
||||
err := s.BulkDelete(context.Background(), []state.DeleteRequest{{Key: "foo"}, {Key: "bar"}})
|
||||
assert.NoError(t, err, "Key must be exists")
|
||||
})
|
||||
}
|
||||
|
@ -202,19 +202,19 @@ func TestSet(t *testing.T) {
|
|||
t.Run("With key", func(t *testing.T) {
|
||||
conn.EXPECT().Set("foo", []byte("\"bar\""), int32(anyVersion)).Return(stat, nil).Times(1)
|
||||
|
||||
err := s.Set(context.TODO(), &state.SetRequest{Key: "foo", Value: "bar"})
|
||||
err := s.Set(context.Background(), &state.SetRequest{Key: "foo", Value: "bar"})
|
||||
assert.NoError(t, err, "Key must be set")
|
||||
})
|
||||
t.Run("With key and version", func(t *testing.T) {
|
||||
conn.EXPECT().Set("foo", []byte("\"bar\""), int32(123)).Return(stat, nil).Times(1)
|
||||
|
||||
err := s.Set(context.TODO(), &state.SetRequest{Key: "foo", Value: "bar", ETag: &etag})
|
||||
err := s.Set(context.Background(), &state.SetRequest{Key: "foo", Value: "bar", ETag: &etag})
|
||||
assert.NoError(t, err, "Key must be set")
|
||||
})
|
||||
t.Run("With key and concurrency", func(t *testing.T) {
|
||||
conn.EXPECT().Set("foo", []byte("\"bar\""), int32(anyVersion)).Return(stat, nil).Times(1)
|
||||
|
||||
err := s.Set(context.TODO(), &state.SetRequest{
|
||||
err := s.Set(context.Background(), &state.SetRequest{
|
||||
Key: "foo",
|
||||
Value: "bar",
|
||||
ETag: &etag,
|
||||
|
@ -226,14 +226,14 @@ func TestSet(t *testing.T) {
|
|||
t.Run("With error", func(t *testing.T) {
|
||||
conn.EXPECT().Set("foo", []byte("\"bar\""), int32(anyVersion)).Return(nil, zk.ErrUnknown).Times(1)
|
||||
|
||||
err := s.Set(context.TODO(), &state.SetRequest{Key: "foo", Value: "bar"})
|
||||
err := s.Set(context.Background(), &state.SetRequest{Key: "foo", Value: "bar"})
|
||||
assert.EqualError(t, err, "zk: unknown error")
|
||||
})
|
||||
t.Run("With NoNode error and retry", func(t *testing.T) {
|
||||
conn.EXPECT().Set("foo", []byte("\"bar\""), int32(anyVersion)).Return(nil, zk.ErrNoNode).Times(1)
|
||||
conn.EXPECT().Create("foo", []byte("\"bar\""), int32(0), nil).Return("/foo", nil).Times(1)
|
||||
|
||||
err := s.Set(context.TODO(), &state.SetRequest{Key: "foo", Value: "bar"})
|
||||
err := s.Set(context.Background(), &state.SetRequest{Key: "foo", Value: "bar"})
|
||||
assert.NoError(t, err, "Key must be create")
|
||||
})
|
||||
}
|
||||
|
@ -252,7 +252,7 @@ func TestBulkSet(t *testing.T) {
|
|||
&zk.SetDataRequest{Path: "bar", Data: []byte("\"foo\""), Version: int32(anyVersion)},
|
||||
}).Return([]zk.MultiResponse{{}, {}}, nil).Times(1)
|
||||
|
||||
err := s.BulkSet(context.TODO(), []state.SetRequest{
|
||||
err := s.BulkSet(context.Background(), []state.SetRequest{
|
||||
{Key: "foo", Value: "bar"},
|
||||
{Key: "bar", Value: "foo"},
|
||||
})
|
||||
|
@ -267,7 +267,7 @@ func TestBulkSet(t *testing.T) {
|
|||
{Error: zk.ErrUnknown}, {Error: zk.ErrNoAuth},
|
||||
}, nil).Times(1)
|
||||
|
||||
err := s.BulkSet(context.TODO(), []state.SetRequest{
|
||||
err := s.BulkSet(context.Background(), []state.SetRequest{
|
||||
{Key: "foo", Value: "bar"},
|
||||
{Key: "bar", Value: "foo"},
|
||||
})
|
||||
|
@ -284,7 +284,7 @@ func TestBulkSet(t *testing.T) {
|
|||
&zk.CreateRequest{Path: "foo", Data: []byte("\"bar\"")},
|
||||
}).Return([]zk.MultiResponse{{}, {}}, nil).Times(1)
|
||||
|
||||
err := s.BulkSet(context.TODO(), []state.SetRequest{
|
||||
err := s.BulkSet(context.Background(), []state.SetRequest{
|
||||
{Key: "foo", Value: "bar"},
|
||||
{Key: "bar", Value: "foo"},
|
||||
})
|
||||
|
|
|
@ -91,37 +91,37 @@ func TestPostgreSQL(t *testing.T) {
|
|||
eTagTest := func(ctx flow.Context) error {
|
||||
etag900invalid := "900invalid"
|
||||
|
||||
err1 := stateStore.Set(context.TODO(), &state.SetRequest{
|
||||
err1 := stateStore.Set(context.Background(), &state.SetRequest{
|
||||
Key: "k",
|
||||
Value: "v1",
|
||||
})
|
||||
assert.NoError(t, err1)
|
||||
resp1, err2 := stateStore.Get(context.TODO(), &state.GetRequest{
|
||||
resp1, err2 := stateStore.Get(context.Background(), &state.GetRequest{
|
||||
Key: "k",
|
||||
})
|
||||
|
||||
assert.NoError(t, err2)
|
||||
err3 := stateStore.Set(context.TODO(), &state.SetRequest{
|
||||
err3 := stateStore.Set(context.Background(), &state.SetRequest{
|
||||
Key: "k",
|
||||
Value: "v2",
|
||||
ETag: resp1.ETag,
|
||||
})
|
||||
assert.NoError(t, err3)
|
||||
|
||||
resp11, err12 := stateStore.Get(context.TODO(), &state.GetRequest{
|
||||
resp11, err12 := stateStore.Get(context.Background(), &state.GetRequest{
|
||||
Key: "k",
|
||||
})
|
||||
expectedEtag := *resp11.ETag
|
||||
assert.NoError(t, err12)
|
||||
|
||||
err4 := stateStore.Set(context.TODO(), &state.SetRequest{
|
||||
err4 := stateStore.Set(context.Background(), &state.SetRequest{
|
||||
Key: "k",
|
||||
Value: "v3",
|
||||
ETag: &etag900invalid,
|
||||
})
|
||||
|
||||
assert.Error(t, err4)
|
||||
resp, err := stateStore.Get(context.TODO(), &state.GetRequest{
|
||||
resp, err := stateStore.Get(context.Background(), &state.GetRequest{
|
||||
Key: "k",
|
||||
})
|
||||
|
||||
|
@ -133,7 +133,7 @@ func TestPostgreSQL(t *testing.T) {
|
|||
}
|
||||
|
||||
transactionsTest := func(ctx flow.Context) error {
|
||||
err := stateStore.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := stateStore.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: []state.TransactionalStateOperation{
|
||||
{
|
||||
Operation: state.Upsert,
|
||||
|
@ -185,12 +185,12 @@ func TestPostgreSQL(t *testing.T) {
|
|||
},
|
||||
})
|
||||
assert.Equal(t, nil, err)
|
||||
resp1, err := stateStore.Get(context.TODO(), &state.GetRequest{
|
||||
resp1, err := stateStore.Get(context.Background(), &state.GetRequest{
|
||||
Key: "reqKey1",
|
||||
})
|
||||
assert.Equal(t, "\"reqVal101\"", string(resp1.Data))
|
||||
|
||||
resp3, err := stateStore.Get(context.TODO(), &state.GetRequest{
|
||||
resp3, err := stateStore.Get(context.Background(), &state.GetRequest{
|
||||
Key: "reqKey3",
|
||||
})
|
||||
assert.Equal(t, "\"reqVal103\"", string(resp3.Data))
|
||||
|
|
|
@ -165,24 +165,24 @@ func TestRedis(t *testing.T) {
|
|||
etag1 := "1"
|
||||
etag100 := "100"
|
||||
|
||||
err1 := stateStore.Set(context.TODO(), &state.SetRequest{
|
||||
err1 := stateStore.Set(context.Background(), &state.SetRequest{
|
||||
Key: "k",
|
||||
Value: "v1",
|
||||
})
|
||||
assert.Equal(t, nil, err1)
|
||||
err2 := stateStore.Set(context.TODO(), &state.SetRequest{
|
||||
err2 := stateStore.Set(context.Background(), &state.SetRequest{
|
||||
Key: "k",
|
||||
Value: "v2",
|
||||
ETag: &etag1,
|
||||
})
|
||||
assert.Equal(t, nil, err2)
|
||||
err3 := stateStore.Set(context.TODO(), &state.SetRequest{
|
||||
err3 := stateStore.Set(context.Background(), &state.SetRequest{
|
||||
Key: "k",
|
||||
Value: "v3",
|
||||
ETag: &etag100,
|
||||
})
|
||||
assert.Error(t, err3)
|
||||
resp, err := stateStore.Get(context.TODO(), &state.GetRequest{
|
||||
resp, err := stateStore.Get(context.Background(), &state.GetRequest{
|
||||
Key: "k",
|
||||
})
|
||||
assert.Equal(t, nil, err)
|
||||
|
@ -194,7 +194,7 @@ func TestRedis(t *testing.T) {
|
|||
|
||||
// Transaction related test - also for Multi
|
||||
upsertTest := func(ctx flow.Context) error {
|
||||
err := stateStore.Multi(context.TODO(), &state.TransactionalStateRequest{
|
||||
err := stateStore.Multi(context.Background(), &state.TransactionalStateRequest{
|
||||
Operations: []state.TransactionalStateOperation{
|
||||
{
|
||||
Operation: state.Upsert,
|
||||
|
@ -246,13 +246,13 @@ func TestRedis(t *testing.T) {
|
|||
},
|
||||
})
|
||||
assert.Equal(t, nil, err)
|
||||
resp1, err := stateStore.Get(context.TODO(), &state.GetRequest{
|
||||
resp1, err := stateStore.Get(context.Background(), &state.GetRequest{
|
||||
Key: "reqKey1",
|
||||
})
|
||||
assert.Equal(t, "2", *resp1.ETag)
|
||||
assert.Equal(t, "\"reqVal101\"", string(resp1.Data))
|
||||
|
||||
resp3, err := stateStore.Get(context.TODO(), &state.GetRequest{
|
||||
resp3, err := stateStore.Get(context.Background(), &state.GetRequest{
|
||||
Key: "reqKey3",
|
||||
})
|
||||
assert.Equal(t, "2", *resp3.ETag)
|
||||
|
|
Loading…
Reference in New Issue