@@ -45,67 +45,53 @@ class SetSnapshotTest : public UpdateTestBase {
4545};
4646
4747TEST_F (SetSnapshotTest, SetCurrentSnapshotValid) {
48- // Create transaction and SetSnapshot
49- ICEBERG_UNWRAP_OR_FAIL (auto txn, table_->NewTransaction ());
50- ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, SetSnapshot::Make (txn));
48+ ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, table_->NewSetSnapshot ());
49+ EXPECT_EQ (set_snapshot->kind (), PendingUpdate::Kind::kSetSnapshot );
5150
52- // Set current snapshot to the older snapshot
5351 set_snapshot->SetCurrentSnapshot (kOldestSnapshotId );
5452
55- // Apply and verify
56- ICEBERG_UNWRAP_OR_FAIL (auto result, set_snapshot->Apply ());
57- EXPECT_NE (result, nullptr );
58- EXPECT_EQ (result->snapshot_id , kOldestSnapshotId );
53+ ICEBERG_UNWRAP_OR_FAIL (auto snapshot_id, set_snapshot->Apply ());
54+ EXPECT_EQ (snapshot_id, kOldestSnapshotId );
55+
56+ // Commit and verify the change was persisted
57+ EXPECT_THAT (set_snapshot->Commit (), IsOk ());
58+ ICEBERG_UNWRAP_OR_FAIL (auto reloaded, catalog_->LoadTable (table_ident_));
59+ ICEBERG_UNWRAP_OR_FAIL (auto current_snapshot, reloaded->current_snapshot ());
60+ EXPECT_EQ (current_snapshot->snapshot_id , kOldestSnapshotId );
5961}
6062
6163TEST_F (SetSnapshotTest, SetCurrentSnapshotToCurrentSnapshot) {
62- // Create transaction and SetSnapshot
63- ICEBERG_UNWRAP_OR_FAIL (auto txn, table_->NewTransaction ());
64- ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, SetSnapshot::Make (txn));
65-
66- // Set current snapshot to the current snapshot (no-op)
64+ ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, table_->NewSetSnapshot ());
6765 set_snapshot->SetCurrentSnapshot (kCurrentSnapshotId );
6866
69- // Apply and verify
70- ICEBERG_UNWRAP_OR_FAIL (auto result, set_snapshot->Apply ());
71- EXPECT_NE (result, nullptr );
72- EXPECT_EQ (result->snapshot_id , kCurrentSnapshotId );
67+ ICEBERG_UNWRAP_OR_FAIL (auto snapshot_id, set_snapshot->Apply ());
68+ EXPECT_EQ (snapshot_id, kCurrentSnapshotId );
7369}
7470
7571TEST_F (SetSnapshotTest, SetCurrentSnapshotInvalid) {
76- // Create transaction and SetSnapshot
77- ICEBERG_UNWRAP_OR_FAIL (auto txn, table_->NewTransaction ());
78- ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, SetSnapshot::Make (txn));
79-
72+ ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, table_->NewSetSnapshot ());
8073 // Try to set to a non-existent snapshot
8174 int64_t invalid_snapshot_id = 9999999999999999 ;
8275 set_snapshot->SetCurrentSnapshot (invalid_snapshot_id);
8376
8477 // Should fail during Apply
8578 auto result = set_snapshot->Apply ();
8679 EXPECT_THAT (result, IsError (ErrorKind::kValidationFailed ));
87- EXPECT_THAT (result, HasErrorMessage (" unknown snapshot id " ));
80+ EXPECT_THAT (result, HasErrorMessage (" is not found " ));
8881}
8982
9083TEST_F (SetSnapshotTest, RollbackToValid) {
91- // Create transaction and SetSnapshot
92- ICEBERG_UNWRAP_OR_FAIL (auto txn, table_->NewTransaction ());
93- ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, SetSnapshot::Make (txn));
94-
84+ ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, table_->NewSetSnapshot ());
9585 // Rollback to the oldest snapshot (which is an ancestor)
9686 set_snapshot->RollbackTo (kOldestSnapshotId );
9787
9888 // Apply and verify
99- ICEBERG_UNWRAP_OR_FAIL (auto result, set_snapshot->Apply ());
100- EXPECT_NE (result, nullptr );
101- EXPECT_EQ (result->snapshot_id , kOldestSnapshotId );
89+ ICEBERG_UNWRAP_OR_FAIL (auto snapshot_id, set_snapshot->Apply ());
90+ EXPECT_EQ (snapshot_id, kOldestSnapshotId );
10291}
10392
10493TEST_F (SetSnapshotTest, RollbackToInvalidSnapshot) {
105- // Create transaction and SetSnapshot
106- ICEBERG_UNWRAP_OR_FAIL (auto txn, table_->NewTransaction ());
107- ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, SetSnapshot::Make (txn));
108-
94+ ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, table_->NewSetSnapshot ());
10995 // Try to rollback to a non-existent snapshot
11096 int64_t invalid_snapshot_id = 9999999999999999 ;
11197 set_snapshot->RollbackTo (invalid_snapshot_id);
@@ -117,26 +103,19 @@ TEST_F(SetSnapshotTest, RollbackToInvalidSnapshot) {
117103}
118104
119105TEST_F (SetSnapshotTest, RollbackToTimeValidOldestSnapshot) {
120- // Create transaction and SetSnapshot
121- ICEBERG_UNWRAP_OR_FAIL (auto txn, table_->NewTransaction ());
122- ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, SetSnapshot::Make (txn));
123-
106+ ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, table_->NewSetSnapshot ());
124107 // Rollback to a time between the two snapshots
125108 // This should select the oldest snapshot
126109 int64_t time_between = (kOldestSnapshotTimestamp + kCurrentSnapshotTimestamp ) / 2 ;
127110 set_snapshot->RollbackToTime (time_between);
128111
129112 // Apply and verify
130- ICEBERG_UNWRAP_OR_FAIL (auto result, set_snapshot->Apply ());
131- EXPECT_NE (result, nullptr );
132- EXPECT_EQ (result->snapshot_id , kOldestSnapshotId );
113+ ICEBERG_UNWRAP_OR_FAIL (auto snapshot_id, set_snapshot->Apply ());
114+ EXPECT_EQ (snapshot_id, kOldestSnapshotId );
133115}
134116
135117TEST_F (SetSnapshotTest, RollbackToTimeBeforeAnySnapshot) {
136- // Create transaction and SetSnapshot
137- ICEBERG_UNWRAP_OR_FAIL (auto txn, table_->NewTransaction ());
138- ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, SetSnapshot::Make (txn));
139-
118+ ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, table_->NewSetSnapshot ());
140119 // Try to rollback to a time before any snapshot
141120 int64_t time_before_all = kOldestSnapshotTimestamp - 1000000 ;
142121 set_snapshot->RollbackToTime (time_before_all);
@@ -148,89 +127,30 @@ TEST_F(SetSnapshotTest, RollbackToTimeBeforeAnySnapshot) {
148127}
149128
150129TEST_F (SetSnapshotTest, RollbackToTimeExactMatch) {
151- // Create transaction and SetSnapshot
152- ICEBERG_UNWRAP_OR_FAIL (auto txn, table_->NewTransaction ());
153- ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, SetSnapshot::Make (txn));
154-
130+ ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, table_->NewSetSnapshot ());
155131 // Rollback to a timestamp just after the oldest snapshot
156132 // This should return the oldest snapshot (the latest one before this time)
157133 int64_t time_just_after_oldest = kOldestSnapshotTimestamp + 1 ;
158134 set_snapshot->RollbackToTime (time_just_after_oldest);
159135
160136 // Apply and verify - should return the oldest snapshot
161- ICEBERG_UNWRAP_OR_FAIL (auto result, set_snapshot->Apply ());
162- EXPECT_NE (result, nullptr );
163- EXPECT_EQ (result->snapshot_id , kOldestSnapshotId );
137+ ICEBERG_UNWRAP_OR_FAIL (auto snapshot_id, set_snapshot->Apply ());
138+ EXPECT_EQ (snapshot_id, kOldestSnapshotId );
164139}
165140
166141TEST_F (SetSnapshotTest, ApplyWithoutChanges) {
167- // Create transaction and SetSnapshot
168- ICEBERG_UNWRAP_OR_FAIL (auto txn, table_->NewTransaction ());
169- ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, SetSnapshot::Make (txn));
170-
142+ ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, table_->NewSetSnapshot ());
171143 // Apply without making any changes (NOOP)
172- ICEBERG_UNWRAP_OR_FAIL (auto result , set_snapshot->Apply ());
144+ ICEBERG_UNWRAP_OR_FAIL (auto snapshot_id , set_snapshot->Apply ());
173145
174146 // Should return current snapshot
175- EXPECT_NE (result, nullptr );
176- EXPECT_EQ (result->snapshot_id , kCurrentSnapshotId );
177- }
147+ EXPECT_EQ (snapshot_id, kCurrentSnapshotId );
178148
179- TEST_F (SetSnapshotTest, MethodChaining) {
180- // Create transaction and SetSnapshot
181- ICEBERG_UNWRAP_OR_FAIL (auto txn, table_->NewTransaction ());
182- ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, SetSnapshot::Make (txn));
183-
184- // Test that methods return reference for chaining
185- // Note: Only the last operation should take effect
186- auto & result1 = set_snapshot->SetCurrentSnapshot (kOldestSnapshotId );
187- EXPECT_EQ (&result1, set_snapshot.get ());
188- }
189-
190- TEST_F (SetSnapshotTest, CommitSuccess) {
191- // Create transaction and SetSnapshot
192- ICEBERG_UNWRAP_OR_FAIL (auto txn, table_->NewTransaction ());
193- ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, SetSnapshot::Make (txn));
194-
195- // Set to oldest snapshot
196- set_snapshot->SetCurrentSnapshot (kOldestSnapshotId );
197-
198- // Commit the change
149+ // Commit NOOP and verify nothing changed
199150 EXPECT_THAT (set_snapshot->Commit (), IsOk ());
200-
201- // Commit the transaction
202- ICEBERG_UNWRAP_OR_FAIL (auto updated_table, txn->Commit ());
203-
204- // Verify the current snapshot was changed
205- ICEBERG_UNWRAP_OR_FAIL (auto reloaded, catalog_->LoadTable (table_ident_));
206- ICEBERG_UNWRAP_OR_FAIL (auto current_snapshot, reloaded->current_snapshot ());
207- EXPECT_EQ (current_snapshot->snapshot_id , kOldestSnapshotId );
208- }
209-
210- TEST_F (SetSnapshotTest, CommitEmptyUpdate) {
211- // Create transaction and SetSnapshot
212- ICEBERG_UNWRAP_OR_FAIL (auto txn, table_->NewTransaction ());
213- ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, SetSnapshot::Make (txn));
214-
215- // Commit without making any changes (NOOP)
216- EXPECT_THAT (set_snapshot->Commit (), IsOk ());
217-
218- // Commit the transaction
219- ICEBERG_UNWRAP_OR_FAIL (auto updated_table, txn->Commit ());
220-
221- // Verify the current snapshot remained the same
222151 ICEBERG_UNWRAP_OR_FAIL (auto reloaded, catalog_->LoadTable (table_ident_));
223152 ICEBERG_UNWRAP_OR_FAIL (auto current_snapshot, reloaded->current_snapshot ());
224153 EXPECT_EQ (current_snapshot->snapshot_id , kCurrentSnapshotId );
225154}
226155
227- TEST_F (SetSnapshotTest, KindReturnsSetSnapshot) {
228- // Create transaction and SetSnapshot
229- ICEBERG_UNWRAP_OR_FAIL (auto txn, table_->NewTransaction ());
230- ICEBERG_UNWRAP_OR_FAIL (auto set_snapshot, SetSnapshot::Make (txn));
231-
232- // Verify the kind is correct
233- EXPECT_EQ (set_snapshot->kind (), PendingUpdate::Kind::kSetSnapshot );
234- }
235-
236156} // namespace iceberg
0 commit comments