|
| 1 | +/* |
| 2 | +Copyright 2025 The llm-d Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package kvblock_test |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/llm-d/llm-d-kv-cache-manager/pkg/kvcache/kvblock" |
| 23 | + "github.com/stretchr/testify/assert" |
| 24 | + "k8s.io/apimachinery/pkg/util/sets" |
| 25 | +) |
| 26 | + |
| 27 | +// testAddBasic is a common test helper function for testing basic Add and Lookup functionality. |
| 28 | +func testAddBasic(t *testing.T, index kvblock.Index) { |
| 29 | + t.Helper() |
| 30 | + |
| 31 | + key := kvblock.Key{ModelName: "12345", ChunkHash: 12345} |
| 32 | + entries := []kvblock.PodEntry{ |
| 33 | + {PodIdentifier: "10.0.0.1", DeviceTier: "gpu"}, |
| 34 | + {PodIdentifier: "10.0.0.2", DeviceTier: "gpu"}, |
| 35 | + } |
| 36 | + |
| 37 | + // Add entries |
| 38 | + err := index.Add(t.Context(), []kvblock.Key{key}, entries) |
| 39 | + assert.NoError(t, err) |
| 40 | + |
| 41 | + // Lookup after add |
| 42 | + hitKeys, podsPerKey, err := index.Lookup(t.Context(), []kvblock.Key{key}, sets.Set[string]{}) |
| 43 | + assert.NoError(t, err) |
| 44 | + assert.Len(t, hitKeys, 1) |
| 45 | + assert.Equal(t, key, hitKeys[0]) |
| 46 | + assert.Equal(t, podsPerKey[key], []string{"10.0.0.1", "10.0.0.2"}) |
| 47 | +} |
0 commit comments