Search in sources :

Example 1 with TXS_MON_LIST

use of org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager.TXS_MON_LIST in project ignite by apache.

the class FunctionalTest method testTransactionsWithLabel.

/**
 * Test transactions with label.
 */
@Test
public void testTransactionsWithLabel() throws Exception {
    try (IgniteEx ignite = (IgniteEx) Ignition.start(Config.getServerConfiguration());
        IgniteClient client = Ignition.startClient(getClientConfiguration())) {
        ClientCache<Integer, String> cache = client.createCache(new ClientCacheConfiguration().setName("cache").setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL));
        SystemView<TransactionView> txsView = ignite.context().systemView().view(TXS_MON_LIST);
        cache.put(0, "value1");
        try (ClientTransaction tx = client.transactions().withLabel("label").txStart()) {
            cache.put(0, "value2");
            assertEquals(1, F.size(txsView.iterator()));
            TransactionView txv = txsView.iterator().next();
            assertEquals("label", txv.label());
            assertEquals("value2", cache.get(0));
        }
        assertEquals("value1", cache.get(0));
        try (ClientTransaction tx = client.transactions().withLabel("label1").withLabel("label2").txStart()) {
            cache.put(0, "value2");
            assertEquals(1, F.size(txsView.iterator()));
            TransactionView txv = txsView.iterator().next();
            assertEquals("label2", txv.label());
            tx.commit();
        }
        assertEquals("value2", cache.get(0));
        // Test concurrent with label and without label transactions.
        try (ClientTransaction tx = client.transactions().withLabel("label").txStart(PESSIMISTIC, READ_COMMITTED)) {
            CyclicBarrier barrier = new CyclicBarrier(2);
            cache.put(0, "value3");
            IgniteInternalFuture<?> fut = GridTestUtils.runAsync(() -> {
                try (ClientTransaction tx1 = client.transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
                    cache.put(1, "value3");
                    barrier.await();
                    assertEquals("value2", cache.get(0));
                    barrier.await();
                } catch (InterruptedException | BrokenBarrierException ignore) {
                // No-op.
                }
            });
            barrier.await();
            assertNull(cache.get(1));
            assertEquals(1, F.size(txsView.iterator(), txv -> txv.label() == null));
            assertEquals(1, F.size(txsView.iterator(), txv -> "label".equals(txv.label())));
            barrier.await();
            fut.get();
        }
        // Test nested transactions is not possible.
        try (ClientTransaction tx = client.transactions().withLabel("label1").txStart()) {
            try (ClientTransaction tx1 = client.transactions().txStart()) {
                fail();
            } catch (ClientException expected) {
            // No-op.
            }
            try (ClientTransaction tx1 = client.transactions().withLabel("label2").txStart()) {
                fail();
            } catch (ClientException expected) {
            // No-op.
            }
        }
    }
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ModifiedExpiryPolicy(javax.cache.expiry.ModifiedExpiryPolicy) BinaryObject(org.apache.ignite.binary.BinaryObject) Arrays(java.util.Arrays) AbstractBinaryArraysTest(org.apache.ignite.internal.binary.AbstractBinaryArraysTest) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) Date(java.util.Date) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) TestEnum(org.apache.ignite.internal.processors.cache.CacheEnumOperationsAbstractTest.TestEnum) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) AccessedExpiryPolicy(javax.cache.expiry.AccessedExpiryPolicy) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) GridTestUtils.runAsync(org.apache.ignite.testframework.GridTestUtils.runAsync) VAL3(org.apache.ignite.internal.processors.cache.CacheEnumOperationsAbstractTest.TestEnum.VAL3) VAL1(org.apache.ignite.internal.processors.cache.CacheEnumOperationsAbstractTest.TestEnum.VAL1) VAL2(org.apache.ignite.internal.processors.cache.CacheEnumOperationsAbstractTest.TestEnum.VAL2) Map(java.util.Map) QueryEntity(org.apache.ignite.cache.QueryEntity) ClientStatus(org.apache.ignite.internal.processors.platform.client.ClientStatus) GridTestUtils.assertThrowsAnyCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsAnyCause) CyclicBarrier(java.util.concurrent.CyclicBarrier) ImmutableSet(com.google.common.collect.ImmutableSet) CachePeekMode(org.apache.ignite.cache.CachePeekMode) SystemView(org.apache.ignite.spi.systemview.view.SystemView) TransactionView(org.apache.ignite.spi.systemview.view.TransactionView) Set(java.util.Set) OPTIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC) READ_COMMITTED(org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED) ClientListenerProcessor(org.apache.ignite.internal.processors.odbc.ClientListenerProcessor) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Stream(java.util.stream.Stream) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) IntStream(java.util.stream.IntStream) TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) ClientServerError(org.apache.ignite.internal.client.thin.ClientServerError) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) PartitionLossPolicy(org.apache.ignite.cache.PartitionLossPolicy) PlatformExpiryPolicy(org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicy) ClientProcessorMXBean(org.apache.ignite.mxbean.ClientProcessorMXBean) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Timeout(org.junit.rules.Timeout) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) LinkedList(java.util.LinkedList) SimpleEntry(java.util.AbstractMap.SimpleEntry) Duration(javax.cache.expiry.Duration) F(org.apache.ignite.internal.util.typedef.F) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) Iterator(java.util.Iterator) TXS_MON_LIST(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager.TXS_MON_LIST) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) T2(org.apache.ignite.internal.util.typedef.T2) TimeUnit(java.util.concurrent.TimeUnit) Ignition(org.apache.ignite.Ignition) Rule(org.junit.Rule) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Collections(java.util.Collections) QueryIndex(org.apache.ignite.cache.QueryIndex) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) CacheMode(org.apache.ignite.cache.CacheMode) ClientConnectorConfiguration(org.apache.ignite.configuration.ClientConnectorConfiguration) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) CyclicBarrier(java.util.concurrent.CyclicBarrier) IgniteEx(org.apache.ignite.internal.IgniteEx) TransactionView(org.apache.ignite.spi.systemview.view.TransactionView) AbstractBinaryArraysTest(org.apache.ignite.internal.binary.AbstractBinaryArraysTest) Test(org.junit.Test)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 UUID (java.util.UUID)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 TimeUnit (java.util.concurrent.TimeUnit)1