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


##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteClusterShanpshotStreamerTest.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * 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.processors.cache.persistence.snapshot;
+
+import java.util.Collections;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataPageEvictionMode;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Test;
+
+import static org.apache.ignite.cluster.ClusterState.ACTIVE;
+import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
+
+/**
+ * Tests snapshot is consistent or snapshot process produces proper warning.
+ */
+public class IgniteClusterShanpshotStreamerTest extends 
AbstractSnapshotSelfTest {
+    /** */
+    private static final String INMEM_DATA_REGION = "inMemDr";
+
+    /** */
+    private IgniteSnapshotManager snpMgr;
+
+    /** */
+    private IgniteEx client;
+
+    /** {@inheritDoc} */
+    @Override public void beforeTestSnapshot() throws Exception {
+        super.beforeTestSnapshot();
+
+        persistence = true;
+
+        dfltCacheCfg.setBackups(2);
+
+        startGrids(3);
+
+        grid(0).cluster().state(ACTIVE);
+
+        client = startClientGrid(G.allGrids().size());
+
+        snpMgr = snp(grid(0));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        // In-memory data region.
+        DataRegionConfiguration inMemDr = new DataRegionConfiguration();
+        inMemDr.setPersistenceEnabled(false);
+        inMemDr.setMaxSize(100L * 1024L * 1024L);
+        inMemDr.setInitialSize(inMemDr.getMaxSize());
+        inMemDr.setName(INMEM_DATA_REGION);
+        inMemDr.setPageEvictionMode(DataPageEvictionMode.RANDOM_2_LRU);
+        cfg.getDataStorageConfiguration().setDataRegionConfigurations(inMemDr);
+
+        return cfg;
+    }
+
+    /**
+     * Tests snapshot consistency wnen streamer starts before snapshot. 
Default receiver.
+     */
+    @Test
+    public void testStreamerWhileSnapshotDefault() throws Exception {
+        doTestDataStreamerWhileSnapshot(true, false);
+    }
+
+    /**
+     * Tests snapshot consistency wnen streamer starts before snapshot. 
Overwriting receiver.
+     */
+    @Test
+    public void testStreamerWhileSnapshotOverwriting() throws Exception {
+        doTestDataStreamerWhileSnapshot(false, true);
+    }
+
+    /**
+     * Tests not affected by streamer cache is restorable from snapshot.
+     */
+    @Test
+    public void testOtherCacheRestores() throws IgniteCheckedException {
+        String cname = "cache2";
+        String expectedWrn = U.field(DataStreamerUpdatesHandler.class, 
"WRN_MSG");
+
+        grid(0).createCache(new 
CacheConfiguration<>(dfltCacheCfg).setName(cname));
+
+        try (IgniteDataStreamer<Integer, Integer> ds = 
grid(0).dataStreamer(cname)) {
+            for (int i = 0; i < 100; ++i)
+                ds.addData(i, i);
+        }
+
+        AtomicBoolean stopLoad = new AtomicBoolean();
+
+        IgniteInternalFuture<?> loadFut = runLoad(grid(0), false, stopLoad);
+
+        try {
+            assertThrows(null, () -> 
snpMgr.createSnapshot(SNAPSHOT_NAME).get(), IgniteException.class, expectedWrn);
+        }
+        finally {
+            stopLoad.set(true);
+            loadFut.get();
+        }
+
+        grid(0).destroyCache(cname);
+        grid(0).destroyCache(dfltCacheCfg.getName());
+
+        snpMgr.restoreSnapshot(SNAPSHOT_NAME, 
Collections.singletonList(cname)).get();
+
+        for (int i = 0; i < 100; ++i)
+            assertEquals(i, grid(0).cache(cname).get(i));
+    }
+
+    /**
+     * Tests streaming into in-memory cache doesn't affect snapshot.
+     */
+    @Test
+    public void testStreamingIntoInMememoryDoesntAffectSnapshot() throws 
IgniteCheckedException {
+        String cache2Name = "cache2";
+        int loadCnt = 1000;
+
+        grid(0).createCache(new 
CacheConfiguration<>(dfltCacheCfg).setName(cache2Name));
+
+        try (IgniteDataStreamer<Object, Object> ds = 
grid(0).dataStreamer(cache2Name)) {
+            for (int i = 0; i < loadCnt; ++i)
+                ds.addData(i, i);
+        }
+
+        grid(0).destroyCache(dfltCacheCfg.getName());
+        dfltCacheCfg.setDataRegionName(INMEM_DATA_REGION);
+        dfltCacheCfg.setEncryptionEnabled(false);
+        grid(0).createCache(dfltCacheCfg);
+
+        AtomicBoolean stop = new AtomicBoolean();
+
+        IgniteInternalFuture<?> loadFut = runLoad(grid(2), false, stop);
+
+        try {
+            snpMgr.createSnapshot(SNAPSHOT_NAME).get();
+        }
+        finally {
+            stop.set(true);
+            loadFut.get();
+        }
+
+        grid(0).destroyCache(cache2Name);
+
+        snpMgr.restoreSnapshot(SNAPSHOT_NAME, null).get();
+
+        for (int i = 0; i < loadCnt; ++i)
+            assertEquals(i, grid(0).cache(cache2Name).get(i));
+    }
+
+    /**
+     * Tests snapshot process throws warning if required.
+     *
+     * @param mustFail If {@code true}, checks snapshot process produces the 
warning. Otherwise, checks snapshot
+     *                 process produces no warning.
+     * @param allowOverwrite 'allowOverwrite' setting.
+     */
+    private void doTestDataStreamerWhileSnapshot(boolean mustFail, boolean 
allowOverwrite) throws Exception {
+        String expectedWrn = U.field(DataStreamerUpdatesHandler.class, 
"WRN_MSG");

Review Comment:
   Fixed



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