This is an automated email from the ASF dual-hosted git repository.

nizhikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new bb3266764d8 IGNITE-18403 Fix usage of explicit work dir for CDC 
(#10445)
bb3266764d8 is described below

commit bb3266764d8095e7016d9af12e802b892d4a38de
Author: Nikolay <[email protected]>
AuthorDate: Fri Dec 16 13:34:18 2022 +0300

    IGNITE-18403 Fix usage of explicit work dir for CDC (#10445)
---
 .../org/apache/ignite/internal/cdc/CdcMain.java    |   1 +
 .../ignite/cdc/CdcNonDefaultWorkDirTest.java       | 109 +++++++++++++++++++++
 .../ignite/testsuites/IgnitePdsTestSuite2.java     |   2 +
 3 files changed, 112 insertions(+)

diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/cdc/CdcMain.java 
b/modules/core/src/main/java/org/apache/ignite/internal/cdc/CdcMain.java
index 2f5cdfd252f..4307c326c86 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cdc/CdcMain.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cdc/CdcMain.java
@@ -346,6 +346,7 @@ public class CdcMain implements Runnable {
                 IgniteConfiguration cfg = super.prepareIgniteConfiguration();
 
                 
cfg.setIgniteInstanceName(cdcInstanceName(igniteCfg.getIgniteInstanceName()));
+                cfg.setWorkDirectory(igniteCfg.getWorkDirectory());
 
                 if (!F.isEmpty(cdcCfg.getMetricExporterSpi()))
                     cfg.setMetricExporterSpi(cdcCfg.getMetricExporterSpi());
diff --git 
a/modules/core/src/test/java/org/apache/ignite/cdc/CdcNonDefaultWorkDirTest.java
 
b/modules/core/src/test/java/org/apache/ignite/cdc/CdcNonDefaultWorkDirTest.java
new file mode 100644
index 00000000000..b0fd392f4fa
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/cdc/CdcNonDefaultWorkDirTest.java
@@ -0,0 +1,109 @@
+/*
+ * 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.cdc;
+
+import java.io.File;
+import java.util.concurrent.CountDownLatch;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.cdc.CdcMain;
+import org.apache.ignite.internal.processors.metric.MetricRegistry;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static 
org.apache.ignite.configuration.DataStorageConfiguration.DFLT_WAL_CDC_PATH;
+import static 
org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.DFLT_STORE_DIR;
+
+/** */
+public class CdcNonDefaultWorkDirTest extends GridCommonAbstractTest {
+    /** */
+    public static final String CONSISTENT_ID = "node";
+
+    /** */
+    public static final String DFLT_WORK_DIR;
+
+    static {
+        String dir = null;
+
+        try {
+            dir = U.defaultWorkDirectory();
+        }
+        catch (IgniteCheckedException ignored) {
+            // No-op.
+        }
+
+        DFLT_WORK_DIR = dir;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        assertNotNull(DFLT_WORK_DIR);
+        assertTrue(new File(new File(DFLT_WORK_DIR, DFLT_STORE_DIR), 
CONSISTENT_ID).mkdirs());
+        assertTrue(new File(new File(DFLT_WORK_DIR, DFLT_WAL_CDC_PATH), 
CONSISTENT_ID).mkdirs());
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        U.delete(new File(DFLT_WORK_DIR));
+        U.nullifyHomeDirectory();
+        U.getIgniteHome();
+    }
+
+    /** Tests CDC start with non default work directory. */
+    @Test
+    public void testCdcStartWithNonDefaultWorkDir() throws Exception {
+        U.nullifyHomeDirectory();
+
+        U.setIgniteHome("/not/existed/ignite/home");
+
+        IgniteConfiguration cfg = new IgniteConfiguration()
+            .setWorkDirectory(DFLT_WORK_DIR)
+            .setDataStorageConfiguration(new DataStorageConfiguration())
+            .setConsistentId(CONSISTENT_ID);
+
+        cfg.getDataStorageConfiguration()
+            .getDefaultDataRegionConfiguration()
+            .setPersistenceEnabled(true)
+            .setCdcEnabled(true);
+
+        CountDownLatch started = new CountDownLatch(1);
+
+        CdcConfiguration cdcCfg = new CdcConfiguration();
+
+        cdcCfg.setConsumer(new AbstractCdcTest.UserCdcConsumer() {
+            @Override public void start(MetricRegistry mreg) {
+                super.start(mreg);
+
+                started.countDown();
+            }
+        });
+
+        IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new 
CdcMain(cfg, null, cdcCfg));
+
+        try {
+            assertTrue(started.await(10, SECONDS));
+        }
+        finally {
+            fut.cancel();
+        }
+    }
+}
diff --git 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java
 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java
index a73b7584c1d..8b39f3e54ed 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java
@@ -22,6 +22,7 @@ import java.util.Collection;
 import java.util.List;
 import org.apache.ignite.cdc.CdcCacheConfigOnRestartTest;
 import org.apache.ignite.cdc.CdcCacheVersionTest;
+import org.apache.ignite.cdc.CdcNonDefaultWorkDirTest;
 import org.apache.ignite.cdc.CdcSelfTest;
 import org.apache.ignite.cdc.RestartWithWalForceArchiveTimeoutTest;
 import org.apache.ignite.cdc.WalForCdcTest;
@@ -156,6 +157,7 @@ public class IgnitePdsTestSuite2 {
         GridTestUtils.addTestIfNeeded(suite, 
RestartWithWalForceArchiveTimeoutTest.class, ignoredTests);
         GridTestUtils.addTestIfNeeded(suite, WalForCdcTest.class, 
ignoredTests);
         GridTestUtils.addTestIfNeeded(suite, 
CdcCacheConfigOnRestartTest.class, ignoredTests);
+        GridTestUtils.addTestIfNeeded(suite, CdcNonDefaultWorkDirTest.class, 
ignoredTests);
 
         // new style folders with generated consistent ID test
         GridTestUtils.addTestIfNeeded(suite, 
IgniteUidAsConsistentIdMigrationTest.class, ignoredTests);

Reply via email to