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

Function TestWriteBatch_Close

driver/hybriddb/write_batch_test.go:190–235  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

188}
189
190func TestWriteBatch_Close(t *testing.T) {
191 tempDir := t.TempDir()
192 cfg := &config.Config{
193 LevelDB: config.LevelDBConfig{
194 CacheSize: 64 * 1024 * 1024,
195 BlockSize: 4 * 1024,
196 WriteBufferSize: 4 * 1024 * 1024,
197 MaxOpenFiles: 1000,
198 Compression: true,
199 },
200 }
201
202 db, err := Store{}.Open(tempDir, cfg)
203 require.NoError(t, err)
204 defer db.Close()
205
206 wb := db.NewWriteBatch()
207
208 // Add some operations
209 wb.Put([]byte("key1"), []byte("value1"))
210 wb.Put([]byte("key2"), []byte("value2"))
211
212 // Close the batch
213 wb.Close()
214
215 // After closing, operations should not panic
216 func() {
217 defer func() {
218 if r := recover(); r != nil {
219 t.Fatalf("WriteBatch operations panicked after close: %v", r)
220 }
221 }()
222
223 wb.Put([]byte("key3"), []byte("value3"))
224 wb.Delete([]byte("key1"))
225 _ = wb.Commit()
226 _ = wb.SyncCommit()
227 _ = wb.Rollback()
228 _ = wb.Data()
229 }()
230
231 // Values should not be written since batch was closed before commit
232 val, err := db.Get([]byte("key1"))
233 require.NoError(t, err)
234 assert.Nil(t, val)
235}
236
237func TestWriteBatch_Data(t *testing.T) {
238 tempDir := t.TempDir()

Callers

nothing calls this directly

Calls 11

PutMethod · 0.95
CloseMethod · 0.95
DeleteMethod · 0.95
CommitMethod · 0.95
SyncCommitMethod · 0.95
RollbackMethod · 0.95
DataMethod · 0.95
CloseMethod · 0.65
OpenMethod · 0.45
NewWriteBatchMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected