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

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

                Author: ASF GitHub Bot
            Created on: 24/Sep/24 18:23
            Start Date: 24/Sep/24 18:23
    Worklog Time Spent: 10m 
      Work Description: khandelwal-prateek commented on code in PR #4059:
URL: https://github.com/apache/gobblin/pull/4059#discussion_r1773794344


##########
gobblin-temporal/src/test/java/org/apache/gobblin/temporal/ddm/workflow/impl/AbstractNestingExecWorkflowImplTest.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.temporal.ddm.workflow.impl;

Review Comment:
   update package to `org.apache.gobblin.temporal.util.nesting.workflow`



##########
gobblin-temporal/src/main/java/org/apache/gobblin/temporal/util/nesting/workflow/AbstractNestingExecWorkflowImpl.java:
##########
@@ -130,11 +134,9 @@ protected Duration 
calcPauseDurationBeforeCreatingSubTree(int numDirectLeavesChi
    *     List<Integer> naiveUniformity = 
Collections.nCopies(numSubTreesPerSubTree, numSubTreeChildren);
    * @return each sub-tree's desired size, in ascending sub-tree order
    */
-  protected static List<Integer> consolidateSubTreeGrandChildren(
-      final int numSubTreesPerSubTree,
-      final int numChildrenTotal,
-      final int numSubTreeChildren
-  ) {
+  @VisibleForTesting
+  public static List<Integer> consolidateSubTreeGrandChildren(final int 
numSubTreesPerSubTree,

Review Comment:
   I understand that you added `@VisibleForTesting` and changed modifier to 
public for testing this method. However, this change is not required if we 
follow the same package structure for the test class and we can access 
protected methods without exposing them publicly. We can revert the modifier 
change and place the test class in the same package instead.



##########
gobblin-temporal/src/test/java/org/apache/gobblin/temporal/ddm/workflow/impl/AbstractNestingExecWorkflowImplTest.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.temporal.ddm.workflow.impl;
+
+import java.time.Duration;
+import java.util.List;
+import java.util.Optional;
+
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import io.temporal.workflow.Async;
+import io.temporal.workflow.Promise;
+import io.temporal.workflow.Workflow;
+
+import org.apache.gobblin.temporal.util.nesting.work.WorkflowAddr;
+import org.apache.gobblin.temporal.util.nesting.work.Workload;
+import 
org.apache.gobblin.temporal.util.nesting.workflow.AbstractNestingExecWorkflowImpl;
+
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(Workflow.class)
+public class AbstractNestingExecWorkflowImplTest {
+
+  @Mock
+  private Workload<String> mockWorkload;
+
+  @Mock
+  private WorkflowAddr mockWorkflowAddr;
+
+  @Mock
+  private Workload.WorkSpan<String> mockWorkSpan;
+
+  @Mock
+  private Promise<Object> mockPromise;
+
+  private AbstractNestingExecWorkflowImpl<String, Object> workflow;
+
+  @BeforeClass
+  public void setup() {
+    // PowerMockito is required to mock static methods in the Workflow class
+    Mockito.mockStatic(Workflow.class);
+    Mockito.mockStatic(Async.class);
+    Mockito.mockStatic(Promise.class);
+    this.mockWorkload = Mockito.mock(Workload.class);
+    this.mockWorkflowAddr = Mockito.mock(WorkflowAddr.class);
+    this.mockWorkSpan = Mockito.mock(Workload.WorkSpan.class);
+    this.mockPromise = Mockito.mock(Promise.class);
+
+    workflow = new AbstractNestingExecWorkflowImpl<String, Object>() {
+      @Override
+      protected Promise<Object> launchAsyncActivity(String task) {
+        return mockPromise;
+      }
+    };
+  }
+
+  @Test
+  public void testPerformWorkload_NoWorkSpan() {
+    // Arrange
+    Mockito.when(mockWorkload.getSpan(Mockito.anyInt(), 
Mockito.anyInt())).thenReturn(Optional.empty());
+
+    // Act
+    int result = workflow.performWorkload(mockWorkflowAddr, mockWorkload, 0, 
10, 5, Optional.empty());
+
+    // Assert
+    Assert.assertEquals(0, result);
+    Mockito.verify(mockWorkload, Mockito.times(2)).getSpan(0, 5);
+  }
+
+  @Test
+  public void testCalcPauseDurationBeforeCreatingSubTree_NoPause() {
+    // Act
+    Duration result = workflow.calcPauseDurationBeforeCreatingSubTree(50);
+
+    // Assert
+    Assert.assertEquals(Duration.ZERO, result);
+  }
+
+  @Test
+  public void testCalcPauseDurationBeforeCreatingSubTree_PauseRequired() {
+    // Act
+    Duration result = workflow.calcPauseDurationBeforeCreatingSubTree(150);
+
+    // Assert
+    Assert.assertEquals(
+        
Duration.ofSeconds(AbstractNestingExecWorkflowImpl.NUM_SECONDS_TO_PAUSE_BEFORE_CREATING_SUB_TREE_DEFAULT),
+        result);
+  }
+
+  @Test
+  public void testConsolidateSubTreeGrandChildren() {
+    // Act
+    List<Integer> result = 
AbstractNestingExecWorkflowImpl.consolidateSubTreeGrandChildren(3, 10, 2);
+
+    // Assert
+    Assert.assertEquals(3, result.size());
+    Assert.assertEquals(Integer.valueOf(0), result.get(0));
+    Assert.assertEquals(Integer.valueOf(0), result.get(1));
+    Assert.assertEquals(Integer.valueOf(6), result.get(2));
+  }
+
+  @Test(expectedExceptions = AssertionError.class)
+  public void testPerformWorkload_LaunchesChildWorkflows() {

Review Comment:
   I see you've covered some scenarios, like handling an empty WorkSpan and 
testing the pause duration. However, the current tests don't fully capture the 
functionality(creating child workflows, subtrees handling, result calculation 
and edge cases) of the performWorkload method. It would be useful to add 
overall coverage for a method when we are adding tests for it, this ensures 
that the tests fulfill the original intent of thoroughly validating the 
behavior of missing tests. This would also help avoid the need for additional 
work on this method again later, unless we are making changes to it.





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

    Worklog Id:     (was: 936191)
    Time Spent: 20m  (was: 10m)

> Unit tests for Gobblin Temporal Module
> --------------------------------------
>
>                 Key: GOBBLIN-2160
>                 URL: https://issues.apache.org/jira/browse/GOBBLIN-2160
>             Project: Apache Gobblin
>          Issue Type: Improvement
>            Reporter: Aditya Pratap Singh
>            Priority: Minor
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> Unit tests for Gobblin Temporal Module



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

Reply via email to