MCPcopy
hub / github.com/kopia/kopia / TestGrowingMap

Function TestGrowingMap

internal/bigmap/bigmap_internal_test.go:54–95  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

52}
53
54func TestGrowingMap(t *testing.T) {
55 ctx := testlogging.Context(t)
56
57 impl, err := newInternalMapWithOptions(ctx, true, &Options{
58 InitialSizeLogarithm: 9,
59 NumMemorySegments: 3,
60 MemorySegmentSize: 1000,
61 FileSegmentSize: 4 << 20,
62 })
63 require.NoError(t, err)
64
65 defer impl.Close(ctx)
66
67 h := sha256.New()
68
69 // insert 20K hashes
70 for i := range 20000 {
71 var keybuf, valbuf, valbuf2 [sha256.Size]byte
72
73 k := sha256Key(h, keybuf[:0], i)
74 v := sha256Key(h, valbuf[:0], i+3)
75
76 require.True(t, impl.PutIfAbsent(ctx, k, v))
77
78 // ensure that previously written key is still there.
79 pkindex := i / 2
80 pk := sha256Key(h, keybuf[:0], pkindex)
81 require.True(t, impl.Contains(pk))
82
83 pv, ok := impl.Get(valbuf2[:0], pk)
84 require.True(t, ok)
85 require.Equal(t, pv, sha256Key(h, valbuf[:0], pkindex+3))
86
87 // ensure that key not written yet is not there.
88 nk := sha256Key(h, keybuf[:0], i+1)
89
90 require.False(t, impl.Contains(nk))
91
92 _, ok2 := impl.Get(valbuf2[:0], nk)
93 require.False(t, ok2)
94 }
95}
96
97func TestGrowingSet(t *testing.T) {
98 ctx := testlogging.Context(t)

Callers

nothing calls this directly

Calls 8

ContextFunction · 0.92
EqualMethod · 0.80
sha256KeyFunction · 0.70
CloseMethod · 0.65
GetMethod · 0.65
PutIfAbsentMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected