[ 
https://issues.apache.org/jira/browse/GOBBLIN-1851?focusedWorklogId=871621&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-871621
 ]

ASF GitHub Bot logged work on GOBBLIN-1851:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 18/Jul/23 19:43
            Start Date: 18/Jul/23 19:43
    Worklog Time Spent: 10m 
      Work Description: umustafi commented on code in PR #3715:
URL: https://github.com/apache/gobblin/pull/3715#discussion_r1267238091


##########
gobblin-runtime/src/test/java/org/apache/gobblin/runtime/api/MysqlMultiActiveLeaseArbiterTest.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gobblin.runtime.api;
+
+import com.typesafe.config.Config;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.gobblin.config.ConfigBuilder;
+import org.apache.gobblin.configuration.ConfigurationKeys;
+import org.apache.gobblin.metastore.testing.ITestMetastoreDatabase;
+import org.apache.gobblin.metastore.testing.TestMetastoreDatabaseFactory;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+@Slf4j
+public class MysqlMultiActiveLeaseArbiterTest {
+  private static final int EPSILON = 30000;
+  private static final int LINGER = 80000;
+  private static final String USER = "testUser";
+  private static final String PASSWORD = "testPassword";
+  private static final String TABLE = "mysql_multi_active_lease_arbiter_store";
+  private static final String flowGroup = "testFlowGroup";
+  private static final String flowName = "testFlowName";
+  private static final String flowExecutionId = "12345677";
+  private static DagActionStore.DagAction launchDagAction =
+      new DagActionStore.DagAction(flowGroup, flowName, flowExecutionId, 
DagActionStore.FlowActionType.LAUNCH);
+
+  private static final long eventTimeMillis = System.currentTimeMillis();
+  private MysqlMultiActiveLeaseArbiter mysqlMultiActiveLeaseArbiter;
+
+  // The setup functionality verifies that the initialization of the tables is 
done correctly and verifies any SQL
+  // syntax errors.
+  @BeforeClass
+  public void setUp() throws Exception {
+    ITestMetastoreDatabase testDb = TestMetastoreDatabaseFactory.get();
+
+    Config config = ConfigBuilder.create()
+        .addPrimitive(ConfigurationKeys.MYSQL_LEASE_ARBITER_PREFIX + "." + 
ConfigurationKeys.SCHEDULER_EVENT_EPSILON_MILLIS_KEY, EPSILON)
+        .addPrimitive(ConfigurationKeys.MYSQL_LEASE_ARBITER_PREFIX + "." + 
ConfigurationKeys.SCHEDULER_EVENT_LINGER_MILLIS_KEY, LINGER)
+        .addPrimitive(ConfigurationKeys.MYSQL_LEASE_ARBITER_PREFIX + "." + 
ConfigurationKeys.STATE_STORE_DB_URL_KEY, testDb.getJdbcUrl())
+        .addPrimitive(ConfigurationKeys.MYSQL_LEASE_ARBITER_PREFIX + "." + 
ConfigurationKeys.STATE_STORE_DB_USER_KEY, USER)
+        .addPrimitive(ConfigurationKeys.MYSQL_LEASE_ARBITER_PREFIX + "." + 
ConfigurationKeys.STATE_STORE_DB_PASSWORD_KEY, PASSWORD)
+        .addPrimitive(ConfigurationKeys.MYSQL_LEASE_ARBITER_PREFIX + "." + 
ConfigurationKeys.STATE_STORE_DB_TABLE_KEY, TABLE)
+        .build();
+
+    this.mysqlMultiActiveLeaseArbiter = new 
MysqlMultiActiveLeaseArbiter(config);
+  }
+
+  /*
+     Tests all cases of trying to acquire a lease (CASES 1-6 detailed below) 
for a flow action event with one
+     participant involved.
+  */
+  @Test
+  public void testAcquireLeaseSingleParticipant() throws Exception {
+    // Tests CASE 1 of acquire lease for a flow action event not present in DB
+    MultiActiveLeaseArbiter.LeaseAttemptStatus firstLaunchStatus =
+        mysqlMultiActiveLeaseArbiter.tryAcquireLease(launchDagAction, 
eventTimeMillis);
+    Assert.assertTrue(firstLaunchStatus instanceof 
MultiActiveLeaseArbiter.LeaseObtainedStatus);
+    MultiActiveLeaseArbiter.LeaseObtainedStatus firstObtainedStatus =
+        (MultiActiveLeaseArbiter.LeaseObtainedStatus) firstLaunchStatus;
+    Assert.assertTrue(firstObtainedStatus.getEventTimestamp() <=
+        firstObtainedStatus.getLeaseAcquisitionTimestamp());
+    Assert.assertTrue(firstObtainedStatus.getFlowAction().equals(
+        new DagActionStore.DagAction(flowGroup, flowName, flowExecutionId, 
DagActionStore.FlowActionType.LAUNCH)));
+
+    // Verify that different DagAction types for the same flow can have leases 
at the same time
+    DagActionStore.DagAction killDagAction = new
+        DagActionStore.DagAction(flowGroup, flowName, flowExecutionId, 
DagActionStore.FlowActionType.KILL);
+    MultiActiveLeaseArbiter.LeaseAttemptStatus killStatus =
+        mysqlMultiActiveLeaseArbiter.tryAcquireLease(killDagAction, 
eventTimeMillis);
+    Assert.assertTrue(killStatus instanceof 
MultiActiveLeaseArbiter.LeaseObtainedStatus);
+    MultiActiveLeaseArbiter.LeaseObtainedStatus killObtainedStatus =
+        (MultiActiveLeaseArbiter.LeaseObtainedStatus) killStatus;
+    Assert.assertTrue(
+        killObtainedStatus.getLeaseAcquisitionTimestamp() >= 
killObtainedStatus.getEventTimestamp());
+
+    // Tests CASE 2 of acquire lease for a flow action event that already has 
a valid lease for the same event in db

Review Comment:
   I initially tried to make it separate tests but it was easier to write this 
way since a lot of them related to one another. For now my priority is to get 
this tested and merged. I'll add a TODO to refactor it in the future. 





Issue Time Tracking
-------------------

    Worklog Id:     (was: 871621)
    Time Spent: 1h 50m  (was: 1h 40m)

> Unit Testing of Multi-active Algorithm
> --------------------------------------
>
>                 Key: GOBBLIN-1851
>                 URL: https://issues.apache.org/jira/browse/GOBBLIN-1851
>             Project: Apache Gobblin
>          Issue Type: Bug
>          Components: gobblin-service
>            Reporter: Urmi Mustafi
>            Assignee: Abhishek Tiwari
>            Priority: Major
>          Time Spent: 1h 50m
>  Remaining Estimate: 0h
>
> Tests all cases of trying to acquire a lease for a flow action event with one 
> participant involved and makes corresponding fixes in the 
> `MultiActiveLeaseArbiter`. 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to