Java Code Examples for org.apache.ignite.transactions.Transaction#commit()

The following examples show how to use org.apache.ignite.transactions.Transaction#commit() . 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: GridCacheVersionMultinodeTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param key Key.
 * @param txMode Non null tx mode if explicit transaction should be started.
 * @throws Exception If failed.
 */
private void checkVersion(String key, @Nullable TransactionConcurrency txMode) throws Exception {
    IgniteCache<String, Integer> cache = jcache(0);

    Transaction tx = null;

    if (txMode != null)
        tx = cache.unwrap(Ignite.class).transactions().txStart(txMode, REPEATABLE_READ);

    try {
        cache.put(key, 1);

        if (tx != null)
            tx.commit();
    }
    finally {
        if (tx != null)
            tx.close();
    }

    checkEntryVersion(key);
}
 
Example 2
Source File: CacheTxFastFinishTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param tx Transaction.
 * @param commit Commit flag.
 * @param readOnly {@code true} if checked tx did no writes.
 */
protected void checkNormalTxFinish(Transaction tx, boolean commit, boolean readOnly) {
    IgniteInternalTx tx0 = ((TransactionProxyImpl)tx).tx();

    if (commit) {
        tx.commit();

        checkNormalCommittedTx(tx0, readOnly);
    }
    else {
        tx.rollback();

        assertNull(prepareFuture(tx0));
        assertNotNull(finishFuture(tx0));
    }
}
 
Example 3
Source File: IgniteCacheReadThroughStoreCallTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param cache Cache.
 * @param c Cache operation Closure.
 * @param concurrency Transaction concurrency.
 * @param isolation Transaction isolation.
 * @param expLoadCnt Expected number of store 'load' calls.
 * @throws Exception If failed.
 */
private void checkReadThrough(IgniteCache<Object, Object> cache,
    IgniteRunnable c,
    @Nullable TransactionConcurrency concurrency,
    @Nullable TransactionIsolation isolation,
    int expLoadCnt) throws Exception {
    TestStore.loadCnt.set(0);

    Transaction tx = isolation != null ? cache.unwrap(Ignite.class).transactions().txStart(concurrency, isolation)
        : null;

    try {
        c.run();

        if (tx != null)
            tx.commit();
    }
    finally {
        if (tx != null)
            tx.close();
    }

    assertEquals(expLoadCnt, TestStore.loadCnt.get());
}
 
Example 4
Source File: GridCacheAbstractFullApiSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param concurrency Concurrency.
 * @throws Exception If failed.
 */
private void checkTransformAfterRemove(TransactionConcurrency concurrency) throws Exception {
    IgniteCache<String, Integer> cache = jcache();

    cache.put("key", 4);

    Transaction tx = txShouldBeUsed() ? ignite(0).transactions().txStart(concurrency, READ_COMMITTED) : null;

    try {
        cache.remove("key");

        cache.invoke("key", INCR_PROCESSOR);
        cache.invoke("key", INCR_PROCESSOR);
        cache.invoke("key", INCR_PROCESSOR);

        if (tx != null)
            tx.commit();
    }
    finally {
        if (tx != null)
            tx.close();
    }

    assertEquals((Integer)3, cache.get("key"));
}
 
Example 5
Source File: IgniteCacheReplicatedQuerySelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param loc Explicit query locality flag.
 * @throws Exception if failed.
 */
private void doTestLocalQuery(boolean loc) throws Exception {
    cache1.clear();

    Transaction tx = ignite1.transactions().txStart();

    try {
        cache1.put(new CacheKey(1), new CacheValue("1"));
        cache1.put(new CacheKey(2), new CacheValue("2"));
        cache1.put(new CacheKey(3), new CacheValue("3"));
        cache1.put(new CacheKey(4), new CacheValue("4"));

        tx.commit();

        info("Committed transaction: " + tx);
    }
    catch (IgniteException e) {
        tx.rollback();

        throw e;
    }

    checkLocalQueryResults(cache1, loc);
    checkLocalQueryResults(cache2, loc);
    checkLocalQueryResults(cache3, loc);
}
 
Example 6
Source File: GridCacheColocatedDebugTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param explicitTx Whether or not start implicit tx.
 * @param concurrency Tx concurrency.
 * @param isolation Tx isolation.
 * @throws Exception If failed.
 */
private void checkSinglePut(boolean explicitTx, TransactionConcurrency concurrency, TransactionIsolation isolation)
    throws Exception {
    startGrid();

    try {
        Transaction tx = explicitTx ? grid().transactions().txStart(concurrency, isolation) : null;

        try {
            IgniteCache<Object, Object> cache = jcache();

            cache.putAll(F.asMap(1, "Hello", 2, "World"));

            if (tx != null)
                tx.commit();

            System.out.println(cache.localMetrics());

            assertEquals("Hello", cache.get(1));
            assertEquals("World", cache.get(2));
            assertNull(cache.get(3));
        }
        finally {
            if (tx != null)
                tx.close();
        }
    }
    finally {
        stopAllGrids();
    }
}
 
Example 7
Source File: GridCacheAbstractTxReadTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Tests sequential value write and read inside transaction.
 * @param concurrency Transaction concurrency.
 * @param isolation Transaction isolation.
 * @throws IgniteCheckedException If failed
 */
protected void checkTransactionalRead(TransactionConcurrency concurrency, TransactionIsolation isolation)
    throws IgniteCheckedException {
    IgniteCache<String, Integer> cache = jcache(0);

    cache.clear();

    Transaction tx = grid(0).transactions().txStart(concurrency, isolation);

    try {
        cache.put("key", 1);

        assertEquals("Invalid value after put", 1, cache.get("key").intValue());

        tx.commit();
    }
    finally {
        tx.close();
    }

    assertEquals("Invalid cache size after put", 1, cache.size());

    try {
        tx = grid(0).transactions().txStart(concurrency, isolation);

        assertEquals("Invalid value inside transactional read", Integer.valueOf(1), cache.get("key"));

        tx.commit();
    }
    finally {
        tx.close();
    }
}
 
Example 8
Source File: GridCacheReferenceCleanupSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Crates callable for sync op with async commit test.
 *
 * @return Callable.
 * @throws Exception If failed.
 */
private Callable<Collection<WeakReference<Object>>> syncOpAsyncCommitCallable() throws Exception {
    return new Callable<Collection<WeakReference<Object>>>() {
        @Override public Collection<WeakReference<Object>> call() throws Exception {
            Collection<WeakReference<Object>> refs = new ArrayList<>();

            Ignite g = startGrid();

            try {
                IgniteCache<Integer, TestValue> cache = g.cache(DEFAULT_CACHE_NAME);

                refs.add(new WeakReference<Object>(cacheContext(cache)));

                Transaction tx = g.transactions().txStart();

                TestValue val = new TestValue(0);

                refs.add(new WeakReference<Object>(val));

                cache.put(0, val);

                tx.commit();
            }
            finally {
                G.stop(g.name(), cancel);
            }

            return refs;
        }
    };
}
 
Example 9
Source File: GridCacheReferenceCleanupSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Crates callable for async ops with async commit test.
 *
 * @return Callable.
 * @throws Exception If failed.
 */
private Callable<Collection<WeakReference<Object>>> asyncOpsAsyncCommitCallable() throws Exception {
    return new Callable<Collection<WeakReference<Object>>>() {
        @Override public Collection<WeakReference<Object>> call() throws Exception {
            Collection<WeakReference<Object>> refs = new ArrayList<>();

            Ignite g = startGrid();

            try {
                IgniteCache<Integer, TestValue> cache = g.cache(DEFAULT_CACHE_NAME);

                refs.add(new WeakReference<Object>(cacheContext(cache)));

                Transaction tx = g.transactions().txStart();

                for (int i = 0; i < 1000; i++) {
                    TestValue val = new TestValue(i);

                    refs.add(new WeakReference<Object>(val));

                    cache.putAsync(i, val).get();
                }

                tx.commit();
            }
            finally {
                G.stop(g.name(), cancel);
            }

            return refs;
        }
    };
}
 
Example 10
Source File: GridCacheSlowTxWarnTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param g Grid.
 * @param cacheName Cache.
 * @param simulateTimeout Simulate timeout.
 * @param configureTimeout Alter configuration of TX manager.
 * @throws Exception If failed.
 */
private void checkCache(Ignite g, String cacheName, boolean simulateTimeout,
    boolean configureTimeout) throws Exception {
    if (configureTimeout) {
        GridCacheAdapter<Integer, Integer> cache = ((IgniteKernal)g).internalCache(cacheName);

        cache.context().tm().slowTxWarnTimeout(500);
    }

    IgniteCache<Object, Object> cache1 = g.cache(cacheName);

    Transaction tx = g.transactions().txStart();

    try {
        cache1.put(1, 1);

        if (simulateTimeout)
            Thread.sleep(800);

        tx.commit();
    }
    finally {
        tx.close();
    }

    tx = g.transactions().txStart();

    try {
        cache1.put(1, 1);

        if (simulateTimeout)
            Thread.sleep(800);

        tx.rollback();
    }
    finally {
        tx.close();
    }
}
 
Example 11
Source File: GridCacheAbstractFullApiSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param put Whether to put value.
 * @param concurrency Concurrency.
 * @param isolation Isolation.
 * @throws Exception If failed.
 */
private void checkTransformReturnValue(boolean put,
    TransactionConcurrency concurrency,
    TransactionIsolation isolation)
    throws Exception {
    IgniteCache<String, Integer> cache = jcache();

    if (!put)
        cache.put("key", 1);

    Transaction tx = txShouldBeUsed() ? ignite(0).transactions().txStart(concurrency, isolation) : null;

    try {
        if (put)
            cache.put("key", 1);

        cache.invoke("key", INCR_PROCESSOR);

        assertEquals((Integer)2, cache.get("key"));

        if (tx != null) {
            // Second get inside tx. Make sure read value is not transformed twice.
            assertEquals((Integer)2, cache.get("key"));

            tx.commit();
        }
    }
    finally {
        if (tx != null)
            tx.close();
    }
}
 
Example 12
Source File: IgniteCacheConfigVariationsFullApiTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param concurrency Transaction concurrency.
 * @param isolation Transaction isolation.
 * @param incrProcessor Increment processor.
 * @param rmvProseccor Remove processor.
 */
private void checkInvoke(TransactionConcurrency concurrency, TransactionIsolation isolation,
    EntryProcessor<Object, Object, Object> incrProcessor,
    EntryProcessor<Object, Object, Object> rmvProseccor) {
    IgniteCache cache = jcache();

    final Object key1 = key(1);
    final Object key2 = key(2);
    final Object key3 = key(3);

    final Object val1 = value(1);
    final Object val2 = value(2);
    final Object val3 = value(3);

    cache.put(key2, val1);
    cache.put(key3, val3);

    Transaction tx = txShouldBeUsed() ? ignite(0).transactions().txStart(concurrency, isolation) : null;

    try {
        assertNull(cache.invoke(key1, incrProcessor, dataMode));
        assertEquals(val1, cache.invoke(key2, incrProcessor, dataMode));
        assertEquals(val3, cache.invoke(key3, rmvProseccor));

        if (tx != null)
            tx.commit();
    }
    catch (Exception e) {
        e.printStackTrace();

        throw e;
    }
    finally {
        if (tx != null)
            tx.close();
    }

    assertEquals(val1, cache.get(key1));
    assertEquals(val2, cache.get(key2));
    assertNull(cache.get(key3));

    for (int i = 0; i < gridCount(); i++)
        assertNull("Failed for cache: " + i, jcache(i).localPeek(key3, ONHEAP));

    cache.remove(key1);
    cache.put(key2, val1);
    cache.put(key3, val3);

    assertNull(cache.invoke(key1, incrProcessor, dataMode));
    assertEquals(val1, cache.invoke(key2, incrProcessor, dataMode));
    assertEquals(val3, cache.invoke(key3, rmvProseccor));

    assertEquals(val1, cache.get(key1));
    assertEquals(val2, cache.get(key2));
    assertNull(cache.get(key3));

    for (int i = 0; i < gridCount(); i++)
        assertNull(jcache(i).localPeek(key3, ONHEAP));
}
 
