Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add cases for rocksdb multiple dirty delete calls #867

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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