rippled
Basics_test.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <test/nodestore/TestBase.h>
21 #include <ripple/nodestore/DummyScheduler.h>
22 #include <ripple/nodestore/Manager.h>
23 #include <ripple/nodestore/impl/DecodedBlob.h>
24 #include <ripple/nodestore/impl/EncodedBlob.h>
25 
26 namespace ripple {
27 namespace NodeStore {
28 
29 // Tests predictable batches, and NodeObject blob encoding
30 //
32 {
33 public:
34  // Make sure predictable object generation works!
35  void testBatches (std::uint64_t const seedValue)
36  {
37  testcase ("batch");
38 
39  auto batch1 = createPredictableBatch (
40  numObjectsToTest, seedValue);
41 
42  auto batch2 = createPredictableBatch (
43  numObjectsToTest, seedValue);
44 
45  BEAST_EXPECT(areBatchesEqual (batch1, batch2));
46 
47  auto batch3 = createPredictableBatch (
48  numObjectsToTest, seedValue + 1);
49 
50  BEAST_EXPECT(! areBatchesEqual (batch1, batch3));
51  }
52 
53  // Checks encoding/decoding blobs
54  void testBlobs (std::uint64_t const seedValue)
55  {
56  testcase ("encoding");
57 
58  auto batch = createPredictableBatch (
59  numObjectsToTest, seedValue);
60 
61  EncodedBlob encoded;
62  for (int i = 0; i < batch.size (); ++i)
63  {
64  encoded.prepare (batch [i]);
65 
66  DecodedBlob decoded (encoded.getKey (), encoded.getData (), encoded.getSize ());
67 
68  BEAST_EXPECT(decoded.wasOk ());
69 
70  if (decoded.wasOk ())
71  {
72  std::shared_ptr<NodeObject> const object (decoded.createObject ());
73 
74  BEAST_EXPECT(isSame(batch[i], object));
75  }
76  }
77  }
78 
79  void run () override
80  {
81  std::uint64_t const seedValue = 50;
82 
83  testBatches (seedValue);
84 
85  testBlobs (seedValue);
86  }
87 };
88 
89 BEAST_DEFINE_TESTSUITE(NodeStoreBasic,ripple_core,ripple);
90 
91 }
92 }
ripple::NodeStore::DecodedBlob::wasOk
bool wasOk() const noexcept
Determine if the decoding was successful.
Definition: DecodedBlob.h:45
ripple::NodeStore::NodeStoreBasic_test::testBatches
void testBatches(std::uint64_t const seedValue)
Definition: Basics_test.cpp:35
ripple::NodeStore::EncodedBlob::getSize
std::size_t getSize() const noexcept
Definition: EncodedBlob.h:44
ripple::NodeStore::DecodedBlob
Parsed key/value blob into NodeObject components.
Definition: DecodedBlob.h:38
ripple::NodeStore::TestBase
Definition: TestBase.h:68
std::shared_ptr< NodeObject >
ripple::NodeStore::EncodedBlob::getData
void const * getData() const noexcept
Definition: EncodedBlob.h:49
ripple::NodeStore::TestBase::areBatchesEqual
static bool areBatchesEqual(Batch const &lhs, Batch const &rhs)
Definition: TestBase.h:117
ripple::NodeStore::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(Backend, ripple_core, ripple)
ripple::NodeStore::DecodedBlob::createObject
std::shared_ptr< NodeObject > createObject()
Create a NodeObject from this data.
Definition: DecodedBlob.cpp:73
ripple::NodeStore::NodeStoreBasic_test::testBlobs
void testBlobs(std::uint64_t const seedValue)
Definition: Basics_test.cpp:54
ripple::NodeStore::NodeStoreBasic_test
Definition: Basics_test.cpp:31
std::uint64_t
ripple::NodeStore::TestBase::numObjectsToTest
static const int numObjectsToTest
Definition: TestBase.h:75
ripple::NodeStore::NodeStoreBasic_test::run
void run() override
Definition: Basics_test.cpp:79
ripple::NodeStore::TestBase::createPredictableBatch
static Batch createPredictableBatch(int numObjects, std::uint64_t seed)
Definition: TestBase.h:80
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::NodeStore::isSame
bool isSame(std::shared_ptr< NodeObject > const &lhs, std::shared_ptr< NodeObject > const &rhs)
Returns true if objects are identical.
Definition: TestBase.h:57
ripple::NodeStore::EncodedBlob
Utility for producing flattened node objects.
Definition: EncodedBlob.h:34
ripple::NodeStore::EncodedBlob::getKey
void const * getKey() const noexcept
Definition: EncodedBlob.h:39
ripple::NodeStore::EncodedBlob::prepare
void prepare(std::shared_ptr< NodeObject > const &object)
Definition: EncodedBlob.cpp:27