Example 13
Source File: GridCacheAbstractFullApiSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testGetAndPutIfAbsentAsyncOld() throws Exception {
    Transaction tx = txShouldBeUsed() ? transactions().txStart() : null;

    IgniteCache<String, Integer> cache = jcache();

    IgniteCache<String, Integer> cacheAsync = cache.withAsync();

    try {
        cacheAsync.getAndPutIfAbsent("key", 1);

        IgniteFuture<Integer> fut1 = cacheAsync.future();

        assertNull(fut1.get());
        assertEquals((Integer)1, cache.get("key"));

        cacheAsync.getAndPutIfAbsent("key", 2);

        IgniteFuture<Integer> fut2 = cacheAsync.future();

        assertEquals((Integer)1, fut2.get());
        assertEquals((Integer)1, cache.get("key"));

        if (tx != null)
            tx.commit();
    }
    finally {
        if (tx != null)
            tx.close();
    }

    // Check swap.
    cache.put("key2", 1);

    cache.localEvict(Collections.singleton("key2"));

    cacheAsync.getAndPutIfAbsent("key2", 3);

    assertEquals((Integer)1, cacheAsync.<Integer>future().get());

    // Check db.
    if (!isMultiJvm()) {
        storeStgy.putToStore("key3", 3);

        cacheAsync.getAndPutIfAbsent("key3", 4);

        assertEquals((Integer)3, cacheAsync.<Integer>future().get());
    }

    cache.localEvict(Collections.singleton("key2"));

    // Same checks inside tx.
    tx = txShouldBeUsed() ? transactions().txStart() : null;

    try {
        cacheAsync.getAndPutIfAbsent("key2", 3);

        assertEquals(1, cacheAsync.future().get());

        if (tx != null)
            tx.commit();

        assertEquals((Integer)1, cache.get("key2"));
    }
    finally {
        if (tx != null)
            tx.close();
    }
}
 
Example 14
Source File: GridCacheAbstractFullApiSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testGetAndPutIfAbsentAsync() throws Exception {
    Transaction tx = txShouldBeUsed() ? transactions().txStart() : null;

    IgniteCache<String, Integer> cache = jcache();

    try {
        IgniteFuture<Integer> fut1 = cache.getAndPutIfAbsentAsync("key", 1);

        assertNull(fut1.get());
        assertEquals((Integer)1, cache.get("key"));

        IgniteFuture<Integer> fut2 = cache.getAndPutIfAbsentAsync("key", 2);

        assertEquals((Integer)1, fut2.get());
        assertEquals((Integer)1, cache.get("key"));

        if (tx != null)
            tx.commit();
    }
    finally {
        if (tx != null)
            tx.close();
    }

    // Check swap.
    cache.put("key2", 1);

    cache.localEvict(Collections.singleton("key2"));

    assertEquals((Integer)1, cache.getAndPutIfAbsentAsync("key2", 3).get());

    // Check db.
    if (!isMultiJvm()) {
        storeStgy.putToStore("key3", 3);

        assertEquals((Integer)3, cache.getAndPutIfAbsentAsync("key3", 4).get());
    }

    cache.localEvict(Collections.singleton("key2"));

    // Same checks inside tx.
    tx = txShouldBeUsed() ? transactions().txStart() : null;

    try {
        assertEquals(1, (int)cache.getAndPutIfAbsentAsync("key2", 3).get());

        if (tx != null)
            tx.commit();

        assertEquals((Integer)1, cache.get("key2"));
    }
    finally {
        if (tx != null)
            tx.close();
    }
}
 
Example 15
Source File: GridCacheAbstractFullApiSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param concurrency Concurrency.
 * @param isolation Isolation.
 * @throws Exception If failed.
 */
