tkalkirill commented on code in PR #1666:
URL: https://github.com/apache/ignite-3/pull/1666#discussion_r1115769680


##########
modules/storage-api/src/test/java/org/apache/ignite/internal/storage/util/MvPartitionStoragesTest.java:
##########
@@ -0,0 +1,606 @@
+/*
+ * 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.storage.util;
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static java.util.concurrent.CompletableFuture.failedFuture;
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static 
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static 
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willFailFast;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.containsString;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import 
org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import 
org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
+import org.apache.ignite.internal.schema.configuration.TableConfiguration;
+import org.apache.ignite.internal.storage.MvPartitionStorage;
+import org.apache.ignite.internal.storage.StorageException;
+import org.apache.ignite.internal.storage.StorageRebalanceException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.function.Executable;
+
+/**
+ * Class for testing {@link MvPartitionStorages}.
+ */
+@ExtendWith(ConfigurationExtension.class)
+public class MvPartitionStoragesTest {
+    @InjectConfiguration
+    private TableConfiguration tableConfig;
+
+    private MvPartitionStorages<MvPartitionStorage> mvPartitionStorages;
+
+    @BeforeEach
+    void setUp() {
+        mvPartitionStorages = new MvPartitionStorages(tableConfig.value());
+    }
+
+    @Test
+    void testGet() {
+        assertThrows(IllegalArgumentException.class, () -> 
getMvStorage(getPartitionIdOutOfConfig()));
+
+        assertNull(getMvStorage(0));
+
+        assertThat(createMvStorage(0), willCompleteSuccessfully());
+
+        assertNotNull(getMvStorage(0));
+
+        assertNull(getMvStorage(1));
+    }
+
+    @Test
+    void testCreate() {
+        assertThat(createMvStorage(0), willCompleteSuccessfully());
+
+        CompletableFuture<Void> startCreateMvStorageFuture = new 
CompletableFuture<>();
+        CompletableFuture<Void> finishCreateMvStorageFuture = new 
CompletableFuture<>();
+
+        CompletableFuture<?> createMvStorageFuture = runAsync(() ->
+                assertThat(mvPartitionStorages.create(1, partId -> {
+                    startCreateMvStorageFuture.complete(null);
+
+                    assertThat(finishCreateMvStorageFuture, 
willCompleteSuccessfully());
+
+                    return mock(MvPartitionStorage.class);
+                }), willCompleteSuccessfully())
+        );
+
+        assertThat(startCreateMvStorageFuture, willCompleteSuccessfully());
+
+        assertThrowsWithMessage(StorageException.class, () -> 
createMvStorage(1), "Storage is in process of being created");
+
+        finishCreateMvStorageFuture.complete(null);
+
+        assertThat(createMvStorageFuture, willCompleteSuccessfully());
+    }
+
+    @Test
+    void testCreateError() {
+        assertThrows(IllegalArgumentException.class, () -> 
createMvStorage(getPartitionIdOutOfConfig()));
+
+        assertThat(createMvStorage(0), willCompleteSuccessfully());
+
+        assertThrowsWithMessage(StorageException.class, () -> 
createMvStorage(0), "Storage already exists");
+
+        // What if there is an error during the operation?
+
+        assertThat(mvPartitionStorages.create(2, partId -> {
+            throw new RuntimeException("from test");
+        }), willFailFast(RuntimeException.class));
+
+        assertNull(getMvStorage(2));
+    }
+
+    @Test
+    void testCreateDuringDestroy() {
+        assertThat(createMvStorage(0), willCompleteSuccessfully());
+
+        MvPartitionStorage mvStorage = getMvStorage(0);
+
+        CompletableFuture<Void> startDestroyMvStorageFuture = new 
CompletableFuture<>();
+        CompletableFuture<Void> finishDestroyMvStorageFuture = new 
CompletableFuture<>();
+
+        CompletableFuture<?> destroyMvStorageFuture = runAsync(() ->
+                assertThat(mvPartitionStorages.destroy(0, mvStorage1 -> {
+                    startDestroyMvStorageFuture.complete(null);
+
+                    return finishDestroyMvStorageFuture;
+                }), willCompleteSuccessfully())
+        );
+
+        assertThat(startDestroyMvStorageFuture, willCompleteSuccessfully());
+
+        CompletableFuture<MvPartitionStorage> reCreateMvStorageFuture = 
createMvStorage(0);
+
+        assertThrowsWithMessage(StorageException.class, () -> 
createMvStorage(0),
+                "Creation of the storage after its destruction is already 
planned"
+        );
+
+        finishDestroyMvStorageFuture.complete(null);
+
+        assertThat(destroyMvStorageFuture, willCompleteSuccessfully());
+
+        assertThat(reCreateMvStorageFuture, willCompleteSuccessfully());
+
+        assertNotSame(mvStorage, getMvStorage(0));
+    }
+
+    @Test
+    void testCreateDuringDestroyError() {
+        assertThat(createMvStorage(0), willCompleteSuccessfully());
+
+        // What if there is an error during the destroy?
+
+        MvPartitionStorage mvStorage = getMvStorage(0);
+
+        CompletableFuture<Void> startErrorDestroyMvStorageFuture = new 
CompletableFuture<>();
+        CompletableFuture<Void> finishErrorDestroyMvStorageFuture = new 
CompletableFuture<>();
+
+        CompletableFuture<?> errorDestroyMvStorageFuture = runAsync(() ->
+                assertThat(mvPartitionStorages.destroy(0, mvStorage1 -> {
+                    startErrorDestroyMvStorageFuture.complete(null);
+
+                    return finishErrorDestroyMvStorageFuture;
+                }), willCompleteSuccessfully())
+        );
+
+        assertThat(startErrorDestroyMvStorageFuture, 
willCompleteSuccessfully());
+
+        CompletableFuture<MvPartitionStorage> errorReCreateMvStorageFuture = 
createMvStorage(0);
+
+        finishErrorDestroyMvStorageFuture.completeExceptionally(new 
RuntimeException("from test"));
+
+        assertThat(errorDestroyMvStorageFuture, 
willFailFast(RuntimeException.class));
+        assertThat(errorReCreateMvStorageFuture, 
willFailFast(RuntimeException.class));
+
+        assertNull(getMvStorage(0));
+    }
+
+    @Test
+    void testCreateAfterDestroy() {

Review Comment:
   No, do you think it's needed? what to check in 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]

Reply via email to