You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2021/04/28 08:10:26 UTC

[kudu] branch master updated: KUDU-2612: address TODOs in TestKuduTransaction

This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new 79c99ea  KUDU-2612: address TODOs in TestKuduTransaction
79c99ea is described below

commit 79c99ea20a5c978a91037a4e1540ea744a83725e
Author: Alexey Serbin <al...@apache.org>
AuthorDate: Wed Apr 28 00:00:14 2021 -0700

    KUDU-2612: address TODOs in TestKuduTransaction
    
    Change-Id: If76b7fb375528939e4af0c0d6e7fc7222109b70a
    Reviewed-on: http://gerrit.cloudera.org:8080/17355
    Reviewed-by: Andrew Wong <aw...@cloudera.com>
    Tested-by: Kudu Jenkins
---
 .../apache/kudu/client/TestKuduTransaction.java    | 66 ++++++++++++----------
 1 file changed, 35 insertions(+), 31 deletions(-)

diff --git a/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduTransaction.java b/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduTransaction.java
index 60ca48d..956bb68 100644
--- a/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduTransaction.java
+++ b/java/kudu-client/src/test/java/org/apache/kudu/client/TestKuduTransaction.java
@@ -234,14 +234,12 @@ public class TestKuduTransaction {
       "--txn_manager_enabled",
   })
   @TabletServerConfig(flags = {
-      "--txn_schedule_background_tasks=false"
+      "--txn_schedule_background_tasks=false",
+      "--txn_status_manager_inject_latency_finalize_commit_ms=1000",
   })
   public void testIsCommitComplete() throws Exception {
     KuduTransaction txn = client.newTransaction();
-
     txn.commit(false);
-    // TODO(aserbin): artificially delay the transaction's commit phase once
-    //                the transaction commit orchestration is implemented
     assertFalse(txn.isCommitComplete());
   }
 
@@ -305,34 +303,15 @@ public class TestKuduTransaction {
   }
 
   /**
-   * Test scenario that starts a new transaction and commits it in a synchronous
-   * way (i.e. waits for the transaction to be committed).
-   *
-   * TODO(aserbin): uncomment this once txn commit orchestration is ready
-  @Test(timeout = 100000)
-  @MasterServerConfig(flags = {
-      "--txn_manager_enabled",
-  })
-  public void testCommitAnEmptyTransactionWait() throws Exception {
-    KuduTransaction txn = client.newTransaction();
-    txn.commit(true);
-    assertTrue(txn.isCommitComplete());
-  }
-   */
-
-  /**
-   * A test scenario to start a new transaction and commit it in a synchronous
-   * way (i.e. wait for the transaction to be committed) when the back-end is
-   * running in the test-only mode to immediately finalize a transaction
-   * right after transitioning its state to COMMIT_IN_PROGRESS.
+   * Test scenario that starts a new empty transaction and commits it in a
+   * synchronous way (i.e. waits for the transaction to be committed).
    *
-   * TODO(aserbin): remove this scenario once txn commit orchestration is ready
    */
   @Test(timeout = 100000)
   @MasterServerConfig(flags = {
       "--txn_manager_enabled",
   })
-  public void testCommitAnEmptyTransactionWaitFake2PCO() throws Exception {
+  public void testCommitAnEmptyTransactionWait() throws Exception {
     KuduTransaction txn = client.newTransaction();
     txn.commit(true);
     assertTrue(txn.isCommitComplete());
@@ -394,18 +373,40 @@ public class TestKuduTransaction {
       "--txn_manager_enabled",
   })
   public void testNewTransactionalSession() throws Exception {
+    final String TABLE_NAME = "new_transactional_session";
+    client.createTable(
+        TABLE_NAME,
+        ClientTestUtil.getBasicSchema(),
+        new CreateTableOptions().addHashPartitions(ImmutableList.of("key"), 2));
+
     KuduTransaction txn = client.newTransaction();
     assertNotNull(txn);
     KuduSession session = txn.newKuduSession();
     assertNotNull(session);
-    // TODO(aserbin): insert a few rows and rollback the transaction; run a
-    //                table scan: the rows should not be there
+    session.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH);
+
+    KuduTable table = client.openTable(TABLE_NAME);
+    Insert insert = createBasicSchemaInsert(table, 1);
+    session.apply(insert);
+    session.flush();
+
+    // Rollback the transaction.
     txn.rollback();
+
+    assertFalse(session.isClosed());
+    assertEquals(0, session.countPendingErrors());
+
+    KuduScanner scanner = new KuduScanner.KuduScannerBuilder(asyncClient, table)
+        .readMode(AsyncKuduScanner.ReadMode.READ_YOUR_WRITES)
+        .build();
+    assertEquals(0, countRowsInScan(scanner));
   }
 
   /**
    * Test scenario that starts a transaction and creates a new transactional
-   * AsyncKuduSession based on the newly started transaction.
+   * AsyncKuduSession based on the newly started transaction. No rows are
+   * inserted: it should be possible to rollback the empty transaction with
+   * no errors reported.
    */
   @Test(timeout = 100000)
   @MasterServerConfig(flags = {
@@ -416,9 +417,12 @@ public class TestKuduTransaction {
     assertNotNull(txn);
     AsyncKuduSession session = txn.newAsyncKuduSession();
     assertNotNull(session);
-    // TODO(aserbin): insert a few rows and rollback the transaction; run a
-    //                table scan: the rows should not be there
+
+    // Rollback the empty transaction.
     txn.rollback();
+
+    assertFalse(session.isClosed());
+    assertEquals(0, session.countPendingErrors());
   }
 
   /**