http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b89b472d/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheAbstractNodeRestartSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheAbstractNodeRestartSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheAbstractNodeRestartSelfTest.java deleted file mode 100644 index f46828f..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheAbstractNodeRestartSelfTest.java +++ /dev/null @@ -1,886 +0,0 @@ -/* - * 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.gridgain.grid.kernal.processors.cache.distributed; - -import org.apache.ignite.*; -import org.apache.ignite.cache.*; -import org.apache.ignite.cluster.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.transactions.*; -import org.apache.ignite.spi.discovery.tcp.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; -import org.gridgain.testframework.junits.common.*; - -import java.util.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; - -import static org.apache.ignite.cache.CacheConfiguration.*; -import static org.apache.ignite.cache.GridCachePreloadMode.*; -import static org.apache.ignite.transactions.IgniteTxConcurrency.*; -import static org.apache.ignite.transactions.IgniteTxIsolation.*; - -/** - * Test node restart. - */ -@SuppressWarnings({"PointlessArithmeticExpression"}) -public abstract class GridCacheAbstractNodeRestartSelfTest extends GridCommonAbstractTest { - /** Cache name. */ - protected static final String CACHE_NAME = "TEST_CACHE"; - - /** */ - private static final long TEST_TIMEOUT = 5 * 60 * 1000; - - /** Default backups. */ - private static final int DFLT_BACKUPS = 1; - - /** Partitions. */ - private static final int DFLT_PARTITIONS = 521; - - /** Preload batch size. */ - private static final int DFLT_BATCH_SIZE = DFLT_PRELOAD_BATCH_SIZE; - - /** Number of key backups. Each test method can set this value as required. */ - protected int backups = DFLT_BACKUPS; - - /** */ - private static final int DFLT_NODE_CNT = 4; - - /** */ - private static final int DFLT_KEY_CNT = 100; - - /** */ - private static final int DFLT_RETRIES = 10; - - /** */ - private static final Random RAND = new Random(); - - /** */ - private static volatile int idx = -1; - - /** Preload mode. */ - protected GridCachePreloadMode preloadMode = ASYNC; - - /** */ - protected int preloadBatchSize = DFLT_BATCH_SIZE; - - /** Number of partitions. */ - protected int partitions = DFLT_PARTITIONS; - - /** Node count. */ - protected int nodeCnt = DFLT_NODE_CNT; - - /** Key count. */ - protected int keyCnt = DFLT_KEY_CNT; - - /** Retries. */ - private int retries = DFLT_RETRIES; - - /** */ - private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration c = super.getConfiguration(gridName); - - // Discovery. - TcpDiscoverySpi disco = new TcpDiscoverySpi(); - - disco.setIpFinder(ipFinder); - - c.setDiscoverySpi(disco); - - return c; - } - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - stopAllGrids(); - } - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - backups = DFLT_BACKUPS; - partitions = DFLT_PARTITIONS; - preloadMode = ASYNC; - preloadBatchSize = DFLT_BATCH_SIZE; - nodeCnt = DFLT_NODE_CNT; - keyCnt = DFLT_KEY_CNT; - retries = DFLT_RETRIES; - idx = -1; - } - - /** {@inheritDoc} */ - @Override protected long getTestTimeout() { - return TEST_TIMEOUT; - } - - /** - * @throws Exception If failed. - */ - private void startGrids() throws Exception { - for (int i = 0; i < nodeCnt; i++) { - startGrid(i); - - if (idx < 0) - idx = i; - } - } - - /** - * @throws Exception If failed. - */ - public void testRestart() throws Exception { - preloadMode = SYNC; - partitions = 3; - nodeCnt = 2; - keyCnt = 10; - retries = 3; - - info("*** STARTING TEST ***"); - - startGrids(); - - try { - GridCache<Integer, String> c = grid(idx).cache(CACHE_NAME); - - for (int j = 0; j < retries; j++) { - for (int i = 0; i < keyCnt; i++) - c.putx(i, Integer.toString(i)); - - info("Stored items."); - - checkGet(c, j); - - info("Stopping node: " + idx); - - stopGrid(idx); - - info("Starting node: " + idx); - - Ignite ignite = startGrid(idx); - - c = ignite.cache(CACHE_NAME); - - checkGet(c, j); - } - } - finally { - stopAllGrids(true); - } - } - - /** - * @param c Cache. - * @param attempt Attempt. - * @throws Exception If failed. - */ - private void checkGet(GridCache<Integer, String> c, int attempt) throws Exception { - for (int i = 0; i < keyCnt; i++) { - String v = c.get(i); - - if (v == null) { - printFailureDetails(c, i, attempt); - - fail("Value is null [key=" + i + ", attempt=" + attempt + "]"); - } - - if (!Integer.toString(i).equals(v)) { - printFailureDetails(c, i, attempt); - - fail("Wrong value for key [key=" + - i + ", actual value=" + v + ", expected value=" + Integer.toString(i) + "]"); - } - } - - info("Read items."); - } - - /** - * @return Transaction concurrency to use in tests. - */ - protected IgniteTxConcurrency txConcurrency() { - return PESSIMISTIC; - } - - /** - * @throws Exception If failed. - */ - public void testRestartWithPutTwoNodesNoBackups() throws Throwable { - backups = 0; - nodeCnt = 2; - keyCnt = 10; - partitions = 29; - preloadMode = ASYNC; - - long duration = 30000; - - checkRestartWithPut(duration, 1, 1); - } - - /** - * @throws Exception If failed. - */ - public void testRestartWithTxTwoNodesNoBackups() throws Throwable { - backups = 0; - nodeCnt = 2; - keyCnt = 10; - partitions = 29; - preloadMode = ASYNC; - - long duration = 30000; - - checkRestartWithTx(duration, 1, 1); - } - - /** - * @throws Exception If failed. - */ - public void testRestartWithPutTwoNodesOneBackup() throws Throwable { - backups = 1; - nodeCnt = 2; - keyCnt = 10; - partitions = 29; - preloadMode = ASYNC; - - long duration = 30000; - - checkRestartWithPut(duration, 1, 1); - } - - /** - * @throws Exception If failed. - */ - public void testRestartWithTxTwoNodesOneBackup() throws Throwable { - backups = 1; - nodeCnt = 2; - keyCnt = 10; - partitions = 29; - preloadMode = ASYNC; - - long duration = 30000; - - checkRestartWithTx(duration, 1, 1); - } - - /** - * @throws Exception If failed. - */ - public void testRestartWithPutFourNodesNoBackups() throws Throwable { - backups = 0; - nodeCnt = 4; - keyCnt = 10; - partitions = 29; - preloadMode = ASYNC; - - long duration = 60000; - - checkRestartWithPut(duration, 2, 2); - } - - /** - * @throws Exception If failed. - */ - public void testRestartWithTxFourNodesNoBackups() throws Throwable { - backups = 0; - nodeCnt = 4; - keyCnt = 10; - partitions = 29; - preloadMode = ASYNC; - - long duration = 60000; - - checkRestartWithTx(duration, 2, 2); - } - - /** - * @throws Exception If failed. - */ - public void testRestartWithPutFourNodesOneBackups() throws Throwable { - backups = 1; - nodeCnt = 4; - keyCnt = 10; - partitions = 29; - preloadMode = ASYNC; - - long duration = 60000; - - checkRestartWithPut(duration, 2, 2); - } - - /** - * @throws Exception If failed. - */ - public void testRestartWithTxFourNodesOneBackups() throws Throwable { - backups = 1; - nodeCnt = 4; - keyCnt = 10; - partitions = 29; - preloadMode = ASYNC; - - long duration = 60000; - - checkRestartWithTx(duration, 2, 2); - } - - /** - * @throws Exception If failed. - */ - public void testRestartWithPutSixNodesTwoBackups() throws Throwable { - backups = 2; - nodeCnt = 6; - keyCnt = 10; - partitions = 29; - preloadMode = ASYNC; - - long duration = 90000; - - checkRestartWithPut(duration, 3, 3); - } - - /** - * @throws Exception If failed. - */ - public void testRestartWithTxSixNodesTwoBackups() throws Throwable { - backups = 2; - nodeCnt = 6; - keyCnt = 10; - partitions = 29; - preloadMode = ASYNC; - - long duration = 90000; - - checkRestartWithTx(duration, 3, 3); - } - - /** - * @throws Exception If failed. - */ - public void testRestartWithPutEightNodesTwoBackups() throws Throwable { - backups = 2; - nodeCnt = 8; - keyCnt = 10; - partitions = 29; - preloadMode = ASYNC; - - long duration = 90000; - - checkRestartWithPut(duration, 4, 4); - } - - /** - * @throws Exception If failed. - */ - public void testRestartWithTxEightNodesTwoBackups() throws Throwable { - backups = 2; - nodeCnt = 8; - keyCnt = 10; - partitions = 29; - preloadMode = ASYNC; - - long duration = 90000; - - checkRestartWithTx(duration, 4, 4); - } - - /** - * @throws Exception If failed. - */ - public void testRestartWithPutTenNodesTwoBackups() throws Throwable { - backups = 2; - nodeCnt = 10; - keyCnt = 10; - partitions = 29; - preloadMode = ASYNC; - - long duration = 90000; - - checkRestartWithPut(duration, 5, 5); - } - - /** - * @throws Exception If failed. - */ - public void testRestartWithTxTenNodesTwoBackups() throws Throwable { - backups = 2; - nodeCnt = 10; - keyCnt = 10; - partitions = 29; - preloadMode = ASYNC; - - long duration = 90000; - - checkRestartWithTx(duration, 5, 5); - } - - /** - * @throws Exception If failed. - */ - public void testRestartWithTxPutAllTenNodesTwoBackups() throws Throwable { - backups = 2; - nodeCnt = 10; - keyCnt = 10; - partitions = 29; - preloadMode = ASYNC; - - long duration = 90000; - - checkRestartWithTxPutAll(duration, 5, 5); - } - - /** - * @throws Exception If failed. - */ - public void testRestartWithTxPutAllFourNodesTwoBackups() throws Throwable { - backups = 2; - nodeCnt = 4; - keyCnt = 10; - partitions = 29; - preloadMode = ASYNC; - - long duration = 90000; - - checkRestartWithTxPutAll(duration, 2, 2); - } - - /** - * @param duration Test duration. - * @param putThreads Put threads count. - * @param restartThreads Restart threads count. - * @throws Exception If failed. - */ - public void checkRestartWithPut(long duration, int putThreads, int restartThreads) throws Throwable { - final long endTime = System.currentTimeMillis() + duration; - - final AtomicReference<Throwable> err = new AtomicReference<>(); - - startGrids(); - - Collection<Thread> threads = new LinkedList<>(); - - try { - final int logFreq = 20; - - final AtomicInteger putCntr = new AtomicInteger(); - - final CyclicBarrier barrier = new CyclicBarrier(putThreads + restartThreads); - - for (int i = 0; i < putThreads; i++) { - final int gridIdx = i; - - Thread t = new Thread(new Runnable() { - @Override public void run() { - try { - barrier.await(); - - info("Starting put thread..."); - - GridCache<Integer, String> cache = grid(gridIdx).cache(CACHE_NAME); - - while (System.currentTimeMillis() < endTime && err.get() == null) { - int key = RAND.nextInt(keyCnt); - - try { - cache.put(key, Integer.toString(key)); - } - catch (IgniteTxRollbackException | ClusterTopologyException ignored) { - // It is ok if primary node leaves grid. - } - - int c = putCntr.incrementAndGet(); - - if (c % logFreq == 0) - info(">>> Put iteration [cnt=" + c + ", key=" + key + ']'); - } - } - catch (Exception e) { - err.compareAndSet(null, e); - - error("Failed to put value in cache.", e); - } - } - }, "put-worker-" + i); - - t.start(); - - threads.add(t); - } - - for (int i = 0; i < restartThreads; i++) { - final int gridIdx = i + putThreads; - - Thread t = new Thread(new Runnable() { - @Override public void run() { - try { - barrier.await(); - - info("Starting restart thread..."); - - int cnt = 0; - - while (System.currentTimeMillis() < endTime && err.get() == null) { - log.info(">>>>>>> Stopping grid " + gridIdx); - - stopGrid(gridIdx); - - log.info(">>>>>>> Starting grid " + gridIdx); - - startGrid(gridIdx); - - int c = ++cnt; - - if (c % logFreq == 0) - info(">>> Restart iteration: " + c); - } - } - catch (Exception e) { - err.compareAndSet(null, e); - - error("Failed to restart grid node.", e); - } - } - }, "restart-worker-" + i); - - t.start(); - - threads.add(t); - } - - for (Thread t : threads) - t.join(); - - if (err.get() != null) - throw err.get(); - } - finally { - stopAllGrids(); - } - } - - /** - * @param duration Test duration. - * @param putThreads Put threads count. - * @param restartThreads Restart threads count. - * @throws Exception If failed. - */ - public void checkRestartWithTx(long duration, int putThreads, int restartThreads) throws Throwable { - final long endTime = System.currentTimeMillis() + duration; - - final AtomicReference<Throwable> err = new AtomicReference<>(); - - startGrids(); - - Collection<Thread> threads = new LinkedList<>(); - - try { - final int logFreq = 20; - - final AtomicInteger txCntr = new AtomicInteger(); - - final CyclicBarrier barrier = new CyclicBarrier(putThreads + restartThreads); - - final int txKeys = 3; - - for (int i = 0; i < putThreads; i++) { - final int gridIdx = i; - - Thread t = new Thread(new Runnable() { - @Override public void run() { - try { - barrier.await(); - - info("Starting put thread..."); - - Ignite ignite = grid(gridIdx); - - UUID locNodeId = ignite.cluster().localNode().id(); - - GridCache<Integer, String> cache = ignite.cache(CACHE_NAME); - - List<Integer> keys = new ArrayList<>(txKeys); - - while (System.currentTimeMillis() < endTime && err.get() == null) { - keys.clear(); - - for (int i = 0; i < txKeys; i++) - keys.add(RAND.nextInt(keyCnt)); - - // Ensure lock order. - Collections.sort(keys); - - int c = 0; - - try { - try (IgniteTx tx = cache.txStart(txConcurrency(), REPEATABLE_READ)) { - c = txCntr.incrementAndGet(); - - if (c % logFreq == 0) - info(">>> Tx iteration started [cnt=" + c + ", keys=" + keys + ", " + - "locNodeId=" + locNodeId + ']'); - - for (int key : keys) { - int op = cacheOp(); - - if (op == 1) - cache.put(key, Integer.toString(key)); - else if (op == 2) - cache.remove(key); - else - cache.get(key); - } - - tx.commit(); - } - catch (ClusterTopologyException ignored) { - // It is ok if primary node leaves grid. - } - } - catch (ClusterTopologyException ignored) { - // It is ok if primary node leaves grid. - } - - if (c % logFreq == 0) - info(">>> Tx iteration finished [cnt=" + c + ", keys=" + keys + ", " + - "locNodeId=" + locNodeId + ']'); - } - - info(">>> " + Thread.currentThread().getName() + " finished."); - } - catch (Exception e) { - err.compareAndSet(null, e); - - error("Failed to put value in cache.", e); - } - } - }, "put-worker-" + i); - - t.start(); - - threads.add(t); - } - - for (int i = 0; i < restartThreads; i++) { - final int gridIdx = i + putThreads; - - Thread t = new Thread(new Runnable() { - @Override public void run() { - try { - barrier.await(); - - info("Starting restart thread..."); - - int cnt = 0; - - while (System.currentTimeMillis() < endTime && err.get() == null) { - stopGrid(gridIdx); - startGrid(gridIdx); - - int c = ++cnt; - - if (c % logFreq == 0) - info(">>> Restart iteration: " + c); - } - - info(">>> " + Thread.currentThread().getName() + " finished."); - } - catch (Exception e) { - err.compareAndSet(null, e); - - error("Failed to restart grid node.", e); - } - } - }, "restart-worker-" + i); - - t.start(); - - threads.add(t); - } - - for (Thread t : threads) - t.join(); - - if (err.get() != null) - throw err.get(); - } - finally { - stopAllGrids(); - } - } - - /** - * @param duration Test duration. - * @param putThreads Put threads count. - * @param restartThreads Restart threads count. - * @throws Exception If failed. - */ - public void checkRestartWithTxPutAll(long duration, int putThreads, int restartThreads) throws Throwable { - final long endTime = System.currentTimeMillis() + duration; - - final AtomicReference<Throwable> err = new AtomicReference<>(); - - startGrids(); - - Collection<Thread> threads = new LinkedList<>(); - - try { - final int logFreq = 20; - - final AtomicInteger txCntr = new AtomicInteger(); - - final CyclicBarrier barrier = new CyclicBarrier(putThreads + restartThreads); - - final int txKeys = 3; - - for (int i = 0; i < putThreads; i++) { - final int gridIdx = i; - - Thread t = new Thread(new Runnable() { - @Override public void run() { - try { - barrier.await(); - - info("Starting put thread..."); - - Ignite ignite = grid(gridIdx); - - UUID locNodeId = ignite.cluster().localNode().id(); - - GridCache<Integer, String> cache = ignite.cache(CACHE_NAME); - - List<Integer> keys = new ArrayList<>(txKeys); - - while (System.currentTimeMillis() < endTime && err.get() == null) { - keys.clear(); - - for (int i = 0; i < txKeys; i++) - keys.add(RAND.nextInt(keyCnt)); - - // Ensure lock order. - Collections.sort(keys); - - int c = 0; - - try (IgniteTx tx = cache.txStart(PESSIMISTIC, REPEATABLE_READ)) { - c = txCntr.incrementAndGet(); - - if (c % logFreq == 0) - info(">>> Tx iteration started [cnt=" + c + ", keys=" + keys + ", " + - "locNodeId=" + locNodeId + ']'); - - Map<Integer, String> batch = new LinkedHashMap<>(); - - for (int key : keys) - batch.put(key, String.valueOf(key)); - - cache.putAll(batch); - - tx.commit(); - } - catch (ClusterTopologyException ignored) { - // It is ok if primary node leaves grid. - } - - if (c % logFreq == 0) - info(">>> Tx iteration finished [cnt=" + c + ", keys=" + keys + ", " + - "locNodeId=" + locNodeId + ']'); - } - } - catch (Exception e) { - err.compareAndSet(null, e); - - error("Failed to put value in cache.", e); - } - } - }, "put-worker-" + i); - - t.start(); - - threads.add(t); - } - - for (int i = 0; i < restartThreads; i++) { - final int gridIdx = i + putThreads; - - Thread t = new Thread(new Runnable() { - @Override public void run() { - try { - barrier.await(); - - info("Starting restart thread..."); - - int cnt = 0; - - while (System.currentTimeMillis() < endTime && err.get() == null) { - stopGrid(gridIdx); - startGrid(gridIdx); - - int c = ++cnt; - - if (c % logFreq == 0) - info(">>> Restart iteration: " + c); - } - } - catch (Exception e) { - err.compareAndSet(null, e); - - error("Failed to restart grid node.", e); - } - } - }, "restart-worker-" + i); - - t.start(); - - threads.add(t); - } - - for (Thread t : threads) - t.join(); - - if (err.get() != null) - throw err.get(); - } - finally { - stopAllGrids(); - } - } - - /** - * @return Cache operation. - */ - private int cacheOp() { - return RAND.nextInt(3) + 1; - } - - /** - * @param c Cache projection. - * @param key Key. - * @param attempt Attempt. - */ - private void printFailureDetails(GridCache<Integer, String> c, int key, int attempt) { - error("*** Failure details ***"); - error("Key: " + key); - error("Partition: " + c.configuration().getAffinity().partition(key)); - error("Attempt: " + attempt); - error("Node: " + c.gridProjection().ignite().cluster().localNode().id()); - } -}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b89b472d/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheAbstractPartitionedByteArrayValuesSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheAbstractPartitionedByteArrayValuesSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheAbstractPartitionedByteArrayValuesSelfTest.java deleted file mode 100644 index 19dad1d..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheAbstractPartitionedByteArrayValuesSelfTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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.gridgain.grid.kernal.processors.cache.distributed; - -import org.apache.ignite.cache.*; -import org.apache.ignite.cache.*; -import org.apache.ignite.configuration.*; - -import static org.apache.ignite.cache.GridCacheAtomicityMode.*; -import static org.apache.ignite.cache.GridCacheMemoryMode.*; -import static org.apache.ignite.cache.GridCacheMode.*; -import static org.apache.ignite.cache.GridCacheWriteSynchronizationMode.*; - -/** - * Tests for byte array values in PARTITIONED caches. - */ -public abstract class GridCacheAbstractPartitionedByteArrayValuesSelfTest extends - GridCacheAbstractDistributedByteArrayValuesSelfTest { - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - TransactionsConfiguration tCfg = new TransactionsConfiguration(); - - tCfg.setTxSerializableEnabled(true); - - cfg.setTransactionsConfiguration(tCfg); - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected CacheConfiguration cacheConfiguration0() { - CacheConfiguration cfg = new CacheConfiguration(); - - cfg.setCacheMode(PARTITIONED); - cfg.setAtomicityMode(TRANSACTIONAL); - cfg.setDistributionMode(distributionMode()); - cfg.setBackups(1); - cfg.setWriteSynchronizationMode(FULL_SYNC); - cfg.setSwapEnabled(true); - cfg.setEvictSynchronized(false); - cfg.setEvictNearSynchronized(false); - cfg.setPortableEnabled(portableEnabled()); - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected CacheConfiguration offheapCacheConfiguration0() { - CacheConfiguration cfg = new CacheConfiguration(); - - cfg.setCacheMode(PARTITIONED); - cfg.setAtomicityMode(TRANSACTIONAL); - cfg.setDistributionMode(distributionMode()); - cfg.setBackups(1); - cfg.setWriteSynchronizationMode(FULL_SYNC); - cfg.setMemoryMode(OFFHEAP_VALUES); - cfg.setOffHeapMaxMemory(100 * 1024 * 1024); - cfg.setQueryIndexEnabled(false); - cfg.setPortableEnabled(portableEnabled()); - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected CacheConfiguration offheapTieredCacheConfiguration0() { - CacheConfiguration cfg = new CacheConfiguration(); - - cfg.setCacheMode(PARTITIONED); - cfg.setAtomicityMode(TRANSACTIONAL); - cfg.setDistributionMode(distributionMode()); - cfg.setBackups(1); - cfg.setWriteSynchronizationMode(FULL_SYNC); - cfg.setMemoryMode(OFFHEAP_TIERED); - cfg.setOffHeapMaxMemory(100 * 1024 * 1024); - cfg.setQueryIndexEnabled(false); - cfg.setPortableEnabled(portableEnabled()); - - return cfg; - } - - /** - * @return Distribution mode. - */ - protected abstract GridCacheDistributionMode distributionMode(); -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b89b472d/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheAbstractPrimarySyncSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheAbstractPrimarySyncSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheAbstractPrimarySyncSelfTest.java deleted file mode 100644 index 2287bd7..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheAbstractPrimarySyncSelfTest.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * 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.gridgain.grid.kernal.processors.cache.distributed; - -import org.apache.ignite.cache.*; -import org.apache.ignite.cache.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.transactions.*; -import org.apache.ignite.spi.discovery.tcp.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; -import org.gridgain.testframework.junits.common.*; - -import static org.apache.ignite.cache.GridCacheAtomicityMode.*; -import static org.apache.ignite.cache.GridCacheMode.*; -import static org.apache.ignite.cache.GridCachePreloadMode.*; -import static org.apache.ignite.transactions.IgniteTxConcurrency.*; -import static org.apache.ignite.transactions.IgniteTxIsolation.*; -import static org.apache.ignite.cache.GridCacheWriteSynchronizationMode.*; - -/** - * Test ensuring that PRIMARY_SYNC mode works correctly. - */ -public abstract class GridCacheAbstractPrimarySyncSelfTest extends GridCommonAbstractTest { - /** Grids count. */ - private static final int GRID_CNT = 3; - - /** IP_FINDER. */ - private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - CacheConfiguration ccfg = new CacheConfiguration(); - - ccfg.setCacheMode(PARTITIONED); - ccfg.setAtomicityMode(TRANSACTIONAL); - ccfg.setWriteSynchronizationMode(PRIMARY_SYNC); - ccfg.setBackups(1); - ccfg.setPreloadMode(SYNC); - ccfg.setDistributionMode(distributionMode()); - - cfg.setCacheConfiguration(ccfg); - - TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); - - discoSpi.setIpFinder(IP_FINDER); - - cfg.setDiscoverySpi(discoSpi); - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - assert GRID_CNT > 1; - - startGrids(GRID_CNT); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - stopAllGrids(); - } - - /** - * @return Distribution mode. - */ - protected abstract GridCacheDistributionMode distributionMode(); - - /** - * @throws Exception If failed. - */ - public void testPrimarySync() throws Exception { - for (int i = 0; i < GRID_CNT; i++) { - for (int j = 0; j < GRID_CNT; j++) { - GridCache<Integer, Integer> cache = grid(j).cache(null); - - if (cache.entry(i).primary()) { - try (IgniteTx tx = cache.txStart(PESSIMISTIC, REPEATABLE_READ)) { - cache.put(i, i); - - tx.commit(); - } - - assert cache.get(i) == i; - - break; - } - } - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b89b472d/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheAtomicTimeoutSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheAtomicTimeoutSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheAtomicTimeoutSelfTest.java deleted file mode 100644 index f2756ec..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheAtomicTimeoutSelfTest.java +++ /dev/null @@ -1,296 +0,0 @@ -/* - * 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.gridgain.grid.kernal.processors.cache.distributed; - -import org.apache.ignite.*; -import org.apache.ignite.cache.*; -import org.apache.ignite.cache.affinity.*; -import org.apache.ignite.cluster.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.spi.*; -import org.apache.ignite.internal.managers.communication.*; -import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.*; -import org.apache.ignite.spi.communication.tcp.*; -import org.apache.ignite.internal.util.direct.*; -import org.apache.ignite.internal.util.nio.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.gridgain.testframework.*; -import org.gridgain.testframework.junits.common.*; - -import java.util.*; - -import static org.apache.ignite.cache.GridCacheAtomicWriteOrderMode.*; -import static org.apache.ignite.cache.GridCacheAtomicityMode.*; -import static org.apache.ignite.cache.GridCacheDistributionMode.*; -import static org.apache.ignite.cache.GridCacheMode.*; -import static org.apache.ignite.cache.GridCacheWriteSynchronizationMode.*; - -/** - * Tests timeout exception when message gets lost. - */ -public class GridCacheAtomicTimeoutSelfTest extends GridCommonAbstractTest { - /** Grid count. */ - public static final int GRID_CNT = 3; - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - TestCommunicationSpi commSpi = new TestCommunicationSpi(); - - commSpi.setSharedMemoryPort(-1); - - cfg.setCommunicationSpi(commSpi); - - CacheConfiguration ccfg = defaultCacheConfiguration(); - - ccfg.setCacheMode(PARTITIONED); - ccfg.setAtomicityMode(ATOMIC); - ccfg.setBackups(1); - ccfg.setAtomicWriteOrderMode(PRIMARY); - ccfg.setDistributionMode(PARTITIONED_ONLY); - ccfg.setWriteSynchronizationMode(FULL_SYNC); - - cfg.setCacheConfiguration(ccfg); - - cfg.setNetworkTimeout(3000); - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - startGrids(GRID_CNT); - } - - @Override protected void afterTestsStopped() throws Exception { - stopAllGrids(); - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - for (int i = 0; i < GRID_CNT; i++) { - final GridKernal grid = (GridKernal)grid(i); - - TestCommunicationSpi commSpi = (TestCommunicationSpi)grid.configuration().getCommunicationSpi(); - - commSpi.skipNearRequest = false; - commSpi.skipNearResponse = false; - commSpi.skipDhtRequest = false; - commSpi.skipDhtResponse = false; - - GridTestUtils.retryAssert(log, 10, 100, new CA() { - @Override public void apply() { - assertTrue(grid.internalCache().context().mvcc().atomicFutures().isEmpty()); - } - }); - } - } - - /** - * @throws Exception If failed. - */ - public void testNearUpdateRequestLost() throws Exception { - Ignite ignite = grid(0); - - TestCommunicationSpi commSpi = (TestCommunicationSpi)grid(0).configuration().getCommunicationSpi(); - - GridCache<Object, Object> cache = ignite.cache(null); - - int key = keyForTest(); - - cache.put(key, 0); - - commSpi.skipNearRequest = true; - - IgniteFuture<Object> fut = cache.putAsync(key, 1); - - Map<UUID, GridCommunicationClient> clients = U.field(commSpi, "clients"); - - GridTcpNioCommunicationClient client = (GridTcpNioCommunicationClient)clients.get(grid(1).localNode().id()); - - client.session().close().get(); - - try { - fut.get(); - - fail(); - } - catch (GridCacheAtomicUpdateTimeoutException ignore) { - // Expected exception. - } - } - - /** - * @throws Exception If failed. - */ - public void testNearUpdateResponseLost() throws Exception { - Ignite ignite = grid(0); - - GridCache<Object, Object> cache = ignite.cache(null); - - int key = keyForTest(); - - cache.put(key, 0); - - TestCommunicationSpi commSpi = (TestCommunicationSpi)grid(1).configuration().getCommunicationSpi(); - - commSpi.skipNearResponse = true; - - IgniteFuture<Object> fut = cache.putAsync(key, 1); - - Map<UUID, GridCommunicationClient> clients = U.field(commSpi, "clients"); - - GridTcpNioCommunicationClient client = (GridTcpNioCommunicationClient)clients.get(grid(0).localNode().id()); - - client.session().close().get(); - - try { - fut.get(); - - fail(); - } - catch (GridCacheAtomicUpdateTimeoutException ignore) { - // Expected exception. - } - } - - /** - * @throws Exception If failed. - */ - public void testDhtUpdateRequestLost() throws Exception { - Ignite ignite = grid(0); - - GridCache<Object, Object> cache = ignite.cache(null); - - int key = keyForTest(); - - cache.put(key, 0); - - TestCommunicationSpi commSpi = (TestCommunicationSpi)grid(1).configuration().getCommunicationSpi(); - - commSpi.skipDhtRequest = true; - - IgniteFuture<Object> fut = cache.putAsync(key, 1); - - Map<UUID, GridCommunicationClient> clients = U.field(commSpi, "clients"); - - GridTcpNioCommunicationClient client = (GridTcpNioCommunicationClient)clients.get(grid(2).localNode().id()); - - client.session().close().get(); - - try { - fut.get(); - - fail(); - } - catch (IgniteCheckedException e) { - assertTrue("Invalid exception thrown: " + e, X.hasCause(e, GridCacheAtomicUpdateTimeoutException.class) - || X.hasSuppressed(e, GridCacheAtomicUpdateTimeoutException.class)); - } - } - - /** - * @throws Exception If failed. - */ - public void testDhtUpdateResponseLost() throws Exception { - Ignite ignite = grid(0); - - GridCache<Object, Object> cache = ignite.cache(null); - - int key = keyForTest(); - - cache.put(key, 0); - - TestCommunicationSpi commSpi = (TestCommunicationSpi)grid(2).configuration().getCommunicationSpi(); - - commSpi.skipDhtResponse = true; - - IgniteFuture<Object> fut = cache.putAsync(key, 1); - - Map<UUID, GridCommunicationClient> clients = U.field(commSpi, "clients"); - - GridTcpNioCommunicationClient client = (GridTcpNioCommunicationClient)clients.get(grid(1).localNode().id()); - - client.session().close().get(); - - try { - fut.get(); - - fail(); - } - catch (IgniteCheckedException e) { - assertTrue("Invalid exception thrown: " + e, X.hasCause(e, GridCacheAtomicUpdateTimeoutException.class) - || X.hasSuppressed(e, GridCacheAtomicUpdateTimeoutException.class)); - } - } - - /** - * @return Key for test; - */ - private int keyForTest() { - int i = 0; - - GridCacheAffinity<Object> aff = grid(0).cache(null).affinity(); - - while (!aff.isPrimary(grid(1).localNode(), i) || !aff.isBackup(grid(2).localNode(), i)) - i++; - - return i; - } - - /** - * Communication SPI that will count single partition update messages. - */ - private static class TestCommunicationSpi extends TcpCommunicationSpi { - /** */ - private boolean skipNearRequest; - - /** */ - private boolean skipNearResponse; - - /** */ - private boolean skipDhtRequest; - - /** */ - private boolean skipDhtResponse; - - /** {@inheritDoc} */ - @Override public void sendMessage(ClusterNode node, GridTcpCommunicationMessageAdapter msg) - throws IgniteSpiException { - if (!skipMessage((GridIoMessage)msg)) - super.sendMessage(node, msg); - } - - /** - * Checks if message should be skipped. - * - * @param msg Message. - */ - private boolean skipMessage(GridIoMessage msg) { - return msg.message() instanceof GridNearAtomicUpdateRequest && skipNearRequest - || msg.message() instanceof GridNearAtomicUpdateResponse && skipNearResponse - || msg.message() instanceof GridDhtAtomicUpdateRequest && skipDhtRequest - || msg.message() instanceof GridDhtAtomicUpdateResponse && skipDhtResponse; - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b89b472d/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheBasicOpAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheBasicOpAbstractTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheBasicOpAbstractTest.java deleted file mode 100644 index 2e09478..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheBasicOpAbstractTest.java +++ /dev/null @@ -1,388 +0,0 @@ -/* - * 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.gridgain.grid.kernal.processors.cache.distributed; - -import org.apache.ignite.*; -import org.apache.ignite.cache.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.events.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.transactions.*; -import org.apache.ignite.spi.discovery.tcp.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; -import org.apache.ignite.internal.util.typedef.*; -import org.gridgain.testframework.junits.common.*; - -import javax.cache.expiry.*; -import java.util.concurrent.*; - -import static java.util.concurrent.TimeUnit.*; -import static org.apache.ignite.transactions.IgniteTxConcurrency.*; -import static org.apache.ignite.transactions.IgniteTxIsolation.*; -import static org.apache.ignite.events.IgniteEventType.*; - -/** - * Simple cache test. - */ -public abstract class GridCacheBasicOpAbstractTest extends GridCommonAbstractTest { - /** Grid 1. */ - private static Ignite ignite1; - - /** Grid 2. */ - private static Ignite ignite2; - - /** Grid 3. */ - private static Ignite ignite3; - - /** */ - private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - TcpDiscoverySpi disco = new TcpDiscoverySpi(); - - disco.setIpFinder(ipFinder); - - cfg.setDiscoverySpi(disco); - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - startGridsMultiThreaded(3); - - ignite1 = grid(0); - ignite2 = grid(1); - ignite3 = grid(2); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - stopAllGrids(); - - ignite1 = null; - ignite2 = null; - ignite3 = null; - } - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - for (Ignite g : G.allGrids()) - g.cache(null).clearAll(); - } - - /** - * - * @throws Exception If error occur. - */ - public void testBasicOps() throws Exception { - CountDownLatch latch = new CountDownLatch(3); - - CacheEventListener lsnr = new CacheEventListener(latch); - - try { - GridCache<String, String> cache1 = ignite1.cache(null); - GridCache<String, String> cache2 = ignite2.cache(null); - GridCache<String, String> cache3 = ignite3.cache(null); - - ignite1.events().localListen(lsnr, EVT_CACHE_OBJECT_PUT, EVT_CACHE_OBJECT_REMOVED); - ignite2.events().localListen(lsnr, EVT_CACHE_OBJECT_PUT, EVT_CACHE_OBJECT_REMOVED); - ignite3.events().localListen(lsnr, EVT_CACHE_OBJECT_PUT, EVT_CACHE_OBJECT_REMOVED); - - assert !cache1.containsKey("1"); - assert !cache2.containsKey("1"); - assert !cache3.containsKey("1"); - - info("First put"); - - cache1.put("1", "a"); - - info("Start latch wait 1"); - - assert latch.await(5, SECONDS); - - info("Stop latch wait 1"); - - assert cache1.containsKey("1"); - assert cache2.containsKey("1"); - assert cache3.containsKey("1"); - - latch = new CountDownLatch(6); - - lsnr.setLatch(latch); - - cache2.put("1", "b"); - cache3.put("1", "c"); - - info("Start latch wait 2"); - - assert latch.await(5, SECONDS); - - info("Stop latch wait 2"); - - assert cache1.containsKey("1"); - assert cache2.containsKey("1"); - assert cache3.containsKey("1"); - - latch = new CountDownLatch(3); - - lsnr.setLatch(latch); - - cache1.remove("1"); - - info("Start latch wait 3"); - - assert latch.await(5, SECONDS); - - info("Stop latch wait 3"); - - assert !cache1.containsKey("1") : "Key set: " + cache1.keySet(); - assert !cache2.containsKey("1") : "Key set: " + cache2.keySet(); - assert !cache3.containsKey("1") : "Key set: " + cache3.keySet(); - } - finally { - ignite1.events().stopLocalListen(lsnr); - ignite2.events().stopLocalListen(lsnr); - ignite3.events().stopLocalListen(lsnr); - } - } - - /** - * @throws Exception If test fails. - */ - public void testBasicOpsAsync() throws Exception { - CountDownLatch latch = new CountDownLatch(3); - - CacheEventListener lsnr = new CacheEventListener(latch); - - try { - GridCache<String, String> cache1 = ignite1.cache(null); - GridCache<String, String> cache2 = ignite2.cache(null); - GridCache<String, String> cache3 = ignite3.cache(null); - - ignite1.events().localListen(lsnr, EVT_CACHE_OBJECT_PUT, EVT_CACHE_OBJECT_REMOVED); - ignite2.events().localListen(lsnr, EVT_CACHE_OBJECT_PUT, EVT_CACHE_OBJECT_REMOVED); - ignite3.events().localListen(lsnr, EVT_CACHE_OBJECT_PUT, EVT_CACHE_OBJECT_REMOVED); - - IgniteFuture<String> f1 = cache1.getAsync("async1"); - - assert f1.get() == null; - - f1 = cache1.putAsync("async1", "asyncval1"); - - assert f1.get() == null; - - f1 = cache1.getAsync("async1"); - - String v1 = f1.get(); - - assert v1 != null; - assert "asyncval1".equals(v1); - - assert latch.await(5, SECONDS); - - IgniteFuture<String> f2 = cache2.getAsync("async1"); - IgniteFuture<String> f3 = cache3.getAsync("async1"); - - String v2 = f2.get(); - String v3 = f3.get(); - - assert v2 != null; - assert v3 != null; - - assert "asyncval1".equals(v2); - assert "asyncval1".equals(v3); - - lsnr.setLatch(latch = new CountDownLatch(3)); - - f2 = cache2.removeAsync("async1"); - - assert "asyncval1".equals(f2.get()); - - assert latch.await(5, SECONDS); - - f1 = cache1.getAsync("async1"); - f2 = cache2.getAsync("async1"); - f3 = cache3.getAsync("async1"); - - v1 = f1.get(); - v2 = f2.get(); - v3 = f3.get(); - - info("Removed v1: " + v1); - info("Removed v2: " + v2); - info("Removed v3: " + v3); - - assert v1 == null; - assert v2 == null; - assert v3 == null; - } - finally { - ignite1.events().stopLocalListen(lsnr); - ignite2.events().stopLocalListen(lsnr); - ignite3.events().stopLocalListen(lsnr); - } - } - - /** - * - * @throws IgniteCheckedException If test fails. - */ - public void testOptimisticTransaction() throws Exception { - CountDownLatch latch = new CountDownLatch(9); - - IgnitePredicate<IgniteEvent> lsnr = new CacheEventListener(latch); - - try { - GridCache<String, String> cache1 = ignite1.cache(null); - GridCache<String, String> cache2 = ignite2.cache(null); - GridCache<String, String> cache3 = ignite3.cache(null); - - ignite1.events().localListen(lsnr, EVT_CACHE_OBJECT_PUT, EVT_CACHE_OBJECT_REMOVED); - ignite2.events().localListen(lsnr, EVT_CACHE_OBJECT_PUT, EVT_CACHE_OBJECT_REMOVED); - ignite3.events().localListen(lsnr, EVT_CACHE_OBJECT_PUT, EVT_CACHE_OBJECT_REMOVED); - - IgniteTx tx = cache1.txStart(OPTIMISTIC, READ_COMMITTED, 0, 0); - - try { - cache1.put("tx1", "val1"); - cache1.put("tx2", "val2"); - cache1.put("tx3", "val3"); - - assert cache2.get("tx1") == null; - assert cache2.get("tx2") == null; - assert cache2.get("tx3") == null; - - assert cache3.get("tx1") == null; - assert cache3.get("tx2") == null; - assert cache3.get("tx3") == null; - - tx.commit(); - } - catch (IgniteCheckedException e) { - tx.rollback(); - - throw e; - } - - assert latch.await(5, SECONDS); - - String b1 = cache2.get("tx1"); - String b2 = cache2.get("tx2"); - String b3 = cache2.get("tx3"); - - String c1 = cache3.get("tx1"); - String c2 = cache3.get("tx2"); - String c3 = cache3.get("tx3"); - - assert b1 != null : "Invalid value: " + b1; - assert b2 != null : "Invalid value: " + b2; - assert b3 != null : "Invalid value: " + b3; - - assert c1 != null : "Invalid value: " + c1; - assert c2 != null : "Invalid value: " + c2; - assert c3 != null : "Invalid value: " + c3; - - assert "val1".equals(b1); - assert "val2".equals(b2); - assert "val3".equals(b3); - - assert "val1".equals(c1); - assert "val2".equals(c2); - assert "val3".equals(c3); - } - finally { - ignite1.events().stopLocalListen(lsnr); - ignite2.events().stopLocalListen(lsnr); - ignite3.events().stopLocalListen(lsnr); - } - } - - /** - * - * @throws Exception In case of error. - */ - public void testPutWithExpiration() throws Exception { - IgniteCache<String, String> cache1 = ignite1.jcache(null); - IgniteCache<String, String> cache2 = ignite2.jcache(null); - IgniteCache<String, String> cache3 = ignite3.jcache(null); - - cache1.put("key", "val"); - - IgniteTx tx = ignite1.transactions().txStart(); - - long ttl = 500; - - cache1.withExpiryPolicy(new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl))).put("key", "val"); - - assert cache1.get("key") != null; - - tx.commit(); - - info("Going to sleep for: " + (ttl + 1000)); - - // Allow for expiration. - Thread.sleep(ttl + 1000); - - String v1 = cache1.get("key"); - String v2 = cache2.get("key"); - String v3 = cache3.get("key"); - - assert v1 == null : "V1 should be null: " + v1; - assert v2 == null : "V2 should be null: " + v2; - assert v3 == null : "V3 should be null: " + v3; - } - - /** - * Event listener. - */ - private class CacheEventListener implements IgnitePredicate<IgniteEvent> { - /** Wait latch. */ - private CountDownLatch latch; - - /** - * @param latch Wait latch. - */ - CacheEventListener(CountDownLatch latch) { - this.latch = latch; - } - - /** - * @param latch New latch. - */ - void setLatch(CountDownLatch latch) { - this.latch = latch; - } - - /** {@inheritDoc} */ - @Override public boolean apply(IgniteEvent evt) { - assert evt.type() == EVT_CACHE_OBJECT_PUT || evt.type() == EVT_CACHE_OBJECT_REMOVED : - "Unexpected event type: " + evt; - - info("Grid cache event: " + evt); - - latch.countDown(); - - return true; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b89b472d/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheClientModesAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheClientModesAbstractSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheClientModesAbstractSelfTest.java deleted file mode 100644 index 86a7c8e..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheClientModesAbstractSelfTest.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * 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.gridgain.grid.kernal.processors.cache.distributed; - -import org.apache.ignite.*; -import org.apache.ignite.cache.*; -import org.apache.ignite.cache.affinity.consistenthash.*; -import org.apache.ignite.cache.store.*; -import org.gridgain.grid.kernal.processors.cache.*; -import org.apache.ignite.internal.util.typedef.*; - -import java.util.concurrent.atomic.*; - -import static org.apache.ignite.cache.GridCacheMode.*; -import static org.apache.ignite.cache.GridCacheDistributionMode.*; - -/** - * Tests near-only cache. - */ -public abstract class GridCacheClientModesAbstractSelfTest extends GridCacheAbstractSelfTest { - /** Grid cnt. */ - private static AtomicInteger gridCnt; - - /** Near-only cache grid name. */ - private static String nearOnlyGridName; - - /** {@inheritDoc} */ - @Override protected int gridCount() { - return 4; - } - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - gridCnt = new AtomicInteger(); - - super.beforeTestsStarted(); - } - - /** {@inheritDoc} */ - @Override protected CacheStore<?, ?> cacheStore() { - return null; - } - - /** {@inheritDoc} */ - @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception { - CacheConfiguration cfg = super.cacheConfiguration(gridName); - - if (gridCnt.getAndIncrement() == 0) { - cfg.setDistributionMode(clientOnly() ? CLIENT_ONLY : NEAR_ONLY); - - nearOnlyGridName = gridName; - } - - cfg.setCacheStoreFactory(null); - cfg.setReadThrough(false); - cfg.setWriteThrough(false); - cfg.setAffinity(new GridCacheConsistentHashAffinityFunction(false, 32)); - cfg.setBackups(1); - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - super.afterTestsStopped(); - - gridCnt.set(0); - } - - /** {@inheritDoc} */ - @Override protected GridCacheMode cacheMode() { - return PARTITIONED; - } - - /** - * @return If {@code true} then uses CLIENT_ONLY mode, otherwise NEAR_ONLY. - */ - protected abstract boolean clientOnly(); - - /** - * @throws Exception If failed. - */ - public void testPutFromClientNode() throws Exception { - GridCache<Object, Object> nearOnly = nearOnlyCache(); - - for (int i = 0; i < 5; i++) - nearOnly.put(i, i); - - nearOnly.putAll(F.asMap(5, 5, 6, 6, 7, 7, 8, 8, 9, 9)); - - for (int key = 0; key < 10; key++) { - for (int i = 1; i < gridCount(); i++) { - if (grid(i).cache(null).affinity().isPrimaryOrBackup(grid(i).localNode(), key)) - assertEquals(key, grid(i).cache(null).peek(key)); - } - - if (nearEnabled()) - assertEquals(key, nearOnly.peek(key)); - - assertNull(nearOnly.peek(key, F.asList(GridCachePeekMode.PARTITIONED_ONLY))); - } - } - - /** - * @throws Exception If failed. - */ - public void testGetFromClientNode() throws Exception { - GridCache<Object, Object> dht = dhtCache(); - - for (int i = 0; i < 10; i++) - dht.put(i, i); - - GridCache<Object, Object> nearOnly = nearOnlyCache(); - - assert dht != nearOnly; - - for (int key = 0; key < 10; key++) { - // At start near only cache does not have any values. - if (nearEnabled()) - assertNull(nearOnly.peek(key)); - - // Get should succeed. - assertEquals(key, nearOnly.get(key)); - - // Now value should be cached. - if (nearEnabled()) - assertEquals(key, nearOnly.peek(key)); - } - } - - /** - * @throws Exception If failed. - */ - public void testNearOnlyAffinity() throws Exception { - for (int i = 0; i < gridCount(); i++) { - Ignite g = grid(i); - - if (F.eq(g.name(), nearOnlyGridName)) { - for (int k = 0; k < 10000; k++) { - GridCache<Object, Object> cache = g.cache(null); - - String key = "key" + k; - - if (cacheMode() == PARTITIONED) - assertFalse(cache.entry(key).primary() || cache.entry(key).backup()); - - assertFalse(cache.affinity().mapKeyToPrimaryAndBackups(key).contains(g.cluster().localNode())); - } - } - else { - boolean foundEntry = false; - boolean foundAffinityNode = false; - - for (int k = 0; k < 10000; k++) { - GridCache<Object, Object> cache = g.cache(null); - - String key = "key" + k; - - if (cache.entry(key).primary() || cache.entry(key).backup()) - foundEntry = true; - - if (cache.affinity().mapKeyToPrimaryAndBackups(key).contains(g.cluster().localNode())) - foundAffinityNode = true; - } - - assertTrue("Did not found primary or backup entry for grid: " + i, foundEntry); - assertTrue("Did not found affinity node for grid: " + i, foundAffinityNode); - } - } - } - - /** - * @return Near only cache for this test. - */ - protected GridCache<Object, Object> nearOnlyCache() { - assert nearOnlyGridName != null; - - return G.ignite(nearOnlyGridName).cache(null); - } - - /** - * @return DHT cache for this test. - */ - protected GridCache<Object, Object> dhtCache() { - for (int i = 0; i < gridCount(); i++) { - if (!nearOnlyGridName.equals(grid(i).name())) - return grid(i).cache(null); - } - - assert false : "Cannot find DHT cache for this test."; - - return null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b89b472d/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheEntrySetAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheEntrySetAbstractSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheEntrySetAbstractSelfTest.java deleted file mode 100644 index 3185724..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheEntrySetAbstractSelfTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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.gridgain.grid.kernal.processors.cache.distributed; - -import org.apache.ignite.cache.*; -import org.apache.ignite.transactions.*; -import org.gridgain.grid.kernal.processors.cache.*; -import org.gridgain.testframework.*; - -import java.util.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; - -import static org.apache.ignite.cache.GridCacheAtomicityMode.*; -import static org.apache.ignite.transactions.IgniteTxConcurrency.*; -import static org.apache.ignite.transactions.IgniteTxIsolation.*; -import static org.apache.ignite.cache.GridCacheWriteSynchronizationMode.*; - -/** - * - */ -public abstract class GridCacheEntrySetAbstractSelfTest extends GridCacheAbstractSelfTest { - /** */ - private static final int GRID_CNT = 2; - - /** */ - private static final String TX_KEY = "txKey"; - - /** {@inheritDoc} */ - @Override protected int gridCount() { - return GRID_CNT; - } - - /** {@inheritDoc} */ - @Override protected GridCacheWriteSynchronizationMode writeSynchronization() { - return FULL_SYNC; - } - - /** {@inheritDoc} */ - @Override protected GridCacheAtomicityMode atomicityMode() { - return TRANSACTIONAL; - } - - /** - * @throws Exception If failed. - */ - public void testEntrySet() throws Exception { - for (int i = 0; i < 10; i++) { - log.info("Iteration: " + i); - - final AtomicInteger cacheIdx = new AtomicInteger(0); - - GridTestUtils.runMultiThreaded(new Callable<Void>() { - @Override public Void call() throws Exception { - int idx = cacheIdx.getAndIncrement(); - - log.info("Use cache " + idx); - - GridCache<Object, Object> cache = grid(idx).cache(null); - - for (int i = 0; i < 100; i++) - putAndCheckEntrySet(cache); - - return null; - } - }, GRID_CNT, "test"); - - for (int j = 0; j < gridCount(); j++) - cache(j).removeAll(); - } - } - - /** - * @param cache Cache. - * @throws Exception If failed. - */ - private void putAndCheckEntrySet(GridCache<Object, Object> cache) throws Exception { - try (IgniteTx tx = cache.txStart(PESSIMISTIC, REPEATABLE_READ)) { - Integer total = (Integer) cache.get(TX_KEY); - - if (total == null) - total = 0; - - int cntr = 0; - - Set<GridCacheEntry<Object, Object>> entries = cache.entrySet(); - - for (GridCacheEntry e : entries) { - if (e.getKey() instanceof Integer) - cntr++; - } - - assertEquals(total, (Integer)cntr); - - cache.putx(cntr + 1, cntr + 1); - - cache.putx(TX_KEY, cntr + 1); - - tx.commit(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b89b472d/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheEntrySetIterationPreloadingSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheEntrySetIterationPreloadingSelfTest.java b/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheEntrySetIterationPreloadingSelfTest.java deleted file mode 100644 index e264b12..0000000 --- a/modules/core/src/test/java/org/gridgain/grid/kernal/processors/cache/distributed/GridCacheEntrySetIterationPreloadingSelfTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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.gridgain.grid.kernal.processors.cache.distributed; - -import org.apache.ignite.cache.*; -import org.apache.ignite.cache.*; -import org.gridgain.grid.kernal.processors.cache.*; - -import java.util.*; - -/** - * Tests entry wrappers after preloading happened. - */ -public class GridCacheEntrySetIterationPreloadingSelfTest extends GridCacheAbstractSelfTest { - /** {@inheritDoc} */ - @Override protected int gridCount() { - return 1; - } - - /** {@inheritDoc} */ - @Override protected GridCacheMode cacheMode() { - return GridCacheMode.PARTITIONED; - } - - /** {@inheritDoc} */ - @Override protected GridCacheDistributionMode distributionMode() { - return GridCacheDistributionMode.PARTITIONED_ONLY; - } - - /** {@inheritDoc} */ - @Override protected GridCacheAtomicityMode atomicityMode() { - return GridCacheAtomicityMode.ATOMIC; - } - - @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception { - CacheConfiguration ccfg = super.cacheConfiguration(gridName); - - ccfg.setPreloadMode(GridCachePreloadMode.SYNC); - - return ccfg; - } - - /** - * @throws Exception If failed. - */ - public void testIteration() throws Exception { - try { - final GridCache<String, Integer> cache = cache(); - - final int entryCnt = 1000; - - for (int i = 0; i < entryCnt; i++) - cache.put(String.valueOf(i), i); - - Collection<GridCacheEntry<String, Integer>> entries = new ArrayList<>(10_000); - - for (int i = 0; i < 10_000; i++) - entries.add(cache.randomEntry()); - - startGrid(1); - startGrid(2); - startGrid(3); - - for (GridCacheEntry<String, Integer> entry : entries) - entry.partition(); - - for (int i = 0; i < entryCnt; i++) - cache.remove(String.valueOf(i)); - } - finally { - stopGrid(3); - stopGrid(2); - stopGrid(1); - } - } -}