(t *testing.T)
| 1018 | } |
| 1019 | |
| 1020 | func TestHashCollision(t *testing.T) { |
| 1021 | t.Parallel() |
| 1022 | |
| 1023 | ml := &mockedLogger{} |
| 1024 | // given |
| 1025 | cache, _ := New(context.Background(), Config{ |
| 1026 | Shards: 16, |
| 1027 | LifeWindow: 5 * time.Second, |
| 1028 | MaxEntriesInWindow: 10, |
| 1029 | MaxEntrySize: 256, |
| 1030 | Verbose: true, |
| 1031 | Hasher: hashStub(5), |
| 1032 | Logger: ml, |
| 1033 | }) |
| 1034 | |
| 1035 | // when |
| 1036 | cache.Set("liquid", []byte("value")) |
| 1037 | cachedValue, err := cache.Get("liquid") |
| 1038 | |
| 1039 | // then |
| 1040 | noError(t, err) |
| 1041 | assertEqual(t, []byte("value"), cachedValue) |
| 1042 | |
| 1043 | // when |
| 1044 | cache.Set("costarring", []byte("value 2")) |
| 1045 | cachedValue, err = cache.Get("costarring") |
| 1046 | |
| 1047 | // then |
| 1048 | noError(t, err) |
| 1049 | assertEqual(t, []byte("value 2"), cachedValue) |
| 1050 | |
| 1051 | // when |
| 1052 | cachedValue, err = cache.Get("liquid") |
| 1053 | |
| 1054 | // then |
| 1055 | assertEqual(t, ErrEntryNotFound, err) |
| 1056 | assertEqual(t, []byte(nil), cachedValue) |
| 1057 | |
| 1058 | assertEqual(t, "Collision detected. Both %q and %q have the same hash %x", ml.lastFormat) |
| 1059 | assertEqual(t, cache.Stats().Collisions, int64(1)) |
| 1060 | } |
| 1061 | |
| 1062 | func TestNilValueCaching(t *testing.T) { |
| 1063 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…