You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2020/06/22 11:50:46 UTC

[GitHub] [ignite] ivandasch commented on a change in pull request #7951: IGNITE-13170 Java thin client: Fix transactions "withLabel"

ivandasch commented on a change in pull request #7951:
URL: https://github.com/apache/ignite/pull/7951#discussion_r443500791



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpClientTransactions.java
##########
@@ -143,6 +137,48 @@ TcpClientTransaction tx() {
         return tx0 == null || tx0.isClosed() ? null : tx0;
     }
 
+    /**
+     * Transactions "withLabel" facade
+     */
+    private class ClientTransactionsWithLabel implements ClientTransactions {
+        /** Transaction label. */
+        private final String lb;
+
+        /**
+         * @param lb Label.

Review comment:
       May be better `@param lb Transaction's label.`?

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpClientTransactions.java
##########
@@ -143,6 +137,48 @@ TcpClientTransaction tx() {
         return tx0 == null || tx0.isClosed() ? null : tx0;
     }
 
+    /**
+     * Transactions "withLabel" facade

Review comment:
       Missing dot at the end.

##########
File path: modules/core/src/test/java/org/apache/ignite/client/FunctionalTest.java
##########
@@ -951,6 +955,105 @@ public void testTransactions() throws Exception {
         }
     }
 
+    /**
+     * 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");
+
+                Thread t = new Thread(() -> {

Review comment:
       May be better `org.apache.ignite.testframework.junits.GridAbstractTest#multithreaded(Callable<?> c, int threadNum)` ?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org