/** * @param cacheAtomicityMode Atomicity mode. * @return Configuration. */ private static CollectionConfiguration collectionConfiguration(CacheAtomicityMode cacheAtomicityMode) { CollectionConfiguration colCfg = new CollectionConfiguration(); colCfg.setAtomicityMode(cacheAtomicityMode); return colCfg; }
@Override public void apply(Ignite ignite) { for (int i = 0; i < 100; i++) { CollectionConfiguration colCfg = new CollectionConfiguration(); colCfg.setBackups(1); colCfg.setCacheMode(PARTITIONED); colCfg.setAtomicityMode(i % 2 == 0 ? TRANSACTIONAL : ATOMIC); IgniteQueue q = ignite.queue("q-" + i, 0, colCfg); q.close(); } } });
/** * @throws Exception If failed. */ @Test public void testNotReuseCache() throws Exception { CollectionConfiguration colCfg1 = collectionConfiguration(); CollectionConfiguration colCfg2 = collectionConfiguration(); if (colCfg2.getAtomicityMode() == ATOMIC) colCfg2.setAtomicityMode(TRANSACTIONAL); else colCfg2.setAtomicityMode(ATOMIC); IgniteQueue queue1 = initQueue(0, "Queue1", 0, colCfg1); IgniteQueue queue2 = initQueue(0, "Queue2", 0, colCfg2); assertNotSame(getQueueCache(queue1), getQueueCache(queue2)); }
@Override public void apply(Ignite ignite) { for (int i = 0; i < 100; i++) { CollectionConfiguration colCfg = new CollectionConfiguration(); colCfg.setCollocated(collocated); colCfg.setBackups(1); colCfg.setCacheMode(PARTITIONED); colCfg.setAtomicityMode(i % 2 == 0 ? TRANSACTIONAL : ATOMIC); IgniteSet set = ignite.set("set-" + i, colCfg); set.close(); } } });
/** * @return Collection configuration. */ protected CollectionConfiguration collectionConfiguration() { CollectionConfiguration colCfg = new CollectionConfiguration(); colCfg.setCacheMode(collectionCacheMode()); colCfg.setAtomicityMode(collectionCacheAtomicityMode()); colCfg.setOffHeapMaxMemory(collectionOffHeapMaxMemory()); if (colCfg.getCacheMode() == PARTITIONED) colCfg.setBackups(1); return colCfg; }
/** * @param collocated Collocation flag. */ private void testCacheReuse(boolean collocated) { Ignite ignite = grid(0); CollectionConfiguration colCfg = collectionConfiguration().setCollocated(collocated); colCfg.setAtomicityMode(ATOMIC); colCfg.setGroupName("grp1"); IgniteSet set1 = ignite.set("set1", colCfg); IgniteSet set2 = ignite.set("set2", colCfg); assertEquals(separated(set1), cctx(set1).cacheId() != cctx(set2).cacheId()); colCfg.setAtomicityMode(TRANSACTIONAL); IgniteSet set3 = ignite.set("set3", colCfg); IgniteSet set4 = ignite.set("set4", colCfg); assertEquals(separated(set3), cctx(set3).cacheId() != cctx(set4).cacheId()); assertTrue(cctx(set1).cacheId() != cctx(set3).cacheId()); assertTrue(cctx(set1).groupId() == cctx(set3).groupId()); colCfg.setGroupName("gtp2"); IgniteSet set5 = ignite.set("set5", colCfg); IgniteSet set6 = ignite.set("set6", colCfg); assertEquals(separated(set5), cctx(set5).cacheId() != cctx(set6).cacheId()); assertTrue(cctx(set1).groupId() != cctx(set5).groupId()); Stream.of(set1, set2, set3, set4, set5, set6).forEach(IgniteSet::close); }
/** * Test that queues within the same group and compatible configurations are stored in the same cache. * * @throws Exception If failed. */ @Test public void testCacheReuse() throws Exception { CollectionConfiguration colCfg = collectionConfiguration(); colCfg.setAtomicityMode(ATOMIC); colCfg.setGroupName("grp1"); IgniteQueue queue1 = initQueue(0, "queue1", 100, colCfg); IgniteQueue queue2 = initQueue(0, "queue2", 100, colCfg); assert cctx(queue1).cacheId() == cctx(queue2).cacheId(); colCfg.setAtomicityMode(TRANSACTIONAL); IgniteQueue queue3 = initQueue(0, "queue3", 100, colCfg); IgniteQueue queue4 = initQueue(0, "queue4", 100, colCfg); assert cctx(queue3).cacheId() == cctx(queue4).cacheId(); assert cctx(queue1).cacheId() != cctx(queue3).cacheId(); assert cctx(queue1).groupId() == cctx(queue3).groupId(); colCfg.setGroupName("gtp2"); IgniteQueue queue5 = initQueue(0, "queue5", 100, colCfg); IgniteQueue queue6 = initQueue(0, "queue6", 100, colCfg); assert cctx(queue5).cacheId() == cctx(queue6).cacheId(); assert cctx(queue1).groupId() != cctx(queue5).groupId(); }
if (cacheCfg.getName().equals(VERTX_CACHE_TEMPLATE_NAME)) { collectionCfg = new CollectionConfiguration(); collectionCfg.setAtomicityMode(cacheCfg.getAtomicityMode()); collectionCfg.setBackups(cacheCfg.getBackups()); break;
if (cacheCfg.getName().equals(VERTX_CACHE_TEMPLATE_NAME)) { collectionCfg = new CollectionConfiguration(); collectionCfg.setAtomicityMode(cacheCfg.getAtomicityMode()); collectionCfg.setBackups(cacheCfg.getBackups()); break;