Files
rippled/src/ripple/nodestore/tests/BasicTests.cpp
Donovan Hide 44c68d6174 Change NodeStore::Backend tests to reflect observed patterns:
Empirical evidence shows a database access pattern with few hits
and many misses (objects that don't exist). This changes the timing
tests so they more accurately reflect rippled's actual usage:
* Add read missing keys test
* Increase numObjectsToTest to 1,000,000
* Alter PredictableObjectFactory to seed RNG once only
* Make NodeStoreTiming a manual test
2014-10-22 19:29:29 -07:00

87 lines
2.6 KiB
C++

//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
namespace ripple {
namespace NodeStore {
// Tests predictable batches, and NodeObject blob encoding
//
class NodeStoreBasic_test : public TestBase
{
public:
// Make sure predictable object generation works!
void testBatches (std::int64_t const seedValue)
{
testcase ("batch");
Batch batch1;
createPredictableBatch (batch1, numObjectsToTest, seedValue);
Batch batch2;
createPredictableBatch (batch2, numObjectsToTest, seedValue);
expect (areBatchesEqual (batch1, batch2), "Should be equal");
Batch batch3;
createPredictableBatch (batch3, numObjectsToTest, seedValue+1);
expect (! areBatchesEqual (batch1, batch3), "Should not be equal");
}
// Checks encoding/decoding blobs
void testBlobs (std::int64_t const seedValue)
{
testcase ("encoding");
Batch batch;
createPredictableBatch (batch, numObjectsToTest, seedValue);
EncodedBlob encoded;
for (int i = 0; i < batch.size (); ++i)
{
encoded.prepare (batch [i]);
DecodedBlob decoded (encoded.getKey (), encoded.getData (), encoded.getSize ());
expect (decoded.wasOk (), "Should be ok");
if (decoded.wasOk ())
{
NodeObject::Ptr const object (decoded.createObject ());
expect (batch [i]->isCloneOf (object), "Should be clones");
}
}
}
void run ()
{
std::int64_t const seedValue = 50;
testBatches (seedValue);
testBlobs (seedValue);
}
};
BEAST_DEFINE_TESTSUITE(NodeStoreBasic,ripple_core,ripple);
}
}