private void checkIgniteTransform(TransactionConcurrency concurrency, TransactionIsolation isolation)
    throws Exception {
    IgniteCache<String, Integer> cache = jcache();

    cache.put("key2", 1);
    cache.put("key3", 3);

    Transaction tx = txShouldBeUsed() ? ignite(0).transactions().txStart(concurrency, isolation) : null;

    try {
        assertEquals("null", cache.invoke("key1", INCR_IGNITE_PROCESSOR));
        assertEquals("1", cache.invoke("key2", INCR_IGNITE_PROCESSOR));
        assertEquals("3", cache.invoke("key3", RMV_IGNITE_PROCESSOR));

        if (tx != null)
            tx.commit();
    }
    catch (Exception e) {
        e.printStackTrace();

        throw e;
    }
    finally {
        if (tx != null)
            tx.close();
    }

    assertEquals((Integer)1, cache.get("key1"));
    assertEquals((Integer)2, cache.get("key2"));
    assertNull(cache.get("key3"));

    for (int i = 0; i < gridCount(); i++)
        assertNull("Failed for cache: " + i, jcache(i).localPeek("key3", ONHEAP));

    cache.remove("key1");
    cache.put("key2", 1);
    cache.put("key3", 3);

    assertEquals("null", cache.invoke("key1", INCR_IGNITE_PROCESSOR));
    assertEquals("1", cache.invoke("key2", INCR_IGNITE_PROCESSOR));
    assertEquals("3", cache.invoke("key3", RMV_IGNITE_PROCESSOR));

    assertEquals((Integer)1, cache.get("key1"));
    assertEquals((Integer)2, cache.get("key2"));
    assertNull(cache.get("key3"));

    for (int i = 0; i < gridCount(); i++)
        assertNull(jcache(i).localPeek("key3", ONHEAP));
}
 
Example 16
Source File: GridCacheAbstractFullApiSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param concurrency Concurrency.
 * @param isolation Isolation.
 * @throws Exception If failed.
 */
private void checkTransform(TransactionConcurrency concurrency, TransactionIsolation isolation) throws Exception {
    IgniteCache<String, Integer> cache = jcache();

    cache.put("key2", 1);
    cache.put("key3", 3);

    Transaction tx = txShouldBeUsed() ? ignite(0).transactions().txStart(concurrency, isolation) : null;

    try {
        assertEquals("null", cache.invoke("key1", INCR_PROCESSOR));
        assertEquals("1", cache.invoke("key2", INCR_PROCESSOR));
        assertEquals("3", cache.invoke("key3", RMV_PROCESSOR));

        if (tx != null)
            tx.commit();
    }
    catch (Exception e) {
        e.printStackTrace();

        throw e;
    }
    finally {
        if (tx != null)
            tx.close();
    }

    assertEquals((Integer)1, cache.get("key1"));
    assertEquals((Integer)2, cache.get("key2"));
    assertNull(cache.get("key3"));

    for (int i = 0; i < gridCount(); i++)
        assertNull("Failed for cache: " + i, jcache(i).localPeek("key3", ONHEAP));

    cache.remove("key1");
    cache.put("key2", 1);
    cache.put("key3", 3);

    assertEquals("null", cache.invoke("key1", INCR_PROCESSOR));
    assertEquals("1", cache.invoke("key2", INCR_PROCESSOR));
    assertEquals("3", cache.invoke("key3", RMV_PROCESSOR));

    assertEquals((Integer)1, cache.get("key1"));
    assertEquals((Integer)2, cache.get("key2"));
    assertNull(cache.get("key3"));

    for (int i = 0; i < gridCount(); i++)
        assertNull(jcache(i).localPeek("key3", ONHEAP));
}
 
Example 17
Source File: GridCacheAbstractFullApiSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param startVal Whether to put value.
 * @param concurrency Concurrency.
 * @throws Exception If failed.
 */
private void checkTransformSequential0(boolean startVal, TransactionConcurrency concurrency)
    throws Exception {
    IgniteCache<String, Integer> cache = jcache();

    final String key = primaryKeysForCache(cache, 1).get(0);

    Transaction tx = txShouldBeUsed() ? ignite(0).transactions().txStart(concurrency, READ_COMMITTED) : null;

    try {
        if (startVal)
            cache.put(key, 2);
        else
            assertEquals(null, cache.get(key));

        Integer expRes = startVal ? 2 : null;

        assertEquals(String.valueOf(expRes), cache.invoke(key, INCR_PROCESSOR));

        expRes = startVal ? 3 : 1;

        assertEquals(String.valueOf(expRes), cache.invoke(key, INCR_PROCESSOR));

        expRes++;

        assertEquals(String.valueOf(expRes), cache.invoke(key, INCR_PROCESSOR));

        if (tx != null)
            tx.commit();
    }
    finally {
        if (tx != null)
            tx.close();
    }

    Integer exp = (startVal ? 2 : 0) + 3;

    assertEquals(exp, cache.get(key));

    for (int i = 0; i < gridCount(); i++) {
        if (ignite(i).affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(grid(i).localNode(), key))
            assertEquals(exp, peek(jcache(i), key));
    }
}
 
