MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / TestDB_Snapshot

Function TestDB_Snapshot

driver/hybriddb/db_test.go:234–277  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

232}
233
234func TestDB_Snapshot(t *testing.T) {
235 tempDir := t.TempDir()
236 cfg := &config.Config{
237 LevelDB: config.LevelDBConfig{
238 CacheSize: 64 * 1024 * 1024,
239 BlockSize: 4 * 1024,
240 WriteBufferSize: 4 * 1024 * 1024,
241 MaxOpenFiles: 1000,
242 Compression: true,
243 },
244 }
245
246 db, err := Store{}.Open(tempDir, cfg)
247 require.NoError(t, err)
248 defer db.Close()
249
250 key := []byte("snapshot-key")
251 value := []byte("snapshot-value")
252
253 // Put initial value
254 err = db.Put(key, value)
255 require.NoError(t, err)
256
257 // Create snapshot
258 snapshot, err := db.NewSnapshot()
259 require.NoError(t, err)
260 defer snapshot.Close()
261
262 // Modify data after snapshot
263 newValue := []byte("new-value")
264 err = db.Put(key, newValue)
265 require.NoError(t, err)
266
267 // Snapshot should still see old value
268 snapshotValue, err := snapshot.Get(key)
269 require.NoError(t, err)
270 assert.Equal(t, value, snapshotValue)
271
272 // Current DB should see new value
273 // We need to ensure cache is invalidated, so we'll get from cold storage
274 currentValue, err := db.Get(key)
275 require.NoError(t, err)
276 assert.Equal(t, newValue, currentValue, "Current DB should see modified value")
277}
278
279func TestDB_Compact(t *testing.T) {
280 tempDir := t.TempDir()

Callers

nothing calls this directly

Calls 8

CloseMethod · 0.95
GetMethod · 0.95
CloseMethod · 0.65
EqualMethod · 0.65
OpenMethod · 0.45
PutMethod · 0.45
NewSnapshotMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected