use of org.apache.twill.discovery.DiscoveryServiceClient in project cdap by caskdata.
the class AppFabricServerTest method startStopServer.
@Test
public void startStopServer() throws Exception {
Injector injector = AppFabricTestHelper.getInjector();
AppFabricServer server = injector.getInstance(AppFabricServer.class);
DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
Service.State state = server.startAndWait();
Assert.assertTrue(state == Service.State.RUNNING);
final EndpointStrategy endpointStrategy = new RandomEndpointStrategy(discoveryServiceClient.discover(Constants.Service.APP_FABRIC_HTTP));
Assert.assertNotNull(endpointStrategy.pick(5, TimeUnit.SECONDS));
state = server.stopAndWait();
Assert.assertTrue(state == Service.State.TERMINATED);
Tasks.waitFor(true, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return endpointStrategy.pick() == null;
}
}, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
}
Aggregations