Java Code Examples for org.apache.ignite.Ignite#createNearCache()
The following examples show how to use
org.apache.ignite.Ignite#createNearCache() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GridCacheClearLocallySelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * Startup routine. * * @throws Exception If failed. */ private void startUp() throws Exception { cachesLoc = (IgniteCache<Integer, Integer>[])Array.newInstance(IgniteCache.class, GRID_CNT); cachesPartitioned = (IgniteCache<Integer, Integer>[])Array.newInstance(IgniteCache.class, GRID_CNT); cachesColocated = (IgniteCache<Integer, Integer>[])Array.newInstance(IgniteCache.class, GRID_CNT); cachesReplicated = (IgniteCache<Integer, Integer>[])Array.newInstance(IgniteCache.class, GRID_CNT); for (int i = 0; i < GRID_CNT; i++) { Ignite ignite = startGrid(i); if (i == 1) { NearCacheConfiguration nearCfg = new NearCacheConfiguration(); ignite.createNearCache(CACHE_PARTITIONED, nearCfg); } if (i == 2) ignite.cache(CACHE_PARTITIONED); cachesLoc[i] = ignite.cache(CACHE_LOCAL); cachesPartitioned[i] = ignite.cache(CACHE_PARTITIONED); cachesColocated[i] = ignite.cache(CACHE_COLOCATED); cachesReplicated[i] = ignite.cache(CACHE_REPLICATED); } }
Example 2
Source File: GridCacheNearOnlyTopologySelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** @throws Exception If failed. */ private void checkStartupNearNode(int nearNodeIdx, int totalNodeCnt) throws Exception { try { cache = true; for (int i = 0; i < totalNodeCnt; i++) { boolean client = nearNodeIdx == i; Ignite ignite = client ? startClientGrid(i) : startGrid(i); if (client) ignite.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration()); } } finally { stopAllGrids(); } }
Example 3
Source File: GridCacheNearOnlyTopologySelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** @throws Exception If failed. */ @Test public void testKeyMapping() throws Exception { try { cache = true; for (int i = 0; i < 4; i++) { boolean client = i == 0; Ignite ignite = client ? startClientGrid(i) : startGrid(i); if (client) ignite.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration()); } for (int i = 0; i < 100; i++) assertFalse("For key: " + i, grid(0).affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(grid(0).localNode(), i)); } finally { stopAllGrids(); } }
Example 4
Source File: TxPessimisticDeadlockDetectionTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param cacheMode Cache mode. * @param syncMode Write sync mode. * @param near Near. * @return Created cache. */ @SuppressWarnings("unchecked") private IgniteCache createCache(CacheMode cacheMode, CacheWriteSynchronizationMode syncMode, boolean near) throws IgniteInterruptedCheckedException, InterruptedException { awaitPartitionMapExchange(); int minorTopVer = grid(0).context().discovery().topologyVersionEx().minorTopologyVersion(); CacheConfiguration ccfg = defaultCacheConfiguration(); ccfg.setName(CACHE_NAME); ccfg.setCacheMode(cacheMode); ccfg.setBackups(1); ccfg.setNearConfiguration(near ? new NearCacheConfiguration() : null); ccfg.setWriteSynchronizationMode(syncMode); if (cacheMode == LOCAL) ccfg.setDataRegionName("dfltPlc"); IgniteCache cache = ignite(0).createCache(ccfg); if (near) { for (int i = 0; i < NODES_CNT; i++) { Ignite client = ignite(i + NODES_CNT); assertTrue(client.configuration().isClientMode()); client.createNearCache(ccfg.getName(), new NearCacheConfiguration<>()); } } waitForLateAffinityAssignment(minorTopVer); return cache; }
Example 5
Source File: TxRollbackAsyncTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @return Started client. * @throws Exception If f nodeailed. */ private Ignite startClient() throws Exception { Ignite client = startClientGrid("client"); assertTrue(client.configuration().isClientMode()); if (nearCacheEnabled()) client.createNearCache(CACHE_NAME, new NearCacheConfiguration<>()); else assertNotNull(client.cache(CACHE_NAME)); return client; }
Example 6
Source File: TxOptimisticDeadlockDetectionTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @param cacheMode Cache mode. * @param syncMode Write sync mode. * @param near Near. * @return Created cache. */ @SuppressWarnings("unchecked") private IgniteCache createCache(CacheMode cacheMode, CacheWriteSynchronizationMode syncMode, boolean near) throws IgniteInterruptedCheckedException, InterruptedException { awaitPartitionMapExchange(); int minorTopVer = grid(0).context().discovery().topologyVersionEx().minorTopologyVersion(); CacheConfiguration ccfg = defaultCacheConfiguration(); ccfg.setName(CACHE_NAME); ccfg.setCacheMode(cacheMode); ccfg.setBackups(1); ccfg.setNearConfiguration(near ? new NearCacheConfiguration() : null); ccfg.setWriteSynchronizationMode(syncMode); IgniteCache cache = ignite(0).createCache(ccfg); if (near) { for (int i = 0; i < NODES_CNT; i++) { Ignite client = ignite(i + NODES_CNT); assertTrue(client.configuration().isClientMode()); client.createNearCache(ccfg.getName(), new NearCacheConfiguration<>()); } } waitForLateAffinityAssignment(minorTopVer); return cache; }
Example 7
Source File: TxRollbackOnTimeoutTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @throws Exception If f nodeailed. * @return Started client. */ private Ignite startClient() throws Exception { Ignite client = startClientGrid("client"); assertTrue(client.configuration().isClientMode()); if (nearCacheEnabled()) client.createNearCache(CACHE_NAME, new NearCacheConfiguration<>()); else assertNotNull(client.cache(CACHE_NAME)); return client; }
Example 8
Source File: IgniteCacheTxRecoveryRollbackTest.java From ignite with Apache License 2.0 | 4 votes |
/** * Stop both tx near node (client2) and primary node, near cache tx on client1 is invalidated. * * @param concurrency Tx concurrency or {@code null} for implicit transaction. * @throws Exception If failed. */ private void nearTx2(final TransactionConcurrency concurrency) throws Exception { startGrids(4); Ignite srv0 = grid(0); srv0.createCache(cacheConfiguration(2, false, false)); awaitPartitionMapExchange(); final Ignite client1 = startClientGrid(4); final Ignite client2 = startClientGrid(5); final Integer key = primaryKey(srv0.cache(DEFAULT_CACHE_NAME)); final IgniteCache<Integer, Integer> cache1 = client1.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<Integer, Integer>()); final IgniteCache<Integer, Integer> cache2 = client2.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<Integer, Integer>()); cache1.put(key, 1); final Integer newVal = 2; testSpi(client2).blockMessages(GridNearTxFinishRequest.class, srv0.name()); testSpi(srv0).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() { @Override public boolean apply(ClusterNode node, Message msg) { return msg instanceof GridDhtTxFinishRequest; } }); IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() { @Override public Void call() throws Exception { log.info("Start put, concurrency: " + concurrency); if (concurrency != null) { try (Transaction tx = client2.transactions().txStart(concurrency, REPEATABLE_READ)) { cache2.put(key, newVal); tx.commit(); } } else cache2.put(key, newVal); return null; } }); U.sleep(500); assertFalse(fut.isDone()); testSpi(client2).waitForBlocked(GridNearTxFinishRequest.class, srv0.name()); stopGrid(client2.name()); stopGrid(srv0.name()); try { fut.get(); } catch (IgniteCheckedException ignore) { // No-op. } final IgniteCache<Integer, Integer> srvCache = grid(1).cache(DEFAULT_CACHE_NAME); GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { return newVal.equals(srvCache.get(key)) && newVal.equals(cache1.get(key)); } }, 5000); checkData(F.asMap(key, newVal)); }
Example 9
Source File: IgniteCacheTxRecoveryRollbackTest.java From ignite with Apache License 2.0 | 4 votes |
/** * Stop tx near node (client2), near cache tx on client1 is either committed * by primary or invalidated. * * @param concurrency Tx concurrency or {@code null} for implicit transaction. * @throws Exception If failed. */ private void nearTx1(final TransactionConcurrency concurrency) throws Exception { startGrids(4); Ignite srv0 = grid(0); final IgniteCache<Integer, Integer> srvCache = srv0.createCache(cacheConfiguration(2, false, false)); awaitPartitionMapExchange(); final Ignite client1 = startClientGrid(4); final Ignite client2 = startClientGrid(5); final Integer key = primaryKey(srv0.cache(DEFAULT_CACHE_NAME)); final IgniteCache<Integer, Integer> cache1 = client1.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<Integer, Integer>()); final IgniteCache<Integer, Integer> cache2 = client2.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<Integer, Integer>()); cache1.put(key, 1); final Integer newVal = 2; testSpi(client2).blockMessages(GridNearTxFinishRequest.class, srv0.name()); IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() { @Override public Void call() throws Exception { log.info("Start put, concurrency: " + concurrency); if (concurrency != null) { try (Transaction tx = client2.transactions().txStart(concurrency, REPEATABLE_READ)) { cache2.put(key, newVal); tx.commit(); } } else cache2.put(key, newVal); return null; } }); U.sleep(500); assertFalse(fut.isDone()); testSpi(client2).waitForBlocked(GridNearTxFinishRequest.class, srv0.name()); stopGrid(client2.name()); try { fut.get(); } catch (IgniteCheckedException ignore) { // No-op. } GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { return newVal.equals(srvCache.get(key)) && newVal.equals(cache1.get(key)); } }, 5000); checkData(F.asMap(key, newVal)); }
Example 10
Source File: IgniteCacheGroupsTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @param cacheMode Cache mode. * @param atomicityMode Atomicity mode. * @param backups Number of backups. * @param heapCache On heap cache flag. * @param nearSrv {@code True} if near cache should be used on a server side. * @param nearClient {@code True} if near cache should be used on a client side. * @throws Exception If failed. */ private void cacheApiTest(CacheMode cacheMode, CacheAtomicityMode atomicityMode, int backups, boolean heapCache, boolean nearSrv, boolean nearClient) throws Exception { Ignite srv0 = ignite(0); NearCacheConfiguration nearCfg = nearSrv ? new NearCacheConfiguration() : null; srv0.createCache(cacheConfiguration(GROUP1, "cache-0", cacheMode, atomicityMode, backups, heapCache) .setNearConfiguration(nearCfg)); srv0.createCache(cacheConfiguration(GROUP1, "cache-1", cacheMode, atomicityMode, backups, heapCache)); srv0.createCache(cacheConfiguration(GROUP2, "cache-2", cacheMode, atomicityMode, backups, heapCache) .setNearConfiguration(nearCfg)); srv0.createCache(cacheConfiguration(null, "cache-3", cacheMode, atomicityMode, backups, heapCache)); if (nearClient) { Ignite clientNode = ignite(4); clientNode.createNearCache("cache-0", new NearCacheConfiguration()); clientNode.createNearCache("cache-2", new NearCacheConfiguration()); } try { for (final Ignite node : Ignition.allGrids()) { List<Callable<?>> ops = new ArrayList<>(); for (int i = 0; i < 4; i++) ops.add(testSet(node.cache("cache-" + i), cacheMode, atomicityMode, backups, heapCache, node)); // Async operations. GridTestUtils.runMultiThreaded(ops, "cacheApiTest"); } } finally { for (int i = 0; i < 4; i++) srv0.destroyCache("cache-" + i); } }
Example 11
Source File: CacheSerializableTransactionsTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @throws Exception If failed. */ @Test public void testNearCacheReaderUpdate() throws Exception { Ignite ignite0 = ignite(0); IgniteCache<Integer, Integer> cache0 = ignite0.createCache(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, false)); final String cacheName = cache0.getName(); try { Ignite client1 = ignite(SRVS); Ignite client2 = ignite(SRVS + 1); IgniteCache<Integer, Integer> cache1 = client1.createNearCache(cacheName, new NearCacheConfiguration<Integer, Integer>()); IgniteCache<Integer, Integer> cache2 = client2.createNearCache(cacheName, new NearCacheConfiguration<Integer, Integer>()); Integer key = primaryKey(ignite(0).cache(cacheName)); try (Transaction tx = client1.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) { assertNull(cache1.get(key)); cache1.put(key, 1); tx.commit(); } try (Transaction tx = client2.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) { assertEquals(1, (Object)cache2.get(key)); cache2.put(key, 2); tx.commit(); } try (Transaction tx = client1.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) { assertEquals(2, (Object)cache1.get(key)); cache1.put(key, 3); tx.commit(); } } finally { destroyCache(cacheName); } }
Example 12
Source File: GridCacheClearSelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @param cacheMode Cache mode. * @param near Near cache flag. * @param keys Keys to clear. * @throws Exception If failed. */ private void testClear(CacheMode cacheMode, boolean near, @Nullable Set<Integer> keys) throws Exception { Ignite client1 = client1(); Ignite client2 = client2(); final String cacheName = DEFAULT_CACHE_NAME; try { CacheConfiguration<Integer, Integer> cfg = new CacheConfiguration<>(cacheName); cfg.setCacheMode(cacheMode); IgniteCache<Integer, Integer> cache1 = near ? client1.createCache(cfg, new NearCacheConfiguration<Integer, Integer>()) : client1.createCache(cfg); IgniteCache<Integer, Integer> cache2 = near ? client2.createNearCache(cacheName, new NearCacheConfiguration<Integer, Integer>()) : client2.<Integer, Integer>cache(cacheName); GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { return ignite(0).cluster().forCacheNodes(cacheName).nodes().size() == 5; } }, 5000); for (int i = 0; i < 10; i++) cache1.put(i, i); for (int i = 0; i < 10; i++) cache2.get(i); assertEquals(10, cache1.size(CachePeekMode.PRIMARY)); assertEquals(10, cache2.size(CachePeekMode.PRIMARY)); assertEquals(near ? 10 : 0, cache1.localSize(CachePeekMode.NEAR)); assertEquals(near ? 10 : 0, cache2.localSize(CachePeekMode.NEAR)); if (F.isEmpty(keys)) cache1.clear(); else if (keys.size() == 1) cache1.clear(F.first(keys)); else cache1.clearAll(keys); int expSize = F.isEmpty(keys) ? 0 : 10 - keys.size(); assertEquals(expSize, cache1.size(CachePeekMode.PRIMARY)); assertEquals(expSize, cache2.size(CachePeekMode.PRIMARY)); assertEquals(near ? expSize : 0, cache1.localSize(CachePeekMode.NEAR)); assertEquals(near ? expSize : 0, cache2.localSize(CachePeekMode.NEAR)); } finally { client1.destroyCache(cacheName); } }
Example 13
Source File: CacheGetInsideLockChangingTopologyTest.java From ignite with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { super.beforeTestsStarted(); startGridsMultiThreaded(SRVS); Ignite client1 = startClientGrid(SRVS); assertTrue(client1.configuration().isClientMode()); Ignite client2 = startClientGrid(SRVS + 1); assertTrue(client2.configuration().isClientMode()); client2.createNearCache(TX_CACHE1, new NearCacheConfiguration<>().setNearEvictionPolicy(new GridCacheAlwaysEvictionPolicy<>())); client2.createNearCache(TX_CACHE2, new NearCacheConfiguration<>().setNearEvictionPolicy(new GridCacheAlwaysEvictionPolicy<>())); client2.createNearCache(ATOMIC_CACHE, new NearCacheConfiguration<>().setNearEvictionPolicy(new GridCacheAlwaysEvictionPolicy<>())); }
Example 14
Source File: GridCacheNearOnlyTopologySelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** @throws Exception If failed. */ @Test public void testNodeLeave() throws Exception { try { cache = true; for (int i = 0; i < 2; i++) { boolean client = i == 0; Ignite ignite = client ? startClientGrid(i) : startGrid(i); if (client) ignite.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<>()); } awaitPartitionMapExchange(); for (int i = 0; i < 10; i++) grid(1).cache(DEFAULT_CACHE_NAME).put(i, i); final Ignite igniteNearOnly = grid(0); final IgniteCache<Object, Object> nearOnly = igniteNearOnly.cache(DEFAULT_CACHE_NAME); // Populate near cache. for (int i = 0; i < 10; i++) { assertEquals(i, nearOnly.get(i)); assertEquals(i, nearOnly.localPeek(i, CachePeekMode.ONHEAP)); } // Stop the only dht node. stopGrid(1); for (int i = 0; i < 10; i++) { assertNull(nearOnly.localPeek(i, CachePeekMode.ONHEAP)); final int key = i; GridTestUtils.assertThrowsWithCause(new Callable<Object>() { @Override public Object call() throws Exception { return nearOnly.get(key); } }, ClusterTopologyCheckedException.class); } // Test optimistic transaction. GridTestUtils.assertThrowsWithCause(new Callable<Object>() { @Override public Object call() throws Exception { try (Transaction tx = igniteNearOnly.transactions().txStart(OPTIMISTIC, REPEATABLE_READ)) { nearOnly.put("key", "val"); tx.commit(); } return null; } }, ClusterTopologyCheckedException.class); // Test pessimistic transaction. GridTestUtils.assertThrowsWithCause(new Callable<Object>() { @Override public Object call() throws Exception { try (Transaction tx = igniteNearOnly.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { nearOnly.put("key", "val"); tx.commit(); } return null; } }, ClusterTopologyCheckedException.class); } finally { stopAllGrids(); } }
Example 15
Source File: CacheStoreUsageMultinodeDynamicStartAbstractTest.java From ignite with Apache License 2.0 | 3 votes |
/** * @param clientStart {@code True} if start cache from client node. * @throws Exception If failed. */ private void checkStoreWithDynamicStart(boolean clientStart) throws Exception { cacheStore = true; CacheConfiguration ccfg = cacheConfiguration(); assertNotNull(ccfg.getCacheStoreFactory()); Ignite srv = ignite(0); Ignite client = ignite(3); Ignite node = clientStart ? client : srv; IgniteCache cache = nearCache ? node.createCache(ccfg, new NearCacheConfiguration()) : node.createCache(ccfg); assertNotNull(cache); try { if (nearCache) client.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<>()); checkStoreUpdate(true); } finally { cache = srv.cache(DEFAULT_CACHE_NAME); if (cache != null) cache.destroy(); } }
Example 16
Source File: NearCachePutAllMultinodeTest.java From ignite with Apache License 2.0 | 3 votes |
/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { startGridsMultiThreaded(GRID_CNT - 2); Ignite grid = startClientGrid(GRID_CNT - 2); grid.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration()); grid = startClientGrid(GRID_CNT - 1); grid.cache(DEFAULT_CACHE_NAME); }
Example 17
Source File: CacheFutureExceptionSelfTest.java From ignite with Apache License 2.0 | 2 votes |
/** * @param nearCache If {@code true} creates near cache on client. * @param cpyOnRead Cache copy on read flag. * @throws Exception If failed. */ private void testGet(boolean nearCache, boolean cpyOnRead) throws Exception { if (MvccFeatureChecker.forcedMvcc()) { if (!MvccFeatureChecker.isSupported(MvccFeatureChecker.Feature.NEAR_CACHE)) return; } fail = false; Ignite srv = grid(0); Ignite client = grid(1); final String cacheName = nearCache ? ("NEAR-CACHE-" + cpyOnRead) : ("CACHE-" + cpyOnRead); CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME); ccfg.setCopyOnRead(cpyOnRead); ccfg.setName(cacheName); IgniteCache<Object, Object> cache = srv.createCache(ccfg); cache.put("key", new NotSerializableClass()); IgniteCache<Object, Object> clientCache = nearCache ? client.createNearCache(cacheName, new NearCacheConfiguration<>()) : client.cache(cacheName); fail = true; final CountDownLatch futLatch = new CountDownLatch(1); clientCache.getAsync("key").listen(new IgniteInClosure<IgniteFuture<Object>>() { @Override public void apply(IgniteFuture<Object> fut) { assertTrue(fut.isDone()); try { fut.get(); fail(); } catch (CacheException e) { log.info("Expected error: " + e); futLatch.countDown(); } } }); assertTrue(futLatch.await(5, SECONDS)); srv.destroyCache(cache.getName()); }
Example 18
Source File: GridCacheNearClientHitTest.java From ignite with Apache License 2.0 | 2 votes |
/** * @throws Exception If failed. */ @Test public void testLocalPeekAfterPrimaryNodeLeft() throws Exception { try { Ignite crd = startGrid("coordinator", getConfiguration("coordinator")); Ignite client = startClientGrid("client", getConfiguration("client")); Ignite srvNode = startGrid("server", getConfiguration("server")); awaitPartitionMapExchange(); IgniteCache<Object, Object> cache = srvNode.getOrCreateCache(cacheConfiguration()); IgniteCache<Object, Object> nearCache = client.createNearCache(CACHE_NAME, nearCacheConfiguration()); UUID serverNodeId = srvNode.cluster().localNode().id(); int remoteKey = 0; for (; ; remoteKey++) { if (crd.affinity(CACHE_NAME).mapKeyToNode(remoteKey).id().equals(serverNodeId)) break; } cache.put(remoteKey, remoteKey); Object value = nearCache.localPeek(remoteKey, NEAR); assertNull("The value should not be loaded from a remote node.", value); nearCache.get(remoteKey); value = nearCache.localPeek(remoteKey, NEAR); assertNotNull("The returned value should not be null.", value); srvNode.close(); awaitPartitionMapExchange(); value = nearCache.localPeek(remoteKey, NEAR); assertNull("The value should not be loaded from a remote node.", value); value = nearCache.get(remoteKey); assertNotNull("The value should be loaded from a remote node.", value); value = nearCache.localPeek(remoteKey, NEAR); assertNotNull("The returned value should not be null.", value); } finally { stopAllGrids(); } }
Example 19
Source File: IgniteOnePhaseCommitNearReadersTest.java From ignite with Apache License 2.0 | 2 votes |
/** * @param backups Backups number. * @throws Exception If failed. */ private void putReaderUpdatePrimaryFails(int backups) throws Exception { testSpi = true; final int SRVS = 3; startGrids(SRVS); awaitPartitionMapExchange(); Ignite srv = ignite(0); srv.createCache(cacheConfiguration(backups)); Ignite client1 = startClientGrid(SRVS); IgniteCache<Object, Object> cache1 = client1.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<>()); Ignite client2 = startClientGrid(SRVS + 1); IgniteCache<Object, Object> cache2 = client2.cache(DEFAULT_CACHE_NAME); Integer key = primaryKey(srv.cache(DEFAULT_CACHE_NAME)); cache1.put(key, 1); spi(srv).blockMessages(GridNearTxPrepareResponse.class, client2.name()); IgniteFuture<?> fut = cache2.putAsync(key, 2); U.sleep(1000); assertFalse(fut.isDone()); stopGrid(0); fut.get(); checkCacheData(F.asMap(key, backups == 0 ? null : 2), DEFAULT_CACHE_NAME); for (TransactionConcurrency concurrency : TransactionConcurrency.values()) { for (TransactionIsolation isolation : TransactionIsolation.values()) { srv = startGrid(0); awaitPartitionMapExchange(true, true, null); key = primaryKey(srv.cache(DEFAULT_CACHE_NAME)); cache1.put(key, 1); spi(srv).blockMessages(GridNearTxPrepareResponse.class, client2.name()); try (Transaction tx = client2.transactions().txStart(concurrency, isolation)) { cache2.putAsync(key, 2); fut = tx.commitAsync(); U.sleep(1000); assertFalse(fut.isDone()); stopGrid(0); if (backups == 0) fut.get(); else { try { fut.get(); fail(); } catch (TransactionRollbackException ignore) { // Expected. } } } checkCacheData(F.asMap(key, backups == 0 ? null : 1), DEFAULT_CACHE_NAME); try (Transaction tx = client2.transactions().txStart(concurrency, isolation)) { cache2.putAsync(key, 2); tx.commit(); } checkCacheData(F.asMap(key, 2), DEFAULT_CACHE_NAME); } } }
Example 20
Source File: IgniteOnePhaseCommitNearReadersTest.java From ignite with Apache License 2.0 | 2 votes |
/** * @param backups Backups number. * @throws Exception If failed. */ private void putReadersUpdate(int backups) throws Exception { final int SRVS = 3; startGrids(SRVS); awaitPartitionMapExchange(); Ignite srv = ignite(0); srv.createCache(cacheConfiguration(backups)); Ignite client1 = startClientGrid(SRVS); IgniteCache<Object, Object> cache1 = client1.createNearCache(DEFAULT_CACHE_NAME, new NearCacheConfiguration<>()); Integer key = primaryKey(srv.cache(DEFAULT_CACHE_NAME)); Ignite client2 = startClientGrid(SRVS + 1); IgniteCache<Object, Object> cache2 = client2.cache(DEFAULT_CACHE_NAME); cache1.put(key, 1); cache2.put(key, 2); checkCacheData(F.asMap(key, 2), DEFAULT_CACHE_NAME); int val = 10; for (TransactionConcurrency concurrency : TransactionConcurrency.values()) { for (TransactionIsolation isolation : TransactionIsolation.values()) { try (Transaction tx = client2.transactions().txStart(concurrency, isolation)) { cache2.put(key, val); tx.commit(); } checkCacheData(F.asMap(key, val), DEFAULT_CACHE_NAME); val++; } } }