Skip to content

Commit

Permalink
test: add cases for rocksdb multiple dirty delete calls (#867)
Browse files Browse the repository at this point in the history
  • Loading branch information
jyeshe authored Aug 31, 2022
1 parent 78467bd commit 27071f4
Showing 1 changed file with 83 additions and 1 deletion.
84 changes: 83 additions & 1 deletion test/ae_mdw/db/rocksdb_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ defmodule AeMdw.Db.RocksDbTest do

import AeMdw.Db.ModelFixtures, only: [new_block: 0, new_kbi: 0]

require Model

describe "dirty operations/3" do
test "writes a key-value only to the transaction" do
{:ok, txn} = RocksDb.transaction_new()
Expand All @@ -17,14 +19,94 @@ defmodule AeMdw.Db.RocksDbTest do
assert :not_found = RocksDb.get(Model.Block, key)
end

test "persists a key-value without transaction" do
test "persists a key-value without a transaction" do
key = :erlang.term_to_binary({new_kbi(), -1})
value = new_block() |> :erlang.term_to_binary()

assert :ok = RocksDb.dirty_put(Model.Block, key, value)
assert {:ok, ^value} = RocksDb.get(Model.Block, key)
end

test "deletes multiple key-values without a transaction (A)" do
Enum.each(1..10_000, fn _i ->
m_block = Model.block(index: index) = new_block()
key = :erlang.term_to_binary(index)
value = :erlang.term_to_binary(m_block)

assert :ok = RocksDb.dirty_put(Model.Block, key, value)
assert :ok = RocksDb.dirty_delete(Model.Block, key)
assert :not_found = RocksDb.get(Model.Block, key)
end)
end

test "deletes multiple key-values without a transaction (B)" do
1..10_000
|> Enum.map(fn _i ->
m_block = Model.block(index: index) = new_block()
key = :erlang.term_to_binary(index)
value = :erlang.term_to_binary(m_block)

assert :ok = RocksDb.dirty_put(Model.Block, key, value)
key
end)
|> Enum.each(fn key ->
assert :ok = RocksDb.dirty_delete(Model.Block, key)
assert :not_found = RocksDb.get(Model.Block, key)
end)
end

test "deletes multiple key-values without a transaction (C)" do
{:ok, txn} = RocksDb.transaction_new()

keys =
Enum.map(1..10_000, fn _i ->
m_block = Model.block(index: index) = new_block()
key = :erlang.term_to_binary(index)
value = :erlang.term_to_binary(m_block)

assert :ok = RocksDb.put(txn, Model.Block, key, value)
key
end)

:ok = RocksDb.transaction_commit(txn)

Enum.each(keys, fn key ->
assert :ok = RocksDb.dirty_delete(Model.Block, key)
assert :not_found = RocksDb.get(Model.Block, key)
end)
end

test "deletes multiple key-values without a transaction (D)" do
{:ok, txn} = RocksDb.transaction_new()

keys =
Enum.map(1..10_000, fn _i ->
index = {System.system_time(), :update_aex9_state}

m_task =
Model.async_task(
index: index,
args: [:crypto.strong_rand_bytes(32)],
extra_args: [{1, 0}, 1]
)

key = :erlang.term_to_binary(index)
value = :erlang.term_to_binary(m_task)

assert :ok = RocksDb.put(txn, Model.AsyncTask, key, value)
key
end)

:ok = RocksDb.transaction_commit(txn)

Enum.each(keys, fn key ->
assert :ok = RocksDb.dirty_delete(Model.AsyncTask, key)
assert :not_found = RocksDb.get(Model.AsyncTask, key)
end)
end
end

describe "delete/3" do
test "delete a key-value from the transaction" do
{:ok, txn} = RocksDb.transaction_new()
key = :erlang.term_to_binary({new_kbi(), -1})
Expand Down

0 comments on commit 27071f4

Please sign in to comment.