chesnokoff commented on code in PR #11969: URL: https://github.com/apache/ignite/pull/11969#discussion_r2070146165
########## modules/compatibility/src/test/java/org/apache/ignite/compatibility/persistence/IgniteNodeFileTreeCompatibilityAbstractTest.java: ########## @@ -0,0 +1,282 @@ +package org.apache.ignite.compatibility.persistence; + +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.cluster.ClusterState; +import org.apache.ignite.compatibility.IgniteReleasedVersion; +import org.apache.ignite.compatibility.testframework.junits.IgniteCompatibilityAbstractTest; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteInClosure; +import org.junit.Before; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; + +/** + * + */ +@RunWith(Parameterized.class) +public abstract class IgniteNodeFileTreeCompatibilityAbstractTest extends IgniteCompatibilityAbstractTest { + /** */ + protected static final String OLD_IGNITE_VERSION = Arrays.stream(IgniteReleasedVersion.values()) + .max(Comparator.comparing(IgniteReleasedVersion::version)) + .map(IgniteReleasedVersion::toString) + .orElseThrow(() -> new IllegalStateException("Enum is empty")); + + /** */ + protected static final String SNAPSHOT_NAME = "test_snapshot"; + + /** */ + protected static final String CACHE_DUMP_NAME = "test_cache_dump"; + + /** */ + protected static final int BASE_CACHE_SIZE = 100; + + /** */ + protected static final int ENTRIES_CNT_FOR_INCREMENT = 100; + + /** */ + @Parameter Review Comment: Add zero index here ########## modules/compatibility/src/test/java/org/apache/ignite/compatibility/persistence/IgniteNodeFileTreeCompatibilityAbstractTest.java: ########## @@ -0,0 +1,282 @@ +package org.apache.ignite.compatibility.persistence; + +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.cluster.ClusterState; +import org.apache.ignite.compatibility.IgniteReleasedVersion; +import org.apache.ignite.compatibility.testframework.junits.IgniteCompatibilityAbstractTest; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteInClosure; +import org.junit.Before; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; + +/** + * + */ Review Comment: Use one line comment ########## modules/compatibility/src/test/java/org/apache/ignite/compatibility/persistence/NodeFileTreeCompatibilityTest.java: ########## @@ -0,0 +1,289 @@ +package org.apache.ignite.compatibility.persistence; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +import org.apache.commons.io.FileUtils; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.junit.Test; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +/** */ +public class NodeFileTreeCompatibilityTest extends IgniteNodeFileTreeCompatibilityAbstractTest { + /** */ + @Parameter(5) + public int nodesCnt; + + /** */ + private static final String OLD_WORK_DIR; + + static { + try { + OLD_WORK_DIR = String.format("%s-%s", U.defaultWorkDirectory(), OLD_IGNITE_VERSION); + } + catch (IgniteCheckedException e) { + throw new RuntimeException(e); + } + } + + /** */ + @Parameters(name = "incSnp={0}, customConsId={1}, cacheDump={2}, customSnpPath={3}, testCacheGrp={4}, nodesCnt={5}") + public static Collection<Object[]> data() { + List<Object[]> data = new ArrayList<>(); + + for (boolean incSnp : Arrays.asList(true, false)) + for (boolean customConsId: Arrays.asList(true, false)) + for (boolean cacheDump : Arrays.asList(true, false)) + for (boolean customSnpPath : Arrays.asList(true, false)) + for (boolean testCacheGrp : Arrays.asList(true, false)) + for (int nodesCnt : Arrays.asList(1, 3)) + if (!incSnp || !cacheDump) + data.add(new Object[]{incSnp, customConsId, cacheDump, customSnpPath, testCacheGrp, nodesCnt}); + + return data; + } + + /** */ + @Test + public void testNodeFileTree() throws Exception { + try { + ArrayList<IgniteEx> oldNodes = new ArrayList<>(nodesCnt); + ArrayList<IgniteEx> curNodes = new ArrayList<>(nodesCnt); + + for (int i = 1; i < nodesCnt; ++i) { + oldNodes.add( + startGrid( + i, + OLD_IGNITE_VERSION, + new ConfigurationClosure(incSnp, consId(customConsId, i), customSnpPath, true, cacheGrpInfo, OLD_WORK_DIR) + ) + ); + } + + oldNodes.add( + startGrid( + nodesCnt, + OLD_IGNITE_VERSION, + new ConfigurationClosure(incSnp, consId(customConsId, nodesCnt), customSnpPath, true, cacheGrpInfo, OLD_WORK_DIR), + new CreateSnapshotClosure(incSnp, cacheDump, cacheGrpInfo) + ) + ); + + stopAllGrids(); + + for (int i = 0; i < nodesCnt; ++i) { + curNodes.add( + startGrid( + i, + new ConfigurationClosure(incSnp, consId(customConsId, i), customSnpPath, true, cacheGrpInfo)::apply + ) + ); + } + + new CreateSnapshotClosure(incSnp, cacheDump, cacheGrpInfo).apply(curNodes.get(0)); + + assertEquals(scanFileTree(OLD_WORK_DIR, ".bin"), scanFileTree(U.defaultWorkDirectory(), ".bin")); + + if (cacheDump) { + assertEquals( + scanFileTree(snpPath(customSnpPath, OLD_WORK_DIR, CACHE_DUMP_NAME), ".dump"), + scanFileTree(snpPath(customSnpPath, U.defaultWorkDirectory(), CACHE_DUMP_NAME), ".dump") + ); + } + else { + assertEquals( + scanSnp(snpPath(customSnpPath, OLD_WORK_DIR, SNAPSHOT_NAME)), + scanSnp(snpPath(customSnpPath, U.defaultWorkDirectory(), SNAPSHOT_NAME)) + ); + } + } + finally { + stopAllGrids(); + + cleanPersistenceDir(false); + + FileUtils.deleteDirectory(new File(OLD_WORK_DIR)); Review Comment: I think it's better to move to `@afterTest` method. And than you can move initialization of OLD_WORK_DIR to `@beforeTest` ########## modules/compatibility/src/test/java/org/apache/ignite/compatibility/persistence/NodeFileTreeCompatibilityTest.java: ########## @@ -0,0 +1,289 @@ +package org.apache.ignite.compatibility.persistence; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +import org.apache.commons.io.FileUtils; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.junit.Test; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +/** */ +public class NodeFileTreeCompatibilityTest extends IgniteNodeFileTreeCompatibilityAbstractTest { + /** */ + @Parameter(5) + public int nodesCnt; + + /** */ + private static final String OLD_WORK_DIR; + + static { + try { + OLD_WORK_DIR = String.format("%s-%s", U.defaultWorkDirectory(), OLD_IGNITE_VERSION); + } + catch (IgniteCheckedException e) { + throw new RuntimeException(e); + } + } + + /** */ + @Parameters(name = "incSnp={0}, customConsId={1}, cacheDump={2}, customSnpPath={3}, testCacheGrp={4}, nodesCnt={5}") + public static Collection<Object[]> data() { + List<Object[]> data = new ArrayList<>(); + + for (boolean incSnp : Arrays.asList(true, false)) Review Comment: extract `Arrays.asList(true, false)` variable ########## modules/compatibility/src/test/java/org/apache/ignite/compatibility/persistence/NodeFileTreeCompatibilityTest.java: ########## @@ -0,0 +1,289 @@ +package org.apache.ignite.compatibility.persistence; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +import org.apache.commons.io.FileUtils; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.junit.Test; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +/** */ +public class NodeFileTreeCompatibilityTest extends IgniteNodeFileTreeCompatibilityAbstractTest { + /** */ + @Parameter(5) + public int nodesCnt; + + /** */ + private static final String OLD_WORK_DIR; + + static { + try { + OLD_WORK_DIR = String.format("%s-%s", U.defaultWorkDirectory(), OLD_IGNITE_VERSION); + } + catch (IgniteCheckedException e) { + throw new RuntimeException(e); + } + } + + /** */ + @Parameters(name = "incSnp={0}, customConsId={1}, cacheDump={2}, customSnpPath={3}, testCacheGrp={4}, nodesCnt={5}") + public static Collection<Object[]> data() { + List<Object[]> data = new ArrayList<>(); + + for (boolean incSnp : Arrays.asList(true, false)) + for (boolean customConsId: Arrays.asList(true, false)) + for (boolean cacheDump : Arrays.asList(true, false)) + for (boolean customSnpPath : Arrays.asList(true, false)) + for (boolean testCacheGrp : Arrays.asList(true, false)) + for (int nodesCnt : Arrays.asList(1, 3)) + if (!incSnp || !cacheDump) + data.add(new Object[]{incSnp, customConsId, cacheDump, customSnpPath, testCacheGrp, nodesCnt}); + + return data; + } + + /** */ + @Test + public void testNodeFileTree() throws Exception { + try { + ArrayList<IgniteEx> oldNodes = new ArrayList<>(nodesCnt); + ArrayList<IgniteEx> curNodes = new ArrayList<>(nodesCnt); Review Comment: Use interface instead of realization in variable declaration ########## modules/compatibility/src/test/java/org/apache/ignite/compatibility/persistence/NodeFileTreeCompatibilityTest.java: ########## @@ -0,0 +1,289 @@ +package org.apache.ignite.compatibility.persistence; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +import org.apache.commons.io.FileUtils; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.junit.Test; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +/** */ +public class NodeFileTreeCompatibilityTest extends IgniteNodeFileTreeCompatibilityAbstractTest { + /** */ + @Parameter(5) + public int nodesCnt; + + /** */ + private static final String OLD_WORK_DIR; + + static { + try { + OLD_WORK_DIR = String.format("%s-%s", U.defaultWorkDirectory(), OLD_IGNITE_VERSION); + } + catch (IgniteCheckedException e) { + throw new RuntimeException(e); + } + } Review Comment: Too complicated. Just move this field to test method and make as variable ########## modules/compatibility/src/test/java/org/apache/ignite/compatibility/persistence/NodeFileTreeCompatibilityTest.java: ########## @@ -0,0 +1,289 @@ +package org.apache.ignite.compatibility.persistence; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +import org.apache.commons.io.FileUtils; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.junit.Test; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +/** */ +public class NodeFileTreeCompatibilityTest extends IgniteNodeFileTreeCompatibilityAbstractTest { + /** */ + @Parameter(5) + public int nodesCnt; + + /** */ + private static final String OLD_WORK_DIR; + + static { + try { + OLD_WORK_DIR = String.format("%s-%s", U.defaultWorkDirectory(), OLD_IGNITE_VERSION); + } + catch (IgniteCheckedException e) { + throw new RuntimeException(e); + } + } + + /** */ + @Parameters(name = "incSnp={0}, customConsId={1}, cacheDump={2}, customSnpPath={3}, testCacheGrp={4}, nodesCnt={5}") + public static Collection<Object[]> data() { + List<Object[]> data = new ArrayList<>(); + + for (boolean incSnp : Arrays.asList(true, false)) + for (boolean customConsId: Arrays.asList(true, false)) + for (boolean cacheDump : Arrays.asList(true, false)) + for (boolean customSnpPath : Arrays.asList(true, false)) + for (boolean testCacheGrp : Arrays.asList(true, false)) + for (int nodesCnt : Arrays.asList(1, 3)) + if (!incSnp || !cacheDump) + data.add(new Object[]{incSnp, customConsId, cacheDump, customSnpPath, testCacheGrp, nodesCnt}); + + return data; + } + + /** */ + @Test + public void testNodeFileTree() throws Exception { + try { + ArrayList<IgniteEx> oldNodes = new ArrayList<>(nodesCnt); + ArrayList<IgniteEx> curNodes = new ArrayList<>(nodesCnt); + + for (int i = 1; i < nodesCnt; ++i) { + oldNodes.add( + startGrid( + i, + OLD_IGNITE_VERSION, + new ConfigurationClosure(incSnp, consId(customConsId, i), customSnpPath, true, cacheGrpInfo, OLD_WORK_DIR) + ) + ); + } + + oldNodes.add( + startGrid( + nodesCnt, + OLD_IGNITE_VERSION, + new ConfigurationClosure(incSnp, consId(customConsId, nodesCnt), customSnpPath, true, cacheGrpInfo, OLD_WORK_DIR), + new CreateSnapshotClosure(incSnp, cacheDump, cacheGrpInfo) + ) + ); + + stopAllGrids(); + + for (int i = 0; i < nodesCnt; ++i) { + curNodes.add( + startGrid( + i, + new ConfigurationClosure(incSnp, consId(customConsId, i), customSnpPath, true, cacheGrpInfo)::apply + ) + ); + } + + new CreateSnapshotClosure(incSnp, cacheDump, cacheGrpInfo).apply(curNodes.get(0)); + + assertEquals(scanFileTree(OLD_WORK_DIR, ".bin"), scanFileTree(U.defaultWorkDirectory(), ".bin")); + + if (cacheDump) { Review Comment: Redundant {} braces ########## modules/compatibility/src/test/java/org/apache/ignite/compatibility/persistence/NodeFileTreeCompatibilityTest.java: ########## @@ -0,0 +1,289 @@ +package org.apache.ignite.compatibility.persistence; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +import org.apache.commons.io.FileUtils; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.junit.Test; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +/** */ +public class NodeFileTreeCompatibilityTest extends IgniteNodeFileTreeCompatibilityAbstractTest { + /** */ + @Parameter(5) + public int nodesCnt; + + /** */ + private static final String OLD_WORK_DIR; + + static { + try { + OLD_WORK_DIR = String.format("%s-%s", U.defaultWorkDirectory(), OLD_IGNITE_VERSION); + } + catch (IgniteCheckedException e) { + throw new RuntimeException(e); + } + } + + /** */ + @Parameters(name = "incSnp={0}, customConsId={1}, cacheDump={2}, customSnpPath={3}, testCacheGrp={4}, nodesCnt={5}") + public static Collection<Object[]> data() { + List<Object[]> data = new ArrayList<>(); + + for (boolean incSnp : Arrays.asList(true, false)) + for (boolean customConsId: Arrays.asList(true, false)) + for (boolean cacheDump : Arrays.asList(true, false)) + for (boolean customSnpPath : Arrays.asList(true, false)) + for (boolean testCacheGrp : Arrays.asList(true, false)) + for (int nodesCnt : Arrays.asList(1, 3)) + if (!incSnp || !cacheDump) + data.add(new Object[]{incSnp, customConsId, cacheDump, customSnpPath, testCacheGrp, nodesCnt}); + + return data; + } + + /** */ + @Test + public void testNodeFileTree() throws Exception { + try { + ArrayList<IgniteEx> oldNodes = new ArrayList<>(nodesCnt); + ArrayList<IgniteEx> curNodes = new ArrayList<>(nodesCnt); + + for (int i = 1; i < nodesCnt; ++i) { + oldNodes.add( + startGrid( + i, + OLD_IGNITE_VERSION, + new ConfigurationClosure(incSnp, consId(customConsId, i), customSnpPath, true, cacheGrpInfo, OLD_WORK_DIR) + ) + ); + } + + oldNodes.add( + startGrid( + nodesCnt, + OLD_IGNITE_VERSION, + new ConfigurationClosure(incSnp, consId(customConsId, nodesCnt), customSnpPath, true, cacheGrpInfo, OLD_WORK_DIR), + new CreateSnapshotClosure(incSnp, cacheDump, cacheGrpInfo) + ) + ); + + stopAllGrids(); + + for (int i = 0; i < nodesCnt; ++i) { + curNodes.add( + startGrid( + i, + new ConfigurationClosure(incSnp, consId(customConsId, i), customSnpPath, true, cacheGrpInfo)::apply + ) + ); + } + + new CreateSnapshotClosure(incSnp, cacheDump, cacheGrpInfo).apply(curNodes.get(0)); + + assertEquals(scanFileTree(OLD_WORK_DIR, ".bin"), scanFileTree(U.defaultWorkDirectory(), ".bin")); + + if (cacheDump) { + assertEquals( + scanFileTree(snpPath(customSnpPath, OLD_WORK_DIR, CACHE_DUMP_NAME), ".dump"), + scanFileTree(snpPath(customSnpPath, U.defaultWorkDirectory(), CACHE_DUMP_NAME), ".dump") + ); + } + else { Review Comment: Redundant {} braces ########## modules/compatibility/src/test/java/org/apache/ignite/compatibility/persistence/IgniteNodeFileTreeCompatibilityAbstractTest.java: ########## @@ -0,0 +1,282 @@ +package org.apache.ignite.compatibility.persistence; + +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.cluster.ClusterState; +import org.apache.ignite.compatibility.IgniteReleasedVersion; +import org.apache.ignite.compatibility.testframework.junits.IgniteCompatibilityAbstractTest; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteInClosure; +import org.junit.Before; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; + +/** + * + */ +@RunWith(Parameterized.class) +public abstract class IgniteNodeFileTreeCompatibilityAbstractTest extends IgniteCompatibilityAbstractTest { + /** */ + protected static final String OLD_IGNITE_VERSION = Arrays.stream(IgniteReleasedVersion.values()) + .max(Comparator.comparing(IgniteReleasedVersion::version)) + .map(IgniteReleasedVersion::toString) + .orElseThrow(() -> new IllegalStateException("Enum is empty")); + + /** */ + protected static final String SNAPSHOT_NAME = "test_snapshot"; + + /** */ + protected static final String CACHE_DUMP_NAME = "test_cache_dump"; + + /** */ + protected static final int BASE_CACHE_SIZE = 100; + + /** */ + protected static final int ENTRIES_CNT_FOR_INCREMENT = 100; + + /** */ + @Parameter + public boolean incSnp; + + /** */ + @Parameter(1) + public boolean customConsId; + + /** */ + @Parameter(2) + public boolean cacheDump; + + /** */ + @Parameter(3) + public boolean customSnpPath; + + /** */ + @Parameter(4) + public boolean testCacheGrp; + + /** */ + protected CacheGroupInfo cacheGrpInfo; + + /** */ + @Before + public void setUp() { + cacheGrpInfo = new CacheGroupInfo("test-cache", testCacheGrp ? 2 : 1); + } + + /** */ + protected static String calcValue(String cacheName, int key) { + return cacheName + "-organization-" + key; + } + + /** */ + protected static String consId(boolean custom, int nodeIdx) { + return custom ? "node-" + nodeIdx : null; + } + + /** */ + protected static String snpDir(boolean custom, String workDirPath, boolean delIfExist) throws IgniteCheckedException { + return U.resolveWorkDirectory(workDirPath, custom ? "ex_snapshots" : "snapshots", delIfExist).getAbsolutePath(); + } + + /** */ + protected static String snpPath(boolean custom, String workDirPath, String snpName) throws IgniteCheckedException { + return Paths.get(snpDir(custom, workDirPath, false), snpName).toString(); + } + + /** + * Configuration closure both for old and current Ignite version. + */ + protected static class ConfigurationClosure implements IgniteInClosure<IgniteConfiguration> { + /** */ + private final boolean incSnp; + + /** */ + private final String consId; + + /** */ + private final boolean customSnpPath; + + /** */ + private final boolean delIfExist; + + /** */ + private final CacheGroupInfo cacheGrpInfo; + + /** */ + private String workDir; + + /** */ + public ConfigurationClosure( + boolean incSnp, + String consId, + boolean customSnpPath, + boolean delIfExist, + CacheGroupInfo cacheGrpInfo + ) throws IgniteCheckedException { + this.incSnp = incSnp; + this.consId = consId; + this.customSnpPath = customSnpPath; + this.delIfExist = delIfExist; + this.cacheGrpInfo = cacheGrpInfo; + workDir = U.defaultWorkDirectory(); + } + + /** */ + public ConfigurationClosure( + boolean incSnp, + String consId, + boolean customSnpPath, + boolean delIfExist, + CacheGroupInfo cacheGrpInfo, + String workDir + ) throws IgniteCheckedException { + this(incSnp, consId, customSnpPath, delIfExist, cacheGrpInfo); + + this.workDir = workDir; + } + + /** {@inheritDoc} */ + @Override public void apply(IgniteConfiguration cfg) { + cfg.setWorkDirectory(workDir); + + DataStorageConfiguration storageCfg = new DataStorageConfiguration(); + + storageCfg.getDefaultDataRegionConfiguration().setPersistenceEnabled(true); + + cfg.setDataStorageConfiguration(storageCfg); + + cfg.setConsistentId(consId); + + storageCfg.setWalCompactionEnabled(incSnp); + + if (delIfExist) { + cfg.setCacheConfiguration( + cacheGrpInfo.cacheNamesList().stream() + .map(cacheName -> new CacheConfiguration<Integer, String>(cacheName) + .setGroupName(cacheGrpInfo.name()) + .setAffinity(new RendezvousAffinityFunction(false, 10)) + ) + .toArray(CacheConfiguration[]::new) + ); + } + + try { + cfg.setSnapshotPath(snpDir(customSnpPath, workDir, delIfExist)); + } + catch (IgniteCheckedException e) { + throw new RuntimeException(e); + } + } + } + + /** + * Snapshot creating closure for old Ignite version. + */ Review Comment: Make one line ########## modules/compatibility/src/test/java/org/apache/ignite/compatibility/persistence/IgniteNodeFileTreeCompatibilityAbstractTest.java: ########## @@ -0,0 +1,282 @@ +package org.apache.ignite.compatibility.persistence; + +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +import org.apache.ignite.cluster.ClusterState; +import org.apache.ignite.compatibility.IgniteReleasedVersion; +import org.apache.ignite.compatibility.testframework.junits.IgniteCompatibilityAbstractTest; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteInClosure; +import org.junit.Before; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; + +/** + * + */ +@RunWith(Parameterized.class) +public abstract class IgniteNodeFileTreeCompatibilityAbstractTest extends IgniteCompatibilityAbstractTest { + /** */ + protected static final String OLD_IGNITE_VERSION = Arrays.stream(IgniteReleasedVersion.values()) + .max(Comparator.comparing(IgniteReleasedVersion::version)) + .map(IgniteReleasedVersion::toString) + .orElseThrow(() -> new IllegalStateException("Enum is empty")); + + /** */ + protected static final String SNAPSHOT_NAME = "test_snapshot"; + + /** */ + protected static final String CACHE_DUMP_NAME = "test_cache_dump"; + + /** */ + protected static final int BASE_CACHE_SIZE = 100; + + /** */ + protected static final int ENTRIES_CNT_FOR_INCREMENT = 100; + + /** */ + @Parameter + public boolean incSnp; + + /** */ + @Parameter(1) + public boolean customConsId; + + /** */ + @Parameter(2) + public boolean cacheDump; + + /** */ + @Parameter(3) + public boolean customSnpPath; + + /** */ + @Parameter(4) + public boolean testCacheGrp; + + /** */ + protected CacheGroupInfo cacheGrpInfo; + + /** */ + @Before + public void setUp() { + cacheGrpInfo = new CacheGroupInfo("test-cache", testCacheGrp ? 2 : 1); + } + + /** */ + protected static String calcValue(String cacheName, int key) { + return cacheName + "-organization-" + key; + } + + /** */ + protected static String consId(boolean custom, int nodeIdx) { + return custom ? "node-" + nodeIdx : null; + } + + /** */ + protected static String snpDir(boolean custom, String workDirPath, boolean delIfExist) throws IgniteCheckedException { + return U.resolveWorkDirectory(workDirPath, custom ? "ex_snapshots" : "snapshots", delIfExist).getAbsolutePath(); + } + + /** */ + protected static String snpPath(boolean custom, String workDirPath, String snpName) throws IgniteCheckedException { + return Paths.get(snpDir(custom, workDirPath, false), snpName).toString(); + } + + /** + * Configuration closure both for old and current Ignite version. + */ Review Comment: Make one line comment ########## modules/compatibility/src/test/java/org/apache/ignite/compatibility/persistence/NodeFileTreeCompatibilityTest.java: ########## @@ -0,0 +1,289 @@ +package org.apache.ignite.compatibility.persistence; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +import org.apache.commons.io.FileUtils; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.junit.Test; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +/** */ +public class NodeFileTreeCompatibilityTest extends IgniteNodeFileTreeCompatibilityAbstractTest { + /** */ + @Parameter(5) + public int nodesCnt; + + /** */ + private static final String OLD_WORK_DIR; + + static { + try { + OLD_WORK_DIR = String.format("%s-%s", U.defaultWorkDirectory(), OLD_IGNITE_VERSION); + } + catch (IgniteCheckedException e) { + throw new RuntimeException(e); + } + } + + /** */ + @Parameters(name = "incSnp={0}, customConsId={1}, cacheDump={2}, customSnpPath={3}, testCacheGrp={4}, nodesCnt={5}") + public static Collection<Object[]> data() { + List<Object[]> data = new ArrayList<>(); + + for (boolean incSnp : Arrays.asList(true, false)) + for (boolean customConsId: Arrays.asList(true, false)) + for (boolean cacheDump : Arrays.asList(true, false)) + for (boolean customSnpPath : Arrays.asList(true, false)) + for (boolean testCacheGrp : Arrays.asList(true, false)) + for (int nodesCnt : Arrays.asList(1, 3)) + if (!incSnp || !cacheDump) + data.add(new Object[]{incSnp, customConsId, cacheDump, customSnpPath, testCacheGrp, nodesCnt}); + + return data; + } + + /** */ + @Test + public void testNodeFileTree() throws Exception { + try { + ArrayList<IgniteEx> oldNodes = new ArrayList<>(nodesCnt); + ArrayList<IgniteEx> curNodes = new ArrayList<>(nodesCnt); + + for (int i = 1; i < nodesCnt; ++i) { + oldNodes.add( + startGrid( + i, + OLD_IGNITE_VERSION, + new ConfigurationClosure(incSnp, consId(customConsId, i), customSnpPath, true, cacheGrpInfo, OLD_WORK_DIR) + ) + ); + } + + oldNodes.add( + startGrid( + nodesCnt, + OLD_IGNITE_VERSION, + new ConfigurationClosure(incSnp, consId(customConsId, nodesCnt), customSnpPath, true, cacheGrpInfo, OLD_WORK_DIR), + new CreateSnapshotClosure(incSnp, cacheDump, cacheGrpInfo) + ) + ); + + stopAllGrids(); + + for (int i = 0; i < nodesCnt; ++i) { Review Comment: Redundant {} braces -- 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: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org