Github user hsaputra commented on a diff in the pull request:
https://github.com/apache/incubator-twill/pull/52#discussion_r34409623
--- Diff:
twill-yarn/src/test/java/org/apache/twill/yarn/EchoServerTestRun.java ---
@@ -107,6 +112,30 @@ public void run() {
controller.changeInstances("EchoServer", 2);
Assert.assertTrue(waitForSize(echoServices, 2, 120));
+ // Test restart on instances for runnable
+
+ TimeUnit.SECONDS.sleep(6L);
--- End diff --
Something like:
```
ResourceReport resourceReport = waitForResourceReport(controller,
"EchoServer", 5L, TimeUnit.SECONDS, 2);
Collection<TwillRunResources> runResources =
resourceReport.getRunnableResources("EchoServer");
for (TwillRunResources twillRunResources : runResources) {
instanceIdToContainerId.put(twillRunResources.getInstanceId(),
twillRunResources.getContainerId());
}
controller.restartAllInstances("EchoServer");
Assert.assertTrue(waitForSize(echoServices, 2, 120));
// Need to sleep here since wait for size could still return the same
containers.
TimeUnit.SECONDS.sleep(3L);
resourceReport = waitForResourceReport(controller, "EchoServer", 5L,
TimeUnit.SECONDS, 2);
runResources = resourceReport.getRunnableResources("EchoServer");
for (TwillRunResources twillRunResources : runResources) {
int instanceId = twillRunResources.getInstanceId();
Assert.assertNotEquals(twillRunResources.getContainerId(),
instanceIdToContainerId.get(instanceId));
}
// Need helper method here to wait for getting resource report because
{@link TwillController#getResourceReport()}
// could return null if the application has not fully started.
private ResourceReport waitForResourceReport(TwillController controller,
String runnable,
long timeout, TimeUnit
timeoutUnit, int numOfResources) {
Stopwatch stopwatch = new Stopwatch();
stopwatch.start();
do {
ResourceReport report = controller.getResourceReport();
if (report == null || report.getRunnableResources(runnable) == null) {
continue;
} else if (report.getRunnableResources(runnable) != null &&
report.getRunnableResources(runnable).size() == numOfResources) {
return report;
}
Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
} while (stopwatch.elapsedTime(timeoutUnit) < timeout);
return null;
}
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---