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

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


The following commit(s) were added to refs/heads/master by this push:
     new ecc7d5f17c HDDS-8925. BaseFreonGenerator may not complete if last 
attempts fail (#4975)
ecc7d5f17c is described below

commit ecc7d5f17c504ee2df41a6f64cf60b4474505ad0
Author: Doroszlai, Attila <[email protected]>
AuthorDate: Tue Jun 27 07:07:22 2023 +0200

    HDDS-8925. BaseFreonGenerator may not complete if last attempts fail (#4975)
---
 .../hadoop/ozone/freon/TestRandomKeyGenerator.java | 35 +++++++++++++++-------
 .../hadoop/ozone/freon/BaseFreonGenerator.java     | 26 ++++++++++++----
 .../freon/FollowerAppendLogEntryGenerator.java     |  2 +-
 3 files changed, 46 insertions(+), 17 deletions(-)

diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/freon/TestRandomKeyGenerator.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/freon/TestRandomKeyGenerator.java
index 5e96bf1dd6..466dfc6e5c 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/freon/TestRandomKeyGenerator.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/freon/TestRandomKeyGenerator.java
@@ -30,8 +30,13 @@ import org.junit.Assert;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
 import picocli.CommandLine;
 
+import static org.apache.ozone.test.GenericTestUtils.waitFor;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
 /**
  * Tests Freon, with MiniOzoneCluster.
  */
@@ -40,14 +45,8 @@ public class TestRandomKeyGenerator {
   private static MiniOzoneCluster cluster;
   private static OzoneConfiguration conf;
 
-  /**
-   * Create a MiniDFSCluster for testing.
-   * <p>
-   * Ozone is made active by setting OZONE_ENABLED = true
-   *
-   */
   @BeforeAll
-  public static void init() throws Exception {
+  static void init() throws Exception {
     conf = new OzoneConfiguration();
     DatanodeRatisServerConfig ratisServerConfig =
         conf.getObject(DatanodeRatisServerConfig.class);
@@ -65,16 +64,30 @@ public class TestRandomKeyGenerator {
     cluster.waitForClusterToBeReady();
   }
 
-  /**
-   * Shutdown MiniDFSCluster.
-   */
   @AfterAll
-  public static void shutdown() {
+  static void shutdown() {
     if (cluster != null) {
       cluster.shutdown();
     }
   }
 
+  @Test
+  @Timeout(5)
+  void singleFailedAttempt() {
+    BaseFreonGenerator subject = new BaseFreonGenerator();
+    subject.setThreadNo(2);
+    subject.setTestNo(1);
+    subject.init();
+
+    assertThrows(RuntimeException.class, () -> subject.runTests(
+        n -> {
+          waitFor(subject::isCompleted, 100, 3000);
+          throw new RuntimeException("fail");
+        }
+    ));
+    assertEquals(1, subject.getFailureCount());
+  }
+
   @Test
   void testDefault() {
     RandomKeyGenerator randomKeyGenerator =
diff --git 
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/BaseFreonGenerator.java
 
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/BaseFreonGenerator.java
index 35e753b41d..8afe064299 100644
--- 
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/BaseFreonGenerator.java
+++ 
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/BaseFreonGenerator.java
@@ -97,7 +97,7 @@ public class BaseFreonGenerator {
   @Option(names = {"-t", "--threads", "--thread"},
       description = "Number of threads used to execute",
       defaultValue = "10")
-  private int threadNo;
+  private int threadNo = 10;
 
   @Option(names = {"--duration"},
       description = "Duration to run the test. "
@@ -245,7 +245,7 @@ public class BaseFreonGenerator {
   }
 
   private void shutdown() {
-    if (failureCounter.get() > 0) {
+    if (!failAtEnd) {
       progressBar.terminate();
     } else {
       progressBar.shutdown();
@@ -273,6 +273,10 @@ public class BaseFreonGenerator {
    * Initialize internal counters, and variables. Call it before runTests.
    */
   public void init() {
+    // run outside of picocli, e.g. unit tests
+    if (freonCommand == null) {
+      freonCommand = new Freon();
+    }
 
     freonCommand.startHttpServer();
 
@@ -329,7 +333,7 @@ public class BaseFreonGenerator {
           Instant.ofEpochMilli(startTime), Instant.now()).getSeconds();
     } else {
       maxValue = testNo;
-      supplier = successCounter::get;
+      supplier = () -> successCounter.get() + failureCounter.get();
     }
     progressBar = new ProgressBar(System.out, maxValue, supplier,
         freonCommand.isInteractive(), realTimeStatusSupplier());
@@ -557,8 +561,20 @@ public class BaseFreonGenerator {
     void executeNextTask(long step) throws Exception;
   }
 
-  public AtomicLong getAttemptCounter() {
-    return attemptCounter;
+  public long getAttemptCount() {
+    return attemptCounter.get();
+  }
+
+  public long getSuccessCount() {
+    return successCounter.get();
+  }
+
+  public long getFailureCount() {
+    return failureCounter.get();
+  }
+
+  public boolean isCompleted() {
+    return completed.get();
   }
 
   public int getThreadNo() {
diff --git 
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/FollowerAppendLogEntryGenerator.java
 
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/FollowerAppendLogEntryGenerator.java
index f1f43f5c53..d76081fd29 100644
--- 
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/FollowerAppendLogEntryGenerator.java
+++ 
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/FollowerAppendLogEntryGenerator.java
@@ -363,7 +363,7 @@ public class FollowerAppendLogEntryGenerator extends 
BaseAppendLogGenerator
     }
     long lastCommit = reply.getFollowerCommit();
     if (lastCommit % 1000 == 0) {
-      long currentIndex = getAttemptCounter().get();
+      long currentIndex = getAttemptCount();
       if (currentIndex - lastCommit > batching * 3) {
         LOG.warn(
             "Last committed index ({}) is behind the current index ({}) on "


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to