/Users/deen/code/yugabyte-db/src/yb/integration-tests/restart-test.cc
Line | Count | Source (jump to first uncovered line) |
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/client/callbacks.h" |
15 | | #include "yb/client/client.h" |
16 | | |
17 | | #include "yb/consensus/log.h" |
18 | | #include "yb/consensus/log_reader.h" |
19 | | |
20 | | #include "yb/integration-tests/mini_cluster.h" |
21 | | #include "yb/integration-tests/yb_table_test_base.h" |
22 | | |
23 | | #include "yb/tablet/tablet_peer.h" |
24 | | |
25 | | #include "yb/tserver/mini_tablet_server.h" |
26 | | #include "yb/tserver/tablet_server.h" |
27 | | #include "yb/tserver/ts_tablet_manager.h" |
28 | | |
29 | | #include "yb/util/test_macros.h" |
30 | | #include "yb/util/test_util.h" |
31 | | |
32 | | DECLARE_bool(TEST_simulate_abrupt_server_restart); |
33 | | |
34 | | namespace yb { |
35 | | namespace integration_tests { |
36 | | |
37 | | class RestartTest : public YBTableTestBase { |
38 | | protected: |
39 | | |
40 | 1 | bool use_external_mini_cluster() override { return false; } |
41 | | |
42 | 1 | size_t num_tablet_servers() override { return 3; } |
43 | | |
44 | 0 | int num_tablets() override { return 1; } |
45 | | |
46 | 0 | void GetTablet(const client::YBTableName& table_name, string* tablet_id) { |
47 | 0 | std::vector<std::string> ranges; |
48 | 0 | std::vector<TabletId> tablet_ids; |
49 | 0 | ASSERT_OK(client_->GetTablets(table_name, 0 /* max_tablets */, &tablet_ids, &ranges)); |
50 | 0 | ASSERT_EQ(tablet_ids.size(), 1); |
51 | 0 | *tablet_id = tablet_ids[0]; |
52 | 0 | } |
53 | | }; |
54 | | |
55 | 0 | TEST_F(RestartTest, WalFooterProperlyInitialized) { |
56 | 0 | FLAGS_TEST_simulate_abrupt_server_restart = true; |
57 | 0 | auto timestamp_before_write = GetCurrentTimeMicros(); |
58 | 0 | PutKeyValue("key", "value"); |
59 | 0 | auto timestamp_after_write = GetCurrentTimeMicros(); |
60 | |
|
61 | 0 | auto* tablet_server = mini_cluster()->mini_tablet_server(0); |
62 | 0 | ASSERT_OK(tablet_server->Restart()); |
63 | 0 | FLAGS_TEST_simulate_abrupt_server_restart = false; |
64 | |
|
65 | 0 | string tablet_id; |
66 | 0 | ASSERT_NO_FATALS(GetTablet(table_.name(), &tablet_id)); |
67 | 0 | std::shared_ptr<tablet::TabletPeer> tablet_peer; |
68 | 0 | ASSERT_OK(tablet_server->server()->tablet_manager()->GetTabletPeer(tablet_id, &tablet_peer)); |
69 | 0 | ASSERT_OK(tablet_server->WaitStarted()); |
70 | 0 | log::SegmentSequence segments; |
71 | 0 | ASSERT_OK(tablet_peer->log()->GetLogReader()->GetSegmentsSnapshot(&segments)); |
72 | |
|
73 | 0 | ASSERT_EQ(2, segments.size()); |
74 | 0 | auto segment = segments[0]; |
75 | 0 | ASSERT_TRUE(segment->HasFooter()); |
76 | 0 | ASSERT_TRUE(segment->footer().has_close_timestamp_micros()); |
77 | 0 | ASSERT_TRUE(segment->footer().close_timestamp_micros() > timestamp_before_write && |
78 | 0 | segment->footer().close_timestamp_micros() < timestamp_after_write); |
79 | |
|
80 | 0 | } |
81 | | |
82 | | } // namespace integration_tests |
83 | | } // namespace yb |