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

Function TestDB_ConcurrentAccess

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

Source from the content-addressed store, hash-verified

325}
326
327func TestDB_ConcurrentAccess(t *testing.T) {
328 tempDir := t.TempDir()
329 cfg := &config.Config{
330 LevelDB: config.LevelDBConfig{
331 CacheSize: 64 * 1024 * 1024,
332 BlockSize: 4 * 1024,
333 WriteBufferSize: 4 * 1024 * 1024,
334 MaxOpenFiles: 1000,
335 Compression: true,
336 },
337 }
338
339 db, err := Store{}.Open(tempDir, cfg)
340 require.NoError(t, err)
341 defer db.Close()
342
343 done := make(chan bool)
344 numGoroutines := 10
345 opsPerGoroutine := 100
346
347 for i := 0; i < numGoroutines; i++ {
348 go func(id int) {
349 for j := 0; j < opsPerGoroutine; j++ {
350 key := []byte(string(rune(id)) + "-" + string(rune(j)))
351 value := []byte(string(rune(id)) + "-value-" + string(rune(j)))
352
353 err := db.Put(key, value)
354 assert.NoError(t, err)
355
356 retrieved, err := db.Get(key)
357 assert.NoError(t, err)
358 assert.Equal(t, value, retrieved)
359 }
360 done <- true
361 }(i)
362 }
363
364 // Wait for all goroutines to complete
365 for i := 0; i < numGoroutines; i++ {
366 <-done
367 }
368}
369
370func TestDB_Repair(t *testing.T) {
371 tempDir := t.TempDir()

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected