http://git-wip-us.apache.org/repos/asf/ignite/blob/00bb4d4d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccConfigurationValidationTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccConfigurationValidationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccConfigurationValidationTest.java new file mode 100644 index 0000000..b0a2ec8 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccConfigurationValidationTest.java @@ -0,0 +1,191 @@ +/* + * 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.mvcc; + +import java.util.concurrent.Callable; +import javax.cache.CacheException; +import javax.cache.configuration.Factory; +import javax.cache.expiry.CreatedExpiryPolicy; +import javax.cache.expiry.Duration; +import javax.cache.expiry.ExpiryPolicy; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.CacheInterceptorAdapter; +import org.apache.ignite.cache.store.CacheStore; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +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; + +import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC; +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; + +/** + * + */ +public class CacheMvccConfigurationValidationTest 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.setMvccEnabled(true); + + ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + super.afterTest(); + } + + /** + * @throws Exception If failed. + */ + public void testMvccModeMismatchForGroup1() throws Exception { + final Ignite node = startGrid(0); + + node.createCache(new CacheConfiguration("cache1").setGroupName("grp1").setAtomicityMode(ATOMIC)); + + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override public Void call() throws Exception { + node.createCache(new CacheConfiguration("cache2").setGroupName("grp1").setAtomicityMode(TRANSACTIONAL)); + + return null; + } + }, CacheException.class, null); + + node.createCache(new CacheConfiguration("cache2").setGroupName("grp1").setAtomicityMode(ATOMIC)); + } + + /** + * @throws Exception If failed. + */ + public void testMvccModeMismatchForGroup2() throws Exception { + final Ignite node = startGrid(0); + + node.createCache(new CacheConfiguration("cache1").setGroupName("grp1").setAtomicityMode(TRANSACTIONAL)); + + GridTestUtils.assertThrows(log, new Callable<Void>() { + @Override public Void call() throws Exception { + node.createCache(new CacheConfiguration("cache2").setGroupName("grp1").setAtomicityMode(ATOMIC)); + + return null; + } + }, CacheException.class, null); + + node.createCache(new CacheConfiguration("cache2").setGroupName("grp1").setAtomicityMode(TRANSACTIONAL)); + } + + /** + * @throws Exception If failed. + */ + public void testTxCacheWithCacheStore() throws Exception { + checkTransactionalModeConflict("cacheStoreFactory", new TestFactory(), + "Transactional cache may not have a third party cache store when MVCC is enabled."); + } + + /** + * @throws Exception If failed. + */ + public void testTxCacheWithExpiryPolicy() throws Exception { + checkTransactionalModeConflict("expiryPolicyFactory0", CreatedExpiryPolicy.factoryOf(Duration.FIVE_MINUTES), + "Transactional cache may not have expiry policy when MVCC is enabled."); + } + + /** + * @throws Exception If failed. + */ + public void testTxCacheWithInterceptor() throws Exception { + checkTransactionalModeConflict("interceptor", new CacheInterceptorAdapter(), + "Transactional cache may not have an interceptor when MVCC is enabled."); + } + + /** + * Check that setting specified property conflicts with transactional cache atomicity mode. + * @param propName Property name. + * @param obj Property value. + * @param errMsg Expected error message. + * @throws IgniteCheckedException if failed. + */ + @SuppressWarnings("ThrowableNotThrown") + private void checkTransactionalModeConflict(String propName, Object obj, String errMsg) + throws Exception { + final String setterName = "set" + propName.substring(0, 1).toUpperCase() + propName.substring(1); + + try (final Ignite node = startGrid(0)) { + final CacheConfiguration cfg = new TestConfiguration("cache"); + + cfg.setAtomicityMode(TRANSACTIONAL); + + U.invoke(TestConfiguration.class, cfg, setterName, obj); + + GridTestUtils.assertThrows(log, new Callable<Void>() { + @SuppressWarnings("unchecked") + @Override public Void call() { + node.getOrCreateCache(cfg); + + return null; + } + }, IgniteCheckedException.class, errMsg); + } + } + + /** + * Dummy class to overcome ambiguous method name "setExpiryPolicyFactory". + */ + private final static class TestConfiguration extends CacheConfiguration { + /** + * + */ + TestConfiguration(String cacheName) { + super(cacheName); + } + + /** + * + */ + @SuppressWarnings("unused") + public void setExpiryPolicyFactory0(Factory<ExpiryPolicy> plcFactory) { + super.setExpiryPolicyFactory(plcFactory); + } + } + + /** + * + */ + private static class TestFactory implements Factory<CacheStore> { + /** Serial version uid. */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public CacheStore create() { + return null; + } + } +}
http://git-wip-us.apache.org/repos/asf/ignite/blob/00bb4d4d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccIteratorWithConcurrentTransactionTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccIteratorWithConcurrentTransactionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccIteratorWithConcurrentTransactionTest.java new file mode 100644 index 0000000..90c5b6e --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccIteratorWithConcurrentTransactionTest.java @@ -0,0 +1,64 @@ +/* + * 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.mvcc; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import javax.cache.Cache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.util.lang.IgniteClosure2X; +import org.apache.ignite.internal.util.typedef.internal.U; + +/** + * + */ +public class CacheMvccIteratorWithConcurrentTransactionTest extends CacheMvccAbstractFeatureTest { + /** + * @throws Exception if failed. + */ + public void testScanQuery() throws Exception { + doTestConsistency(clo); + } + + /** Test closure. */ + private final IgniteClosure2X<CountDownLatch, CountDownLatch, List<Person>> clo = + new IgniteClosure2X<CountDownLatch, CountDownLatch, List<Person>>() { + @Override public List<Person> applyx(CountDownLatch startLatch, CountDownLatch endLatch2) + throws IgniteCheckedException { + Iterator<Cache.Entry<Integer, Person>> it = cache().iterator(); + + List<Cache.Entry<Integer, Person>> pres = new ArrayList<>(); + + for (int i = 0; i < 50; i++) + pres.add(it.next()); + + if (startLatch != null) + startLatch.countDown(); + + while (it.hasNext()) + pres.add(it.next()); + + if (endLatch2 != null) + U.await(endLatch2); + + return entriesToPersons(pres); + } + }; +} http://git-wip-us.apache.org/repos/asf/ignite/blob/00bb4d4d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccLocalEntriesWithConcurrentTransactionTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccLocalEntriesWithConcurrentTransactionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccLocalEntriesWithConcurrentTransactionTest.java new file mode 100644 index 0000000..f4c9781 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccLocalEntriesWithConcurrentTransactionTest.java @@ -0,0 +1,65 @@ +/* + * 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.mvcc; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import javax.cache.Cache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.CachePeekMode; +import org.apache.ignite.internal.util.lang.IgniteClosure2X; +import org.apache.ignite.internal.util.typedef.internal.U; + +/** + * + */ +public class CacheMvccLocalEntriesWithConcurrentTransactionTest extends CacheMvccAbstractFeatureTest { + /** + * @throws Exception if failed. + */ + public void testLocalEntries() throws Exception { + doTestConsistency(clo); + } + + /** Test closure. */ + private final IgniteClosure2X<CountDownLatch, CountDownLatch, List<Person>> clo = + new IgniteClosure2X<CountDownLatch, CountDownLatch, List<Person>>() { + @Override public List<Person> applyx(CountDownLatch startLatch, CountDownLatch endLatch2) + throws IgniteCheckedException { + Iterator<Cache.Entry<Integer, Person>> it = cache().localEntries(CachePeekMode.PRIMARY).iterator(); + + List<Cache.Entry<Integer, Person>> pres = new ArrayList<>(); + + for (int i = 0; i < 10; i++) + pres.add(it.next()); + + if (startLatch != null) + startLatch.countDown(); + + while (it.hasNext()) + pres.add(it.next()); + + if (endLatch2 != null) + U.await(endLatch2); + + return entriesToPersons(pres); + } + }; +} http://git-wip-us.apache.org/repos/asf/ignite/blob/00bb4d4d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccOperationChecksTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccOperationChecksTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccOperationChecksTest.java new file mode 100644 index 0000000..98a06c7 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccOperationChecksTest.java @@ -0,0 +1,201 @@ +/* + * 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.mvcc; + +import java.util.Collection; +import java.util.Collections; +import java.util.Set; +import java.util.concurrent.Callable; +import javax.cache.expiry.EternalExpiryPolicy; +import javax.cache.expiry.ExpiryPolicy; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.CachePeekMode; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.internal.processors.cache.GridCacheAdapter; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteBiPredicate; +import org.apache.ignite.lang.IgniteFuture; +import org.apache.ignite.testframework.GridTestUtils; + +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; +import static org.apache.ignite.cache.CacheMode.PARTITIONED; + +/** + * + */ +public class CacheMvccOperationChecksTest extends CacheMvccAbstractTest { + /** Empty Class[]. */ + private final static Class[] E = new Class[]{}; + + /** {@inheritDoc} */ + protected CacheMode cacheMode() { + return PARTITIONED; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + super.afterTestsStopped(); + } + + /** + * @throws Exception if failed. + */ + public void testClearOperationsUnsupported() throws Exception { + checkOperationUnsupported("clear", m("Clear"), E); + + checkOperationUnsupported("clearAsync", m("Clear"), E); + + checkOperationUnsupported("clear", m("Clear"), t(Object.class), 1); + + checkOperationUnsupported("clearAsync", m("Clear"), t(Object.class), 1); + + checkOperationUnsupported("clearAll", m("Clear"), t(Set.class), Collections.singleton(1)); + + checkOperationUnsupported("clearAllAsync", m("Clear"), t(Set.class), + Collections.singleton(1)); + } + + /** + * @throws Exception if failed. + */ + public void testLoadOperationsUnsupported() throws Exception { + checkOperationUnsupported("loadCache", m("Load"), t(IgniteBiPredicate.class, Object[].class), + P, new Object[]{ 1 }); + + checkOperationUnsupported("loadCacheAsync", m("Load"), t(IgniteBiPredicate.class, Object[].class), + P, new Object[]{ 1 }); + + checkOperationUnsupported("localLoadCache", m("Load"), t(IgniteBiPredicate.class, Object[].class), + P, new Object[]{ 1 }); + + checkOperationUnsupported("localLoadCacheAsync", m("Load"), t(IgniteBiPredicate.class, Object[].class), + P, new Object[]{ 1 }); + } + + /** + * @throws Exception if failed. + */ + public void testLockOperationsUnsupported() throws Exception { + checkOperationUnsupported("lock", m("Lock"), t(Object.class), 1); + + checkOperationUnsupported("lockAll", m("Lock"), t(Collection.class), Collections.singleton(1)); + } + + /** + * @throws Exception if failed. + */ + public void testPeekOperationsUnsupported() throws Exception { + checkOperationUnsupported("localPeek", m("Peek"), t(Object.class, CachePeekMode[].class), 1, + new CachePeekMode[]{CachePeekMode.NEAR}); + } + + /** + * @throws Exception if failed. + */ + public void testEvictOperationsUnsupported() throws Exception { + checkOperationUnsupported("localEvict", m("Evict"), t(Collection.class), Collections.singleton(1)); + } + + /** + * @throws Exception if failed. + */ + public void testWithExpiryPolicyUnsupported() throws Exception { + checkOperationUnsupported("withExpiryPolicy", m("withExpiryPolicy"), t(ExpiryPolicy.class), + EternalExpiryPolicy.factoryOf().create()); + } + + /** + * @param opTypeName Operation type name. + * @return Typical error message from {@link GridCacheAdapter}. + */ + private static String m(String opTypeName) { + return opTypeName + " operations are not supported on transactional caches when MVCC is enabled."; + } + + /** + * @param types Parameter types. + * @return Types array. + */ + private static Class[] t(Class... types) { + return types; + } + + /** + * @param mtdName Method name. + * @param errMsg Expected error message. + * @param paramTypes Operation param types. + * @param args Operation arguments. + * @throws Exception if failed. + */ + @SuppressWarnings("ThrowableNotThrown") + private void checkOperationUnsupported(String mtdName, String errMsg, Class[] paramTypes, + Object... args) throws Exception { + final boolean async = mtdName.endsWith("Async"); + + try (final Ignite node = startGrid(0)) { + final CacheConfiguration<Integer, String> cfg = new CacheConfiguration<>("cache"); + + cfg.setCacheMode(cacheMode()); + cfg.setAtomicityMode(TRANSACTIONAL); + + try (IgniteCache<Integer, String> cache = node.createCache(cfg)) { + GridTestUtils.assertThrows(log, new Callable<Void>() { + @SuppressWarnings("unchecked") + @Override public Void call() throws Exception { + try { + Object o = U.invoke(null, cache, mtdName, paramTypes, args); + + if (async) { + assertTrue(o instanceof IgniteFuture<?>); + + ((IgniteFuture)o).get(); + } + } + catch (Exception e) { + if (e.getCause() == null) + throw e; + + if (e.getCause().getCause() == null) + throw e; + + throw (Exception)e.getCause().getCause(); + } + + return null; + } + }, UnsupportedOperationException.class, errMsg); + } + } + } + + /** + * + */ + private final static IgniteBiPredicate<Object, Object> P = new IgniteBiPredicate<Object, Object>() { + @Override public boolean apply(Object o, Object o2) { + return false; + } + }; +} http://git-wip-us.apache.org/repos/asf/ignite/blob/00bb4d4d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccPartitionedCoordinatorFailoverTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccPartitionedCoordinatorFailoverTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccPartitionedCoordinatorFailoverTest.java new file mode 100644 index 0000000..3ea1c5b --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccPartitionedCoordinatorFailoverTest.java @@ -0,0 +1,144 @@ +/* + * 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.mvcc; + +import org.apache.ignite.cache.CacheMode; + +import static org.apache.ignite.internal.processors.cache.mvcc.CacheMvccAbstractTest.ReadMode.GET; +import static org.apache.ignite.internal.processors.cache.mvcc.CacheMvccAbstractTest.ReadMode.SCAN; +import static org.apache.ignite.internal.processors.cache.mvcc.CacheMvccAbstractTest.WriteMode.PUT; +import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; +import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ; + +/** + * Coordinator failover test for partitioned caches. + */ +public class CacheMvccPartitionedCoordinatorFailoverTest extends CacheMvccAbstractCoordinatorFailoverTest { + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return CacheMode.PARTITIONED; + } + + /** + * @throws Exception If failed. + */ + public void testAccountsTxGet_ClientServer_Backups2_CoordinatorFails_Persistence() throws Exception { + persistence = true; + + accountsTxReadAll(4, 2, 2, DFLT_PARTITION_COUNT, + null, true, GET, PUT, DFLT_TEST_TIME, RestartMode.RESTART_CRD); + } + + /** + * @throws Exception If failed. + */ + public void testAccountsTxGet_Server_Backups1_CoordinatorFails() throws Exception { + accountsTxReadAll(2, 0, 1, DFLT_PARTITION_COUNT, + null, true, GET, PUT, DFLT_TEST_TIME, RestartMode.RESTART_CRD); + } + + /** + * @throws Exception If failed. + */ + public void testAccountsTxScan_ClientServer_Backups2_CoordinatorFails() throws Exception { + accountsTxReadAll(4, 2, 2, DFLT_PARTITION_COUNT, + null, true, SCAN, PUT, DFLT_TEST_TIME, RestartMode.RESTART_CRD); + } + + /** + * @throws Exception If failed. + */ + public void testAccountsTxScan_Server_Backups1_CoordinatorFails_Persistence() throws Exception { + persistence = true; + + accountsTxReadAll(2, 0, 1, DFLT_PARTITION_COUNT, + null, true, SCAN, PUT, DFLT_TEST_TIME, RestartMode.RESTART_CRD); + } + + /** + * @throws Exception If failed. + */ + public void testPutAllGetAll_ClientServer_Backups2_RestartCoordinator_GetPut() throws Exception { + putAllGetAll(RestartMode.RESTART_CRD, 4, 2, 2, DFLT_PARTITION_COUNT, + null, GET, PUT); + } + + /** + * @throws Exception If failed. + */ + public void testPutAllGetAll_ClientServer_Backups1_RestartCoordinator_GetPut_Persistence() throws Exception { + persistence = true; + + putAllGetAll(RestartMode.RESTART_CRD, 2, 1, 1, 64, + null, GET, PUT); + } + + /** + * @throws Exception If failed. + */ + public void testUpdate_N_Objects_ClientServer_Backups1_PutGet_CoordinatorFails_Persistence() throws Exception { + persistence = true; + + updateNObjectsTest(3, 5, 3, 1, DFLT_PARTITION_COUNT, DFLT_TEST_TIME, + null, GET, PUT, RestartMode.RESTART_CRD); + } + + /** + * @throws Exception If failed. + */ + public void testUpdate_N_Objects_ClientServer_Backups1__PutGet_CoordinatorFails() throws Exception { + updateNObjectsTest(10, 3, 2, 1, DFLT_PARTITION_COUNT, DFLT_TEST_TIME, + null, GET, PUT, RestartMode.RESTART_CRD); + } + + + /** + * @throws Exception If failed. + */ + public void testGetReadInProgressCoordinatorFails() throws Exception { + readInProgressCoordinatorFails(false, false, PESSIMISTIC, REPEATABLE_READ, GET, PUT, null); + } + + /** + * @throws Exception If failed. + */ + public void testGetReadInsideTxInProgressCoordinatorFails() throws Exception { + readInProgressCoordinatorFails(false, true, PESSIMISTIC, REPEATABLE_READ, GET, PUT, null); + } + + /** + * @throws Exception If failed. + */ + public void testGetReadInProgressCoordinatorFails_ReadDelay() throws Exception { + readInProgressCoordinatorFails(true, false, PESSIMISTIC, REPEATABLE_READ, GET, PUT, null); + } + + /** + * @throws Exception If failed. + */ + public void testGetReadInsideTxInProgressCoordinatorFails_ReadDelay() throws Exception { + readInProgressCoordinatorFails(true, true, PESSIMISTIC, REPEATABLE_READ, GET, PUT, null); + } + + /** + * @throws Exception If failed. + */ + public void testReadInProgressCoordinatorFailsSimple_FromServerPutGet() throws Exception { + readInProgressCoordinatorFailsSimple(false, null, GET, PUT); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/00bb4d4d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccProcessorTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccProcessorTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccProcessorTest.java new file mode 100644 index 0000000..411a4b7 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccProcessorTest.java @@ -0,0 +1,97 @@ +/* + * 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.mvcc; + +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.cache.mvcc.txlog.TxState; + +import static org.apache.ignite.cache.CacheMode.PARTITIONED; + +/** + * + */ +public class CacheMvccProcessorTest extends CacheMvccAbstractTest { + /** {@inheritDoc} */ + protected CacheMode cacheMode() { + return PARTITIONED; + } + + /** + * @throws Exception If failed. + */ + public void testTreeWithPersistence() throws Exception { + persistence = true; + + checkTreeOperations(); + } + + /** + * @throws Exception If failed. + */ + public void testTreeWithoutPersistence() throws Exception { + persistence = true; + + checkTreeOperations(); + } + + /** + * @throws Exception If failed. + */ + private void checkTreeOperations() throws Exception { + IgniteEx grid = startGrid(0); + + grid.cluster().active(true); + + MvccProcessorImpl mvccProcessor = mvccProcessor(grid); + + assertEquals(TxState.NA, mvccProcessor.state(new MvccVersionImpl(1, 1, MvccUtils.MVCC_OP_COUNTER_NA))); + + mvccProcessor.updateState(new MvccVersionImpl(1, 1, MvccUtils.MVCC_OP_COUNTER_NA), TxState.PREPARED); + mvccProcessor.updateState(new MvccVersionImpl(1, 2, MvccUtils.MVCC_OP_COUNTER_NA), TxState.PREPARED); + mvccProcessor.updateState(new MvccVersionImpl(1, 3, MvccUtils.MVCC_OP_COUNTER_NA), TxState.COMMITTED); + mvccProcessor.updateState(new MvccVersionImpl(1, 4, MvccUtils.MVCC_OP_COUNTER_NA), TxState.ABORTED); + mvccProcessor.updateState(new MvccVersionImpl(1, 5, MvccUtils.MVCC_OP_COUNTER_NA), TxState.ABORTED); + mvccProcessor.updateState(new MvccVersionImpl(1, 6, MvccUtils.MVCC_OP_COUNTER_NA), TxState.PREPARED); + + if (persistence) { + stopGrid(0, false); + grid = startGrid(0); + + grid.cluster().active(true); + + mvccProcessor = mvccProcessor(grid); + } + + assertEquals(TxState.PREPARED, mvccProcessor.state(new MvccVersionImpl(1, 1, MvccUtils.MVCC_OP_COUNTER_NA))); + assertEquals(TxState.PREPARED, mvccProcessor.state(new MvccVersionImpl(1, 2, MvccUtils.MVCC_OP_COUNTER_NA))); + assertEquals(TxState.COMMITTED, mvccProcessor.state(new MvccVersionImpl(1, 3, MvccUtils.MVCC_OP_COUNTER_NA))); + assertEquals(TxState.ABORTED, mvccProcessor.state(new MvccVersionImpl(1, 4, MvccUtils.MVCC_OP_COUNTER_NA))); + assertEquals(TxState.ABORTED, mvccProcessor.state(new MvccVersionImpl(1, 5, MvccUtils.MVCC_OP_COUNTER_NA))); + assertEquals(TxState.PREPARED, mvccProcessor.state(new MvccVersionImpl(1, 6, MvccUtils.MVCC_OP_COUNTER_NA))); + + mvccProcessor.removeUntil(new MvccVersionImpl(1, 5, MvccUtils.MVCC_OP_COUNTER_NA)); + + assertEquals(TxState.NA, mvccProcessor.state(new MvccVersionImpl(1, 1, MvccUtils.MVCC_OP_COUNTER_NA))); + assertEquals(TxState.NA, mvccProcessor.state(new MvccVersionImpl(1, 2, MvccUtils.MVCC_OP_COUNTER_NA))); + assertEquals(TxState.NA, mvccProcessor.state(new MvccVersionImpl(1, 3, MvccUtils.MVCC_OP_COUNTER_NA))); + assertEquals(TxState.NA, mvccProcessor.state(new MvccVersionImpl(1, 4, MvccUtils.MVCC_OP_COUNTER_NA))); + assertEquals(TxState.NA, mvccProcessor.state(new MvccVersionImpl(1, 5, MvccUtils.MVCC_OP_COUNTER_NA))); + assertEquals(TxState.PREPARED, mvccProcessor.state(new MvccVersionImpl(1, 6, MvccUtils.MVCC_OP_COUNTER_NA))); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/00bb4d4d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccReplicatedCoordinatorFailoverTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccReplicatedCoordinatorFailoverTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccReplicatedCoordinatorFailoverTest.java new file mode 100644 index 0000000..dc948cd --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccReplicatedCoordinatorFailoverTest.java @@ -0,0 +1,30 @@ +/* + * 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.mvcc; + +import org.apache.ignite.cache.CacheMode; + +/** + * Coordinator failover test for replicated caches. + */ +public class CacheMvccReplicatedCoordinatorFailoverTest extends CacheMvccAbstractCoordinatorFailoverTest { + /** {@inheritDoc} */ + @Override protected CacheMode cacheMode() { + return CacheMode.REPLICATED; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/00bb4d4d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccScanQueryWithConcurrentTransactionTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccScanQueryWithConcurrentTransactionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccScanQueryWithConcurrentTransactionTest.java new file mode 100644 index 0000000..8af6a5b --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccScanQueryWithConcurrentTransactionTest.java @@ -0,0 +1,76 @@ +/* + * 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.mvcc; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import javax.cache.Cache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.query.QueryCursor; +import org.apache.ignite.cache.query.ScanQuery; +import org.apache.ignite.internal.util.lang.IgniteClosure2X; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteBiPredicate; + +/** + * + */ +public class CacheMvccScanQueryWithConcurrentTransactionTest extends CacheMvccAbstractFeatureTest { + /** + * @throws Exception if failed. + */ + public void testScanQuery() throws Exception { + doTestConsistency(clo); + } + + /** Test closure. */ + private final IgniteClosure2X<CountDownLatch, CountDownLatch, List<Person>> clo = + new IgniteClosure2X<CountDownLatch, CountDownLatch, List<Person>>() { + @Override public List<Person> applyx(CountDownLatch startLatch, CountDownLatch endLatch2) + throws IgniteCheckedException { + IgniteBiPredicate<Integer, Person> f = new IgniteBiPredicate<Integer, Person>() { + @Override public boolean apply(Integer k, Person v) { + return k % 2 == 0; + } + }; + + try (QueryCursor<Cache.Entry<Integer, Person>> cur = cache().query(new ScanQuery<Integer, Person>() + .setFilter(f))) { + Iterator<Cache.Entry<Integer, Person>> it = cur.iterator(); + + List<Cache.Entry<Integer, Person>> pres = new ArrayList<>(); + + for (int i = 0; i < 50; i++) + pres.add(it.next()); + + if (startLatch != null) + startLatch.countDown(); + + while (it.hasNext()) + pres.add(it.next()); + + if (endLatch2 != null) + U.await(endLatch2); + + return entriesToPersons(pres); + } + } + }; +} http://git-wip-us.apache.org/repos/asf/ignite/blob/00bb4d4d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSizeWithConcurrentTransactionTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSizeWithConcurrentTransactionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSizeWithConcurrentTransactionTest.java new file mode 100644 index 0000000..2b8b73e --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSizeWithConcurrentTransactionTest.java @@ -0,0 +1,52 @@ +/* + * 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.mvcc; + +import java.util.concurrent.CountDownLatch; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.util.lang.IgniteClosure2X; +import org.apache.ignite.internal.util.typedef.internal.U; + +/** + * + */ +public class CacheMvccSizeWithConcurrentTransactionTest extends CacheMvccAbstractFeatureTest { + /** + * @throws Exception if failed. + */ + public void testSize() throws Exception { + doTestConsistency(clo); + } + + /** Test closure. */ + private final IgniteClosure2X<CountDownLatch, CountDownLatch, Integer> clo = + new IgniteClosure2X<CountDownLatch, CountDownLatch, Integer>() { + @Override public Integer applyx(CountDownLatch startLatch, CountDownLatch endLatch2) + throws IgniteCheckedException { + if (startLatch != null) + startLatch.countDown(); + + int res = cache().size(); + + if (endLatch2 != null) + U.await(endLatch2); + + return res; + } + }; +}