You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2017/06/11 20:03:50 UTC
[24/47] ignite git commit: IGNITE-5267 - Moved ignite-ps module to
ignite-core
http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRemoveDuringRebalancingTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRemoveDuringRebalancingTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRemoveDuringRebalancingTest.java
new file mode 100644
index 0000000..e855859
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsRemoveDuringRebalancingTest.java
@@ -0,0 +1,143 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.util.concurrent.Callable;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheRebalanceMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.MemoryConfiguration;
+import org.apache.ignite.configuration.MemoryPolicyConfiguration;
+import org.apache.ignite.configuration.PersistentStoreConfiguration;
+import org.apache.ignite.configuration.WALMode;
+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.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ *
+ */
+public class IgnitePdsRemoveDuringRebalancingTest extends GridCommonAbstractTest {
+ /** */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ cfg.setCacheConfiguration(
+ new CacheConfiguration()
+ .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
+ .setBackups(1)
+ .setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC)
+ .setRebalanceMode(CacheRebalanceMode.SYNC)
+ );
+
+ MemoryConfiguration dbCfg = new MemoryConfiguration();
+
+ dbCfg.setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4);
+ dbCfg.setPageSize(1024);
+
+ MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration();
+
+ memPlcCfg.setName("dfltMemPlc");
+ memPlcCfg.setInitialSize(100 * 1024 * 1024);
+ memPlcCfg.setMaxSize(100 * 1024 * 1024);
+ memPlcCfg.setSwapFilePath("db");
+
+ dbCfg.setMemoryPolicies(memPlcCfg);
+ dbCfg.setDefaultMemoryPolicyName("dfltMemPlc");
+
+ cfg.setMemoryConfiguration(dbCfg);
+
+ cfg.setPersistentStoreConfiguration(
+ new PersistentStoreConfiguration()
+ .setWalMode(WALMode.LOG_ONLY)
+ );
+
+ cfg.setDiscoverySpi(
+ new TcpDiscoverySpi()
+ .setIpFinder(IP_FINDER)
+ );
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ stopAllGrids();
+
+ deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false));
+
+ U.delete(new File(U.getIgniteHome(), "db"));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ G.stopAll(true);
+
+ deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false));
+
+ U.delete(new File(U.getIgniteHome(), "db"));
+ }
+
+ /**
+ * @throws Exception if failed.
+ */
+ public void testRemovesDuringRebalancing() throws Exception {
+ IgniteEx ig = startGrid(0);
+
+ try (IgniteDataStreamer<Object, Object> streamer = ig.dataStreamer(null)) {
+ streamer.allowOverwrite(true);
+
+ for (int i = 0; i < 100_000; i++)
+ streamer.addData(i, i);
+ }
+
+ final IgniteCache<Object, Object> cache = ig.cache(null);
+
+ IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ return startGrid(1);
+ }
+ });
+
+ for (int i = 0; i < 100_000; i++)
+ cache.remove(i);
+
+ fut.get();
+
+ IgniteEx another = grid(1);
+
+ IgniteCache<Object, Object> cache1 = another.cache(null);
+
+ for (int i = 0; i < 100_000; i++)
+ assertNull(cache1.localPeek(i));
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsSingleNodePutGetPersistenceTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsSingleNodePutGetPersistenceTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsSingleNodePutGetPersistenceTest.java
new file mode 100644
index 0000000..1f861c7
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsSingleNodePutGetPersistenceTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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;
+
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.PersistentStoreConfiguration;
+import org.apache.ignite.configuration.WALMode;
+import org.apache.ignite.internal.processors.database.IgniteDbSingleNodePutGetTest;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+/**
+ *
+ */
+public class IgnitePdsSingleNodePutGetPersistenceTest extends IgniteDbSingleNodePutGetTest {
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ cfg.setPersistentStoreConfiguration(
+ new PersistentStoreConfiguration()
+ .setWalMode(WALMode.LOG_ONLY)
+ );
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false));
+
+ super.beforeTest();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false));
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsTxCacheRebalancingTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsTxCacheRebalancingTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsTxCacheRebalancingTest.java
new file mode 100644
index 0000000..c641ea4
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsTxCacheRebalancingTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheRebalanceMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.configuration.CacheConfiguration;
+
+/**
+ *
+ */
+public class IgnitePdsTxCacheRebalancingTest extends IgnitePdsCacheRebalancingAbstractTest {
+ /** {@inheritDoc} */
+ @Override protected CacheConfiguration cacheConfiguration(String cacheName) {
+ CacheConfiguration ccfg = new CacheConfiguration(cacheName);
+
+ ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
+ ccfg.setCacheMode(CacheMode.PARTITIONED);
+ ccfg.setRebalanceMode(CacheRebalanceMode.SYNC);
+ ccfg.setBackups(1);
+ ccfg.setRebalanceDelay(10_000);
+ ccfg.setAffinity(new RendezvousAffinityFunction(false, 32));
+ ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
+
+ return ccfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ explicitTx = false;
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTopologyChangesWithConstantLoadExplicitTx() throws Exception {
+ explicitTx = true;
+
+ testTopologyChangesWithConstantLoad();
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistenceMetricsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistenceMetricsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistenceMetricsSelfTest.java
new file mode 100644
index 0000000..72e0b61
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistenceMetricsSelfTest.java
@@ -0,0 +1,228 @@
+/*
+ * 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;
+
+import java.io.Serializable;
+import java.util.Objects;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.MemoryMetrics;
+import org.apache.ignite.PersistenceMetrics;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.MemoryConfiguration;
+import org.apache.ignite.configuration.MemoryPolicyConfiguration;
+import org.apache.ignite.configuration.PersistentStoreConfiguration;
+import org.apache.ignite.configuration.WALMode;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.PAX;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ *
+ */
+public class IgnitePersistenceMetricsSelfTest extends GridCommonAbstractTest {
+ /** */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** */
+ private static final String GROUP1 = "grp1";
+
+ /** */
+ private boolean activeOnStart = true;
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ GridTestUtils.deleteDbFiles();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ GridTestUtils.deleteDbFiles();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ cfg.setConsistentId(gridName);
+
+ cfg.setActiveOnStart(activeOnStart);
+
+ MemoryConfiguration memCfg = new MemoryConfiguration();
+ memCfg.setPageSize(1024);
+
+ memCfg.setDefaultMemoryPolicyName("dflt-plc");
+
+ MemoryPolicyConfiguration memPlc = new MemoryPolicyConfiguration();
+ memPlc.setName("dflt-plc");
+ memPlc.setMaxSize(10 * 1024 * 1024);
+ memPlc.setMetricsEnabled(true);
+
+ memCfg.setMemoryPolicies(memPlc);
+
+ cfg.setMemoryConfiguration(memCfg);
+
+ cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration()
+ .setMetricsEnabled(true).setWalMode(WALMode.LOG_ONLY));
+
+ cfg.setBinaryConfiguration(new BinaryConfiguration().setCompactFooter(false));
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
+
+ cfg.setCacheConfiguration(cacheConfiguration(GROUP1, "cache", PARTITIONED, ATOMIC, 1));
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ GridTestUtils.deleteDbFiles();
+
+ super.afterTest();
+ }
+
+ /**
+ * @param grpName Cache group name.
+ * @param name Cache name.
+ * @param cacheMode Cache mode.
+ * @param atomicityMode Atomicity mode.
+ * @param backups Backups number.
+ * @return Cache configuration.
+ */
+ private CacheConfiguration cacheConfiguration(
+ String grpName,
+ String name,
+ CacheMode cacheMode,
+ CacheAtomicityMode atomicityMode,
+ int backups
+ ) {
+ CacheConfiguration ccfg = new CacheConfiguration();
+
+ ccfg.setName(name);
+ ccfg.setGroupName(grpName);
+ ccfg.setAtomicityMode(atomicityMode);
+ ccfg.setBackups(backups);
+ ccfg.setCacheMode(cacheMode);
+ ccfg.setWriteSynchronizationMode(FULL_SYNC);
+
+ return ccfg;
+ }
+
+ /**
+ * @throws Exception if failed.
+ */
+ public void testPersistenceMetrics() throws Exception {
+ final IgniteEx ig = startGrid(0);
+
+ try {
+ IgniteCache<Object, Object> cache = ig.cache("cache");
+
+ for (int i = 0; i < 10; i++)
+ cache.put(i, new Person("first-" + i, "last-" + i));
+
+ {
+ MemoryMetrics memMetrics = ig.memoryMetrics("dflt-plc");
+
+ assertNotNull(memMetrics);
+ assertTrue(memMetrics.getDirtyPages() > 0);
+ }
+
+ ig.context().cache().context().database().waitForCheckpoint("test");
+
+ GridTestUtils.waitForCondition(new PAX() {
+ @Override public boolean applyx() {
+ PersistenceMetrics pMetrics = ig.persistentStoreMetrics();
+
+ assertNotNull(pMetrics);
+
+ return pMetrics.getLastCheckpointTotalPagesNumber() != 0 &&
+ pMetrics.getLastCheckpointDataPagesNumber() != 0;
+ }
+ }, 5_000);
+ }
+ finally {
+ stopAllGrids();
+ }
+ }
+
+ /**
+ *
+ */
+ static class Person implements Serializable {
+ /** */
+ @GridToStringInclude
+ @QuerySqlField(index = true, groups = "full_name")
+ private String fName;
+
+ /** */
+ @GridToStringInclude
+ @QuerySqlField(index = true, groups = "full_name")
+ private String lName;
+
+ /**
+ * @param fName First name.
+ * @param lName Last name.
+ */
+ public Person(String fName, String lName) {
+ this.fName = fName;
+ this.lName = lName;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(Person.class, this);
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ Person person = (Person)o;
+
+ return Objects.equals(fName, person.fName) &&
+ Objects.equals(lName, person.lName);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return Objects.hash(fName, lName);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreCacheGroupsTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreCacheGroupsTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreCacheGroupsTest.java
new file mode 100644
index 0000000..57cc8d0
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreCacheGroupsTest.java
@@ -0,0 +1,508 @@
+/*
+ * 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;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.Random;
+import java.util.concurrent.ThreadLocalRandom;
+import javax.cache.Cache;
+import javax.cache.expiry.ExpiryPolicy;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.MemoryConfiguration;
+import org.apache.ignite.configuration.PersistentStoreConfiguration;
+import org.apache.ignite.configuration.WALMode;
+import org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ *
+ */
+public class IgnitePersistentStoreCacheGroupsTest extends GridCommonAbstractTest {
+ /** */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** */
+ private static final String GROUP1 = "grp1";
+
+ /** */
+ private static final String GROUP2 = "grp2";
+
+ /** */
+ private CacheConfiguration[] ccfgs;
+
+ /** */
+ private boolean activeOnStart = true;
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ GridTestUtils.deleteDbFiles();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ GridTestUtils.deleteDbFiles();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ cfg.setConsistentId(gridName);
+
+ cfg.setActiveOnStart(activeOnStart);
+
+ MemoryConfiguration memCfg = new MemoryConfiguration();
+ memCfg.setPageSize(1024);
+ memCfg.setDefaultMemoryPolicySize(10 * 1024 * 1024);
+
+ cfg.setMemoryConfiguration(memCfg);
+
+ cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration().setWalMode(WALMode.LOG_ONLY));
+
+ cfg.setBinaryConfiguration(new BinaryConfiguration().setCompactFooter(false));
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
+
+ if (ccfgs != null) {
+ cfg.setCacheConfiguration(ccfgs);
+
+ ccfgs = null;
+ }
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ GridTestUtils.deleteDbFiles();
+
+ super.afterTest();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testClusterRestartStaticCaches1() throws Exception {
+ clusterRestart(1, true);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testClusterRestartStaticCaches2() throws Exception {
+ clusterRestart(3, true);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testClusterRestartDynamicCaches1() throws Exception {
+ clusterRestart(1, false);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testClusterRestartDynamicCaches2() throws Exception {
+ clusterRestart(3, false);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @SuppressWarnings("unchecked")
+ public void testClusterRestartCachesWithH2Indexes() throws Exception {
+ CacheConfiguration[] ccfgs1 = new CacheConfiguration[5];
+
+ // Several caches with the same indexed type (and index names).
+ ccfgs1[0] = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1).
+ setIndexedTypes(Integer.class, Person.class);
+ ccfgs1[1] = cacheConfiguration(GROUP1, "c2", PARTITIONED, TRANSACTIONAL, 1).
+ setIndexedTypes(Integer.class, Person.class);
+ ccfgs1[2] = cacheConfiguration(GROUP2, "c3", PARTITIONED, ATOMIC, 1).
+ setIndexedTypes(Integer.class, Person.class);
+ ccfgs1[3] = cacheConfiguration(GROUP2, "c4", PARTITIONED, TRANSACTIONAL, 1).
+ setIndexedTypes(Integer.class, Person.class);
+ ccfgs1[4] = cacheConfiguration(null, "c5", PARTITIONED, ATOMIC, 1).
+ setIndexedTypes(Integer.class, Person.class);
+
+ String[] caches = {"c1", "c2", "c3", "c4", "c5"};
+
+ startGrids(3);
+
+ Ignite node = ignite(0);
+
+ node.createCaches(Arrays.asList(ccfgs1));
+
+ putPersons(caches, node);
+
+ checkPersons(caches, node);
+ checkPersonsQuery(caches, node);
+
+ stopAllGrids();
+
+ startGrids(3);
+
+ awaitPartitionMapExchange();
+
+ node = ignite(0);
+
+ checkPersons(caches, node);
+ checkPersonsQuery(caches, node);
+
+ Random rnd = ThreadLocalRandom.current();
+
+ int idx = rnd.nextInt(caches.length);
+
+ String cacheName = caches[idx];
+ CacheConfiguration cacheCfg = ccfgs1[idx];
+
+ node.destroyCache(cacheName);
+
+ node.createCache(cacheCfg);
+
+ putPersons(new String[]{cacheName}, node);
+
+ checkPersons(caches, node);
+ checkPersonsQuery(caches, node);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void _testExpiryPolicy() throws Exception {
+ long ttl = 10000;
+
+ activeOnStart = false;
+
+ CacheConfiguration[] ccfgs1 = new CacheConfiguration[5];
+
+ ccfgs1[0] = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1);
+ ccfgs1[1] = cacheConfiguration(GROUP1, "c2", PARTITIONED, TRANSACTIONAL, 1);
+ ccfgs1[2] = cacheConfiguration(GROUP2, "c3", PARTITIONED, ATOMIC, 1);
+ ccfgs1[3] = cacheConfiguration(GROUP2, "c4", PARTITIONED, TRANSACTIONAL, 1);
+ ccfgs1[4] = cacheConfiguration(null, "c5", PARTITIONED, ATOMIC, 1);
+
+ String[] caches = {"c1", "c2", "c3", "c4", "c5"};
+
+ startGrids(3);
+
+ Ignite node = ignite(0);
+
+ node.active(true);
+
+ node.createCaches(Arrays.asList(ccfgs1));
+
+ ExpiryPolicy plc = new PlatformExpiryPolicy(ttl, -2, -2);
+
+ for (String cacheName : caches) {
+ IgniteCache<Object, Object> cache = node.cache(cacheName).withExpiryPolicy(plc);
+
+ for (int i = 0; i < 10; i++)
+ cache.put(i, cacheName + i);
+ }
+
+ long deadline = System.currentTimeMillis() + (long)(ttl * 1.2);
+
+ stopAllGrids();
+
+ startGrids(3);
+
+ node = ignite(0);
+
+ node.active(true);
+
+ for (String cacheName : caches) {
+ IgniteCache<Object, Object> cache = node.cache(cacheName);
+
+ for (int i = 0; i < 10; i++)
+ assertEquals(cacheName + i, cache.get(i));
+
+ assertEquals(10, cache.size());
+ }
+
+ // Wait for expiration.
+ Thread.sleep(Math.max(deadline - System.currentTimeMillis(), 0));
+
+ for (String cacheName : caches) {
+ IgniteCache<Object, Object> cache = node.cache(cacheName);
+
+ assertEquals(0, cache.size());
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCreateDropCache() throws Exception {
+ ccfgs = new CacheConfiguration[]{cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1)
+ .setIndexedTypes(Integer.class, Person.class)};
+
+ Ignite ignite = startGrid();
+
+ ignite.cache("c1").destroy();
+
+ stopGrid();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCreateDropCache1() throws Exception {
+ CacheConfiguration ccfg1 = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1);
+
+ CacheConfiguration ccfg2 = cacheConfiguration(GROUP1, "c2", PARTITIONED, ATOMIC, 1);
+
+ Ignite ignite = startGrid();
+
+ ignite.createCaches(Arrays.asList(ccfg1, ccfg2));
+
+
+ ignite.cache("c1").destroy();
+
+ ignite.cache("c2").destroy();
+
+ ignite.createCache(ccfg1);
+ ignite.createCache(ccfg2);
+
+ stopGrid();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCreateDropCache2() throws Exception {
+ CacheConfiguration ccfg1 = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1)
+ .setIndexedTypes(Integer.class, Person.class);
+
+ CacheConfiguration ccfg2 = cacheConfiguration(GROUP1, "c2", PARTITIONED, ATOMIC, 1)
+ .setIndexedTypes(Integer.class, Person.class);
+
+ Ignite ignite = startGrid();
+
+ ignite.createCaches(Arrays.asList(ccfg1, ccfg2));
+
+ ignite.cache("c1").destroy();
+
+ ignite.createCache(ccfg1);
+
+ stopGrid();
+ }
+
+ /**
+ * @param caches Cache names to put data into.
+ * @param node Ignite node.
+ */
+ private void putPersons(String[] caches, Ignite node) {
+ for (String cacheName : caches) {
+ IgniteCache<Object, Object> cache = node.cache(cacheName);
+
+ for (int i = 0; i < 10; i++)
+ cache.put(i, new Person("" + i, cacheName));
+ }
+ }
+
+ /**
+ * @param caches Cache names to invoke a query against to.
+ * @param node Ignite node.
+ */
+ private void checkPersons(String[] caches, Ignite node) {
+ for (String cacheName : caches) {
+ IgniteCache<Object, Object> cache = node.cache(cacheName);
+
+ for (int i = 0; i < 10; i++)
+ assertEquals(new Person("" + i, cacheName), cache.get(i));
+
+ assertEquals(10, cache.size());
+ }
+ }
+
+ /**
+ * @param caches Cache names to invoke a query against to.
+ * @param node Ignite node.
+ */
+ private void checkPersonsQuery(String[] caches, Ignite node) {
+ SqlQuery<Integer, Person> qry = new SqlQuery<>(
+ Person.class, "SELECT p.* FROM Person p WHERE p.lname=? ORDER BY p.fname");
+
+ for (String cacheName : caches) {
+ IgniteCache<Object, Object> cache = node.cache(cacheName);
+
+ List<Cache.Entry<Integer, Person>> persons = cache.query(qry.setArgs(cacheName)).getAll();
+
+ for (int i = 0; i < 10; i++)
+ assertEquals(new Person("" + i, cacheName), persons.get(i).getValue());
+
+ assertEquals(10, persons.size());
+ }
+ }
+
+ /**
+ * @param nodes Nodes number.
+ * @param staticCaches {@code True} if caches should be statically configured.
+ * @throws Exception If failed.
+ */
+ private void clusterRestart(int nodes, boolean staticCaches) throws Exception {
+ CacheConfiguration[] ccfgs = new CacheConfiguration[5];
+
+ ccfgs[0] = cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 1);
+ ccfgs[1] = cacheConfiguration(GROUP1, "c2", PARTITIONED, TRANSACTIONAL, 1);
+ ccfgs[2] = cacheConfiguration(GROUP2, "c3", PARTITIONED, ATOMIC, 1);
+ ccfgs[3] = cacheConfiguration(GROUP2, "c4", PARTITIONED, TRANSACTIONAL, 1);
+ ccfgs[4] = cacheConfiguration(null, "c5", PARTITIONED, ATOMIC, 1);
+
+ String[] caches = {"c1", "c2", "c3", "c4", "c5"};
+
+ for (int i = 0; i < nodes; i++) {
+ if (staticCaches)
+ this.ccfgs = ccfgs;
+
+ startGrid(i);
+ }
+
+ Ignite node = ignite(0);
+
+ if (!staticCaches)
+ node.createCaches(Arrays.asList(ccfgs));
+
+ for (String cacheName : caches) {
+ IgniteCache<Object, Object> cache = node.cache(cacheName);
+
+ for (int i = 0; i < 10; i++) {
+ cache.put(i, cacheName + i);
+
+ assertEquals(cacheName + i, cache.get(i));
+ }
+
+ assertEquals(10, cache.size());
+ }
+
+ stopAllGrids();
+
+ node = startGrids(nodes);
+
+ awaitPartitionMapExchange();
+
+ for (String cacheName : caches) {
+ IgniteCache<Object, Object> cache = node.cache(cacheName);
+
+ for (int i = 0; i < 10; i++)
+ assertEquals(cacheName + i, cache.get(i));
+
+ assertEquals(10, cache.size());
+ }
+ }
+
+ /**
+ * @param grpName Cache group name.
+ * @param name Cache name.
+ * @param cacheMode Cache mode.
+ * @param atomicityMode Atomicity mode.
+ * @param backups Backups number.
+ * @return Cache configuration.
+ */
+ private CacheConfiguration cacheConfiguration(
+ String grpName,
+ String name,
+ CacheMode cacheMode,
+ CacheAtomicityMode atomicityMode,
+ int backups
+ ) {
+ CacheConfiguration ccfg = new CacheConfiguration();
+
+ ccfg.setName(name);
+ ccfg.setGroupName(grpName);
+ ccfg.setAtomicityMode(atomicityMode);
+ ccfg.setBackups(backups);
+ ccfg.setCacheMode(cacheMode);
+ ccfg.setWriteSynchronizationMode(FULL_SYNC);
+
+ return ccfg;
+ }
+
+ /**
+ *
+ */
+ static class Person implements Serializable {
+ /** */
+ @GridToStringInclude
+ @QuerySqlField(index = true, groups = "full_name")
+ String fName;
+
+ /** */
+ @GridToStringInclude
+ @QuerySqlField(index = true, groups = "full_name")
+ String lName;
+
+ /**
+ * @param fName First name.
+ * @param lName Last name.
+ */
+ public Person(String fName, String lName) {
+ this.fName = fName;
+ this.lName = lName;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(Person.class, this);
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+ Person person = (Person)o;
+ return Objects.equals(fName, person.fName) &&
+ Objects.equals(lName, person.lName);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return Objects.hash(fName, lName);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreDataStructuresTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreDataStructuresTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreDataStructuresTest.java
new file mode 100644
index 0000000..6494903
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePersistentStoreDataStructuresTest.java
@@ -0,0 +1,196 @@
+/*
+ * 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;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteAtomicLong;
+import org.apache.ignite.IgniteAtomicSequence;
+import org.apache.ignite.IgniteQueue;
+import org.apache.ignite.IgniteSet;
+import org.apache.ignite.configuration.CollectionConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.MemoryConfiguration;
+import org.apache.ignite.configuration.MemoryPolicyConfiguration;
+import org.apache.ignite.configuration.PersistentStoreConfiguration;
+import org.apache.ignite.configuration.WALMode;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ *
+ */
+public class IgnitePersistentStoreDataStructuresTest extends GridCommonAbstractTest {
+ /** */
+ private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+
+ MemoryConfiguration dbCfg = new MemoryConfiguration();
+
+ MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration();
+
+ memPlcCfg.setName("dfltMemPlc");
+ memPlcCfg.setInitialSize(200 * 1024 * 1024);
+ memPlcCfg.setMaxSize(200 * 1024 * 1024);
+
+ dbCfg.setMemoryPolicies(memPlcCfg);
+ dbCfg.setDefaultMemoryPolicyName("dfltMemPlc");
+
+ cfg.setMemoryConfiguration(dbCfg);
+
+ cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration().setWalMode(WALMode.LOG_ONLY));
+
+ cfg.setActiveOnStart(false);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ GridTestUtils.deleteDbFiles();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ GridTestUtils.deleteDbFiles();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testQueue() throws Exception {
+ Ignite ignite = startGrids(4);
+
+ ignite.active(true);
+
+ IgniteQueue<Object> queue = ignite.queue("testQueue", 100, new CollectionConfiguration());
+
+ for (int i = 0; i < 100; i++)
+ queue.offer(i);
+
+ stopAllGrids();
+
+ ignite = startGrids(4);
+
+ ignite.active(true);
+
+ queue = ignite.queue("testQueue", 0, null);
+
+ for (int i = 0; i < 100; i++)
+ assertEquals(i, queue.poll());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testAtomic() throws Exception {
+ Ignite ignite = startGrids(4);
+
+ ignite.active(true);
+
+ IgniteAtomicLong atomicLong = ignite.atomicLong("testLong", 0, true);
+
+ for (int i = 0; i < 100; i++)
+ atomicLong.incrementAndGet();
+
+ stopAllGrids();
+
+ ignite = startGrids(4);
+
+ ignite.active(true);
+
+ atomicLong = ignite.atomicLong("testLong", 0, false);
+
+ for (int i = 100; i != 0; )
+ assertEquals(i--, atomicLong.getAndDecrement());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testSequence() throws Exception {
+ Ignite ignite = startGrids(4);
+
+ ignite.active(true);
+
+ IgniteAtomicSequence sequence = ignite.atomicSequence("testSequence", 0, true);
+
+ int i = 0;
+
+ while (i < 1000) {
+ sequence.incrementAndGet();
+
+ i++;
+ }
+
+ stopAllGrids();
+
+ ignite = startGrids(4);
+
+ ignite.active(true);
+
+ sequence = ignite.atomicSequence("testSequence", 0, false);
+
+ assertTrue(sequence.incrementAndGet() > i);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testSet() throws Exception {
+ Ignite ignite = startGrids(4);
+
+ ignite.active(true);
+
+ IgniteSet<Object> set = ignite.set("testSet", new CollectionConfiguration());
+
+ for (int i = 0; i < 100; i++)
+ set.add(i);
+
+ stopAllGrids();
+
+ ignite = startGrids(4);
+
+ ignite.active(true);
+
+ set = ignite.set("testSet", null);
+
+ assertFalse(set.add(99));
+
+ for (int i = 0; i < 100; i++)
+ assertTrue(set.contains(i));
+
+ assertEquals(100, set.size());
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/MemoryPolicyInitializationTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/MemoryPolicyInitializationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/MemoryPolicyInitializationTest.java
new file mode 100644
index 0000000..9a49b6c
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/MemoryPolicyInitializationTest.java
@@ -0,0 +1,313 @@
+/*
+ * 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;
+
+import java.util.Collection;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.MemoryConfiguration;
+import org.apache.ignite.configuration.MemoryPolicyConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.configuration.MemoryConfiguration.DFLT_MEM_PLC_DEFAULT_NAME;
+
+/**
+ *
+ */
+public class MemoryPolicyInitializationTest extends GridCommonAbstractTest {
+ /** */
+ private static final String CUSTOM_NON_DEFAULT_MEM_PLC_NAME = "custom_mem_plc";
+
+ /** */
+ private static final long USER_CUSTOM_MEM_PLC_SIZE = 10 * 1024 * 1024;
+
+ /** */
+ private static final long USER_DEFAULT_MEM_PLC_SIZE = 99 * 1024 * 1024;
+
+ /** */
+ private MemoryConfiguration memCfg;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+ cfg.setMemoryConfiguration(memCfg);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ memCfg = null;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+ }
+
+ /**
+ * Verifies that expected memory policies are allocated when used doesn't provide any MemoryPolicyConfiguration.
+ */
+ public void testNoConfigProvided() throws Exception {
+ memCfg = null;
+
+ IgniteEx ignite = startGrid(0);
+
+ Collection<MemoryPolicy> allMemPlcs = ignite.context().cache().context().database().memoryPolicies();
+
+ assertTrue(allMemPlcs.size() == 2);
+
+ verifyDefaultAndSystemMemoryPolicies(allMemPlcs);
+ }
+
+ /**
+ * Verifies that expected memory policies are allocated when used provides MemoryPolicyConfiguration
+ * with non-default custom MemoryPolicy.
+ */
+ public void testCustomConfigNoDefault() throws Exception {
+ prepareCustomNoDefaultConfig();
+
+ IgniteEx ignite = startGrid(0);
+
+ Collection<MemoryPolicy> allMemPlcs = ignite.context().cache().context().database().memoryPolicies();
+
+ assertTrue(allMemPlcs.size() == 3);
+
+ verifyDefaultAndSystemMemoryPolicies(allMemPlcs);
+
+ assertTrue("Custom non-default memory policy is not presented",
+ isMemoryPolicyPresented(allMemPlcs, CUSTOM_NON_DEFAULT_MEM_PLC_NAME));
+ }
+
+ /**
+ * User is allowed to configure memory policy with 'default' name,
+ * in that case Ignite instance will use this user-defined memory policy as a default one.
+ */
+ public void testCustomConfigOverridesDefault() throws Exception {
+ prepareCustomConfigWithOverridingDefault();
+
+ IgniteEx ignite = startGrid(0);
+
+ IgniteCacheDatabaseSharedManager dbMgr = ignite.context().cache().context().database();
+
+ Collection<MemoryPolicy> allMemPlcs = dbMgr.memoryPolicies();
+
+ assertTrue(allMemPlcs.size() == 2);
+
+ verifyDefaultAndSystemMemoryPolicies(allMemPlcs);
+
+ MemoryPolicy dfltMemPlc = U.field(dbMgr, "dfltMemPlc");
+
+ assertTrue(dfltMemPlc.config().getMaxSize() == USER_DEFAULT_MEM_PLC_SIZE);
+ }
+
+ /**
+ * User is allowed to define fully custom memory policy and make it default by setting its name to memory config.
+ *
+ * At the same time user still can create a memory policy with name 'default'
+ * which although won't be used as default.
+ */
+ public void testCustomConfigOverridesDefaultNameAndDeclaresDefault() throws Exception {
+ prepareCustomConfigWithOverriddenDefaultName();
+
+ IgniteEx ignite = startGrid(0);
+
+ IgniteCacheDatabaseSharedManager dbMgr = ignite.context().cache().context().database();
+
+ Collection<MemoryPolicy> allMemPlcs = dbMgr.memoryPolicies();
+
+ assertTrue(allMemPlcs.size() == 3);
+
+ verifyDefaultAndSystemMemoryPolicies(allMemPlcs);
+
+ MemoryPolicy dfltMemPlc = U.field(dbMgr, "dfltMemPlc");
+
+ assertTrue(dfltMemPlc.config().getMaxSize() == USER_CUSTOM_MEM_PLC_SIZE);
+ }
+
+ /**
+ * Test for verification that caches with not specified memory policy name,
+ * with specified default memory policy name and specified custom memory policy name
+ * all started with correct memory policy.
+ */
+ public void testCachesOnOverriddenMemoryPolicy() throws Exception {
+ prepareCustomConfigWithOverridingDefaultAndCustom();
+
+ IgniteEx ignite = startGrid(0);
+
+ CacheConfiguration cache1Cfg = new CacheConfiguration()
+ .setName("cache1");
+
+ IgniteCache cache1 = ignite.createCache(cache1Cfg);
+
+ verifyCacheMemoryPolicy(cache1, DFLT_MEM_PLC_DEFAULT_NAME);
+
+ CacheConfiguration cache2Cfg = new CacheConfiguration()
+ .setName("cache2")
+ .setMemoryPolicyName(CUSTOM_NON_DEFAULT_MEM_PLC_NAME);
+
+ IgniteCache cache2 = ignite.createCache(cache2Cfg);
+
+ verifyCacheMemoryPolicy(cache2, CUSTOM_NON_DEFAULT_MEM_PLC_NAME);
+
+ CacheConfiguration cache3Cfg = new CacheConfiguration()
+ .setName("cache3")
+ .setMemoryPolicyName(DFLT_MEM_PLC_DEFAULT_NAME);
+
+ IgniteCache cache3 = ignite.createCache(cache3Cfg);
+
+ verifyCacheMemoryPolicy(cache3, DFLT_MEM_PLC_DEFAULT_NAME);
+ }
+
+ /**
+ * Test for verification that caches with not specified memory policy name,
+ * with specified default memory policy name and specified custom memory policy name
+ * all started with correct memory policy.
+ */
+ public void testCachesOnUserDefinedDefaultMemoryPolicy() throws Exception {
+ prepareCustomConfigWithOverriddenDefaultName();
+
+ IgniteEx ignite = startGrid(0);
+
+ CacheConfiguration cache1Cfg = new CacheConfiguration()
+ .setName("cache1");
+
+ IgniteCache cache1 = ignite.createCache(cache1Cfg);
+
+ verifyCacheMemoryPolicy(cache1, CUSTOM_NON_DEFAULT_MEM_PLC_NAME);
+
+ CacheConfiguration cache2Cfg = new CacheConfiguration()
+ .setName("cache2")
+ .setMemoryPolicyName(CUSTOM_NON_DEFAULT_MEM_PLC_NAME);
+
+ IgniteCache cache2 = ignite.createCache(cache2Cfg);
+
+ verifyCacheMemoryPolicy(cache2, CUSTOM_NON_DEFAULT_MEM_PLC_NAME);
+
+ CacheConfiguration cache3Cfg = new CacheConfiguration()
+ .setName("cache3")
+ .setMemoryPolicyName(DFLT_MEM_PLC_DEFAULT_NAME);
+
+ IgniteCache cache3 = ignite.createCache(cache3Cfg);
+
+ verifyCacheMemoryPolicy(cache3, DFLT_MEM_PLC_DEFAULT_NAME);
+ }
+
+ /**
+ * @param cache Cache.
+ * @param plcName Policy name.
+ */
+ private void verifyCacheMemoryPolicy(IgniteCache cache, String plcName) {
+ GridCacheContext ctx = U.field(cache, "ctx");
+
+ assertEquals(plcName, ctx.memoryPolicy().config().getName());
+ }
+
+ /**
+ *
+ */
+ private void prepareCustomConfigWithOverriddenDefaultName() {
+ memCfg = new MemoryConfiguration();
+
+ memCfg.setDefaultMemoryPolicyName(CUSTOM_NON_DEFAULT_MEM_PLC_NAME);
+
+ memCfg.setMemoryPolicies(new MemoryPolicyConfiguration()
+ .setName(CUSTOM_NON_DEFAULT_MEM_PLC_NAME)
+ .setInitialSize(USER_CUSTOM_MEM_PLC_SIZE)
+ .setMaxSize(USER_CUSTOM_MEM_PLC_SIZE),
+
+ new MemoryPolicyConfiguration()
+ .setName(DFLT_MEM_PLC_DEFAULT_NAME)
+ .setInitialSize(USER_CUSTOM_MEM_PLC_SIZE)
+ .setMaxSize(USER_DEFAULT_MEM_PLC_SIZE)
+ );
+ }
+
+
+ /**
+ *
+ */
+ private void prepareCustomConfigWithOverridingDefault() {
+ memCfg = new MemoryConfiguration();
+
+ memCfg.setMemoryPolicies(new MemoryPolicyConfiguration()
+ .setName(DFLT_MEM_PLC_DEFAULT_NAME)
+ .setInitialSize(USER_CUSTOM_MEM_PLC_SIZE)
+ .setMaxSize(USER_DEFAULT_MEM_PLC_SIZE)
+ );
+ }
+
+ /**
+ *
+ */
+ private void prepareCustomConfigWithOverridingDefaultAndCustom() {
+ memCfg = new MemoryConfiguration();
+
+ memCfg.setMemoryPolicies(new MemoryPolicyConfiguration()
+ .setName(DFLT_MEM_PLC_DEFAULT_NAME)
+ .setInitialSize(USER_CUSTOM_MEM_PLC_SIZE)
+ .setMaxSize(USER_DEFAULT_MEM_PLC_SIZE),
+
+ new MemoryPolicyConfiguration()
+ .setName(CUSTOM_NON_DEFAULT_MEM_PLC_NAME)
+ .setInitialSize(USER_CUSTOM_MEM_PLC_SIZE)
+ .setMaxSize(USER_CUSTOM_MEM_PLC_SIZE)
+ );
+ }
+
+ /**
+ * @param allMemPlcs Collection of all memory policies.
+ */
+ private void verifyDefaultAndSystemMemoryPolicies(Collection<MemoryPolicy> allMemPlcs) {
+ assertTrue("Default memory policy is not presented",
+ isMemoryPolicyPresented(allMemPlcs, DFLT_MEM_PLC_DEFAULT_NAME));
+
+ assertTrue("System memory policy is not presented",
+ isMemoryPolicyPresented(allMemPlcs, IgniteCacheDatabaseSharedManager.SYSTEM_MEMORY_POLICY_NAME));
+ }
+
+ /**
+ *
+ */
+ private void prepareCustomNoDefaultConfig() {
+ memCfg = new MemoryConfiguration();
+
+ memCfg.setMemoryPolicies(new MemoryPolicyConfiguration()
+ .setName(CUSTOM_NON_DEFAULT_MEM_PLC_NAME)
+ .setInitialSize(USER_CUSTOM_MEM_PLC_SIZE)
+ .setMaxSize(USER_CUSTOM_MEM_PLC_SIZE)
+ );
+ }
+
+ /**
+ * @param memPlcs Collection of memory policies.
+ * @param nameToVerify Excepted name of memory policy.
+ */
+ private boolean isMemoryPolicyPresented(Collection<MemoryPolicy> memPlcs, String nameToVerify) {
+ for (MemoryPolicy memPlc : memPlcs) {
+ if (nameToVerify.equals(memPlc.config().getName()))
+ return true;
+ }
+
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsMultiNodePutGetRestartTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsMultiNodePutGetRestartTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsMultiNodePutGetRestartTest.java
new file mode 100644
index 0000000..e244333
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsMultiNodePutGetRestartTest.java
@@ -0,0 +1,242 @@
+/*
+ * 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.db;
+
+import java.io.File;
+import java.io.Serializable;
+import java.util.List;
+import java.util.UUID;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.cache.CacheRebalanceMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.MemoryPolicyConfiguration;
+import org.apache.ignite.configuration.PersistentStoreConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.configuration.MemoryConfiguration;
+
+/**
+ *
+ */
+public class IgnitePdsMultiNodePutGetRestartTest extends GridCommonAbstractTest {
+ /** */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** */
+ private static final int GRID_CNT = 3;
+
+ /** */
+ private static final String CACHE_NAME = "cache";
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ MemoryConfiguration dbCfg = new MemoryConfiguration();
+
+ MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration();
+
+ memPlcCfg.setName("dfltMemPlc");
+ memPlcCfg.setInitialSize(100 * 1024 * 1024);
+ memPlcCfg.setMaxSize(100 * 1024 * 1024);
+
+ dbCfg.setDefaultMemoryPolicyName("dfltMemPlc");
+ dbCfg.setMemoryPolicies(memPlcCfg);
+
+ cfg.setMemoryConfiguration(dbCfg);
+
+ CacheConfiguration ccfg = new CacheConfiguration(CACHE_NAME);
+
+ ccfg.setIndexedTypes(Integer.class, DbValue.class);
+
+ ccfg.setRebalanceMode(CacheRebalanceMode.NONE);
+
+ ccfg.setAffinity(new RendezvousAffinityFunction(false, 32));
+
+ ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
+
+ cfg.setCacheConfiguration(ccfg);
+
+ cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration());
+ cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER));
+
+ cfg.setMarshaller(null);
+
+ BinaryConfiguration bCfg = new BinaryConfiguration();
+
+ bCfg.setCompactFooter(false);
+
+ cfg.setBinaryConfiguration(bCfg);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false));
+
+ super.beforeTest();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false));
+ }
+
+ /**
+ * @throws Exception if failed.
+ */
+ public void testPutGetSimple() throws Exception {
+ String home = U.getIgniteHome();
+
+ File allocPath = new File(home, "work/db/" + UUID.randomUUID());
+
+ allocPath.mkdirs();
+
+ info(">>> Will use path: " + allocPath);
+
+ startGrids(GRID_CNT);
+
+ try {
+ IgniteEx ig = grid(0);
+
+ checkPutGetSql(ig, true);
+ }
+ finally {
+ stopAllGrids();
+ }
+
+ info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
+ info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
+ info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
+
+ startGrids(GRID_CNT);
+
+ try {
+ IgniteEx ig = grid(0);
+
+ checkPutGetSql(ig, false);
+ }
+ finally {
+ stopAllGrids();
+ }
+ }
+
+ /**
+ * @param ig Ig.
+ * @param write Write.
+ */
+ private void checkPutGetSql(IgniteEx ig, boolean write) {
+ IgniteCache<Integer, DbValue> cache = ig.cache(CACHE_NAME);
+
+ if (write) {
+ try (IgniteDataStreamer<Object, Object> streamer = ig.dataStreamer(CACHE_NAME)) {
+ for (int i = 0; i < 10_000; i++)
+ streamer.addData(i, new DbValue(i, "value-" + i, i));
+ }
+ }
+
+ List<List<?>> res = cache.query(new SqlFieldsQuery("select ival from dbvalue where ival < ? order by ival asc")
+ .setArgs(10_000)).getAll();
+
+ assertEquals(10_000, res.size());
+
+ for (int i = 0; i < 10_000; i++) {
+ assertEquals(1, res.get(i).size());
+ assertEquals(i, res.get(i).get(0));
+ }
+
+ assertEquals(1, cache.query(new SqlFieldsQuery("select lval from dbvalue where ival = 7899")).getAll().size());
+ assertEquals(5000, cache.query(new SqlFieldsQuery("select lval from dbvalue where ival >= 5000 and ival < 10000"))
+ .getAll().size());
+
+ for (int i = 0; i < 10_000; i++)
+ assertEquals(new DbValue(i, "value-" + i, i), cache.get(i));
+ }
+
+ /**
+ *
+ */
+ private static class DbValue implements Serializable {
+ /** */
+ @QuerySqlField(index = true)
+ private int iVal;
+
+ /** */
+ @QuerySqlField(index = true)
+ private String sVal;
+
+ /** */
+ @QuerySqlField
+ private long lVal;
+
+ /**
+ * @param iVal Integer value.
+ * @param sVal String value.
+ * @param lVal Long value.
+ */
+ public DbValue(int iVal, String sVal, long lVal) {
+ this.iVal = iVal;
+ this.sVal = sVal;
+ this.lVal = lVal;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ DbValue dbVal = (DbValue)o;
+
+ return iVal == dbVal.iVal && lVal == dbVal.lVal &&
+ !(sVal != null ? !sVal.equals(dbVal.sVal) : dbVal.sVal != null);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ int res = iVal;
+
+ res = 31 * res + (sVal != null ? sVal.hashCode() : 0);
+ res = 31 * res + (int)(lVal ^ (lVal >>> 32));
+
+ return res;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(DbValue.class, this);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionDuringPartitionClearTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionDuringPartitionClearTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionDuringPartitionClearTest.java
new file mode 100644
index 0000000..fb7113f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionDuringPartitionClearTest.java
@@ -0,0 +1,174 @@
+/*
+ * 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.db;
+
+import java.util.concurrent.Callable;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheRebalanceMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.MemoryConfiguration;
+import org.apache.ignite.configuration.MemoryPolicyConfiguration;
+import org.apache.ignite.configuration.PersistentStoreConfiguration;
+import org.apache.ignite.configuration.WALMode;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ *
+ */
+public class IgnitePdsPageEvictionDuringPartitionClearTest extends GridCommonAbstractTest {
+ /** */
+ public static final String CACHE_NAME = "cache";
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ CacheConfiguration ccfg = new CacheConfiguration(CACHE_NAME)
+ .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL)
+ .setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC)
+ .setAffinity(new RendezvousAffinityFunction(false, 128))
+ .setRebalanceMode(CacheRebalanceMode.SYNC)
+ .setBackups(1);
+
+ cfg.setCacheConfiguration(ccfg);
+
+ // Intentionally set small page cache size.
+
+ MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration();
+
+ memPlcCfg.setInitialSize(70 * 1024 * 1024);
+ memPlcCfg.setMaxSize(70 * 1024 * 1024);
+
+ memPlcCfg.setName("dfltMemPlc");
+
+ MemoryConfiguration memCfg = new MemoryConfiguration();
+
+ memCfg.setMemoryPolicies(memPlcCfg);
+
+ memCfg.setDefaultMemoryPolicyName(memPlcCfg.getName());
+
+ cfg.setMemoryConfiguration(memCfg);
+
+ cfg.setPersistentStoreConfiguration(
+ new PersistentStoreConfiguration()
+ .setWalMode(WALMode.LOG_ONLY)
+ );
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected long getTestTimeout() {
+ return 20 * 60 * 1000;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ System.setProperty(GridCacheDatabaseSharedManager.IGNITE_PDS_CHECKPOINT_TEST_SKIP_SYNC, "true");
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ System.clearProperty(GridCacheDatabaseSharedManager.IGNITE_PDS_CHECKPOINT_TEST_SKIP_SYNC);
+ }
+
+ /**
+ * @throws Exception if failed.
+ */
+ public void testPageEvictionOnNodeStart() throws Exception {
+ for (int r = 0; r < 3; r++) {
+ deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false));
+
+ startGrids(2);
+
+ try {
+ Ignite ig = ignite(0);
+
+ IgniteDataStreamer<Object, Object> streamer = ig.dataStreamer(CACHE_NAME);
+
+ for (int i = 0; i < 300_000; i++) {
+ streamer.addData(i, new TestValue(i));
+
+ if (i > 0 && i % 10_000 == 0)
+ info("Done: " + i);
+ }
+
+ streamer.flush();
+
+ IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ IgniteEx ig = startGrid(2);
+
+ info(">>>>>>>>>>>");
+ info(">>>>>>>>>>>");
+ info(">>>>>>>>>>>");
+
+ return ig;
+ }
+ });
+
+ for (int i = 500_000; i < 1_000_000; i++) {
+ streamer.addData(i, new TestValue(i));
+
+ if (i > 0 && i % 10_000 == 0) {
+ info("Done: " + i);
+
+ U.sleep(1000);
+ }
+ }
+
+ streamer.close();
+
+ fut.get();
+ }
+ finally {
+ stopAllGrids();
+
+ deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false));
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ private static class TestValue {
+ /** */
+ private int id;
+
+ /** */
+ private byte[] payload = new byte[512];
+
+ /**
+ * @param id ID.
+ */
+ private TestValue(int id) {
+ this.id = id;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionTest.java
new file mode 100644
index 0000000..e8bc701
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsPageEvictionTest.java
@@ -0,0 +1,239 @@
+/*
+ * 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.db;
+
+import java.io.Serializable;
+import java.util.List;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.cache.CacheRebalanceMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.MemoryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.MemoryPolicyConfiguration;
+import org.apache.ignite.configuration.PersistentStoreConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ *
+ */
+public class IgnitePdsPageEvictionTest extends GridCommonAbstractTest {
+ /** IP finder. */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** Test entry count. */
+ public static final int ENTRY_CNT = 1_000_000;
+
+ /** Cache name. */
+ private static final String CACHE_NAME = "cache";
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ MemoryConfiguration memCfg = new MemoryConfiguration();
+
+ memCfg.setConcurrencyLevel(Runtime.getRuntime().availableProcessors() * 4);
+
+ memCfg.setPageSize(1024);
+
+ MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration();
+
+ memPlcCfg.setName("dfltMemPlc");
+ memPlcCfg.setInitialSize(50 * 1024 * 1024);
+ memPlcCfg.setMaxSize(50 * 1024 * 1024);
+
+ memCfg.setMemoryPolicies(memPlcCfg);
+ memCfg.setDefaultMemoryPolicyName("dfltMemPlc");
+
+ cfg.setMemoryConfiguration(memCfg);
+
+ CacheConfiguration<DbKey, DbValue> ccfg = new CacheConfiguration<>(CACHE_NAME);
+
+ ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
+ ccfg.setRebalanceMode(CacheRebalanceMode.NONE);
+ ccfg.setIndexedTypes(DbKey.class, DbValue.class);
+ ccfg.setAffinity(new RendezvousAffinityFunction(false, 32));
+
+ cfg.setCacheConfiguration(ccfg);
+
+ cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration());
+
+ cfg.setDiscoverySpi(
+ new TcpDiscoverySpi()
+ .setIpFinder(IP_FINDER)
+ );
+
+ cfg.setMarshaller(null);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false));
+
+ stopAllGrids();
+
+ startGrids(1);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false));
+ }
+
+ /**
+ * @throws Exception if failed.
+ */
+ public void testPageEvictionSql() throws Exception {
+ IgniteEx ig = grid(0);
+
+ try (IgniteDataStreamer<DbKey, DbValue> streamer = ig.dataStreamer(CACHE_NAME)) {
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ streamer.addData(new DbKey(i), new DbValue(i, "value-" + i, Long.MAX_VALUE - i));
+
+ if (i > 0 && i % 10_000 == 0)
+ info("Done put: " + i);
+ }
+ }
+
+ IgniteCache<DbKey, DbValue> cache = ignite(0).cache(CACHE_NAME);
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ assertEquals(Long.MAX_VALUE - i, cache.get(new DbKey(i)).lVal);
+
+ if (i > 0 && i % 10_000 == 0)
+ info("Done get: " + i);
+ }
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ List<List<?>> rows = cache.query(
+ new SqlFieldsQuery("select lVal from DbValue where iVal=?").setArgs(i)
+ ).getAll();
+
+ assertEquals(1, rows.size());
+ assertEquals(Long.MAX_VALUE - i, rows.get(0).get(0));
+
+ if (i > 0 && i % 10_000 == 0)
+ info("Done SQL query: " + i);
+ }
+ }
+
+ /**
+ *
+ */
+ private static class DbKey implements Serializable {
+ /** */
+ private int val;
+
+ /**
+ * @param val Value.
+ */
+ private DbKey(int val) {
+ this.val = val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || !(o instanceof DbKey))
+ return false;
+
+ DbKey key = (DbKey)o;
+
+ return val == key.val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return val;
+ }
+ }
+
+ /**
+ *
+ */
+ private static class DbValue implements Serializable {
+ /** */
+ @QuerySqlField(index = true)
+ private int iVal;
+
+ /** */
+ @QuerySqlField(index = true)
+ private String sVal;
+
+ /** */
+ @QuerySqlField
+ private long lVal;
+
+ /**
+ * @param iVal Integer value.
+ * @param sVal String value.
+ * @param lVal Long value.
+ */
+ private DbValue(int iVal, String sVal, long lVal) {
+ this.iVal = iVal;
+ this.sVal = sVal;
+ this.lVal = lVal;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ DbValue dbVal = (DbValue)o;
+
+ return iVal == dbVal.iVal && lVal == dbVal.lVal &&
+ !(sVal != null ? !sVal.equals(dbVal.sVal) : dbVal.sVal != null);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ int res = iVal;
+
+ res = 31 * res + (sVal != null ? sVal.hashCode() : 0);
+ res = 31 * res + (int)(lVal ^ (lVal >>> 32));
+
+ return res;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(DbValue.class, this);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/6bf5ce46/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsRebalancingOnNotStableTopologyTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsRebalancingOnNotStableTopologyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsRebalancingOnNotStableTopologyTest.java
new file mode 100644
index 0000000..0724eb9
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/db/IgnitePdsRebalancingOnNotStableTopologyTest.java
@@ -0,0 +1,215 @@
+/*
+ * 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.db;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.cache.PartitionLossPolicy;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.MemoryConfiguration;
+import org.apache.ignite.configuration.MemoryPolicyConfiguration;
+import org.apache.ignite.configuration.PersistentStoreConfiguration;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.testframework.junits.multijvm.IgniteProcessProxy;
+
+/**
+ * We start writing to unstable cluster.
+ * After that we start killing node.
+ * There will be entries in WAL which belongs to evicted partitions.
+ * We should ignore them (not throw exceptions). This point is tested.
+ */
+public class IgnitePdsRebalancingOnNotStableTopologyTest extends GridCommonAbstractTest {
+ /** Checkpoint frequency. */
+ private static final long CHECKPOINT_FREQUENCY = 2_000_000;
+
+ /** Cluster size. */
+ private static final int CLUSTER_SIZE = 5;
+
+ /** */
+ private static final String CACHE_NAME = "cache1";
+
+ /**
+ * @throws Exception When fails.
+ */
+ public void test() throws Exception {
+ Ignite ex = startGrid(0);
+
+ startGrid(1);
+
+ final CountDownLatch startLatch = new CountDownLatch(1);
+ final CountDownLatch doneLatch = new CountDownLatch(1);
+
+ final Ignite ex1 = ex;
+
+ final AtomicBoolean stop = new AtomicBoolean();
+ final AtomicInteger keyCnt = new AtomicInteger();
+
+ Thread thread = new Thread(new Runnable() {
+ @Override public void run() {
+ ex1.active(true);
+
+ try {
+ checkTopology(2);
+
+ startLatch.countDown();
+
+ IgniteCache<Object, Object> cache1 = ex1.cache(CACHE_NAME);
+
+ int key = keyCnt.get();
+
+ while (!stop.get()) {
+ if (key > 0 && (key % 500 == 0)) {
+ U.sleep(5);
+
+ System.out.println("key = " + key);
+ }
+
+ cache1.put(key, -key);
+
+ key = keyCnt.incrementAndGet();
+ }
+ }
+ catch (Throwable th) {
+ th.printStackTrace();
+ }
+
+ doneLatch.countDown();
+ }
+ });
+
+ thread.setName("Data-Loader");
+ thread.start();
+
+ startLatch.await(60, TimeUnit.SECONDS);
+
+ for (int i = 2; i < CLUSTER_SIZE; i++) {
+ startGrid(i);
+
+ U.sleep(5000);
+ }
+
+ U.sleep(10000);
+
+ IgniteProcessProxy.kill("db.RebalancingOnNotStableTopologyTest2");
+
+ Thread.sleep(5000);
+
+ IgniteProcessProxy.kill("db.RebalancingOnNotStableTopologyTest1");
+
+ assert doneLatch.getCount() > 0;
+
+ stop.set(true);
+
+ doneLatch.await(600, TimeUnit.SECONDS);
+
+ IgniteProcessProxy.killAll();
+
+ stopAllGrids();
+
+ //start cluster. it will cause memory restoration and reading WAL.
+ ex = startGrids(CLUSTER_SIZE);
+
+ ex.active(true);
+
+ checkTopology(CLUSTER_SIZE);
+
+ IgniteCache<Object, Object> cache1 = ex.cache(CACHE_NAME);
+
+ assert keyCnt.get() > 0;
+
+ for (int i = 0; i < keyCnt.get(); i++)
+ assertEquals(-i, cache1.get(i));
+
+ System.out.println("Test finished with total keys count = " + keyCnt.get());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ cfg.setActiveOnStart(false);
+
+ CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>(CACHE_NAME);
+
+ ccfg.setPartitionLossPolicy(PartitionLossPolicy.READ_ONLY_SAFE);
+ ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
+ ccfg.setCacheMode(CacheMode.PARTITIONED);
+ ccfg.setAffinity(new RendezvousAffinityFunction(false, 32));
+ ccfg.setBackups(2);
+
+ cfg.setCacheConfiguration(ccfg);
+
+ cfg.setPersistentStoreConfiguration(
+ new PersistentStoreConfiguration()
+ .setCheckpointingFrequency(CHECKPOINT_FREQUENCY)
+ );
+
+ MemoryConfiguration memCfg = new MemoryConfiguration();
+
+ MemoryPolicyConfiguration memPlcCfg = new MemoryPolicyConfiguration();
+
+ memPlcCfg.setName("dfltMemPlc");
+ memPlcCfg.setInitialSize(200 * 1024 * 1024);
+ memPlcCfg.setMaxSize(200 * 1024 * 1024);
+
+ memCfg.setMemoryPolicies(memPlcCfg);
+ memCfg.setDefaultMemoryPolicyName("dfltMemPlc");
+
+ cfg.setMemoryConfiguration(memCfg);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected boolean isMultiJvm() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected boolean checkTopology() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ stopAllGrids();
+
+ deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ deleteRecursively(U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected long getTestTimeout() {
+ return TimeUnit.MINUTES.toMillis(10);
+ }
+}