mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-30 23:09:23 +02:00
storage: add minimum record version hint (#5569)
* storage: add minimum record version hint * use response record version * fix record version in query response
This commit is contained in:
parent
cd731789be
commit
3891293fa7
8 changed files with 433 additions and 297 deletions
78
pkg/storage/querier_caching_test.go
Normal file
78
pkg/storage/querier_caching_test.go
Normal file
|
@ -0,0 +1,78 @@
|
|||
package storage_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/testing/protocmp"
|
||||
|
||||
"github.com/pomerium/pomerium/internal/testutil"
|
||||
databrokerpb "github.com/pomerium/pomerium/pkg/grpc/databroker"
|
||||
"github.com/pomerium/pomerium/pkg/storage"
|
||||
)
|
||||
|
||||
func TestCachingQuerier(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx := testutil.GetContext(t, time.Minute)
|
||||
cache := storage.NewGlobalCache(time.Hour)
|
||||
q1 := storage.NewStaticQuerier(&databrokerpb.Record{
|
||||
Version: 1,
|
||||
Type: "t1",
|
||||
Id: "r1",
|
||||
})
|
||||
q2 := storage.NewStaticQuerier(&databrokerpb.Record{
|
||||
Version: 2,
|
||||
Type: "t1",
|
||||
Id: "r1",
|
||||
})
|
||||
|
||||
res, err := storage.NewCachingQuerier(q1, cache).Query(ctx, &databrokerpb.QueryRequest{
|
||||
Type: "t1",
|
||||
Limit: 1,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, cmp.Diff(&databrokerpb.QueryResponse{
|
||||
Records: []*databrokerpb.Record{{Version: 1, Type: "t1", Id: "r1"}},
|
||||
TotalCount: 1,
|
||||
RecordVersion: 1,
|
||||
}, res, protocmp.Transform()))
|
||||
|
||||
res, err = storage.NewCachingQuerier(q2, cache).Query(ctx, &databrokerpb.QueryRequest{
|
||||
Type: "t1",
|
||||
Limit: 1,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, cmp.Diff(&databrokerpb.QueryResponse{
|
||||
Records: []*databrokerpb.Record{{Version: 1, Type: "t1", Id: "r1"}},
|
||||
TotalCount: 1,
|
||||
RecordVersion: 1,
|
||||
}, res, protocmp.Transform()), "should use the cached version")
|
||||
|
||||
res, err = storage.NewCachingQuerier(q2, cache).Query(ctx, &databrokerpb.QueryRequest{
|
||||
Type: "t1",
|
||||
Limit: 1,
|
||||
MinimumRecordVersionHint: proto.Uint64(1),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, cmp.Diff(&databrokerpb.QueryResponse{
|
||||
Records: []*databrokerpb.Record{{Version: 1, Type: "t1", Id: "r1"}},
|
||||
TotalCount: 1,
|
||||
RecordVersion: 1,
|
||||
}, res, protocmp.Transform()), "should use the cached version")
|
||||
|
||||
res, err = storage.NewCachingQuerier(q2, cache).Query(ctx, &databrokerpb.QueryRequest{
|
||||
Type: "t1",
|
||||
Limit: 1,
|
||||
MinimumRecordVersionHint: proto.Uint64(2),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, cmp.Diff(&databrokerpb.QueryResponse{
|
||||
Records: []*databrokerpb.Record{{Version: 2, Type: "t1", Id: "r1"}},
|
||||
TotalCount: 1,
|
||||
RecordVersion: 2,
|
||||
}, res, protocmp.Transform()), "should query the new version")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue