Search in sources :

Example 21 with DiscoveryServiceClient

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);
}
Also used : DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy) EndpointStrategy(co.cask.cdap.common.discovery.EndpointStrategy) Injector(com.google.inject.Injector) Service(com.google.common.util.concurrent.Service) IOException(java.io.IOException) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy) Test(org.junit.Test)

Aggregations

DiscoveryServiceClient (org.apache.twill.discovery.DiscoveryServiceClient)21 Injector (com.google.inject.Injector)13 RandomEndpointStrategy (co.cask.cdap.common.discovery.RandomEndpointStrategy)12 AbstractModule (com.google.inject.AbstractModule)10 CConfiguration (co.cask.cdap.common.conf.CConfiguration)9 DiscoveryRuntimeModule (co.cask.cdap.common.guice.DiscoveryRuntimeModule)9 TransactionManager (org.apache.tephra.TransactionManager)9 EndpointStrategy (co.cask.cdap.common.discovery.EndpointStrategy)8 DatasetService (co.cask.cdap.data2.datafabric.dataset.service.DatasetService)8 ConfigModule (co.cask.cdap.common.guice.ConfigModule)7 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)6 AuthorizationEnforcementModule (co.cask.cdap.security.authorization.AuthorizationEnforcementModule)6 Discoverable (org.apache.twill.discovery.Discoverable)6 BeforeClass (org.junit.BeforeClass)6 Test (org.junit.Test)6 AuthenticationContextModules (co.cask.cdap.security.auth.context.AuthenticationContextModules)5 AuthorizationTestModule (co.cask.cdap.security.authorization.AuthorizationTestModule)5 TransactionSystemClient (org.apache.tephra.TransactionSystemClient)5 SConfiguration (co.cask.cdap.common.conf.SConfiguration)4 IOModule (co.cask.cdap.common.guice.IOModule)4