Java Code Examples for org.apache.ignite.IgniteCache#removeAll()
The following examples show how to use
org.apache.ignite.IgniteCache#removeAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GridCacheAbstractFullApiSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception In case of error. */ @Test public void testRemoveAllAsyncOld() throws Exception { IgniteCache<String, Integer> cache = jcache(); IgniteCache<String, Integer> cacheAsync = cache.withAsync(); cache.put("key1", 1); cache.put("key2", 2); cache.put("key3", 3); checkSize(F.asSet("key1", "key2", "key3")); cacheAsync.removeAll(F.asSet("key1", "key2")); assertNull(cacheAsync.future().get()); checkSize(F.asSet("key3")); checkContainsKey(false, "key1"); checkContainsKey(false, "key2"); checkContainsKey(true, "key3"); }
Example 2
Source File: IgniteCacheExpiryPolicyWithStoreAbstractTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception If failed. */ @Test public void testLoadCache() throws Exception { IgniteCache<Integer, Integer> cache = jcache(0); final Integer key = primaryKey(cache); storeMap.put(key, 100); try { cache.loadCache(null); checkTtl(key, 500, false); assertEquals((Integer)100, cache.localPeek(key, CachePeekMode.ONHEAP)); U.sleep(600); checkExpired(key); } finally { cache.removeAll(); } }
Example 3
Source File: SqlIndexConsistencyAfterInterruptAtomicCacheOperationTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception On error. */ @Test public void testRemoveAll() throws Exception { IgniteEx ign = startGrid(0); IgniteCache<Object, Object> cache = ign.createCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME) .setAtomicityMode(atomicity()) .setIndexedTypes(Integer.class, Integer.class)); final Map<Integer, Integer> batch = new HashMap<>(); for (int i = 0; i < KEYS; ++i) batch.put(i, i); cache.putAll(batch); Thread t = new Thread(() -> { cache.removeAll(batch.keySet()); }); t.start(); t.interrupt(); t.join(); assertEquals(cache.size(), cache.query(new SqlFieldsQuery("select * from Integer")).getAll().size()); }
Example 4
Source File: IgniteCacheConfigVariationsFullApiTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception In case of error. */ @Test public void testRemoveAllAsyncOld() throws Exception { IgniteCache<String, Integer> cache = jcache(); IgniteCache<String, Integer> cacheAsync = cache.withAsync(); cache.put("key1", 1); cache.put("key2", 2); cache.put("key3", 3); checkSize(F.asSet("key1", "key2", "key3")); cacheAsync.removeAll(F.asSet("key1", "key2")); assertNull(cacheAsync.future().get()); checkSize(F.asSet("key3")); checkContainsKey(false, "key1"); checkContainsKey(false, "key2"); checkContainsKey(true, "key3"); }
Example 5
Source File: GridCachePartitionedMultiNodeFullApiSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception If failed. */ @Test public void testPutAllRemoveAll() throws Exception { for (int i = 0; i < gridCount(); i++) info(">>>>> Grid" + i + ": " + grid(i).localNode().id()); Map<Integer, Integer> putMap = new LinkedHashMap<>(); int size = 100; for (int i = 0; i < size; i++) putMap.put(i, i * i); IgniteCache<Object, Object> c0 = grid(0).cache(DEFAULT_CACHE_NAME); IgniteCache<Object, Object> c1 = grid(1).cache(DEFAULT_CACHE_NAME); c0.putAll(putMap); c1.removeAll(new HashSet<>(putMap.keySet())); for (int i = 0; i < size; i++) { assertNull(c0.get(i)); assertNull(c1.get(i)); } }
Example 6
Source File: CacheClientStoreSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception If failed. */ private void doTestNoStore() throws Exception { factory = null; Ignite ignite = startClientGrid("client-1"); IgniteCache<Object, Object> cache = ignite.cache(CACHE_NAME); cache.get(0); cache.getAll(F.asSet(0, 1)); cache.getAndPut(0, 0); cache.getAndPutIfAbsent(0, 0); cache.getAndRemove(0); cache.getAndReplace(0, 0); cache.put(0, 0); cache.putAll(F.asMap(0, 0, 1, 1)); cache.putIfAbsent(0, 0); cache.remove(0); cache.remove(0, 0); cache.removeAll(F.asSet(0, 1)); cache.removeAll(); cache.invoke(0, new EP()); cache.invokeAll(F.asSet(0, 1), new EP()); }
Example 7
Source File: BinaryTxCacheLocalEntriesSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** * @throws Exception If failed. */ @Test public void testLocalEntries() throws Exception { IgniteCache<Integer, BinaryObject> cache = grid(0).cache(DEFAULT_CACHE_NAME).withKeepBinary(); final int ENTRY_CNT = 10; for (int i = 0; i < ENTRY_CNT; i++) cache.put(i, userObject("user-" + i)); assertEquals(ENTRY_CNT, cache.localSize(CachePeekMode.ALL)); for (int i = 0; i < gridCount(); i++) jcache(i).withKeepBinary().localEntries(); cache.removeAll(); }
Example 8
Source File: BankDataGenerator.java From ignite-book-code-samples with GNU General Public License v3.0 | 5 votes |
public static IgniteCache<String, CashBackDictionaryData> initSavigsCache(Ignite ignite) { CacheConfiguration savingsCacheCfg = new CacheConfiguration().setName(SAVINGS_CACHE); IgniteCache<String, CashBackDictionaryData> result = ignite.getOrCreateCache(savingsCacheCfg); result.removeAll(); result.put("meal", new CashBackDictionaryData(new BigDecimal(0.01),"meal shopping"));; result.put("entertainment", new CashBackDictionaryData(new BigDecimal(0.02),"entertainment"));; return result; }
Example 9
Source File: GridCacheHashMapPutAllWarningsTest.java From ignite with Apache License 2.0 | 5 votes |
/** * @throws Exception If failed. */ @Test public void testTreeMapRemoveAllEntries() throws Exception { List<String> messages = Collections.synchronizedList(new ArrayList<>()); testLog = new ListeningTestLogger(false, log()); testLog.registerListener((s) -> { if (s.contains("deadlock")) messages.add(s); }); Ignite ignite = startGrid(0); startGrid(1); IgniteCache<Integer, String> c = ignite.getOrCreateCache(new CacheConfiguration<Integer, String>("entries") .setCacheMode(CacheMode.REPLICATED) .setAtomicityMode(CacheAtomicityMode.ATOMIC) .setBackups(1)); for (int i = 0; i < 1000; i++) { c.put(i, "foo"); c.put(i * 2, "bar"); } c.removeAll(); assertEquals(0, c.size()); for (String message : messages) { assertFalse(message.contains("Unordered collection ")); assertFalse(message.contains("operation on cache")); } }
Example 10
Source File: IgniteCacheProcessProxy.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public Void call() { IgniteCache<K, V> cache = cache(); cache.removeAll(); if (async) cache.future().get(); return null; }
Example 11
Source File: CacheSqlQueryValueCopySelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected void afterTest() throws Exception { IgniteCache<Integer, Value> cache = grid(0).cache(DEFAULT_CACHE_NAME); cache.removeAll(); super.afterTest(); }
Example 12
Source File: DmlInsideTransactionTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Run DML query and check that DML is not allowed or not inside transaction. Also checked that using DML will not * lead to rollback. * * @param query Query with DML operation to be run. * @param isAllowed true in case DML should work inside transaction, false otherwise. */ private void runDmlInTransactionTest(Query query, boolean isAllowed) { IgniteEx ignite = grid(0); IgniteCache<PersonKey, Person> cache = ignite.cache(CACHE_PERSON); cache.removeAll(); assertEquals(0, cache.query(new SqlFieldsQuery("SELECT * FROM TEST.Person")).getAll().size()); try (Transaction tx = ignite.transactions().txStart()) { cache.put(new PersonKey(1L), new Person("person", 2)); if (isAllowed) cache.query(query); else { assertThrows(log, () -> { cache.query(query); return null; }, CacheException.class, "DML statements are not allowed inside a transaction over cache(s) with TRANSACTIONAL atomicity"); } tx.commit(); } assertTrue(!cache.query(new SqlFieldsQuery("SELECT * FROM TEST.Person")).getAll().isEmpty()); }
Example 13
Source File: IgniteSqlNotNullConstraintTest.java From ignite with Apache License 2.0 | 5 votes |
/** */ private void executeForNodeAndCache(CacheConfiguration ccfg, Ignite ignite, TestClosure clo, TransactionConcurrency concurrency, TransactionIsolation isolation) throws Exception { String cacheName = ccfg.getName(); IgniteCache cache; if (ignite.configuration().isClientMode() && ccfg.getCacheMode() == CacheMode.PARTITIONED && ccfg.getNearConfiguration() != null) cache = ignite.getOrCreateNearCache(ccfg.getName(), ccfg.getNearConfiguration()); else cache = ignite.cache(ccfg.getName()); cache.removeAll(); assertEquals(0, cache.size()); clo.configure(ignite, cache, concurrency, isolation); log.info("Running test with node " + ignite.name() + ", cache " + cacheName); clo.key1 = 1; clo.key2 = 4; clo.run(); }
Example 14
Source File: GridCacheAbstractFullApiSelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @param async If {@code true} uses asynchronous operation. * @throws Exception In case of error. */ private void globalRemoveAllOld(boolean async) throws Exception { IgniteCache<String, Integer> cache = jcache(); cache.put("key1", 1); cache.put("key2", 2); cache.put("key3", 3); checkSize(F.asSet("key1", "key2", "key3")); IgniteCache<String, Integer> asyncCache = cache.withAsync(); if (async) { asyncCache.removeAll(F.asSet("key1", "key2")); asyncCache.future().get(); } else cache.removeAll(F.asSet("key1", "key2")); checkSize(F.asSet("key3")); checkContainsKey(false, "key1"); checkContainsKey(false, "key2"); checkContainsKey(true, "key3"); // Put values again. cache.put("key1", 1); cache.put("key2", 2); cache.put("key3", 3); if (async) { IgniteCache<String, Integer> asyncCache0 = jcache(gridCount() > 1 ? 1 : 0).withAsync(); asyncCache0.removeAll(); asyncCache0.future().get(); } else jcache(gridCount() > 1 ? 1 : 0).removeAll(); assertEquals(0, cache.localSize()); long entryCnt = hugeRemoveAllEntryCount(); for (int i = 0; i < entryCnt; i++) cache.put(String.valueOf(i), i); for (int i = 0; i < entryCnt; i++) assertEquals(Integer.valueOf(i), cache.get(String.valueOf(i))); if (async) { asyncCache.removeAll(); asyncCache.future().get(); } else cache.removeAll(); for (int i = 0; i < entryCnt; i++) assertNull(cache.get(String.valueOf(i))); }
Example 15
Source File: IgniteCachePeekModesAbstractTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @throws InterruptedException If failed. */ @Test public void testLocalPartitionSizeFlags() throws InterruptedException { if (true) // TODO GG-11148. return; if (cacheMode() != LOCAL) return; awaitPartitionMapExchange(); checkEmpty(); int part = 0; IgniteCache<Integer, String> cache0 = jcache(0); Set<Integer> keys = new HashSet<>(); for (int i = 0; i < 200; i++) { cache0.put(i, "test_val"); keys.add(i); } try { int totalKeys = 200; T2<Integer, Integer> swapKeys = swapKeysCount(0); T2<Integer, Integer> offheapKeys = offheapKeysCount(0); int totalSwap = swapKeys.get1() + swapKeys.get2(); int totalOffheap = offheapKeys.get1() + offheapKeys.get2(); log.info("Keys [total=" + totalKeys + ", offheap=" + offheapKeys + ", swap=" + swapKeys + ']'); assertTrue(totalSwap + totalOffheap < totalKeys); assertEquals(totalKeys, cache0.localSize()); assertEquals(totalKeys, cache0.localSizeLong(part, ALL)); assertEquals(totalOffheap, cache0.localSizeLong(part, OFFHEAP)); assertEquals(totalSwap, cache0.localSizeLong(part)); assertEquals(totalKeys - (totalSwap + totalOffheap), cache0.localSizeLong(part, ONHEAP)); assertEquals(totalOffheap, cache0.sizeLong(part, OFFHEAP)); assertEquals(totalSwap, cache0.sizeLong(part)); assertEquals(totalKeys - (totalSwap + totalOffheap), cache0.sizeLong(part, ONHEAP)); assertEquals(totalOffheap, cache0.localSizeLong(part, OFFHEAP, PRIMARY)); assertEquals(totalSwap, cache0.localSizeLong(part, PRIMARY)); assertEquals(totalKeys - (totalSwap + totalOffheap), cache0.localSizeLong(part, ONHEAP, PRIMARY)); assertEquals(totalOffheap, cache0.localSizeLong(part, OFFHEAP, BACKUP)); assertEquals(totalSwap, cache0.localSizeLong(part, BACKUP)); assertEquals(totalKeys - (totalSwap + totalOffheap), cache0.localSizeLong(part, ONHEAP, BACKUP)); } finally { cache0.removeAll(keys); } }
Example 16
Source File: GridCacheAbstractFullApiSelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @param async If {@code true} uses asynchronous operation. * @throws Exception In case of error. */ private void globalRemoveAll(boolean async) throws Exception { IgniteCache<String, Integer> cache = jcache(); cache.put("key1", 1); cache.put("key2", 2); cache.put("key3", 3); checkSize(F.asSet("key1", "key2", "key3")); if (async) cache.removeAllAsync(F.asSet("key1", "key2")).get(); else cache.removeAll(F.asSet("key1", "key2")); checkSize(F.asSet("key3")); checkContainsKey(false, "key1"); checkContainsKey(false, "key2"); checkContainsKey(true, "key3"); // Put values again. cache.put("key1", 1); cache.put("key2", 2); cache.put("key3", 3); if (async) jcache(gridCount() > 1 ? 1 : 0).removeAllAsync().get(); else jcache(gridCount() > 1 ? 1 : 0).removeAll(); assertEquals(0, cache.localSize()); long entryCnt = hugeRemoveAllEntryCount(); for (int i = 0; i < entryCnt; i++) cache.put(String.valueOf(i), i); for (int i = 0; i < entryCnt; i++) assertEquals(Integer.valueOf(i), cache.get(String.valueOf(i))); if (async) cache.removeAllAsync().get(); else cache.removeAll(); for (int i = 0; i < entryCnt; i++) assertNull(cache.get(String.valueOf(i))); }
Example 17
Source File: IgniteCacheConfigVariationsFullApiTest.java From ignite with Apache License 2.0 | 4 votes |
/** * @param async If {@code true} uses asynchronous operation. * @param oldAsync Use old async API. * @throws Exception In case of error. */ private void globalRemoveAll(boolean async, boolean oldAsync) throws Exception { IgniteCache<String, Integer> cache = jcache(); cache.put("key1", 1); cache.put("key2", 2); cache.put("key3", 3); checkSize(F.asSet("key1", "key2", "key3")); IgniteCache<String, Integer> asyncCache = cache.withAsync(); if (async) { if (oldAsync) { asyncCache.removeAll(F.asSet("key1", "key2")); asyncCache.future().get(); } else cache.removeAllAsync(F.asSet("key1", "key2")).get(); } else cache.removeAll(F.asSet("key1", "key2")); checkSize(F.asSet("key3")); checkContainsKey(false, "key1"); checkContainsKey(false, "key2"); checkContainsKey(true, "key3"); // Put values again. cache.put("key1", 1); cache.put("key2", 2); cache.put("key3", 3); if (async) { if (oldAsync) { IgniteCache asyncCache0 = jcache(gridCount() > 1 ? 1 : 0).withAsync(); asyncCache0.removeAll(); asyncCache0.future().get(); } else jcache(gridCount() > 1 ? 1 : 0).removeAllAsync().get(); } else jcache(gridCount() > 1 ? 1 : 0).removeAll(); assertEquals(0, cache.localSize()); long entryCnt = hugeRemoveAllEntryCount(); for (int i = 0; i < entryCnt; i++) cache.put(String.valueOf(i), i); for (int i = 0; i < entryCnt; i++) assertEquals(Integer.valueOf(i), cache.get(String.valueOf(i))); if (async) { if (oldAsync) { asyncCache.removeAll(); asyncCache.future().get(); } else cache.removeAllAsync().get(); } else cache.removeAll(); for (int i = 0; i < entryCnt; i++) assertNull(cache.get(String.valueOf(i))); }
Example 18
Source File: CacheStoreSessionListenerReadWriteThroughDisabledAbstractTest.java From ignite with Apache License 2.0 | 4 votes |
/** * Tests that there are no calls of {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} and * {@link CacheStoreSessionListener#onSessionStart(CacheStoreSession)} * while {@link IgniteCache#removeAll(Set)} performed. * * @throws Exception If failed. */ @Test public void testBatchRemove() throws Exception { IgniteCache<Object, Object> cache = grid(0).getOrCreateCache(DEFAULT_CACHE_NAME); Random r = new Random(); Set<Object> values = new HashSet<>(); for (int i = 0; i < CNT; ++i) { int key = r.nextInt(); cache.put(key, "test-value"); values.add(key); } cache.removeAll(values); }
Example 19
Source File: GridJtaTransactionManagerSelfTest.java From ignite with Apache License 2.0 | 2 votes |
/** * @throws Exception If failed. */ @Test public void testJtaTxContextSwitchWithExistingTx() throws Exception { for (TransactionIsolation isolation : TransactionIsolation.values()) { TransactionConfiguration cfg = grid().context().config().getTransactionConfiguration(); cfg.setDefaultTxConcurrency(txConcurrency); cfg.setDefaultTxIsolation(isolation); TransactionManager jtaTm = jotm.getTransactionManager(); IgniteCache<Integer, String> cache = jcache(); jtaTm.begin(); Transaction tx1 = jtaTm.getTransaction(); cache.put(1, Integer.toString(1)); assertNotNull(grid().transactions().tx()); assertEquals(ACTIVE, grid().transactions().tx().state()); assertEquals(Integer.toString(1), cache.get(1)); jtaTm.suspend(); jtaTm.begin(); Transaction tx2 = jtaTm.getTransaction(); assertNotSame(tx1, tx2); cache.put(2, Integer.toString(2)); try { jtaTm.resume(tx1); fail("jtaTm.resume shouldn't success."); } catch (IllegalStateException ignored) { // No-op. } finally { jtaTm.rollback(); //rolling back tx2 } jtaTm.resume(tx1); jtaTm.rollback(); cache.removeAll(); } }
Example 20
Source File: GridJtaTransactionManagerSelfTest.java From ignite with Apache License 2.0 | 2 votes |
/** * Test for switching tx context by JTA Manager. * * @throws Exception If failed. */ @Test public void testJtaTxContextSwitch() throws Exception { for (TransactionIsolation isolation : TransactionIsolation.values()) { TransactionConfiguration cfg = grid().context().config().getTransactionConfiguration(); cfg.setDefaultTxConcurrency(txConcurrency); cfg.setDefaultTxIsolation(isolation); TransactionManager jtaTm = jotm.getTransactionManager(); IgniteCache<Integer, String> cache = jcache(); assertNull(grid().transactions().tx()); jtaTm.begin(); Transaction tx1 = jtaTm.getTransaction(); cache.put(1, Integer.toString(1)); assertNotNull(grid().transactions().tx()); assertEquals(ACTIVE, grid().transactions().tx().state()); assertEquals(Integer.toString(1), cache.get(1)); jtaTm.suspend(); assertNull(grid().transactions().tx()); assertNull(cache.get(1)); jtaTm.begin(); Transaction tx2 = jtaTm.getTransaction(); assertNotSame(tx1, tx2); cache.put(2, Integer.toString(2)); assertNotNull(grid().transactions().tx()); assertEquals(ACTIVE, grid().transactions().tx().state()); assertEquals(Integer.toString(2), cache.get(2)); jtaTm.commit(); assertNull(grid().transactions().tx()); assertEquals(Integer.toString(2), cache.get(2)); jtaTm.resume(tx1); assertNotNull(grid().transactions().tx()); assertEquals(ACTIVE, grid().transactions().tx().state()); cache.put(3, Integer.toString(3)); jtaTm.commit(); assertEquals("1", cache.get(1)); assertEquals("2", cache.get(2)); assertEquals("3", cache.get(3)); assertNull(grid().transactions().tx()); cache.removeAll(); } }