(t *testing.T)
| 76 | } |
| 77 | |
| 78 | func TestNestedTxnMergedIteration(t *testing.T) { |
| 79 | baseTxn, db, batch := newTxn(t, []byte(nil)) |
| 80 | defer func() { baseTxn.Close(); db.Close(); baseTxn.Discard() }() |
| 81 | // create a nested transaction |
| 82 | nested := NewTxn(baseTxn, baseTxn, nil, false, true, true, baseTxn.writeVersion) |
| 83 | // set and and flush a value in the parent transaction |
| 84 | require.NoError(t, nested.Set(lib.JoinLenPrefix([]byte("a")), []byte("a"))) |
| 85 | require.NoError(t, baseTxn.Commit()) |
| 86 | // set and flush a value in the nested transaction |
| 87 | require.NoError(t, nested.Set(lib.JoinLenPrefix([]byte("b")), []byte("b"))) |
| 88 | require.NoError(t, nested.Commit()) |
| 89 | // flush the batch |
| 90 | require.NoError(t, batch.Commit(&pebble.WriteOptions{Sync: false})) |
| 91 | // set a value in the parent transaction to not be flushed |
| 92 | require.NoError(t, baseTxn.Set(lib.JoinLenPrefix([]byte("c")), []byte("c"))) |
| 93 | // set a value in the nested transaction to not be flushed |
| 94 | require.NoError(t, nested.Set(lib.JoinLenPrefix([]byte("d")), []byte("d"))) |
| 95 | |
| 96 | // create a new iterator on the nested transaction |
| 97 | iter, err := nested.NewIterator(nil, false, false) |
| 98 | require.NoError(t, err) |
| 99 | expected := []string{"a", "b", "c", "d"} |
| 100 | got := []string{} |
| 101 | for ; iter.Valid(); iter.Next() { |
| 102 | got = append(got, string(iter.Value())) |
| 103 | } |
| 104 | iter.Close() |
| 105 | // confirm the iterator returns the expected values |
| 106 | require.Equal(t, expected, got) |
| 107 | |
| 108 | // create a new reverse iterator on the nested transaction |
| 109 | iter, err = nested.NewIterator(nil, true, false) |
| 110 | require.NoError(t, err) |
| 111 | expected = []string{"d", "c", "b", "a"} |
| 112 | got = []string{} |
| 113 | for ; iter.Valid(); iter.Next() { |
| 114 | got = append(got, string(iter.Value())) |
| 115 | } |
| 116 | iter.Close() |
| 117 | require.Equal(t, expected, got) |
| 118 | } |
| 119 | |
| 120 | func TestTxnWriteSetGet(t *testing.T) { |
| 121 | prefix := lib.JoinLenPrefix([]byte("1/")) |
nothing calls this directly
no test coverage detected