diff --git a/utilities/transactions/transaction_test.cc b/utilities/transactions/transaction_test.cc index 5b00630f1..caf1566b9 100644 --- a/utilities/transactions/transaction_test.cc +++ b/utilities/transactions/transaction_test.cc @@ -5619,7 +5619,7 @@ TEST_P(TransactionStressTest, SeqAdvanceTest) { size_t branch = 0; auto seq = db_impl->GetLatestSequenceNumber(); exp_seq = seq; - txn_t0(0); + TestTxn0(0); seq = db_impl->TEST_GetLastVisibleSequence(); ASSERT_EQ(exp_seq, seq); @@ -5637,11 +5637,11 @@ TEST_P(TransactionStressTest, SeqAdvanceTest) { } // Doing it twice might detect some bugs - txn_t0(1); + TestTxn0(1); seq = db_impl->TEST_GetLastVisibleSequence(); ASSERT_EQ(exp_seq, seq); - txn_t1(0); + TestTxn1(0); seq = db_impl->TEST_GetLastVisibleSequence(); ASSERT_EQ(exp_seq, seq); @@ -5658,7 +5658,7 @@ TEST_P(TransactionStressTest, SeqAdvanceTest) { ASSERT_EQ(exp_seq, seq); } - txn_t3(0); + TestTxn3(0); seq = db_impl->TEST_GetLastVisibleSequence(); ASSERT_EQ(exp_seq, seq); @@ -5675,7 +5675,7 @@ TEST_P(TransactionStressTest, SeqAdvanceTest) { ASSERT_EQ(exp_seq, seq); } - txn_t4(0); + TestTxn4(0); seq = db_impl->TEST_GetLastVisibleSequence(); ASSERT_EQ(exp_seq, seq); @@ -5693,7 +5693,7 @@ TEST_P(TransactionStressTest, SeqAdvanceTest) { ASSERT_EQ(exp_seq, seq); } - txn_t2(0); + TestTxn2(0); seq = db_impl->TEST_GetLastVisibleSequence(); ASSERT_EQ(exp_seq, seq); diff --git a/utilities/transactions/transaction_test.h b/utilities/transactions/transaction_test.h index 52e8acd44..0b86453a4 100644 --- a/utilities/transactions/transaction_test.h +++ b/utilities/transactions/transaction_test.h @@ -223,12 +223,10 @@ class TransactionTestBase : public ::testing::Test { std::atomic expected_commits = {0}; // Without Prepare, the commit does not write to WAL std::atomic with_empty_commits = {0}; - std::function txn_t0_with_status = [&](size_t index, - Status exp_s) { + void TestTxn0(size_t index) { // Test DB's internal txn. It involves no prepare phase nor a commit marker. - WriteOptions wopts; - auto s = db->Put(wopts, "key" + std::to_string(index), "value"); - ASSERT_EQ(exp_s, s); + auto s = db->Put(WriteOptions(), "key" + std::to_string(index), "value"); + ASSERT_OK(s); if (txn_db_options.write_policy == TxnDBWritePolicy::WRITE_COMMITTED) { // Consume one seq per key exp_seq++; @@ -241,11 +239,9 @@ class TransactionTestBase : public ::testing::Test { } } with_empty_commits++; - }; - std::function txn_t0 = [&](size_t index) { - return txn_t0_with_status(index, Status::OK()); - }; - std::function txn_t1 = [&](size_t index) { + } + + void TestTxn1(size_t index) { // Testing directly writing a write batch. Functionality-wise it is // equivalent to commit without prepare. WriteBatch wb; @@ -253,8 +249,7 @@ class TransactionTestBase : public ::testing::Test { ASSERT_OK(wb.Put("k1" + istr, "v1")); ASSERT_OK(wb.Put("k2" + istr, "v2")); ASSERT_OK(wb.Put("k3" + istr, "v3")); - WriteOptions wopts; - auto s = db->Write(wopts, &wb); + auto s = db->Write(WriteOptions(), &wb); if (txn_db_options.write_policy == TxnDBWritePolicy::WRITE_COMMITTED) { // Consume one seq per key exp_seq += 3; @@ -268,12 +263,12 @@ class TransactionTestBase : public ::testing::Test { } ASSERT_OK(s); with_empty_commits++; - }; - std::function txn_t2 = [&](size_t index) { + } + + void TestTxn2(size_t index) { // Commit without prepare. It should write to DB without a commit marker. - TransactionOptions txn_options; - WriteOptions write_options; - Transaction* txn = db->BeginTransaction(write_options, txn_options); + Transaction* txn = + db->BeginTransaction(WriteOptions(), TransactionOptions()); auto istr = std::to_string(index); ASSERT_OK(txn->SetName("xid" + istr)); ASSERT_OK(txn->Put(Slice("foo" + istr), Slice("bar"))); @@ -301,12 +296,12 @@ class TransactionTestBase : public ::testing::Test { } delete txn; with_empty_commits++; - }; - std::function txn_t3 = [&](size_t index) { + } + + void TestTxn3(size_t index) { // A full 2pc txn that also involves a commit marker. - TransactionOptions txn_options; - WriteOptions write_options; - Transaction* txn = db->BeginTransaction(write_options, txn_options); + Transaction* txn = + db->BeginTransaction(WriteOptions(), TransactionOptions()); auto istr = std::to_string(index); ASSERT_OK(txn->SetName("xid" + istr)); ASSERT_OK(txn->Put(Slice("foo" + istr), Slice("bar"))); @@ -334,12 +329,12 @@ class TransactionTestBase : public ::testing::Test { exp_seq++; } delete txn; - }; - std::function txn_t4 = [&](size_t index) { + } + + void TestTxn4(size_t index) { // A full 2pc txn that also involves a commit marker. - TransactionOptions txn_options; - WriteOptions write_options; - Transaction* txn = db->BeginTransaction(write_options, txn_options); + Transaction* txn = + db->BeginTransaction(WriteOptions(), TransactionOptions()); auto istr = std::to_string(index); ASSERT_OK(txn->SetName("xid" + istr)); ASSERT_OK(txn->Put(Slice("foo" + istr), Slice("bar"))); @@ -375,7 +370,7 @@ class TransactionTestBase : public ::testing::Test { } } delete txn; - }; + } // Test that we can change write policy after a clean shutdown (which would // empty the WAL) diff --git a/utilities/transactions/write_prepared_transaction_test.cc b/utilities/transactions/write_prepared_transaction_test.cc index 4bc1f3744..86a9511a4 100644 --- a/utilities/transactions/write_prepared_transaction_test.cc +++ b/utilities/transactions/write_prepared_transaction_test.cc @@ -1714,19 +1714,19 @@ TEST_P(SeqAdvanceConcurrentTest, SeqAdvanceConcurrent) { size_t d = (n % base[bi + 1]) / base[bi]; switch (d) { case 0: - threads.emplace_back(txn_t0, bi); + threads.emplace_back(&TransactionTestBase::TestTxn0, this, bi); break; case 1: - threads.emplace_back(txn_t1, bi); + threads.emplace_back(&TransactionTestBase::TestTxn1, this, bi); break; case 2: - threads.emplace_back(txn_t2, bi); + threads.emplace_back(&TransactionTestBase::TestTxn2, this, bi); break; case 3: - threads.emplace_back(txn_t3, bi); + threads.emplace_back(&TransactionTestBase::TestTxn3, this, bi); break; case 4: - threads.emplace_back(txn_t3, bi); + threads.emplace_back(&TransactionTestBase::TestTxn3, this, bi); break; default: FAIL(); @@ -1794,7 +1794,7 @@ TEST_P(WritePreparedTransactionTest, BasicRecovery) { ASSERT_OK(ReOpen()); WritePreparedTxnDB* wp_db = dynamic_cast(db); - txn_t0(0); + TestTxn0(0); TransactionOptions txn_options; WriteOptions write_options; @@ -1809,7 +1809,7 @@ TEST_P(WritePreparedTransactionTest, BasicRecovery) { ASSERT_OK(s); auto prep_seq_0 = txn0->GetId(); - txn_t1(0); + TestTxn1(0); index++; Transaction* txn1 = db->BeginTransaction(write_options, txn_options); @@ -1822,7 +1822,7 @@ TEST_P(WritePreparedTransactionTest, BasicRecovery) { ASSERT_OK(s); auto prep_seq_1 = txn1->GetId(); - txn_t2(0); + TestTxn2(0); ReadOptions ropt; PinnableSlice pinnable_val; @@ -1858,7 +1858,7 @@ TEST_P(WritePreparedTransactionTest, BasicRecovery) { ASSERT_TRUE(s.IsNotFound()); pinnable_val.Reset(); - txn_t3(0); + TestTxn3(0); // Test that a recovered txns will be properly marked committed for the next // recovery