navinko commented on code in PR #11275:
URL: https://github.com/apache/ozone/pull/11275#discussion_r4061500528
##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/balancer/TestContainerBalancer.java:
##########
@@ -459,6 +460,59 @@ public void testRejectInvalidStartupConfiguration() throws
Exception {
assertSame(ContainerBalancerTask.Status.STOPPED,
containerBalancer.getBalancerStatus());
}
+ /**
+ * Verifies that a start request rejected during validation does not update
startedAt of last run.
+ * Prevents startedAt from advancing past stoppedAt, which previously caused
a negative duration and CLI status crash.
+ */
+ @Test
+ public void testRejectedStartDoesNotModifyStartedAt() throws Exception {
+ // The test first starts and immediately stops the balancer normally.This
creates a realistic "previous state"
+ // in system memory and later trigger a bad request and verify that
startedAt remains identical to startedAtBefore,
+ // rather than being wrongly overwritten with "now", which would make
startedAt come after stoppedAt which resulted
+ // negative balancing duration.
+ startBalancer(balancerConfiguration);
+ assertSame(ContainerBalancerTask.Status.RUNNING,
containerBalancer.getBalancerStatus());
+ stopBalancer();
+ assertSame(ContainerBalancerTask.Status.STOPPED,
containerBalancer.getBalancerStatus());
+
+ ContainerBalancerStatusInfo before =
containerBalancer.getBalancerStatusInfo();
+ assertNotNull(before);
+ OffsetDateTime startedAtBefore = before.getStartedAt();
+ OffsetDateTime stoppedAt = before.getStoppedAt();
+ assertNotNull(startedAtBefore);
+ assertNotNull(stoppedAt);
+
+ // Pause so that system time advances before the second start attempt so a
timestamp overwrite becomes measurable.
+ Thread.sleep(20);
+
+ // A start that is rejected during validation. Here we used an invalid
config this is just one of many rejection
+ // paths (safe mode, non-leader SCM, already running, etc.).
+ OzoneConfiguration invalidConf = new OzoneConfiguration();
Review Comment:
Thank you! Ah i missed reusing the existing pattern, updated now.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]