MCPcopy
hub / github.com/grafana/dskit / TestMemcachedClient_GetMulti

Function TestMemcachedClient_GetMulti

cache/memcached_client_test.go:109–158  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

107}
108
109func TestMemcachedClient_GetMulti(t *testing.T) {
110 t.Run("no allocator", func(t *testing.T) {
111 client, backend, err := setupDefaultMemcachedClient()
112 require.NoError(t, err)
113 client.SetAsync("foo", []byte("bar"), 10*time.Second)
114 require.NoError(t, client.wait())
115
116 ctx := context.Background()
117 res := client.GetMulti(ctx, []string{"foo"})
118 require.Equal(t, map[string][]byte{"foo": []byte("bar")}, res)
119 require.Equal(t, 0, backend.allocations)
120 })
121
122 t.Run("with allocator", func(t *testing.T) {
123 client, backend, err := setupDefaultMemcachedClient()
124 require.NoError(t, err)
125 client.SetAsync("foo", []byte("bar"), 10*time.Second)
126 require.NoError(t, client.wait())
127
128 res := client.GetMulti(context.Background(), []string{"foo"}, WithAllocator(&nopAllocator{}))
129 require.Equal(t, map[string][]byte{"foo": []byte("bar")}, res)
130 require.Equal(t, 1, backend.allocations)
131 })
132
133 t.Run("multiple batches", func(t *testing.T) {
134 client, backend, err := setupDefaultMemcachedClient()
135 client.config.MaxGetMultiBatchSize = 2
136
137 require.NoError(t, err)
138 client.SetMultiAsync(map[string][]byte{
139 "foo1": []byte("bar1"),
140 "foo2": []byte("bar2"),
141 "foo3": []byte("bar3"),
142 "foo4": []byte("bar4"),
143 "foo5": []byte("bar5"),
144 }, 10*time.Second)
145 require.NoError(t, client.wait())
146
147 ctx := context.Background()
148 res := client.GetMulti(ctx, []string{"foo1", "foo2", "foo3", "foo4", "foo5"})
149 require.Equal(t, map[string][]byte{
150 "foo1": []byte("bar1"),
151 "foo2": []byte("bar2"),
152 "foo3": []byte("bar3"),
153 "foo4": []byte("bar4"),
154 "foo5": []byte("bar5"),
155 }, res)
156 require.Equal(t, 0, backend.allocations)
157 })
158}
159
160func TestMemcachedClient_GetMultiWithError(t *testing.T) {
161 t.Run("returns error from backend", func(t *testing.T) {

Callers

nothing calls this directly

Calls 8

WithAllocatorFunction · 0.85
RunMethod · 0.80
waitMethod · 0.80
SetAsyncMethod · 0.65
GetMultiMethod · 0.65
SetMultiAsyncMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected