/** * @param useCollocatedData Use colocated data. * @return Key. */ public Object key(boolean useCollocatedData) { return useCollocatedData ? new AffinityKey<>(id, orgId) : id; }
assert new AffinityKey<>("p1", "o1").equals(row.get(0)); assert Person.class.getName().equals(row.get(1).getClass().getName()); assert "John White".equals(row.get(2)); assert new AffinityKey<>("p2", "o1").equals(row.get(0)); assert Person.class.getName().equals(row.get(1).getClass().getName()); assert "Joe Black".equals(row.get(2)); assert new AffinityKey<>("p3", "o2").equals(row.get(0)); assert Person.class.getName().equals(row.get(1).getClass().getName()); assert "Mike Green".equals(row.get(2));
/** * */ @Test public void testMethodAffinityMapper() { AffinityKeyMapper mapper = new GridCacheDefaultAffinityKeyMapper(); GridTestUtils.setFieldValue(mapper, "ignite", grid()); List<AffinityKey<Integer>> keys = new ArrayList<>(); for (int i = 1; i <= 10; i++) keys.add(new AffinityKey<>(i, Integer.toString(i))); for (int i = 1; i <= 10; i++) { AffinityKey<Integer> key = keys.get(i - 1); Object mapped = mapper.affinityKey(key); info("Mapped key: " + mapped); assertNotNull(mapped); assertSame(key.affinityKey(), mapped); } }
/** * @param useColocatedData Use colocated data. * @return Key. */ public Object key(boolean useColocatedData) { return useColocatedData ? new AffinityKey<>(id, refOrderId) : id; }
/** * @return Custom affinity key to guarantee that purchase is always collocated with person. */ public AffinityKey<Integer> key() { return new AffinityKey<>(id, organizationId); }
/** * @param useColocatedData Use colocated data. * @return Key. */ public Object key(boolean useColocatedData) { return useColocatedData ? new AffinityKey<>(id, orderId) : id; }
/** * @param useColocatedData Use colocated data.* * @return Key. */ public Object key(boolean useColocatedData) { return useColocatedData ? new AffinityKey<>(id, orderId) : id; }
/** * @return Custom affinity key to guarantee that person is always collocated with organization. */ public AffinityKey<Integer> key() { return new AffinityKey<>(id, orgId); }
/** * @param useCollocatedData Use collocated data. * @return Key. */ public Object key(boolean useCollocatedData) { return useCollocatedData ? new AffinityKey<>(id, orgId) : id; }
public Object key(boolean useColocatedData) { return useColocatedData ? new AffinityKey<>(id, rootOrderId) : id; } }
/** * @param cacheKey Cache key. * @param terminalId Terminal ID. * @return Cached object. */ @SuppressWarnings({"RedundantCast"}) private <T> Object get(String cacheKey, String terminalId) { Object key = new AffinityKey<>(cacheKey, terminalId); return (T) ignite.cache(DEFAULT_CACHE_NAME).get(key); } }
/** * @param name Timer name. * @param xid XID. * @param key Key. * @param termId Terminal ID. */ private void startTimer(String name, @Nullable IgniteUuid xid, @Nullable String key, String termId) { ConcurrentMap<String, T5<Long, Long, Long, IgniteUuid, Object>> m = timers.get(Thread.currentThread()); if (m == null) { ConcurrentMap<String, T5<Long, Long, Long, IgniteUuid, Object>> old = timers.putIfAbsent(Thread.currentThread(), m = new ConcurrentHashMap<>()); if (old != null) m = old; } T5<Long, Long, Long, IgniteUuid, Object> t = m.get(name); if (t == null) { T5<Long, Long, Long, IgniteUuid, Object> old = m.putIfAbsent(name, t = new T5<>()); if (old != null) t = old; } t.set1(System.currentTimeMillis()); t.set2(0L); t.set4(xid); t.set5(key == null ? null : new AffinityKey<String>(key, termId) {}); }
assertEquals(new AffinityKey<>("p1", "o1"), row.get(0)); assertEquals("John White", row.get(1)); assertEquals(25, row.get(2)); assertEquals(new AffinityKey<>("p2", "o1"), row.get(0)); assertEquals("Joe Black", row.get(1)); assertEquals(35, row.get(2)); assertEquals(new AffinityKey<>("p3", "o2"), row.get(0)); assertEquals("Mike Green", row.get(1)); assertEquals(40, row.get(2));
/** @throws Exception If failed. */ @Test public void testExecuteWithArguments() throws Exception { QueryCursor<List<?>> qry = personCache .query(sqlFieldsQuery("select _KEY, name, age from Person where age > ?").setArgs(30)); List<List<?>> res = new ArrayList<>(qry.getAll()); dedup(res); assertEquals(2, res.size()); Collections.sort(res, new Comparator<List<?>>() { @Override public int compare(List<?> row1, List<?> row2) { return ((Integer)row1.get(2)).compareTo((Integer)row2.get(2)); } }); int cnt = 0; for (List<?> row : res) { assertEquals(3, row.size()); if (cnt == 0) { assertEquals(new AffinityKey<>("p2", "o1"), row.get(0)); assertEquals("Joe Black", row.get(1)); assertEquals(35, row.get(2)); } if (cnt == 1) { assertEquals(new AffinityKey<>("p3", "o2"), row.get(0)); assertEquals("Mike Green", row.get(1)); assertEquals(40, row.get(2)); } cnt++; } assert cnt == 2; }
/** */ @Test public void testSubQueryWithAggregate() { CacheConfiguration ccfg1 = cacheConfig("pers", true, AffinityKey.class, Person2.class); IgniteCache<AffinityKey<Integer>, Person2> c1 = ignite(0).getOrCreateCache(ccfg1); try { int orgId = 100500; c1.put(new AffinityKey<>(1, orgId), new Person2(orgId, "Vasya")); c1.put(new AffinityKey<>(2, orgId), new Person2(orgId, "Another Vasya")); List<List<?>> rs = c1.query(new SqlFieldsQuery("select name, " + "select count(1) from Person2 q where q.orgId = p.orgId " + "from Person2 p order by name desc")).getAll(); assertEquals(2, rs.size()); assertEquals("Vasya", rs.get(0).get(0)); assertEquals(2L, rs.get(0).get(1)); assertEquals("Another Vasya", rs.get(1).get(0)); assertEquals(2L, rs.get(1).get(1)); } finally { c1.destroy(); } }
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { startGridsMultiThreaded(3); IgniteCache<String, Organization> orgCache = grid(0).cache("org"); orgCache.put("o1", new Organization(1, "A")); orgCache.put("o2", new Organization(2, "B")); IgniteCache<AffinityKey<String>, Person> personCache = grid(0).cache("pers"); personCache.put(new AffinityKey<>("p1", "o1"), new Person("John White", 25, 1)); personCache.put(new AffinityKey<>("p2", "o1"), new Person("Joe Black", 35, 1)); personCache.put(new AffinityKey<>("p3", "o2"), new Person("Mike Green", 40, 2)); }
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { startGrids(3); IgniteCache<String, Organization> orgCache = grid(0).cache("org"); assert orgCache != null; orgCache.put("o1", new Organization(1, "A")); orgCache.put("o2", new Organization(2, "B")); IgniteCache<AffinityKey, Person> personCache = grid(0).cache("pers"); assert personCache != null; personCache.put(new AffinityKey<>("p1", "o1"), new Person(1, "John White", 25, 1)); personCache.put(new AffinityKey<>("p2", "o1"), new Person(2, "Joe Black", 35, 1)); personCache.put(new AffinityKey<>("p3", "o2"), new Person(3, "Mike Green", 40, 2)); }
personCache.put(new AffinityKey<>("p1", "o1"), new Person("John White", 25, 1)); personCache.put(new AffinityKey<>("p2", "o1"), new Person("Joe Black", 35, 1)); personCache.put(new AffinityKey<>("p3", "o2"), new Person("Mike Green", 40, 2));
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { startGrids(3); IgniteCache<String, Organization> orgCache = jcache(grid(0), cacheConfiguration(), "org", String.class, Organization.class); assert orgCache != null; orgCache.put("o1", new Organization(1, "A")); orgCache.put("o2", new Organization(2, "B")); IgniteCache<AffinityKey, Person> personCache = jcache(grid(0), cacheConfiguration(), "pers", AffinityKey.class, Person.class); assert personCache != null; personCache.put(new AffinityKey<>("p1", "o1"), new Person(1, "John White", 25, 1)); personCache.put(new AffinityKey<>("p2", "o1"), new Person(2, "Joe Black", 35, 1)); personCache.put(new AffinityKey<>("p3", "o2"), new Person(3, "Mike Green", 40, 2)); }
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { super.beforeTestsStarted(); startGrids(3); IgniteCache<String, Organization> orgCache = jcache(grid(0), cacheConfiguration(), "org", String.class, Organization.class); assert orgCache != null; orgCache.put("o1", new Organization(1, "A")); orgCache.put("o2", new Organization(2, "B")); IgniteCache<AffinityKey, Person> personCache = jcache(grid(0), cacheConfiguration(), "pers", AffinityKey.class, Person.class); assert personCache != null; personCache.put(new AffinityKey<>("p1", "o1"), new Person(1, "John White", 25, 1)); personCache.put(new AffinityKey<>("p2", "o1"), new Person(2, "Joe Black", 35, 1)); personCache.put(new AffinityKey<>("p3", "o2"), new Person(3, "Mike Green", 40, 2)); }