Example 18
Source File: GridCacheEmptyEntriesAbstractSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Checks that gets work for implicit txs.
 *
 * @param ignite Ignite instance.
 * @param cache Cache to test.
 * @throws Exception If failed.
 */
private void checkExplicitTx(Ignite ignite, IgniteCache<String, String> cache) throws Exception {
    Transaction tx = ignite.transactions().txStart();

    try {
        assertNull(cache.get("key1"));

        tx.commit();
    }
    finally {
        tx.close();
    }

    tx = ignite.transactions().txStart();

    try {
        assertNull(cache.getAsync("key2").get());

        tx.commit();
    }
    finally {
        tx.close();
    }

    tx = ignite.transactions().txStart();

    try {
        assertTrue(cache.getAll(F.asSet("key3", "key4")).isEmpty());

        tx.commit();
    }
    finally {
        tx.close();
    }

    tx = ignite.transactions().txStart();

    try {
        assertTrue(((Map)cache.getAllAsync(F.asSet("key5", "key6")).get()).isEmpty());

        tx.commit();
    }
    finally {
        tx.close();
    }

    tx = ignite.transactions().txStart();

    try {
        cache.put("key7", "key7");

        cache.remove("key7");

        assertNull(cache.get("key7"));

        tx.commit();
    }
    finally {
        tx.close();
    }

    checkEmpty(cache);
}
 
Example 19
Source File: GridCacheNearOneNodeSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** @throws Exception If failed. */
@Test
public void testTransactionSingleGetRemove() throws Exception {
    IgniteCache<Object, Object> cache = jcache();

    cache.put(1, "val1");

    assertEquals("val1", dhtPeek(1));
    assertNull(near().peekEx(1));

    Transaction tx = grid().transactions().txStart(PESSIMISTIC, REPEATABLE_READ);

    assertEquals("val1", cache.get(1));

    assertTrue(cache.remove(1));

    tx.commit();

    assertNull(dhtPeek(1));
    assertNull(near().peekEx(1));
}
 
Example 20
Source File: CacheStoreUsageMultinodeAbstractTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param cache Cache.
 * @param key Key.
 * @param tc Transaction concurrency mode.
 * @throws Exception If failed.
 */
protected void testStoreUpdate(IgniteCache<Object, Object> cache,
   Object key,
   @Nullable TransactionConcurrency tc)
    throws Exception
{
    boolean storeOnPrimary = atomicityMode() == ATOMIC || locStore || writeBehind;

    assertTrue(writeMap.isEmpty());

    Ignite ignite = cache.unwrap(Ignite.class);

    Affinity<Object> obj = ignite.affinity(cache.getName());

    ClusterNode node = obj.mapKeyToNode(key);

    assertNotNull(node);

    String expNode = storeOnPrimary ? (String)node.attribute(ATTR_IGNITE_INSTANCE_NAME) : ignite.name();

    assertNotNull(expNode);

    log.info("Put [node=" + ignite.name() +
        ", key=" + key +
        ", primary=" + node.attribute(ATTR_IGNITE_INSTANCE_NAME) +
        ", tx=" + tc +
        ", nearCache=" + (cache.getConfiguration(CacheConfiguration.class).getNearConfiguration() != null) +
        ", storeOnPrimary=" + storeOnPrimary + ']');

    Transaction tx = tc != null ? ignite.transactions().txStart(tc, REPEATABLE_READ) : null;

    try {
        cache.put(key, key);

        if (tx != null)
            tx.commit();
    }
    finally {
        if (tx != null)
            tx.close();
    }

    boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {
        @Override public boolean apply() {
            return !writeMap.isEmpty();
        }
    }, 1000);

    assertTrue("Store is not updated", wait);

    assertEquals("Write on wrong node: " + writeMap, locStore ? 2 : 1, writeMap.size());

    if (!locStore)
        assertEquals(expNode, writeMap.keySet().iterator().next());

    writeMap.clear();
}