Montura commented on code in PR #7134:
URL: https://github.com/apache/ozone/pull/7134#discussion_r1742356485
##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/balancer/TestContainerBalancerStatusInfo.java:
##########
@@ -55,4 +57,30 @@ void testGetIterationStatistics() {
});
}
+
+ /**
+ * @see <a
href="https://issues.apache.org/jira/browse/HDDS-11350">HDDS-11350</a>
+ */
+ @Test
+ void
testGetCurrentIterationsStatisticDoesNotThrowNullPointerExceptionWhenBalancingThreadIsSleeping()
{
+ MockedSCM mockedScm = new MockedSCM(new TestableCluster(10,
OzoneConsts.GB));
+ OzoneConfiguration ozoneConfig = new OzoneConfiguration();
+ ContainerBalancerConfiguration config =
ozoneConfig.getObject(ContainerBalancerConfiguration.class);
+
+ config.setIterations(2);
+ // the following config makes the balancing thread go to sleep while
waiting for DU to be triggered in DNs and
+ // updated storage reports to arrive via DN heartbeats - of course, this
is a unit test and NodeManager, DNs etc.
+ // are all mocked
+ config.setTriggerDuEnable(true);
+ mockedScm.init(config, ozoneConfig);
+
+ // run ContainerBalancerTask in a new thread and have the current thread
call getCurrentIterationsStatistic
+ StorageContainerManager scm = mockedScm.getStorageContainerManager();
Review Comment:
Then this part could be rewritten as following:
```
ContainerBalancerTask task = mockedScm.createBalancerTask(config);
Thread thread = new Thread(task);
thread.setDaemon(true);
thread.start();
Assertions.assertDoesNotThrow(task::getCurrentIterationsStatistic);
```
--
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]