Vladsz83 commented on code in PR #13666:
URL: https://github.com/apache/ignite/pull/13666#discussion_r4323532359


##########
modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerListSnapshotTest.java:
##########
@@ -0,0 +1,348 @@
+/*
+ * 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.util;
+
+import java.io.File;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collection;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.management.snapshot.SnapshotListCommand;
+import 
org.apache.ignite.internal.processors.cache.persistence.filename.SnapshotFileTree;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+import static java.nio.file.Files.newDirectoryStream;
+import static org.apache.ignite.cluster.ClusterState.ACTIVE;
+import static 
org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK;
+import static 
org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.snp;
+import static org.junit.Assume.assumeFalse;
+import static org.junit.Assume.assumeTrue;
+
+/** Test for the command '--snapshot list'. */
+public class GridCommandHandlerListSnapshotTest extends 
GridCommandHandlerAbstractTest {
+    /** External storage path. */
+    private static final String EXT_STORAGE_PATH = "extStorage";
+
+    /** Flag to use {@link 
DataStorageConfiguration#setExtraSnapshotPaths(String...)}. */
+    private boolean extStorages;
+
+    /** Resolved external storages paths. {@code null} if {@code extStorages} 
is {@code false}. */
+    private @Nullable String[] extStoragePaths;
+
+    /** Consistent id postfix. */
+    private @Nullable String cstIdPostfix = "";
+
+    /** Flag setting the usage of a custom snapshot path. */
+    @Parameter(1)
+    public boolean customPath;
+
+    /** Flag setting the usage of dedicated, own node working directories. */
+    @Parameter(2)
+    public boolean separatedWorkDir;
+
+    /** Flag to add external server node after the snapshot creation. */
+    @Parameter(3)
+    public boolean addExtraSrvr;
+
+    /** Number of incremental snapshots to add to the main test snapshots. */
+    @Parameter(4)
+    public int incCnt;
+
+    /** */
+    @Parameters(name = "cmdHnd={0}, customPath={1}, ownWorkDir={2}, 
addExtraSrvr={3}, incCnt={4}")
+    public static Collection<?> parameters() {
+        return GridTestUtils.cartesianProduct(
+            commandHandlers(),
+            F.asList(false, true), // Custom snapshot path.
+            F.asList(false, true), // Separated (own) work directories.
+            F.asList(false, true), // Add a server node after the snapshot 
creation.
+            F.asList(0, 2) // Number of incremental snapshots.
+        );
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+
+        cleanPersistenceDir();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        /** Handy if test running is interrupted and {@link #afterTest()} 
isn't invoked. */
+        cleanPersistenceDir();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void cleanPersistenceDir() throws Exception {
+        // Also cleans separated snapshot working directories and custom 
snapshot paths.
+        try (DirectoryStream<Path> files = 
newDirectoryStream(Paths.get(U.defaultWorkDirectory()))) {
+            for (Path path : files)
+                U.delete(path);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        String workDir = separatedWorkDir
+            ? new File(U.defaultWorkDirectory(), 
igniteInstanceName).getAbsolutePath()
+            : U.defaultWorkDirectory();
+
+        cfg.setWorkDirectory(workDir);
+
+        cfg.getDataStorageConfiguration().setWalCompactionEnabled(incCnt > 0);
+
+        if (extStorages) {
+            cfg.getDataStorageConfiguration().setExtraStoragePaths(
+                workDir + File.separator,
+                workDir + File.separator + EXT_STORAGE_PATH
+            );
+
+            extStoragePaths = 
cfg.getDataStorageConfiguration().getExtraStoragePaths();
+
+            cfg.getDataStorageConfiguration().setExtraSnapshotPaths("", 
EXT_STORAGE_PATH);
+        }
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getTestIgniteInstanceName() {
+        return super.getTestIgniteInstanceName() + cstIdPostfix;
+    }
+
+    /** */
+    @Test
+    public void testNoSnapshots() throws Exception {
+        doTestSnapshotsLists(0, false, false);
+    }
+
+    /** */
+    @Test
+    public void testSingleSnapshot() throws Exception {
+        doTestSnapshotsLists(1, false, false);
+    }
+
+    /** */
+    @Test
+    public void testSeveralSnapshots() throws Exception {
+        doTestSnapshotsLists(3, false, false);
+    }
+
+    /** */
+    @Test
+    public void testOneNodeMisses() throws Exception {
+        // Doesn't matter here.
+//        assumeFalse(incCnt > 0);

Review Comment:
   Done.



-- 
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