rdblue commented on code in PR #6706: URL: https://github.com/apache/iceberg/pull/6706#discussion_r1098073489
########## core/src/test/java/org/apache/iceberg/TestSnapshotOperations.java: ########## @@ -0,0 +1,209 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iceberg; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import org.apache.iceberg.io.FileIO; +import org.apache.iceberg.io.LocationProvider; +import org.apache.iceberg.relocated.com.google.common.collect.Lists; +import org.apache.iceberg.util.SerializableSupplier; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.mockito.Mockito; + +@RunWith(Parameterized.class) +public class TestSnapshotOperations extends TableTestBase { + @Parameterized.Parameters(name = "formatVersion = {0}") + public static Object[] parameters() { + return new Object[] {1, 2}; + } + + public TestSnapshotOperations(int formatVersion) { + super(formatVersion); + } + + private Snapshot currentSnapshot; + private List<Snapshot> allSnapshots; + private SerializableSupplier<List<Snapshot>> snapshotSupplier; + + @Before + public void before() { + table.newFastAppend().appendFile(FILE_A).commit(); + table.newFastAppend().appendFile(FILE_B).commit(); + + this.currentSnapshot = table.currentSnapshot(); + this.allSnapshots = Lists.newArrayList(table.snapshots()); + + // Anonymous class is required for proper mocking as opposed to lambda + this.snapshotSupplier = + new SerializableSupplier<List<Snapshot>>() { + @Override + public List<Snapshot> get() { + return allSnapshots; + } + }; + } + + @Test + public void testSnapshotsLoadBehavior() { + SerializableSupplier<List<Snapshot>> snapshotsSupplierMock = Mockito.spy(snapshotSupplier); + + List<Snapshot> initialSnapshots = + currentSnapshot != null + ? Collections.singletonList(currentSnapshot) + : Collections.emptyList(); + + SnapshotOperations snapshotOperations = + SnapshotOperations.buildFromEmpty() + .snapshots(initialSnapshots) Review Comment: This could just be `allSnapshots` right? The supplier will get called either way. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org