/Users/deen/code/yugabyte-db/src/yb/tserver/remote_bootstrap_rocksdb_session-test.cc
Line | Count | Source |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #include "yb/rpc/proxy.h" |
15 | | |
16 | | #include "yb/tserver/remote_bootstrap_session-test.h" |
17 | | |
18 | | #include "yb/util/result.h" |
19 | | #include "yb/util/status_log.h" |
20 | | |
21 | | namespace yb { |
22 | | namespace tserver { |
23 | | |
24 | | class RemoteBootstrapRocksDBTest : public RemoteBootstrapSessionTest { |
25 | | public: |
26 | 4 | RemoteBootstrapRocksDBTest() : RemoteBootstrapSessionTest(YQL_TABLE_TYPE) {} |
27 | | |
28 | 3 | void SetUp() override { |
29 | 3 | RemoteBootstrapSessionTest::SetUp(); |
30 | 3 | } |
31 | | |
32 | 3 | void TearDown() override { |
33 | 3 | RemoteBootstrapSessionTest::TearDown(); |
34 | 3 | } |
35 | | }; |
36 | | |
37 | 1 | TEST_F(RemoteBootstrapRocksDBTest, TestCheckpointDirectory) { |
38 | 1 | string checkpoint_dir; |
39 | 1 | { |
40 | 1 | auto temp_session = make_scoped_refptr<RemoteBootstrapSession>( |
41 | 1 | tablet_peer_, "TestTempSession", "FakeUUID", nullptr /* nsessions */); |
42 | 1 | CHECK_OK(temp_session->Init()); |
43 | 1 | checkpoint_dir = temp_session->checkpoint_dir_; |
44 | 1 | ASSERT_FALSE(checkpoint_dir.empty()); |
45 | 1 | ASSERT_TRUE(env_->FileExists(checkpoint_dir)); |
46 | 1 | bool is_dir = false; |
47 | 1 | ASSERT_OK(env_->IsDirectory(checkpoint_dir, &is_dir)); |
48 | 1 | ASSERT_TRUE(is_dir); |
49 | 1 | vector<string> rocksdb_files; |
50 | 1 | ASSERT_OK(env_->GetChildren(checkpoint_dir, &rocksdb_files)); |
51 | | // Ignore "." and ".." entries. |
52 | 1 | ASSERT_GT(rocksdb_files.size(), 2); |
53 | 1 | } |
54 | | // Verify that destructor deleted the checkpoint directory. |
55 | 1 | ASSERT_FALSE(env_->FileExists(checkpoint_dir)); |
56 | 1 | } |
57 | | |
58 | 1 | TEST_F(RemoteBootstrapRocksDBTest, CheckSuperBlockHasRocksDBFields) { |
59 | 1 | auto superblock = session_->tablet_superblock(); |
60 | 1 | const auto& kv_store = superblock.kv_store(); |
61 | 1 | LOG(INFO) << superblock.ShortDebugString(); |
62 | 1 | ASSERT_EQ(1, kv_store.tables_size()); |
63 | 1 | ASSERT_EQ(YQL_TABLE_TYPE, kv_store.tables(0).table_type()); |
64 | 1 | ASSERT_TRUE(kv_store.has_rocksdb_dir()); |
65 | | |
66 | 1 | const auto& checkpoint_dir = session_->checkpoint_dir_; |
67 | 1 | vector<string> checkpoint_files; |
68 | 1 | ASSERT_OK(env_->GetChildren(checkpoint_dir, &checkpoint_files)); |
69 | | |
70 | | // Ignore "." and ".." entries in session_->checkpoint_dir_. |
71 | 1 | ASSERT_EQ(kv_store.rocksdb_files().size(), checkpoint_files.size() - 2); |
72 | 5 | for (int i = 0; i < kv_store.rocksdb_files().size(); ++i) { |
73 | 4 | const auto& rocksdb_file_name = kv_store.rocksdb_files(i).name(); |
74 | 4 | auto rocksdb_file_size_bytes = kv_store.rocksdb_files(i).size_bytes(); |
75 | 4 | auto file_path = JoinPathSegments(checkpoint_dir, rocksdb_file_name); |
76 | 4 | ASSERT_TRUE(env_->FileExists(file_path)); |
77 | 4 | uint64 file_size_bytes = ASSERT_RESULT(env_->GetFileSize(file_path)); |
78 | 4 | ASSERT_EQ(rocksdb_file_size_bytes, file_size_bytes); |
79 | 4 | } |
80 | 1 | } |
81 | | |
82 | 1 | TEST_F(RemoteBootstrapRocksDBTest, TestNonExistentRocksDBFile) { |
83 | 1 | GetDataPieceInfo info; |
84 | 1 | auto status = session_->GetRocksDBFilePiece("SomeNonExistentFile", &info); |
85 | 1 | ASSERT_TRUE(status.IsNotFound()); |
86 | 1 | } |
87 | | |
88 | | } // namespace tserver |
89 | | } // namespace yb |