umustafi commented on code in PR #3721:
URL: https://github.com/apache/gobblin/pull/3721#discussion_r1274213535


##########
gobblin-runtime/src/test/java/org/apache/gobblin/runtime/api/MysqlMultiActiveLeaseArbiterTest.java:
##########
@@ -143,4 +159,128 @@ public void testAcquireLeaseSingleParticipant() throws 
Exception {
     Assert.assertTrue(sixthObtainedStatus.getEventTimestamp()
         <= sixthObtainedStatus.getLeaseAcquisitionTimestamp());
   }
+
+  /*
+     Tests CONDITIONALLY_ACQUIRE_LEASE_IF_NEW_ROW_STATEMENT to ensure an 
insertion is not attempted unless the table
+     state remains the same as the prior read, which expects no row matching 
the primary key in the table
+     Note: this isolates and tests CASE 1 in which another participant could 
have acquired the lease between the time
+     the read was done and subsequent write was carried out
+  */
+  @Test //(dependsOnMethods = "testAcquireLeaseSingleParticipant")
+  public void testConditionallyAcquireLeaseIfNewRow() throws IOException {
+    // Inserting the first time should update 1 row
+    int numRowsUpdated = 
this.mysqlMultiActiveLeaseArbiter.withPreparedStatement(formattedAcquireLeaseNewRowStatement,
+        insertStatement -> {
+          completeInsertPreparedStatement(insertStatement, resumeDagAction);
+          return insertStatement.executeUpdate();
+        }, true);
+    Assert.assertEquals(numRowsUpdated, 1);

Review Comment:
   Here I want to test cases of trying to acquire a lease after processing the 
result of the initial GET query where we find that either no such lease exists 
in the store, lease has expired, or lease was completed for a distinct event, 
where another participant has altered the table state before the current 
participant tries the insert. The public API tested here is `tryAcquireLease` 
called by multiple participants at once but I'm isolating the behavior I want 
to test by verifying the INSERTION SQL statements execute only if table state 
has not changed from the initial read. Does that make sense? 



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to