tkalkirill commented on code in PR #1720: URL: https://github.com/apache/ignite-3/pull/1720#discussion_r1122167096
########## modules/table/src/test/java/org/apache/ignite/internal/table/distributed/gc/MvGcTest.java: ########## @@ -0,0 +1,358 @@ +/* + * 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.ignite.internal.table.distributed.gc; + +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willFailFast; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willTimeoutFast; +import static org.apache.ignite.internal.util.IgniteUtils.closeAllManually; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.internal.hlc.HybridTimestamp; +import org.apache.ignite.internal.table.distributed.StorageUpdateHandler; +import org.apache.ignite.internal.table.distributed.replicator.TablePartitionId; +import org.apache.ignite.lang.ErrorGroups.Gc; +import org.apache.ignite.lang.IgniteInternalException; +import org.jetbrains.annotations.Nullable; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; + +/** + * For testing {@link MvGc}. + */ +public class MvGcTest { + private static final int PARTITION_ID = 0; + + private MvGc gc; + + @BeforeEach + void setUp() { + gc = new MvGc("test", 1); + } + + @AfterEach + void tearDown() throws Exception { + closeAllManually(gc); + } + + @Test + void testAddStorageWithoutLowWatermark() { + CompletableFuture<Void> invokeVacuumMethodFuture = new CompletableFuture<>(); + + gc.addStorage(createTablePartitionId(), createWithCompleteFutureOnVacuum(invokeVacuumMethodFuture, null)); + + // We expect that StorageUpdateHandler#vacuum will not be called. + assertThat(invokeVacuumMethodFuture, willTimeoutFast()); + } + + @Test + void testAddStorageWithLowWatermark() { + HybridTimestamp lowWatermark = new HybridTimestamp(1, 1); + + gc.updateLowWatermark(lowWatermark); + + CompletableFuture<Void> invokeVacuumMethodFuture = new CompletableFuture<>(); + + gc.addStorage(createTablePartitionId(), createWithCompleteFutureOnVacuum(invokeVacuumMethodFuture, lowWatermark)); + + // We expect StorageUpdateHandler#vacuum to be called with the set low watermark. + assertThat(invokeVacuumMethodFuture, willCompleteSuccessfully()); + } + + @Test + void testStartVacuumOnSuccessfulUpdateLowWatermark() { + CompletableFuture<Void> invokeVacuumMethodFuture0 = new CompletableFuture<>(); + CompletableFuture<Void> invokeVacuumMethodFuture1 = new CompletableFuture<>(); + + HybridTimestamp lowWatermark0 = new HybridTimestamp(1, 1); + + StorageUpdateHandler storageUpdateHandler0 = createWithCompleteFutureOnVacuum(invokeVacuumMethodFuture0, lowWatermark0); + StorageUpdateHandler storageUpdateHandler1 = createWithCompleteFutureOnVacuum(invokeVacuumMethodFuture1, lowWatermark0); + + gc.addStorage(createTablePartitionId(), storageUpdateHandler0); + gc.addStorage(createTablePartitionId(), storageUpdateHandler1); + + gc.updateLowWatermark(lowWatermark0); + + // We expect StorageUpdateHandler#vacuum to be called with the set lowWatermark0. + assertThat(invokeVacuumMethodFuture0, willCompleteSuccessfully()); + assertThat(invokeVacuumMethodFuture1, willCompleteSuccessfully()); + + // What happens if we increase low watermark ? + Review Comment: Fix it -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
