diff options
Diffstat (limited to 'searchlib/src/tests/indexmetainfo')
-rw-r--r-- | searchlib/src/tests/indexmetainfo/.gitignore | 5 | ||||
-rw-r--r-- | searchlib/src/tests/indexmetainfo/CMakeLists.txt | 8 | ||||
-rw-r--r-- | searchlib/src/tests/indexmetainfo/DESC | 2 | ||||
-rw-r--r-- | searchlib/src/tests/indexmetainfo/FILES | 1 | ||||
-rw-r--r-- | searchlib/src/tests/indexmetainfo/bogus1.txt | 1 | ||||
-rw-r--r-- | searchlib/src/tests/indexmetainfo/bogus10.txt | 4 | ||||
-rw-r--r-- | searchlib/src/tests/indexmetainfo/bogus2.txt | 1 | ||||
-rw-r--r-- | searchlib/src/tests/indexmetainfo/bogus3.txt | 1 | ||||
-rw-r--r-- | searchlib/src/tests/indexmetainfo/bogus4.txt | 1 | ||||
-rw-r--r-- | searchlib/src/tests/indexmetainfo/bogus5.txt | 7 | ||||
-rw-r--r-- | searchlib/src/tests/indexmetainfo/bogus6.txt | 7 | ||||
-rw-r--r-- | searchlib/src/tests/indexmetainfo/bogus7.txt | 4 | ||||
-rw-r--r-- | searchlib/src/tests/indexmetainfo/bogus8.txt | 4 | ||||
-rw-r--r-- | searchlib/src/tests/indexmetainfo/bogus9.txt | 4 | ||||
-rw-r--r-- | searchlib/src/tests/indexmetainfo/indexmetainfo_test.cpp | 127 | ||||
-rw-r--r-- | searchlib/src/tests/indexmetainfo/meta-info.txt | 12 |
16 files changed, 189 insertions, 0 deletions
diff --git a/searchlib/src/tests/indexmetainfo/.gitignore b/searchlib/src/tests/indexmetainfo/.gitignore new file mode 100644 index 00000000000..ddc0b5f4582 --- /dev/null +++ b/searchlib/src/tests/indexmetainfo/.gitignore @@ -0,0 +1,5 @@ +.depend +Makefile +indexmetainfo_test +test-save.txt +searchlib_indexmetainfo_test_app diff --git a/searchlib/src/tests/indexmetainfo/CMakeLists.txt b/searchlib/src/tests/indexmetainfo/CMakeLists.txt new file mode 100644 index 00000000000..607ab7b7e5b --- /dev/null +++ b/searchlib/src/tests/indexmetainfo/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(searchlib_indexmetainfo_test_app + SOURCES + indexmetainfo_test.cpp + DEPENDS + searchlib +) +vespa_add_test(NAME searchlib_indexmetainfo_test_app COMMAND searchlib_indexmetainfo_test_app) diff --git a/searchlib/src/tests/indexmetainfo/DESC b/searchlib/src/tests/indexmetainfo/DESC new file mode 100644 index 00000000000..ee312b5fcdc --- /dev/null +++ b/searchlib/src/tests/indexmetainfo/DESC @@ -0,0 +1,2 @@ +Test the API class used to access the 'meta-info.txt' file used to +hold meta information for an index. diff --git a/searchlib/src/tests/indexmetainfo/FILES b/searchlib/src/tests/indexmetainfo/FILES new file mode 100644 index 00000000000..8a96f5f3311 --- /dev/null +++ b/searchlib/src/tests/indexmetainfo/FILES @@ -0,0 +1 @@ +indexmetainfo.cpp diff --git a/searchlib/src/tests/indexmetainfo/bogus1.txt b/searchlib/src/tests/indexmetainfo/bogus1.txt new file mode 100644 index 00000000000..6d412ad302e --- /dev/null +++ b/searchlib/src/tests/indexmetainfo/bogus1.txt @@ -0,0 +1 @@ +noAssign diff --git a/searchlib/src/tests/indexmetainfo/bogus10.txt b/searchlib/src/tests/indexmetainfo/bogus10.txt new file mode 100644 index 00000000000..e4f500cf897 --- /dev/null +++ b/searchlib/src/tests/indexmetainfo/bogus10.txt @@ -0,0 +1,4 @@ +nextSnapshotId=128 +snapshot.0.valid=false +snapshot.0.syncToken=bogus +snapshot.0.dirName=foo diff --git a/searchlib/src/tests/indexmetainfo/bogus2.txt b/searchlib/src/tests/indexmetainfo/bogus2.txt new file mode 100644 index 00000000000..9895913aece --- /dev/null +++ b/searchlib/src/tests/indexmetainfo/bogus2.txt @@ -0,0 +1 @@ +=noKey diff --git a/searchlib/src/tests/indexmetainfo/bogus3.txt b/searchlib/src/tests/indexmetainfo/bogus3.txt new file mode 100644 index 00000000000..73c7da9da74 --- /dev/null +++ b/searchlib/src/tests/indexmetainfo/bogus3.txt @@ -0,0 +1 @@ +unknownKey=magicValue diff --git a/searchlib/src/tests/indexmetainfo/bogus4.txt b/searchlib/src/tests/indexmetainfo/bogus4.txt new file mode 100644 index 00000000000..d841e7509ca --- /dev/null +++ b/searchlib/src/tests/indexmetainfo/bogus4.txt @@ -0,0 +1 @@ +nextSnapshotId=illegalNumber diff --git a/searchlib/src/tests/indexmetainfo/bogus5.txt b/searchlib/src/tests/indexmetainfo/bogus5.txt new file mode 100644 index 00000000000..08c64d393ba --- /dev/null +++ b/searchlib/src/tests/indexmetainfo/bogus5.txt @@ -0,0 +1,7 @@ +nextSnapshotId=128 +snapshot.1.valid=true +snapshot.1.syncToken=50 +snapshot.1.dirName=foo +snapshot.0.valid=false +snapshot.0.syncToken=100 +snapshot.0.dirName=bar diff --git a/searchlib/src/tests/indexmetainfo/bogus6.txt b/searchlib/src/tests/indexmetainfo/bogus6.txt new file mode 100644 index 00000000000..5506704db80 --- /dev/null +++ b/searchlib/src/tests/indexmetainfo/bogus6.txt @@ -0,0 +1,7 @@ +nextSnapshotId=128 +snapshot.0.valid=true +snapshot.0.syncToken=50 +snapshot.0.dirName=foo +snapshot.2.valid=false +snapshot.2.syncToken=100 +snapshot.2.dirName=bar diff --git a/searchlib/src/tests/indexmetainfo/bogus7.txt b/searchlib/src/tests/indexmetainfo/bogus7.txt new file mode 100644 index 00000000000..efbc17b40b6 --- /dev/null +++ b/searchlib/src/tests/indexmetainfo/bogus7.txt @@ -0,0 +1,4 @@ +nextSnapshotId=128 +snapshot..valid=true +snapshot..syncToken=50 +snapshot..dirName=foo diff --git a/searchlib/src/tests/indexmetainfo/bogus8.txt b/searchlib/src/tests/indexmetainfo/bogus8.txt new file mode 100644 index 00000000000..e359ca68f12 --- /dev/null +++ b/searchlib/src/tests/indexmetainfo/bogus8.txt @@ -0,0 +1,4 @@ +nextSnapshotId=128 +snapshot.x.valid=true +snapshot.x.syncToken=50 +snapshot.x.dirName=foo diff --git a/searchlib/src/tests/indexmetainfo/bogus9.txt b/searchlib/src/tests/indexmetainfo/bogus9.txt new file mode 100644 index 00000000000..5dd606d8942 --- /dev/null +++ b/searchlib/src/tests/indexmetainfo/bogus9.txt @@ -0,0 +1,4 @@ +nextSnapshotId=128 +snapshot.0.valid=xyz +snapshot.0.syncToken=50 +snapshot.0.dirName=foo diff --git a/searchlib/src/tests/indexmetainfo/indexmetainfo_test.cpp b/searchlib/src/tests/indexmetainfo/indexmetainfo_test.cpp new file mode 100644 index 00000000000..e7dc828c9e5 --- /dev/null +++ b/searchlib/src/tests/indexmetainfo/indexmetainfo_test.cpp @@ -0,0 +1,127 @@ +// 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("indexmetainfo_test"); +#include <vespa/vespalib/testkit/testapp.h> +#include <vespa/searchlib/common/indexmetainfo.h> + +using search::IndexMetaInfo; + +typedef IndexMetaInfo::Snapshot Snap; + +TEST_SETUP(Test) + +int +Test::Main() +{ + TEST_INIT("indexmetainfo_test"); + { // load pregenerated file + IndexMetaInfo info(""); + EXPECT_TRUE(info.load()); + ASSERT_TRUE(info.snapshots().size() == 4); + EXPECT_TRUE(info.snapshots()[0].valid); + EXPECT_TRUE(info.snapshots()[0].syncToken == 50); + EXPECT_TRUE(info.snapshots()[0].dirName == "foo"); + EXPECT_TRUE(!info.snapshots()[1].valid); + EXPECT_TRUE(info.snapshots()[1].syncToken == 100); + EXPECT_TRUE(info.snapshots()[1].dirName == "bar"); + EXPECT_TRUE(info.snapshots()[2].valid); + EXPECT_TRUE(info.snapshots()[2].syncToken == 200); + EXPECT_TRUE(info.snapshots()[2].dirName == "baz"); + EXPECT_TRUE(!info.snapshots()[3].valid); + EXPECT_TRUE(info.snapshots()[3].syncToken == 500); + EXPECT_TRUE(info.snapshots()[3].dirName == "last"); + { + Snap s = info.getBestSnapshot(); + EXPECT_TRUE(s.valid); + EXPECT_TRUE(s.syncToken == 200); + EXPECT_TRUE(s.dirName == "baz"); + } + { + Snap s = info.getSnapshot(100); + EXPECT_TRUE(!s.valid); + EXPECT_TRUE(s.syncToken == 100); + EXPECT_TRUE(s.dirName == "bar"); + } + { + Snap s = info.getSnapshot(666); + EXPECT_TRUE(!s.valid); + EXPECT_TRUE(s.syncToken == 0); + EXPECT_TRUE(s.dirName == ""); + } + { + EXPECT_TRUE(info.invalidateSnapshot(200)); + Snap s = info.getBestSnapshot(); + EXPECT_TRUE(s.valid); + EXPECT_TRUE(s.syncToken == 50); + EXPECT_TRUE(s.dirName == "foo"); + } + { + EXPECT_TRUE(info.invalidateSnapshot(50)); + Snap s = info.getBestSnapshot(); + EXPECT_TRUE(!s.valid); + EXPECT_TRUE(s.syncToken == 0); + EXPECT_TRUE(s.dirName == ""); + } + { + EXPECT_TRUE(info.validateSnapshot(500)); + Snap s = info.getBestSnapshot(); + EXPECT_TRUE(s.valid); + EXPECT_TRUE(s.syncToken == 500); + EXPECT_TRUE(s.dirName == "last"); + } + { + EXPECT_TRUE(!info.invalidateSnapshot(666)); + EXPECT_TRUE(!info.validateSnapshot(666)); + } + { + info.clear(); + EXPECT_TRUE(info.snapshots().size() == 0); + Snap s = info.getBestSnapshot(); + EXPECT_TRUE(!s.valid); + EXPECT_TRUE(s.syncToken == 0); + EXPECT_TRUE(s.dirName == ""); + } + } + { // load file that does not exist + IndexMetaInfo info("."); + EXPECT_TRUE(!info.load("file-not-present.txt")); + } + { // load files with errors should fail + IndexMetaInfo info("."); + EXPECT_TRUE(!info.load("bogus1.txt")); + EXPECT_TRUE(!info.load("bogus2.txt")); + EXPECT_TRUE(!info.load("bogus3.txt")); + EXPECT_TRUE(!info.load("bogus4.txt")); + EXPECT_TRUE(!info.load("bogus5.txt")); + EXPECT_TRUE(!info.load("bogus6.txt")); + EXPECT_TRUE(!info.load("bogus7.txt")); + EXPECT_TRUE(!info.load("bogus8.txt")); + EXPECT_TRUE(!info.load("bogus9.txt")); + EXPECT_TRUE(!info.load("bogus10.txt")); + } + { // save/load/save/load/save/load test + std::string file("test-save.txt"); + IndexMetaInfo a("."); + IndexMetaInfo b("."); + EXPECT_TRUE(a.addSnapshot(Snap(true, 50, "foo"))); + EXPECT_TRUE(a.addSnapshot(Snap(false, 100, "bar"))); + EXPECT_TRUE(!a.addSnapshot(Snap(false, 100, "bar"))); + EXPECT_TRUE(a.save(file)); + EXPECT_TRUE(b.load(file)); + ASSERT_TRUE(b.snapshots().size() == 2); + EXPECT_TRUE(b.snapshots()[0] == Snap(true, 50, "foo")); + EXPECT_TRUE(b.snapshots()[1] == Snap(false, 100, "bar")); + EXPECT_TRUE(a.save(file)); + EXPECT_TRUE(b.load(file)); + ASSERT_TRUE(b.snapshots().size() == 2); + EXPECT_TRUE(b.snapshots()[0] == Snap(true, 50, "foo")); + EXPECT_TRUE(b.snapshots()[1] == Snap(false, 100, "bar")); + a.removeSnapshot(100); + EXPECT_TRUE(a.save(file)); + EXPECT_TRUE(b.load(file)); + ASSERT_TRUE(b.snapshots().size() == 1); + EXPECT_TRUE(b.snapshots()[0] == Snap(true, 50, "foo")); + } + TEST_DONE(); +} diff --git a/searchlib/src/tests/indexmetainfo/meta-info.txt b/searchlib/src/tests/indexmetainfo/meta-info.txt new file mode 100644 index 00000000000..20182f5786c --- /dev/null +++ b/searchlib/src/tests/indexmetainfo/meta-info.txt @@ -0,0 +1,12 @@ +snapshot.0.valid=true +snapshot.0.syncToken=50 +snapshot.0.dirName=foo +snapshot.1.valid=true +snapshot.1.syncToken=200 +snapshot.1.dirName=baz +snapshot.2.valid=false +snapshot.2.syncToken=100 +snapshot.2.dirName=bar +snapshot.3.valid=false +snapshot.3.syncToken=500 +snapshot.3.dirName=last |