### Question:
AppFabricServer extends AbstractIdleService { @Override protected void shutDown() throws Exception { coreSchedulerService.stopAndWait(); bootstrapService.stopAndWait(); systemAppManagementService.stopAndWait(); cancelHttpService.cancel(); programRuntimeService.stopAndWait(); applicationLifecycleService.stopAndWait(); programNotificationSubscriberService.stopAndWait(); runRecordCorrectorService.stopAndWait(); provisioningService.stopAndWait(); } @Inject  AppFabricServer(CConfiguration cConf, SConfiguration sConf,
                         DiscoveryService discoveryService,
                         @Named(Constants.Service.MASTER_SERVICES_BIND_ADDRESS) InetAddress hostname,
                         @Named(Constants.AppFabric.HANDLERS_BINDING) Set<HttpHandler> handlers,
                         @Nullable MetricsCollectionService metricsCollectionService,
                         ProgramRuntimeService programRuntimeService,
                         RunRecordCorrectorService runRecordCorrectorService,
                         ApplicationLifecycleService applicationLifecycleService,
                         ProgramNotificationSubscriberService programNotificationSubscriberService,
                         @Named("appfabric.services.names") Set<String> servicesNames,
                         @Named("appfabric.handler.hooks") Set<String> handlerHookNames,
                         CoreSchedulerService coreSchedulerService,
                         ProvisioningService provisioningService,
                         BootstrapService bootstrapService,
                         SystemAppManagementService systemAppManagementService);   }### Answer:
@Test public void startStopServer() throws Exception { Injector injector = AppFabricTestHelper.getInjector(); try { AppFabricServer server = injector.getInstance(AppFabricServer.class); DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class); Service.State state = server.startAndWait(); Assert.assertSame(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.assertSame(state, Service.State.TERMINATED); Tasks.waitFor(true, () -> endpointStrategy.pick() == null, 5, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); } finally { AppFabricTestHelper.shutdown(); } }
@Test public void testSSL() throws IOException { CConfiguration cConf = CConfiguration.create(); cConf.setBoolean(Constants.Security.SSL.INTERNAL_ENABLED, true); SConfiguration sConf = SConfiguration.create(); final Injector injector = AppFabricTestHelper.getInjector(cConf, sConf); try { final DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class); AppFabricServer appFabricServer = injector.getInstance(AppFabricServer.class); appFabricServer.startAndWait(); Assert.assertTrue(appFabricServer.isRunning()); Supplier<EndpointStrategy> endpointStrategySupplier = Suppliers.memoize( () -> new RandomEndpointStrategy(() -> discoveryServiceClient.discover(Constants.Service.APP_FABRIC_HTTP))) ::get; Discoverable discoverable = endpointStrategySupplier.get().pick(3, TimeUnit.SECONDS); Assert.assertNotNull(discoverable); Assert.assertTrue(URIScheme.HTTPS.isMatch(discoverable)); InetSocketAddress addr = discoverable.getSocketAddress(); SSLSocket socket = (SSLSocket) LDAPLoginModule.TrustAllSSLSocketFactory.getDefault() .createSocket(addr.getHostName(), addr.getPort()); socket.setSoTimeout(5000); socket.startHandshake(); appFabricServer.stopAndWait(); } finally { AppFabricTestHelper.shutdown(); } }