diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /searchcore/src/tests/proton/bucketdb |
Publish
Diffstat (limited to 'searchcore/src/tests/proton/bucketdb')
5 files changed, 180 insertions, 0 deletions
diff --git a/searchcore/src/tests/proton/bucketdb/bucketdb/.gitignore b/searchcore/src/tests/proton/bucketdb/bucketdb/.gitignore new file mode 100644 index 00000000000..3512e4268a1 --- /dev/null +++ b/searchcore/src/tests/proton/bucketdb/bucketdb/.gitignore @@ -0,0 +1 @@ +searchcore_bucketdb_test_app diff --git a/searchcore/src/tests/proton/bucketdb/bucketdb/CMakeLists.txt b/searchcore/src/tests/proton/bucketdb/bucketdb/CMakeLists.txt new file mode 100644 index 00000000000..f07ded6d89b --- /dev/null +++ b/searchcore/src/tests/proton/bucketdb/bucketdb/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(searchcore_bucketdb_test_app + SOURCES + bucketdb_test.cpp + DEPENDS + searchcore_bucketdb +) +vespa_add_test(NAME searchcore_bucketdb_test_app COMMAND searchcore_bucketdb_test_app) diff --git a/searchcore/src/tests/proton/bucketdb/bucketdb/DESC b/searchcore/src/tests/proton/bucketdb/bucketdb/DESC new file mode 100644 index 00000000000..59057628f89 --- /dev/null +++ b/searchcore/src/tests/proton/bucketdb/bucketdb/DESC @@ -0,0 +1 @@ +bucketdb test. Take a look at bucketdb_test.cpp for details. diff --git a/searchcore/src/tests/proton/bucketdb/bucketdb/FILES b/searchcore/src/tests/proton/bucketdb/bucketdb/FILES new file mode 100644 index 00000000000..c5cd1105c23 --- /dev/null +++ b/searchcore/src/tests/proton/bucketdb/bucketdb/FILES @@ -0,0 +1 @@ +bucketdb_test.cpp diff --git a/searchcore/src/tests/proton/bucketdb/bucketdb/bucketdb_test.cpp b/searchcore/src/tests/proton/bucketdb/bucketdb/bucketdb_test.cpp new file mode 100644 index 00000000000..6895e469319 --- /dev/null +++ b/searchcore/src/tests/proton/bucketdb/bucketdb/bucketdb_test.cpp @@ -0,0 +1,169 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/fastos/fastos.h> +#include <vespa/log/log.h> +LOG_SETUP("bucketdb_test"); + +#include <vespa/searchcore/proton/bucketdb/bucket_db_explorer.h> +#include <vespa/searchcore/proton/bucketdb/bucketdb.h> +#include <vespa/vespalib/data/slime/slime.h> +#include <vespa/vespalib/testkit/testapp.h> + +using namespace document; +using namespace proton; +using namespace proton::bucketdb; +using namespace vespalib::slime; +using storage::spi::BucketChecksum; +using storage::spi::BucketInfo; +using storage::spi::Timestamp; +using vespalib::Slime; + +constexpr uint32_t MIN_NUM_BITS = 8u; +const GlobalId GID_1("111111111111"); +const BucketId BUCKET_1(MIN_NUM_BITS, GID_1.convertToBucketId().getRawId()); +const Timestamp TIME_1(1u); +const Timestamp TIME_2(2u); +const Timestamp TIME_3(3u); + +typedef BucketInfo::ReadyState RS; +typedef SubDbType SDT; + +void +assertDocCount(uint32_t ready, + uint32_t notReady, + uint32_t removed, + const BucketState &state) +{ + EXPECT_EQUAL(ready, state.getReadyCount()); + EXPECT_EQUAL(notReady, state.getNotReadyCount()); + EXPECT_EQUAL(removed, state.getRemovedCount()); + BucketInfo info = state; + EXPECT_EQUAL(ready + notReady, info.getDocumentCount()); + EXPECT_EQUAL(ready + notReady + removed, info.getEntryCount()); +} + +void +assertReady(bool expReady, + const BucketInfo &info) +{ + EXPECT_EQUAL(expReady, info.isReady()); +} + +struct Fixture +{ + BucketDB _db; + Fixture() + : _db() + {} + const BucketState &add(const Timestamp ×tamp, + SubDbType subDbType) { + return _db.add(GID_1, BUCKET_1, timestamp, subDbType); + } + BucketState remove(const Timestamp ×tamp, + SubDbType subDbType) { + _db.remove(GID_1, BUCKET_1, timestamp, subDbType); + return get(); + } + BucketState get() const { + return _db.get(BUCKET_1); + } + BucketChecksum getChecksum(const Timestamp ×tamp, + SubDbType subDbType) { + BucketDB db; + BucketChecksum retval = db.add(GID_1, BUCKET_1, timestamp, subDbType).getChecksum(); + // Must ensure empty bucket db before destruction. + db.remove(GID_1, BUCKET_1, timestamp, subDbType); + return retval; + } +}; + +TEST_F("require that bucket db tracks doc counts per sub db type", Fixture) +{ + assertDocCount(0, 0, 0, f.get()); + assertDocCount(1, 0, 0, f.add(TIME_1, SDT::READY)); + assertDocCount(1, 1, 0, f.add(TIME_2, SDT::NOTREADY)); + assertDocCount(1, 1, 1, f.add(TIME_3, SDT::REMOVED)); + assertDocCount(0, 1, 1, f.remove(TIME_1, SDT::READY)); + assertDocCount(0, 0, 1, f.remove(TIME_2, SDT::NOTREADY)); + assertDocCount(0, 0, 0, f.remove(TIME_3, SDT::REMOVED)); +} + +TEST_F("require that bucket checksum is a combination of sub db types", Fixture) +{ + BucketChecksum zero(0u); + BucketChecksum ready = f.getChecksum(TIME_1, SDT::READY); + BucketChecksum notReady = f.getChecksum(TIME_2, SDT::NOTREADY); + + EXPECT_EQUAL(zero, f.get().getChecksum()); + EXPECT_EQUAL(ready, f.add(TIME_1, SDT::READY).getChecksum()); + EXPECT_EQUAL(ready + notReady, f.add(TIME_2, SDT::NOTREADY).getChecksum()); + EXPECT_EQUAL(ready + notReady, f.add(TIME_3, SDT::REMOVED).getChecksum()); + EXPECT_EQUAL(notReady, f.remove(TIME_1, SDT::READY).getChecksum()); + EXPECT_EQUAL(zero, f.remove(TIME_2, SDT::NOTREADY).getChecksum()); + EXPECT_EQUAL(zero, f.remove(TIME_3, SDT::REMOVED).getChecksum()); +} + +TEST_F("require that bucket is ready when not having docs in notready sub db", Fixture) +{ + assertReady(true, f.get()); + assertReady(true, f.add(TIME_1, SDT::READY)); + assertReady(false, f.add(TIME_2, SDT::NOTREADY)); + assertReady(false, f.add(TIME_3, SDT::REMOVED)); + assertReady(true, f.remove(TIME_2, SDT::NOTREADY)); + assertReady(true, f.remove(TIME_1, SDT::READY)); + assertReady(true, f.remove(TIME_3, SDT::REMOVED)); +} + +TEST_F("require that bucket can be cached", Fixture) +{ + f.add(TIME_1, SDT::READY); + EXPECT_FALSE(f._db.isCachedBucket(BUCKET_1)); + f._db.cacheBucket(BUCKET_1); + EXPECT_TRUE(f._db.isCachedBucket(BUCKET_1)); + + assertDocCount(1, 0, 0, f._db.cachedGet(BUCKET_1)); + f.add(TIME_2, SDT::NOTREADY); + assertDocCount(1, 0, 0, f._db.cachedGet(BUCKET_1)); + + f._db.uncacheBucket(); + EXPECT_FALSE(f._db.isCachedBucket(BUCKET_1)); + assertDocCount(1, 1, 0, f._db.cachedGet(BUCKET_1)); + + // Must ensure empty bucket db before destruction. + f.remove(TIME_1, SDT::READY); + f.remove(TIME_2, SDT::NOTREADY); +} + +TEST("require that bucket db can be explored") +{ + BucketDBOwner db; + db.takeGuard()->add(GID_1, BUCKET_1, TIME_1, SDT::READY); + { + BucketDBExplorer explorer(db.takeGuard()); + Slime expectSlime; + vespalib::string expectJson = + "{" + " numBuckets: 1," + " buckets: [" + " {" + " id: '0x2000000000000031'," + " checksum: '0x93939394'," + " readyCount: 1," + " notReadyCount: 0," + " removedCount: 0," + " active: false" + " }" + " ]" + "}"; + EXPECT_TRUE(JsonFormat::decode(expectJson, expectSlime) > 0); + Slime actualSlime; + SlimeInserter inserter(actualSlime); + explorer.get_state(inserter, true); + + EXPECT_EQUAL(expectSlime, actualSlime); + } + + // Must ensure empty bucket db before destruction. + db.takeGuard()->remove(GID_1, BUCKET_1, TIME_1, SDT::READY); +} + +TEST_MAIN() { TEST_RUN_ALL(); } |