void testBackend (beast::String type, std::int64_t const seedValue, int numObjectsToTest = 2000) { std::unique_ptr <Manager> manager (make_Manager ()); DummyScheduler scheduler; testcase ((beast::String ("Backend type=") + type).toStdString()); beast::StringPairArray params; beast::File const path (beast::File::createTempFile ("node_db")); params.set ("type", type); params.set ("path", path.getFullPathName ()); // Create a batch Batch batch; createPredictableBatch (batch, 0, numObjectsToTest, seedValue); beast::Journal j; { // Open the backend std::unique_ptr <Backend> backend (manager->make_Backend ( params, scheduler, j)); // Write the batch storeBatch (*backend, batch); { // Read it back in Batch copy; fetchCopyOfBatch (*backend, ©, batch); expect (areBatchesEqual (batch, copy), "Should be equal"); } { // Reorder and read the copy again Batch copy; beast::UnitTestUtilities::repeatableShuffle (batch.size (), batch, seedValue); fetchCopyOfBatch (*backend, ©, batch); expect (areBatchesEqual (batch, copy), "Should be equal"); } } { // Re-open the backend std::unique_ptr <Backend> backend (manager->make_Backend ( params, scheduler, j)); // Read it back in Batch copy; fetchCopyOfBatch (*backend, ©, batch); // Canonicalize the source and destination batches std::sort (batch.begin (), batch.end (), NodeObject::LessThan ()); std::sort (copy.begin (), copy.end (), NodeObject::LessThan ()); expect (areBatchesEqual (batch, copy), "Should be equal"); } }
void testBackend (String type, int64 const seedValue, int numObjectsToTest = 2000) { DummyScheduler scheduler; beginTestCase (String ("Backend type=") + type); StringPairArray params; File const path (File::createTempFile ("node_db")); params.set ("type", type); params.set ("path", path.getFullPathName ()); // Create a batch Batch batch; createPredictableBatch (batch, 0, numObjectsToTest, seedValue); { // Open the backend ScopedPointer <Backend> backend (DatabaseImp::createBackend (params, scheduler)); // Write the batch storeBatch (*backend, batch); { // Read it back in Batch copy; fetchCopyOfBatch (*backend, ©, batch); expect (areBatchesEqual (batch, copy), "Should be equal"); } { // Reorder and read the copy again Batch copy; UnitTestUtilities::repeatableShuffle (batch.size (), batch, seedValue); fetchCopyOfBatch (*backend, ©, batch); expect (areBatchesEqual (batch, copy), "Should be equal"); } } { // Re-open the backend ScopedPointer <Backend> backend (DatabaseImp::createBackend (params, scheduler)); // Read it back in Batch copy; fetchCopyOfBatch (*backend, ©, batch); // Canonicalize the source and destination batches std::sort (batch.begin (), batch.end (), NodeObject::LessThan ()); std::sort (copy.begin (), copy.end (), NodeObject::LessThan ()); expect (areBatchesEqual (batch, copy), "Should be equal"); } }
void testImport (String destBackendType, String srcBackendType, int64 seedValue) { DummyScheduler scheduler; File const node_db (File::createTempFile ("node_db")); StringPairArray srcParams; srcParams.set ("type", srcBackendType); srcParams.set ("path", node_db.getFullPathName ()); // Create a batch Batch batch; createPredictableBatch (batch, 0, numObjectsToTest, seedValue); // Write to source db { ScopedPointer <Database> src (Database::New ("test", scheduler, srcParams)); storeBatch (*src, batch); } Batch copy; { // Re-open the db ScopedPointer <Database> src (Database::New ("test", scheduler, srcParams)); // Set up the destination database File const dest_db (File::createTempFile ("dest_db")); StringPairArray destParams; destParams.set ("type", destBackendType); destParams.set ("path", dest_db.getFullPathName ()); ScopedPointer <Database> dest (Database::New ("test", scheduler, destParams)); beginTestCase (String ("import into '") + destBackendType + "' from '" + srcBackendType + "'"); // Do the import dest->import (*src); // Get the results of the import fetchCopyOfBatch (*dest, ©, batch); } // Canonicalize the source and destination batches std::sort (batch.begin (), batch.end (), NodeObject::LessThan ()); std::sort (copy.begin (), copy.end (), NodeObject::LessThan ()); expect (areBatchesEqual (batch, copy), "Should be equal"); }
void testNodeStore (String type, bool const useEphemeralDatabase, bool const testPersistence, int64 const seedValue, int numObjectsToTest = 2000) { DummyScheduler scheduler; String s; s << String ("NodeStore backend '") + type + "'"; if (useEphemeralDatabase) s << " (with ephemeral database)"; beginTestCase (s); File const node_db (File::createTempFile ("node_db")); StringPairArray nodeParams; nodeParams.set ("type", type); nodeParams.set ("path", node_db.getFullPathName ()); File const temp_db (File::createTempFile ("temp_db")); StringPairArray tempParams; if (useEphemeralDatabase) { tempParams.set ("type", type); tempParams.set ("path", temp_db.getFullPathName ()); } // Create a batch Batch batch; createPredictableBatch (batch, 0, numObjectsToTest, seedValue); { // Open the database ScopedPointer <Database> db (Database::New ("test", scheduler, nodeParams, tempParams)); // Write the batch storeBatch (*db, batch); { // Read it back in Batch copy; fetchCopyOfBatch (*db, ©, batch); expect (areBatchesEqual (batch, copy), "Should be equal"); } { // Reorder and read the copy again Batch copy; UnitTestUtilities::repeatableShuffle (batch.size (), batch, seedValue); fetchCopyOfBatch (*db, ©, batch); expect (areBatchesEqual (batch, copy), "Should be equal"); } } if (testPersistence) { { // Re-open the database without the ephemeral DB ScopedPointer <Database> db (Database::New ("test", scheduler, nodeParams)); // Read it back in Batch copy; fetchCopyOfBatch (*db, ©, batch); // Canonicalize the source and destination batches std::sort (batch.begin (), batch.end (), NodeObject::LessThan ()); std::sort (copy.begin (), copy.end (), NodeObject::LessThan ()); expect (areBatchesEqual (batch, copy), "Should be equal"); } if (useEphemeralDatabase) { // Verify the ephemeral db ScopedPointer <Database> db (Database::New ("test", scheduler, tempParams, StringPairArray ())); // Read it back in Batch copy; fetchCopyOfBatch (*db, ©, batch); // Canonicalize the source and destination batches std::sort (batch.begin (), batch.end (), NodeObject::LessThan ()); std::sort (copy.begin (), copy.end (), NodeObject::LessThan ()); expect (areBatchesEqual (batch, copy), "Should be equal"); } } }