diff --git a/src/ripple/nodestore/tests/BackendTests.cpp b/src/ripple/nodestore/tests/BackendTests.cpp index 8121ccaa1..de674af81 100644 --- a/src/ripple/nodestore/tests/BackendTests.cpp +++ b/src/ripple/nodestore/tests/BackendTests.cpp @@ -43,7 +43,7 @@ public: // Create a batch Batch batch; - createPredictableBatch (batch, 0, numObjectsToTest, seedValue); + createPredictableBatch (batch, numObjectsToTest, seedValue); beast::Journal j; diff --git a/src/ripple/nodestore/tests/BasicTests.cpp b/src/ripple/nodestore/tests/BasicTests.cpp index 7da655d15..a37623bda 100644 --- a/src/ripple/nodestore/tests/BasicTests.cpp +++ b/src/ripple/nodestore/tests/BasicTests.cpp @@ -31,15 +31,15 @@ public: testcase ("batch"); Batch batch1; - createPredictableBatch (batch1, 0, numObjectsToTest, seedValue); + createPredictableBatch (batch1, numObjectsToTest, seedValue); Batch batch2; - createPredictableBatch (batch2, 0, numObjectsToTest, seedValue); + createPredictableBatch (batch2, numObjectsToTest, seedValue); expect (areBatchesEqual (batch1, batch2), "Should be equal"); Batch batch3; - createPredictableBatch (batch3, 1, numObjectsToTest, seedValue); + createPredictableBatch (batch3, numObjectsToTest, seedValue+1); expect (! areBatchesEqual (batch1, batch3), "Should not be equal"); } @@ -50,7 +50,7 @@ public: testcase ("encoding"); Batch batch; - createPredictableBatch (batch, 0, numObjectsToTest, seedValue); + createPredictableBatch (batch, numObjectsToTest, seedValue); EncodedBlob encoded; for (int i = 0; i < batch.size (); ++i) diff --git a/src/ripple/nodestore/tests/DatabaseTests.cpp b/src/ripple/nodestore/tests/DatabaseTests.cpp index 1c9ae8946..a951c10e3 100644 --- a/src/ripple/nodestore/tests/DatabaseTests.cpp +++ b/src/ripple/nodestore/tests/DatabaseTests.cpp @@ -37,7 +37,7 @@ public: // Create a batch Batch batch; - createPredictableBatch (batch, 0, numObjectsToTest, seedValue); + createPredictableBatch (batch, numObjectsToTest, seedValue); beast::Journal j; @@ -113,7 +113,7 @@ public: // Create a batch Batch batch; - createPredictableBatch (batch, 0, numObjectsToTest, seedValue); + createPredictableBatch (batch, numObjectsToTest, seedValue); beast::Journal j; diff --git a/src/ripple/nodestore/tests/TestBase.h b/src/ripple/nodestore/tests/TestBase.h index 1b8ce2768..5ceabe31e 100644 --- a/src/ripple/nodestore/tests/TestBase.h +++ b/src/ripple/nodestore/tests/TestBase.h @@ -44,14 +44,12 @@ public: { public: explicit PredictableObjectFactory (std::int64_t seedValue) - : m_seedValue (seedValue) + : r (seedValue) { } - NodeObject::Ptr createObject (int index) + NodeObject::Ptr createObject () { - beast::Random r (m_seedValue + index); - NodeObjectType type; switch (r.nextInt (4)) { @@ -79,20 +77,19 @@ public: } private: - std::int64_t const m_seedValue; + beast::Random r; }; public: - // Create a predictable batch of objects - static void createPredictableBatch (Batch& batch, int startingIndex, - int numObjects, std::int64_t seedValue) - { + // Create a predictable batch of objects + static void createPredictableBatch(Batch& batch, int numObjects, + std::int64_t seedValue) { batch.reserve (numObjects); PredictableObjectFactory factory (seedValue); for (int i = 0; i < numObjects; ++i) - batch.push_back (factory.createObject (startingIndex + i)); + batch.push_back (factory.createObject ()); } // Compare two batches for equality @@ -152,6 +149,19 @@ public: } } + void fetchMissing(Backend& backend, Batch const& batch) + { + for (int i = 0; i < batch.size (); ++i) + { + NodeObject::Ptr object; + + Status const status = backend.fetch ( + batch [i]->getHash ().cbegin (), &object); + + expect (status == notFound, "Should be notFound"); + } + } + // Store all objects in a batch static void storeBatch (Database& db, Batch const& batch) { diff --git a/src/ripple/nodestore/tests/TimingTests.cpp b/src/ripple/nodestore/tests/TimingTests.cpp index ce49a39d6..931db54de 100644 --- a/src/ripple/nodestore/tests/TimingTests.cpp +++ b/src/ripple/nodestore/tests/TimingTests.cpp @@ -25,7 +25,7 @@ class NodeStoreTiming_test : public TestBase public: enum { - numObjectsToTest = 10000 + numObjectsToTest = 1000000 }; class Stopwatch @@ -68,9 +68,11 @@ public: // Create batches NodeStore::Batch batch1; - createPredictableBatch (batch1, 0, numObjectsToTest, seedValue); + createPredictableBatch (batch1, numObjectsToTest, seedValue); NodeStore::Batch batch2; - createPredictableBatch (batch2, 0, numObjectsToTest, seedValue); + createPredictableBatch (batch2, numObjectsToTest, seedValue); + NodeStore::Batch missingBatch; + createPredictableBatch (missingBatch, numObjectsToTest, seedValue+1); beast::Journal j; @@ -83,19 +85,24 @@ public: // Individual write batch test t.start (); storeBatch (*backend, batch1); - log << " Single write: " << std::to_string (t.getElapsed ()) << " seconds"; + log << " Single write: " << std::to_string (t.getElapsed ()) << " seconds"; // Bulk write batch test t.start (); backend->storeBatch (batch2); - log << " Batch write: " << std::to_string (t.getElapsed ()) << " seconds"; + log << " Batch write: " << std::to_string (t.getElapsed ()) << " seconds"; // Read test Batch copy; t.start (); fetchCopyOfBatch (*backend, ©, batch1); fetchCopyOfBatch (*backend, ©, batch2); - log << " Batch read: " << std::to_string (t.getElapsed ()) << " seconds"; + log << " Batch read: " << std::to_string (t.getElapsed ()) << " seconds"; + + // Read missing keys test + t.start (); + fetchMissing (*backend, missingBatch); + log << " Batch read missing: " << std::to_string (t.getElapsed ()) << " seconds"; } //-------------------------------------------------------------------------- @@ -120,7 +127,7 @@ public: } }; -BEAST_DEFINE_TESTSUITE(NodeStoreTiming,ripple_core,ripple); +BEAST_DEFINE_TESTSUITE_MANUAL(NodeStoreTiming,ripple_core,ripple); } }