/** * Checks that gets work for implicit txs. * * @param cache Cache to test. * @throws Exception If failed. */ private void checkExplicitTx(Ignite ignite, IgniteCache<String, String> cache) throws Exception { IgniteCache<String, String> asyncCache = cache.withAsync(); Transaction tx = ignite.transactions().txStart(); try { assertNull(cache.get("key1")); tx.commit(); } finally { tx.close(); } tx = ignite.transactions().txStart(); try { asyncCache.get("key2"); assertNull(asyncCache.future().get()); tx.commit(); } finally { tx.close(); } tx = ignite.transactions().txStart(); try { assertTrue(cache.getAll(F.asSet("key3", "key4")).isEmpty()); tx.commit(); } finally { tx.close(); } tx = ignite.transactions().txStart(); try { asyncCache.getAll(F.asSet("key5", "key6")); assertTrue(((Map) asyncCache.future().get()).isEmpty()); tx.commit(); } finally { tx.close(); } tx = ignite.transactions().txStart(); try { cache.put("key7", "key7"); cache.remove("key7"); assertNull(cache.get("key7")); tx.commit(); } finally { tx.close(); } checkEmpty(cache); }
/** * Checks that gets work for implicit txs. * * @param cache Cache to test. * @throws Exception If failed. */ private void checkImplicitTx(IgniteCache<String, String> cache) throws Exception { assertNull(cache.get("key1")); IgniteCache<String, String> asyncCache = cache.withAsync(); asyncCache.get("key2"); assertNull(asyncCache.future().get()); assertTrue(cache.getAll(F.asSet("key3", "key4")).isEmpty()); asyncCache.getAll(F.asSet("key5", "key6")); assertTrue(((Map) asyncCache.future().get()).isEmpty()); cache.put("key7", "key7"); cache.remove("key7", "key7"); assertNull(cache.get("key7")); checkEmpty(cache); }
/** {@inheritDoc} */ @Override public void testRemoteNodes() throws Exception { int size = remoteNodeIds().size(); String name = "oneMoreGrid"; try { Ignite g = startGrid(name); UUID joinedId = g.cluster().localNode().id(); assert projection().forRemotes().nodes().size() == size + 1; assert F.nodeIds(projection().forRemotes().nodes()).contains(joinedId); } finally { stopGrid(name); } }
/** @throws Exception If failed. */ public void testGroupIndexOperations() throws Exception { IgniteCache<Integer, GroupIndexTestValue> c = ignite(0) .getOrCreateCache(cacheConfig("grp", false, Integer.class, GroupIndexTestValue.class)); try { // Check group index usage. String qry = "select 1 from GroupIndexTestValue "; String plan = columnQuery(c, "explain " + qry + "where a = 1 and b > 0").get(0).toString(); info("Plan: " + plan); assertTrue(plan.contains("grpIdx")); // Sorted list List<GroupIndexTestValue> list = F.asList( new GroupIndexTestValue(0, 0), new GroupIndexTestValue(0, 5), new GroupIndexTestValue(1, 1), new GroupIndexTestValue(1, 3), new GroupIndexTestValue(2, -1), new GroupIndexTestValue(2, 2)); // Fill cache. for (int i = 0; i < list.size(); i++) c.put(i, list.get(i)); // Check results. assertEquals(1, columnQuery(c, qry + "where a = 1 and b = 1").size()); assertEquals(2, columnQuery(c, qry + "where a = 1 and b < 4").size()); assertEquals(2, columnQuery(c, qry + "where a = 1 and b <= 3").size()); assertEquals(1, columnQuery(c, qry + "where a = 1 and b < 3").size()); assertEquals(2, columnQuery(c, qry + "where a = 1 and b > 0").size()); assertEquals(1, columnQuery(c, qry + "where a = 1 and b > 1").size()); assertEquals(2, columnQuery(c, qry + "where a = 1 and b >= 1").size()); assertEquals(4, columnQuery(c, qry + "where a > 0 and b > 0").size()); assertEquals(4, columnQuery(c, qry + "where a > 0 and b >= 1").size()); assertEquals(3, columnQuery(c, qry + "where a > 0 and b > 1").size()); } finally { c.destroy(); } }
/** {@inheritDoc} */ @Override protected Collection<UUID> remoteNodeIds() { return F.nodeIds(grid(0).cluster().forRemotes().nodes()); }
/** @throws Exception Thrown if test failed. */ public void testA() throws Exception { Collection<Integer> set = new GridConcurrentWeakHashSet<>(); Integer i = 1; assert set.add(i); assert !set.add(i); assert set.contains(i); assert set.size() == 1; Collection<Integer> c = F.asList(2, 3, 4, 5); assert set.addAll(c); assert !set.addAll(c); assert set.containsAll(c); assert set.size() == 1 + c.size(); assert set.remove(i); assert !set.remove(i); assert !set.contains(i); assert set.size() == c.size(); assert set.removeAll(c); assert !set.removeAll(c); assert !set.containsAll(c); assert set.isEmpty(); Collection<Integer> c1 = Arrays.asList(1, 3, 5, 7, 9); int cnt = 0; for (Iterator<Integer> iter = set.iterator(); iter.hasNext(); cnt++) c1.contains(iter.next()); assert set.size() == cnt; assert set.size() == set.toArray().length; assert set.addAll(c1); assert set.retainAll(c); assert !set.retainAll(c); Collection<Integer> c2 = F.retain(c1, true, c); assert set.containsAll(c2); assert !set.containsAll(c1); assert !set.containsAll(c); assert set.size() == c2.size(); set.clear(); assert set.isEmpty(); try { set.iterator().next(); assert false; } catch (NoSuchElementException ignored) { assert true; } try { set.add(null); assert false; } catch (NullPointerException ignored) { assert true; } }
/** @throws Exception Thrown if test failed. */ @SuppressWarnings({"UnusedAssignment"}) public void testB() throws Exception { Collection<SampleBean> set = new GridConcurrentWeakHashSet<>(); SampleBean bean1 = new SampleBean(1); assert set.add(bean1); assert !set.add(bean1); assert set.size() == 1; assert set.contains(bean1); bean1 = null; gc(); assert set.isEmpty(); Collection<SampleBean> c = F.asList(new SampleBean(1), new SampleBean(2), new SampleBean(3), new SampleBean(4)); assert set.addAll(c); assert !set.addAll(c); assert set.size() == c.size(); assert set.containsAll(c); c = null; gc(); assert set.isEmpty(); SampleBean b1 = new SampleBean(1); SampleBean b2 = new SampleBean(2); SampleBean b3 = new SampleBean(3); SampleBean b4 = new SampleBean(4); SampleBean b5 = new SampleBean(5); set.add(b1); set.add(b2); set.add(b3); set.add(b4); set.add(b5); Iterator iter = set.iterator(); assert iter.hasNext(); b2 = null; b3 = null; b4 = null; gc(); int cnt = 0; while (iter.hasNext()) { info(iter.next().toString()); cnt++; } assert set.size() == cnt; }