diff --git a/test/ae_mdw/db/rocksdb_test.exs b/test/ae_mdw/db/rocksdb_test.exs index 20e4a2a0e..5815af0f5 100644 --- a/test/ae_mdw/db/rocksdb_test.exs +++ b/test/ae_mdw/db/rocksdb_test.exs @@ -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() @@ -17,7 +19,7 @@ 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() @@ -25,6 +27,86 @@ defmodule AeMdw.Db.RocksDbTest do 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})