2013-10-16 23:59:46 +02:00
|
|
|
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under the BSD-style license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
//
|
2011-03-18 23:37:00 +01:00
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
|
|
|
|
#include "db/version_edit.h"
|
|
|
|
#include "util/testharness.h"
|
|
|
|
|
2013-10-04 06:49:15 +02:00
|
|
|
namespace rocksdb {
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
static void TestEncodeDecode(const VersionEdit& edit) {
|
|
|
|
std::string encoded, encoded2;
|
|
|
|
edit.EncodeTo(&encoded);
|
2014-01-15 00:32:37 +01:00
|
|
|
VersionEdit parsed;
|
2011-03-18 23:37:00 +01:00
|
|
|
Status s = parsed.DecodeFrom(encoded);
|
|
|
|
ASSERT_TRUE(s.ok()) << s.ToString();
|
|
|
|
parsed.EncodeTo(&encoded2);
|
|
|
|
ASSERT_EQ(encoded, encoded2);
|
|
|
|
}
|
|
|
|
|
|
|
|
class VersionEditTest { };
|
|
|
|
|
|
|
|
TEST(VersionEditTest, EncodeDecode) {
|
|
|
|
static const uint64_t kBig = 1ull << 50;
|
|
|
|
|
2014-01-15 00:32:37 +01:00
|
|
|
VersionEdit edit;
|
2011-03-18 23:37:00 +01:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
TestEncodeDecode(edit);
|
2014-07-02 18:54:20 +02:00
|
|
|
edit.AddFile(3, kBig + 300 + i, kBig + 400 + i, 0,
|
2011-04-21 00:48:11 +02:00
|
|
|
InternalKey("foo", kBig + 500 + i, kTypeValue),
|
2013-06-14 07:09:08 +02:00
|
|
|
InternalKey("zoo", kBig + 600 + i, kTypeDeletion),
|
2014-07-02 18:54:20 +02:00
|
|
|
kBig + 500 + i, kBig + 600 + i);
|
2011-03-18 23:37:00 +01:00
|
|
|
edit.DeleteFile(4, kBig + 700 + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
edit.SetComparatorName("foo");
|
|
|
|
edit.SetLogNumber(kBig + 100);
|
|
|
|
edit.SetNextFile(kBig + 200);
|
|
|
|
edit.SetLastSequence(kBig + 1000);
|
|
|
|
TestEncodeDecode(edit);
|
|
|
|
}
|
|
|
|
|
2014-10-28 22:27:26 +01:00
|
|
|
TEST(VersionEditTest, EncodeEmptyFile) {
|
|
|
|
VersionEdit edit;
|
|
|
|
edit.AddFile(0, 0, 0, 0,
|
|
|
|
InternalKey(),
|
|
|
|
InternalKey(),
|
|
|
|
0, 0);
|
|
|
|
std::string buffer;
|
|
|
|
ASSERT_TRUE(!edit.EncodeTo(&buffer));
|
|
|
|
}
|
|
|
|
|
2013-12-12 02:46:26 +01:00
|
|
|
TEST(VersionEditTest, ColumnFamilyTest) {
|
2014-01-22 02:01:52 +01:00
|
|
|
VersionEdit edit;
|
2013-12-12 02:46:26 +01:00
|
|
|
edit.SetColumnFamily(2);
|
|
|
|
edit.AddColumnFamily("column_family");
|
2014-03-05 21:13:44 +01:00
|
|
|
edit.SetMaxColumnFamily(5);
|
2013-12-12 02:46:26 +01:00
|
|
|
TestEncodeDecode(edit);
|
|
|
|
|
|
|
|
edit.Clear();
|
|
|
|
edit.SetColumnFamily(3);
|
|
|
|
edit.DropColumnFamily();
|
|
|
|
TestEncodeDecode(edit);
|
|
|
|
}
|
|
|
|
|
2013-10-04 06:49:15 +02:00
|
|
|
} // namespace rocksdb
|
2011-03-18 23:37:00 +01:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2013-10-04 06:49:15 +02:00
|
|
|
return rocksdb::test::RunAllTests();
|
2011-03-18 23:37:00 +01:00
|
|
|
}
|