Skip to content

Commit

Permalink
Do Execute after Filler Lease Set
Browse files Browse the repository at this point in the history
  • Loading branch information
tung.tq committed Feb 16, 2023
1 parent bbf9adf commit c51a1ce
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 4 deletions.
2 changes: 2 additions & 0 deletions fake/fake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,7 @@ func TestPipeline__Do_Finish(t *testing.T) {
sess.Execute()

assert.Equal(t, 1, calls)

assert.Nil(t, mc.Close())
})
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/QuangTung97/memproxy
go 1.19

require (
github.com/QuangTung97/go-memcache v0.4.0
github.com/QuangTung97/go-memcache v0.4.1
github.com/matryer/moq v0.3.0
github.com/mgechev/revive v1.2.4
github.com/spaolacci/murmur3 v1.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/GoogleCloudPlatform/cloudsql-proxy v0.0.0-20190129172621-c8b1d7a94ddf/go.mod h1:aJ4qN3TfrelA6NZ6AXsXRfmEVaYin3EDbSPJrKS8OXo=
github.com/QuangTung97/go-memcache v0.4.0 h1:H4TC6Je9YPoUFCrCoyewyN0e6hy51K+0zQcdyox89lA=
github.com/QuangTung97/go-memcache v0.4.0/go.mod h1:Ah+XGAIgskqFgAhZrW4lRvcvDk5Lg2F7LouZCK4ptao=
github.com/QuangTung97/go-memcache v0.4.1 h1:JRVkcgFKhHvSuCInuUlT6K5Kc7o+mDlN/l3yq2DHq9s=
github.com/QuangTung97/go-memcache v0.4.1/go.mod h1:Ah+XGAIgskqFgAhZrW4lRvcvDk5Lg2F7LouZCK4ptao=
github.com/aclements/go-gg v0.0.0-20170118225347-6dbb4e4fefb0/go.mod h1:55qNq4vcpkIuHowELi5C8e+1yUHtoLoOUR9QU5j7Tes=
github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794 h1:xlwdaKcTNVW4PtpQb8aKA4Pjy0CdJHEqvFbAnvR5m2g=
github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794/go.mod h1:7e+I0LQFUI9AXWxOfsQROs9xPhoJtbsyWcjJqDd4KPY=
Expand Down
3 changes: 2 additions & 1 deletion item/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ func (i *Item[T, K]) handleLeaseGranted(
setResponse(fillResp)

if cas > 0 {
i.pipeline.LeaseSet(keyStr, data, cas, memproxy.LeaseSetOptions{})
_ = i.pipeline.LeaseSet(keyStr, data, cas, memproxy.LeaseSetOptions{})
i.sess.AddNextCall(i.pipeline.Execute)
}
})
}
Expand Down
15 changes: 15 additions & 0 deletions item/item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func leaseSetAction(key string) string {
return "lease-set: " + key
}

func leaseSetFuncAction(key string) string {
return "lease-set-func: " + key
}

func fillAction(key string) string {
return "fill: " + key
}
Expand All @@ -91,6 +95,10 @@ func fillFuncAction(key string) string {
return "fill-func: " + key
}

func executeAction() string {
return "execute-func"
}

func newItemTest(options ...Option) *itemTest {
return newItemTestWithSleepDurations(DefaultSleepDurations(), options...)
}
Expand Down Expand Up @@ -132,6 +140,7 @@ func newItemTestWithSleepDurations(
pipe.LowerSessionFunc = func() memproxy.Session {
return sess
}
pipe.ExecuteFunc = func() { i.appendAction(executeAction()) }

i.sess = sess
i.pipe = pipe
Expand Down Expand Up @@ -187,6 +196,7 @@ func (i *itemTest) stubLeaseSet() {
) func() (memproxy.LeaseSetResponse, error) {
i.appendAction(leaseSetAction(key))
return func() (memproxy.LeaseSetResponse, error) {
i.appendAction(leaseSetFuncAction(key))
return memproxy.LeaseSetResponse{}, nil
}
}
Expand Down Expand Up @@ -781,6 +791,9 @@ func TestItem__Multi(t *testing.T) {

fillFuncAction(user2.GetKey().String()),
leaseSetAction(user2.GetKey().String()),

executeAction(),
executeAction(),
}, i.actions)
})

Expand Down Expand Up @@ -830,6 +843,8 @@ func TestItem__Multi(t *testing.T) {

fillFuncAction(user1.GetKey().String()),
leaseSetAction(user1.GetKey().String()),

executeAction(),
}, i.actions)
})
}
Expand Down
8 changes: 8 additions & 0 deletions mhash/mhash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func newHashTest(options ...Option) *hashTest {
pipe.LowerSessionFunc = func() memproxy.Session {
return sess
}
pipe.ExecuteFunc = func() {}

h := &hashTest{
pipe: pipe,
Expand Down Expand Up @@ -965,6 +966,10 @@ func TestHash_Concurrent(t *testing.T) {
}
}

h.pipe.ExecuteFunc = func() {
callOrders = append(callOrders, "execute")
}

fn2 := h.hash.Get(newContext(),
customerUsageRootKey{
Tenant: "TENANT02",
Expand Down Expand Up @@ -1000,6 +1005,9 @@ func TestHash_Concurrent(t *testing.T) {
"lease-set-call:TENANT01:41:",
"filler-func:TENANT02:42:",
"lease-set-call:TENANT02:42:",

"execute",
"execute",
}, callOrders)

getCalls := h.pipe.LeaseGetCalls()
Expand Down
2 changes: 2 additions & 0 deletions mhash/property_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ func newPropertyTest(maxHashesPerBucket int) *propertyTest {
return sess
}

pipe.ExecuteFunc = func() {}

bucketDataMap := map[BucketKey[customerUsageRootKey]][]byte{}

var filler Filler[customerUsageRootKey] = func(
Expand Down

0 comments on commit c51a1ce

Please sign in to comment.