MCPcopy Create free account
hub / github.com/allegro/bigcache / TestHashCollision

Function TestHashCollision

bigcache_test.go:1020–1060  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1018}
1019
1020func 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
1062func TestNilValueCaching(t *testing.T) {
1063 t.Parallel()

Callers

nothing calls this directly

Calls 7

NewFunction · 0.85
hashStubTypeAlias · 0.85
SetMethod · 0.80
StatsMethod · 0.80
noErrorFunction · 0.70
assertEqualFunction · 0.70
GetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…