Search in sources :

Example 6 with ClientTransaction

use of org.apache.ignite.client.ClientTransaction in project ignite by apache.

the class PerformanceStatisticsThinClientTest method checkTx.

/**
 * @param commited {@code True} if check transaction commited.
 */
private void checkTx(boolean commited) throws Exception {
    long startTime = U.currentTimeMillis();
    cleanPerformanceStatisticsDir();
    startCollectStatistics();
    try (ClientTransaction tx = thinClient.transactions().txStart()) {
        for (int i = 0; i < 10; i++) thinClient.cache(DEFAULT_CACHE_NAME).put(i, i * 2);
        if (commited)
            tx.commit();
        else
            tx.rollback();
    }
    AtomicInteger txs = new AtomicInteger();
    stopCollectStatisticsAndRead(new TestHandler() {

        @Override
        public void transaction(UUID nodeId, GridIntList cacheIds, long txStartTime, long duration, boolean txCommited) {
            txs.incrementAndGet();
            assertTrue(F.nodeIds(grid(0).cluster().forServers().nodes()).contains(nodeId));
            assertEquals(1, cacheIds.size());
            assertEquals(CU.cacheId(DEFAULT_CACHE_NAME), cacheIds.get(0));
            assertTrue(txStartTime >= startTime);
            assertTrue(duration >= 0);
            assertEquals(commited, txCommited);
        }
    });
    assertEquals(1, txs.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientTransaction(org.apache.ignite.client.ClientTransaction) UUID(java.util.UUID) GridIntList(org.apache.ignite.internal.util.GridIntList)

Example 7 with ClientTransaction

use of org.apache.ignite.client.ClientTransaction in project ignite by apache.

the class WrongQueryEntityFieldTypeTest method testPutFromThinClientTx.

/**
 */
@Test
public void testPutFromThinClientTx() throws Exception {
    if (mode == ATOMIC)
        return;
    withThinClient((cli, cache) -> {
        for (TransactionConcurrency conc : TransactionConcurrency.values()) {
            for (TransactionIsolation iso : TransactionIsolation.values()) {
                if (conc == OPTIMISTIC && mode == TRANSACTIONAL_SNAPSHOT)
                    continue;
                assertThrowsWithCause(() -> {
                    try (ClientTransaction tx = cli.transactions().txStart(conc, iso)) {
                        cache.put(1, val.get());
                        tx.commit();
                    }
                }, ClientException.class);
                assertNull(cache.withKeepBinary().get(1));
            }
        }
    });
}
Also used : TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) ClientTransaction(org.apache.ignite.client.ClientTransaction) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

ClientTransaction (org.apache.ignite.client.ClientTransaction)7 ClientCacheConfiguration (org.apache.ignite.client.ClientCacheConfiguration)3 ClientTransactions (org.apache.ignite.client.ClientTransactions)3 IgniteClient (org.apache.ignite.client.IgniteClient)3 ClientException (org.apache.ignite.client.ClientException)2 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)2 ClientTransactionConfiguration (org.apache.ignite.configuration.ClientTransactionConfiguration)2 ThinClientConfiguration (org.apache.ignite.configuration.ThinClientConfiguration)2 TransactionConcurrency (org.apache.ignite.transactions.TransactionConcurrency)2 TransactionIsolation (org.apache.ignite.transactions.TransactionIsolation)2 Test (org.junit.Test)2 Map (java.util.Map)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Ignite (org.apache.ignite.Ignite)1 IgniteException (org.apache.ignite.IgniteException)1 BinaryObject (org.apache.ignite.binary.BinaryObject)1