/** @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(); } }
/** @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; }