|
24 | 24 |
|
25 | 25 | namespace iceberg { |
26 | 26 |
|
27 | | -class ExpireSnapshotsTest : public UpdateTestBase { |
28 | | - protected: |
29 | | -}; |
| 27 | +class ExpireSnapshotsTest : public UpdateTestBase {}; |
30 | 28 |
|
31 | | -TEST_F(ExpireSnapshotsTest, Empty) { |
| 29 | +TEST_F(ExpireSnapshotsTest, DefaultExpireByAge) { |
32 | 30 | ICEBERG_UNWRAP_OR_FAIL(auto update, table_->NewExpireSnapshots()); |
33 | 31 | ICEBERG_UNWRAP_OR_FAIL(auto result, update->Apply()); |
34 | | - EXPECT_THAT(result.snapshot_ids_to_remove.size(), 1); |
35 | | - EXPECT_THAT(result.snapshot_ids_to_remove.at(0), 3051729675574597004); |
36 | | - EXPECT_THAT(result.ref_to_remove.empty(), true); |
37 | | - EXPECT_THAT(result.schema_ids_to_remove.empty(), true); |
38 | | - EXPECT_THAT(result.partition_spec_ids_to_remove.empty(), true); |
| 32 | + EXPECT_EQ(result.snapshot_ids_to_remove.size(), 1); |
| 33 | + EXPECT_EQ(result.snapshot_ids_to_remove.at(0), 3051729675574597004); |
39 | 34 | } |
40 | 35 |
|
41 | | -TEST_F(ExpireSnapshotsTest, Keep2) { |
| 36 | +TEST_F(ExpireSnapshotsTest, KeepAll) { |
42 | 37 | ICEBERG_UNWRAP_OR_FAIL(auto update, table_->NewExpireSnapshots()); |
43 | 38 | update->RetainLast(2); |
44 | 39 | ICEBERG_UNWRAP_OR_FAIL(auto result, update->Apply()); |
45 | | - EXPECT_THAT(result.snapshot_ids_to_remove.empty(), true); |
46 | | - EXPECT_THAT(result.ref_to_remove.empty(), true); |
47 | | - EXPECT_THAT(result.schema_ids_to_remove.empty(), true); |
48 | | - EXPECT_THAT(result.partition_spec_ids_to_remove.empty(), true); |
| 40 | + EXPECT_TRUE(result.snapshot_ids_to_remove.empty()); |
| 41 | + EXPECT_TRUE(result.refs_to_remove.empty()); |
49 | 42 | } |
50 | 43 |
|
51 | 44 | TEST_F(ExpireSnapshotsTest, ExpireById) { |
52 | 45 | ICEBERG_UNWRAP_OR_FAIL(auto update, table_->NewExpireSnapshots()); |
53 | 46 | update->ExpireSnapshotId(3051729675574597004); |
54 | | - update->RetainLast(2); |
55 | 47 | ICEBERG_UNWRAP_OR_FAIL(auto result, update->Apply()); |
56 | | - EXPECT_THAT(result.snapshot_ids_to_remove.size(), 1); |
57 | | - EXPECT_THAT(result.snapshot_ids_to_remove.at(0), 3051729675574597004); |
58 | | - EXPECT_THAT(result.ref_to_remove.empty(), true); |
59 | | - EXPECT_THAT(result.schema_ids_to_remove.empty(), true); |
60 | | - EXPECT_THAT(result.partition_spec_ids_to_remove.empty(), true); |
61 | | -} |
62 | | - |
63 | | -TEST_F(ExpireSnapshotsTest, ExpireByIdNotExist) { |
64 | | - ICEBERG_UNWRAP_OR_FAIL(auto update, table_->NewExpireSnapshots()); |
65 | | - update->ExpireSnapshotId(3055729675574597003); |
66 | | - update->RetainLast(2); |
67 | | - auto result = update->Apply(); |
68 | | - EXPECT_THAT(result.has_value(), false); |
69 | | - EXPECT_THAT(result.error().message.contains("Snapshot:3055729675574597003 not exist"), |
70 | | - true); |
| 48 | + EXPECT_EQ(result.snapshot_ids_to_remove.size(), 1); |
| 49 | + EXPECT_EQ(result.snapshot_ids_to_remove.at(0), 3051729675574597004); |
71 | 50 | } |
72 | 51 |
|
73 | | -TEST_F(ExpireSnapshotsTest, ExpireOlderThan1) { |
74 | | - ICEBERG_UNWRAP_OR_FAIL(auto update, table_->NewExpireSnapshots()); |
75 | | - update->ExpireOlderThan(1515100955770 - 1); |
76 | | - ICEBERG_UNWRAP_OR_FAIL(auto result, update->Apply()); |
77 | | - EXPECT_THAT(result.snapshot_ids_to_remove.empty(), true); |
78 | | - EXPECT_THAT(result.ref_to_remove.empty(), true); |
79 | | - EXPECT_THAT(result.schema_ids_to_remove.empty(), true); |
80 | | - EXPECT_THAT(result.partition_spec_ids_to_remove.empty(), true); |
81 | | -} |
82 | | - |
83 | | -TEST_F(ExpireSnapshotsTest, ExpireOlderThan2) { |
84 | | - ICEBERG_UNWRAP_OR_FAIL(auto update, table_->NewExpireSnapshots()); |
85 | | - update->ExpireOlderThan(1515100955770 + 1); |
86 | | - ICEBERG_UNWRAP_OR_FAIL(auto result, update->Apply()); |
87 | | - EXPECT_THAT(result.snapshot_ids_to_remove.size(), 1); |
88 | | - EXPECT_THAT(result.snapshot_ids_to_remove.at(0), 3051729675574597004); |
89 | | - EXPECT_THAT(result.ref_to_remove.empty(), true); |
90 | | - EXPECT_THAT(result.schema_ids_to_remove.empty(), true); |
91 | | - EXPECT_THAT(result.partition_spec_ids_to_remove.empty(), true); |
| 52 | +TEST_F(ExpireSnapshotsTest, ExpireOlderThan) { |
| 53 | + struct TestCase { |
| 54 | + int64_t expire_older_than; |
| 55 | + size_t expected_num_expired; |
| 56 | + }; |
| 57 | + std::vector<TestCase> test_cases = {{1515100955770 - 1, 0}, {1515100955770 + 1, 1}}; |
| 58 | + for (const auto& test_case : test_cases) { |
| 59 | + ICEBERG_UNWRAP_OR_FAIL(auto update, table_->NewExpireSnapshots()); |
| 60 | + update->ExpireOlderThan(test_case.expire_older_than); |
| 61 | + ICEBERG_UNWRAP_OR_FAIL(auto result, update->Apply()); |
| 62 | + EXPECT_EQ(result.snapshot_ids_to_remove.size(), test_case.expected_num_expired); |
| 63 | + } |
92 | 64 | } |
93 | 65 |
|
94 | 66 | } // namespace iceberg |
0 commit comments