Skip to content

Commit

Permalink
fix: broken test cases and unimplemented interface (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
tokers committed Oct 25, 2021
1 parent 91955bc commit e27f30b
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 14 deletions.
11 changes: 9 additions & 2 deletions backends/btree/btree.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ func (b *btreeCache) getLocked(_ context.Context, key string, revision int64) (i

}

func (b *btreeCache) DbSize(_ context.Context) (int64, error) {
return 0, nil
}

func (b *btreeCache) Create(_ context.Context, key string, value []byte, lease int64) (int64, error) {
b.Lock()
defer b.Unlock()
Expand Down Expand Up @@ -273,7 +277,7 @@ func (b *btreeCache) Watch(ctx context.Context, key string, startRevision int64)
b.Lock()
defer b.Unlock()
w := &watcher{
// use the current revisoin as the historical events will be handled at the first time.
// use the current revision as the historical events will be handled at the first time.
startRev: b.currentRevision + 1,
ch: make(chan []*server.Event, 1),
}
Expand Down Expand Up @@ -348,6 +352,9 @@ func (b *btreeCache) makeEvent(kv, prevKV *server.KeyValue, deleteEvent bool) {
if deleteEvent {
ev = &server.Event{
Delete: true,
// Kine uses KV field to get the mod revision, so even for delete event,
// add the kv field.
KV: prevKV,
PrevKV: prevKV,
}
} else {
Expand All @@ -361,7 +368,7 @@ func (b *btreeCache) makeEvent(kv, prevKV *server.KeyValue, deleteEvent bool) {
}

func (b *btreeCache) sendEvents(ctx context.Context) {
// We cleanup the event backlog per 500ms.
// We clean up the event backlog per 500ms.
ticker := time.NewTicker(500 * time.Millisecond)
defer ticker.Stop()
for {
Expand Down
2 changes: 1 addition & 1 deletion etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewEtcdAdapter(opts *AdapterOptions) Adapter {
logger = zap.NewExample()
}
backend := btree.NewBTreeCache(logger)
bridge := server.New(backend)
bridge := server.New(backend, "")
a := &adapter{
logger: logger,
eventsCh: make(chan []*Event),
Expand Down
10 changes: 5 additions & 5 deletions etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func TestEtcdAdapter(t *testing.T) {
resp, err = client.Get(context.Background(), "/apisix/routes", clientv3.WithPrefix())
assert.Nil(t, err, "checking error")
assert.Len(t, resp.Kvs, 2, "checking number of kvs")
assert.Equal(t, resp.Kvs[0].Key, "/apisix/routes/1")
assert.Equal(t, resp.Kvs[1].Key, "/apisix/routes/2")
assert.Equal(t, string(resp.Kvs[0].Key), "/apisix/routes/1")
assert.Equal(t, string(resp.Kvs[1].Key), "/apisix/routes/2")

events = []*Event{
{
Expand Down Expand Up @@ -157,10 +157,10 @@ func TestEtcdAdapterWatch(t *testing.T) {
resp := <-ch
assert.Len(t, resp.Events, 2)
assert.Equal(t, resp.Events[0].Type, clientv3.EventTypePut)
assert.Equal(t, resp.Events[0].Kv.Key, "/apisix/routes/1")
assert.Equal(t, string(resp.Events[0].Kv.Key), "/apisix/routes/1")
assert.Equal(t, resp.Events[0].Kv.Value, []byte("123"))
assert.Equal(t, resp.Events[1].Type, clientv3.EventTypePut)
assert.Equal(t, resp.Events[1].Kv.Key, "/apisix/routes/1")
assert.Equal(t, string(resp.Events[1].Kv.Key), "/apisix/routes/1")
assert.Equal(t, resp.Events[1].Kv.Value, []byte("456"))

events = []*Event{
Expand All @@ -173,7 +173,7 @@ func TestEtcdAdapterWatch(t *testing.T) {
resp = <-ch
assert.Len(t, resp.Events, 1)
assert.Equal(t, resp.Events[0].Type, clientv3.EventTypeDelete)
assert.Equal(t, resp.Events[0].PrevKv.Key, "/apisix/routes/1")
assert.Equal(t, string(resp.Events[0].PrevKv.Key), "/apisix/routes/1")
assert.Equal(t, resp.Events[0].PrevKv.Value, []byte("456"))

cancel()
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ go 1.16

require (
github.com/google/btree v1.0.1
github.com/gorilla/websocket v1.4.2 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/k3s-io/kine v0.7.2
github.com/k3s-io/kine v0.8.0
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/soheilhy/cmux v0.1.5
github.com/stretchr/testify v1.7.0
Expand Down
Loading

0 comments on commit e27f30b

Please sign in to comment.