/** * @param concurrency Concurrency. * @param isolation Isolation. * @throws GridException If test failed. */ private void checkTransactionTimeout( GridCacheTxConcurrency concurrency, GridCacheTxIsolation isolation) throws Exception { boolean wasEx = false; GridCacheTx tx = null; try { GridCache<Integer, String> cache = grid.cache(null); tx = cache.txStart(concurrency, isolation, 50, 0); cache.put(1, "1"); Thread.sleep(100); cache.put(1, "2"); tx.commit(); } catch (GridCacheTxOptimisticException e) { info("Received expected optimistic exception: " + e.getMessage()); wasEx = true; tx.rollback(); } catch (GridCacheTxTimeoutException e) { info("Received expected timeout exception: " + e.getMessage()); wasEx = true; tx.rollback(); } assert wasEx; }
/** * Populates cache with test data. * * @param cache Cache. * @throws GridException In case of error. */ private static void populate(GridCache<Object, Object> cache) throws GridException { cache.put("o1", new Organization(1, "GridGain")); cache.put("o2", new Organization(2, "Other")); // Persons are collocated with their organizations to support joins. cache.put(new GridCacheAffinityKey<String>("p1", "o1"), new Person(1, "John White", 25, 1)); cache.put(new GridCacheAffinityKey<String>("p2", "o1"), new Person(2, "Joe Black", 35, 1)); cache.put(new GridCacheAffinityKey<String>("p3", "o2"), new Person(3, "Mike Green", 40, 2)); }
/** @throws Exception If failed. */ public void testInvalidateFlag() throws Exception { GridEx g0 = grid(0); GridCache<String, String> cache = g0.cache(PARTITIONED_CACHE_NAME); String key = null; for (int i = 0; i < 10_000; i++) { if (!cache.affinity().isPrimaryOrBackup(g0.localNode(), String.valueOf(i))) { key = String.valueOf(i); break; } } assertNotNull(key); cache.put(key, key); // Create entry in near cache, it is invalidated if INVALIDATE flag is set. assertNotNull(cache.peek(key)); GridClientData d = client.data(PARTITIONED_CACHE_NAME); d.flagsOn(GridClientCacheFlag.INVALIDATE).put(key, "zzz"); for (Grid g : G.allGrids()) { cache = g.cache(PARTITIONED_CACHE_NAME); if (cache.affinity().isPrimaryOrBackup(g.localNode(), key)) assertEquals("zzz", cache.peek(key)); else assertNull(cache.peek(key)); } }