@Override public void run(final IgniteCache<Integer, Integer> cache, final Integer key, final Integer val) { cache.putIfAbsent(key, val); } });
@Override public Object call() throws Exception { for (int i = 0; i < TX_CNT; i++) { IgniteCache<Object, Object> cache = jcache(rnd.nextInt(GRID_CNT)); cache.putIfAbsent(rnd.nextInt(1000), "value"); } return null; } }, 4, "putIfAbsent");
@Override public void onLifecycleEvent(LifecycleEventType evt) { if (evt == LifecycleEventType.AFTER_NODE_START) { IgniteCache<Integer, byte[]> c = ignite.cache(DEFAULT_CACHE_NAME); if (c.putIfAbsent(-1, new byte[1])) { populate(c, cnt, KBSIZE); info(">>> POPULATED GRID <<<"); } } } };
/** {@inheritDoc} */ @Override public Boolean call() throws Exception { return cache().putIfAbsent(key, val); } }
@Override public Void call() throws Exception { for (int i = 0; i < ITERATIONS_PER_THREAD && !failed; i++) { if (i % 500 == 0) log.info("Iteration " + i); assertFalse(cache.putIfAbsent(key, 100)); } return null; } }, THREADS, "putxIfAbsent");
@Override public void run() { for (int i = 0; i < 100; i++) { if (!cache1.putIfAbsent(i, i)) { if (all ? !cache2.containsKeys(Collections.singleton(i)) : !cache2.containsKey(i)) fails.incrementAndGet(); } } } }, 100, "put-if-abs");
@Nullable @Override public Object call() throws Exception { for (int i = 0; i < TX_CNT; i++) { IgniteCache<Object, Object> cache = jcache(); int id = rnd.nextInt(1000); if (rnd.nextBoolean()) cache.putIfAbsent(new OrganizationKey(id), new Organization(id, "Name" + id, "City" + id)); else cache.putIfAbsent(new PersonKey(id), new Person(id, rnd.nextInt(), new Date(System.currentTimeMillis()), "Name" + id, i, Gender.random())); } return null; } }, 8, "putIfAbsent");
/** */ @Test public void testPutIfAbsent() { checkOperation(() -> cache.putIfAbsent(1, 1)); }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public ClientResponse process(ClientConnectionContext ctx) { boolean res = cache(ctx).putIfAbsent(key(), val()); return new ClientBooleanResponse(requestId(), res); } }
@Override public void onLifecycleEvent(LifecycleEventType evt) { if (evt == LifecycleEventType.AFTER_NODE_START) { IgniteCache<Integer, String> c = ignite.cache(DEFAULT_CACHE_NAME); if (c.putIfAbsent(-1, "true")) { populate(ignite.<Integer, String>cache(DEFAULT_CACHE_NAME), cnt); info(">>> POPULATED GRID <<<"); } } } };
@Override public Void call() throws Exception { IgniteCache<Object, Object> cache = node1.cache(DEFAULT_CACHE_NAME); try (Transaction tx = node1.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { Integer key = keys.get(idx.getAndIncrement() % keys.size()); cache.putIfAbsent(key, String.valueOf(key)); tx.commit(); } return null; } }, txCnt * 2, "tx");
@Override public Void call() throws Exception { IgniteCache<Object, Object> cache = node0.cache(DEFAULT_CACHE_NAME); try (Transaction tx = node0.transactions().txStart()) { key.set(primaryKey(cache)); cache.putIfAbsent(key.get(), "dummy val"); l1.countDown(); l2.await(); tx.commit(); } return null; } }, "tx-1"));
/** * @param cache Cache. */ private void cacheOp(IgniteCache<Integer, Integer> cache) { boolean b = cache.putIfAbsent(42, 42); log.info("PutIfAbsent: " + b); Integer val = cache.get(42); log.info("Get: " + val); }
/** * @throws Exception In case of error. */ @Test public void testPutIfAbsentAsyncOldConcurrent() throws Exception { IgniteCache cacheAsync = jcache().withAsync(); cacheAsync.putIfAbsent("key1", 1); IgniteFuture<Boolean> fut1 = cacheAsync.future(); cacheAsync.putIfAbsent("key2", 2); IgniteFuture<Boolean> fut2 = cacheAsync.future(); assert fut1.get(); assert fut2.get(); }
/** * @throws Exception In case of error. */ @Test public void testPutIfAbsentAsyncConcurrentOld() throws Exception { IgniteCache<String, Integer> cacheAsync = jcache().withAsync(); cacheAsync.putIfAbsent("key1", 1); IgniteFuture<Boolean> fut1 = cacheAsync.future(); cacheAsync.putIfAbsent("key2", 2); IgniteFuture<Boolean> fut2 = cacheAsync.future(); assert fut1.get(); assert fut2.get(); }
@Override public Void call() throws Exception { for (int i = 0; i < ITERATIONS_PER_THREAD && !failed; i++) { if (i % 500 == 0) log.info("Iteration " + i); try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { cache.putIfAbsent(key, 100); tx.commit(); } } return null; } }, THREADS, "putxIfAbsent");
@Override public Void call() throws Exception { for (int i = 0; i < ITERATIONS_PER_THREAD && !failed; i++) { if (i % 500 == 0) log.info("Iteration " + i); try (Transaction tx = grid(0).transactions().txStart(txConcurrency, REPEATABLE_READ)) { cache.putIfAbsent(key, 100); tx.commit(); } } return null; } }, THREADS, "putxIfAbsent");
/** * @throws Exception If failed. */ @Test public void testPutIfAbsentFromPrimary() throws Exception { IgniteCache<Integer, String> cache = jcache(0); int key = primaryKey(cache); assertTrue(cache.putIfAbsent(key, "val")); checkStoreUsage(1, 1, 0, 1); }
/** * @throws Exception If failed. */ @Test public void testPutIfAbsentFromBackup() throws Exception { IgniteCache<Integer, String> cache = jcache(0); int key = backupKey(cache); assertTrue(cache.putIfAbsent(key, "val")); checkStoreUsage(1, 1, 0, nearCacheConfiguration() == null ? 2 : 1); }
/** * @throws Exception If failed. */ @Test public void testPutIfAbsentFromNear() throws Exception { IgniteCache<Integer, String> cache = jcache(0); int key = nearKey(cache); assertTrue(cache.putIfAbsent(key, "val")); checkStoreUsage(1, 1, 0, nearCacheConfiguration() == null ? 2 : 1); }