Skip to content

Commit

Permalink
Make Fallback Scan call call main scan function (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
ViddyCat authored Jun 5, 2020
1 parent 4fae734 commit 6b4cb1b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

## v3.4.29 (unreleased)
- Nothing changed yet.
- Make fallback cache Scan API call connector Scan API instead of Range

## v3.4.28 (2020-04-06)
- Problem with v.4.27, needed to re-release.
Expand Down
4 changes: 2 additions & 2 deletions connectors/cache/fallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ func (c *Connector) Range(ctx context.Context, ei *dosa.EntityInfo, columnCondit

// Scan returns scan result from origin.
func (c *Connector) Scan(ctx context.Context, ei *dosa.EntityInfo, minimumFields []string, token string, limit int) ([]map[string]dosa.FieldValue, string, error) {
// Scan will just call range with no conditions
return c.Range(ctx, ei, nil, minimumFields, token, limit)
// Make Scan call call Scan directly
return c.Next.Scan(ctx, ei, minimumFields, token, limit)
}

// MultiRead reads from fallback for the keys that failed
Expand Down
16 changes: 8 additions & 8 deletions connectors/cache/fallback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ func TestScan(t *testing.T) {

rangeResponse := []map[string]dosa.FieldValue{{"a": "b"}}
rangeTok := "nextToken"
mockOrigin.EXPECT().Range(context.TODO(), testEi, nil, dosa.All(), "token", 2).Return(rangeResponse, rangeTok, nil)
mockOrigin.EXPECT().Scan(context.TODO(), testEi, []string{}, "token", 2).Return(rangeResponse, rangeTok, nil)

connector := NewConnector(mockOrigin, memory.NewConnector(), nil, nil)
resp, tok, err := connector.Scan(context.TODO(), testEi, []string{}, "token", 2)
Expand Down Expand Up @@ -1207,8 +1207,8 @@ func TestCacheInvalidationPerConfigurations(t *testing.T) {
"tsvp": &testTime,
}

// Cache endpoint config
endpoint := "getEaterPromotions"
// Cache endpoint config
endpoint := "getEaterPromotions"
endpoints := []string{endpoint}
ctx := context.Background()
ctx = SetContextEndpoint(ctx, endpoint)
Expand All @@ -1218,10 +1218,10 @@ func TestCacheInvalidationPerConfigurations(t *testing.T) {
// Fake origin read failing, and then read from redis
mockDownstreamConnector.EXPECT().Read(ctx, testEi, values, dosa.All()).Return(nil, assert.AnError)

connector := NewConnector(mockDownstreamConnector, redisC, nil, cacheableEntities, SetCacheableEndpoints(endpoints...))
connector := NewConnector(mockDownstreamConnector, redisC, nil, cacheableEntities, SetCacheableEndpoints(endpoints...))
connector.setSynchronousMode(true)

// This should return the redis cached value
// This should return the redis cached value
_, err := connector.Read(ctx, testEi, values, nil)
assert.NoError(t, err)

Expand Down Expand Up @@ -1256,19 +1256,19 @@ func TestCacheInvalidationPerConfigurations(t *testing.T) {

assert.EqualValues(t, expectedResult, resp)

// Now upsert data which should remove it from cache
// Now upsert data which should remove it from cache
values = map[string]dosa.FieldValue{
"an_uuid_key": testUUID,
"strkey": "test key string",
"StrV": "test value string",
"BoolV": false,
}
// Expect an upsert call, this should invalidate the cache
// Expect an upsert call, this should invalidate the cache
mockDownstreamConnector.EXPECT().Upsert(ctx, testEi, values).Return(nil)
err = connector.Upsert(ctx, testEi, values)
assert.NoError(t, err)

// Make a read call, make downstream call fail, the redis cache should also return assert.AnError
// Make a read call, make downstream call fail, the redis cache should also return assert.AnError
mockDownstreamConnector.EXPECT().Read(ctx, testEi, values, dosa.All()).Return(nil, assert.AnError)
resp, err = connector.Read(ctx, testEi, values, nil)
assert.Error(t, err)
Expand Down

0 comments on commit 6b4cb1b

Please sign in to comment.