use of com.google.common.util.concurrent.Service in project cdap by caskdata.
the class AbstractProgramRuntimeServiceTest method testUpdateDeadLock.
@Test(timeout = 5000L)
public void testUpdateDeadLock() {
// This test is for testing (CDAP-3716)
// Create a service to simulate an existing running app.
Service service = new TestService();
ProgramId programId = NamespaceId.DEFAULT.app("dummyApp").program(ProgramType.WORKER, "dummy");
RunId runId = RunIds.generate();
ProgramRuntimeService.RuntimeInfo extraInfo = createRuntimeInfo(service, programId, runId);
service.startAndWait();
ProgramRunnerFactory runnerFactory = createProgramRunnerFactory();
TestProgramRuntimeService runtimeService = new TestProgramRuntimeService(CConfiguration.create(), runnerFactory, null, extraInfo);
runtimeService.startAndWait();
// The lookup will get deadlock for CDAP-3716
Assert.assertNotNull(runtimeService.lookup(programId, runId));
service.stopAndWait();
runtimeService.stopAndWait();
}
use of com.google.common.util.concurrent.Service in project cdap by caskdata.
the class AppFabricTestBase method initializeAndStartServices.
protected static void initializeAndStartServices(CConfiguration cConf, @Nullable SConfiguration sConf) throws Exception {
injector = Guice.createInjector(Modules.override(new AppFabricTestModule(cConf, sConf)).with(new AbstractModule() {
@Override
protected void configure() {
// needed because we set Kerberos to true in DefaultNamespaceAdminTest
bind(UGIProvider.class).to(CurrentUGIProvider.class);
}
}));
messagingService = injector.getInstance(MessagingService.class);
if (messagingService instanceof Service) {
((Service) messagingService).startAndWait();
}
txManager = injector.getInstance(TransactionManager.class);
txManager.startAndWait();
dsOpService = injector.getInstance(DatasetOpExecutor.class);
dsOpService.startAndWait();
remoteSysOpService = injector.getInstance(RemoteSystemOperationsService.class);
remoteSysOpService.startAndWait();
datasetService = injector.getInstance(DatasetService.class);
datasetService.startAndWait();
appFabricServer = injector.getInstance(AppFabricServer.class);
appFabricServer.startAndWait();
DiscoveryServiceClient discoveryClient = injector.getInstance(DiscoveryServiceClient.class);
ServiceDiscovered appFabricHttpDiscovered = discoveryClient.discover(Constants.Service.APP_FABRIC_HTTP);
EndpointStrategy endpointStrategy = new RandomEndpointStrategy(appFabricHttpDiscovered);
port = endpointStrategy.pick(1, TimeUnit.SECONDS).getSocketAddress().getPort();
txClient = injector.getInstance(TransactionSystemClient.class);
metricsCollectionService = injector.getInstance(MetricsCollectionService.class);
metricsCollectionService.startAndWait();
metricsService = injector.getInstance(MetricsQueryService.class);
metricsService.startAndWait();
streamService = injector.getInstance(StreamService.class);
streamService.startAndWait();
serviceStore = injector.getInstance(ServiceStore.class);
serviceStore.startAndWait();
metadataService = injector.getInstance(MetadataService.class);
metadataService.startAndWait();
locationFactory = getInjector().getInstance(LocationFactory.class);
streamClient = new StreamClient(getClientConfig(discoveryClient, Constants.Service.STREAMS));
datasetClient = new DatasetClient(getClientConfig(discoveryClient, Constants.Service.DATASET_MANAGER));
createNamespaces();
}
use of com.google.common.util.concurrent.Service in project cdap by caskdata.
the class CommandPortServiceTest method testCommandPortServer.
@Test
public void testCommandPortServer() throws Exception {
IncrementCommandHandler handler = new IncrementCommandHandler();
final CommandPortService server = CommandPortService.builder("test").addCommandHandler("increment", "Increments a counter", handler).build();
final CountDownLatch stopLatch = new CountDownLatch(1);
Futures.addCallback(server.start(), new FutureCallback<Service.State>() {
@Override
public void onSuccess(Service.State result) {
stopLatch.countDown();
}
@Override
public void onFailure(Throwable t) {
stopLatch.countDown();
}
});
// wait a bit for service to start
TimeUnit.SECONDS.sleep(1);
try {
for (int i = 0; i < 10; i++) {
Socket clientSocket = new Socket("localhost", server.getPort());
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream(), "UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream(), "UTF-8"));
writer.write("increment");
writer.newLine();
writer.flush();
String response = reader.readLine();
Assert.assertEquals(i + 1, Integer.parseInt(response));
} finally {
clientSocket.close();
}
}
} finally {
server.stopAndWait();
}
Assert.assertEquals(10, handler.getCounter());
Assert.assertTrue(stopLatch.await(3, TimeUnit.SECONDS));
Assert.assertEquals(Service.State.TERMINATED, server.state());
}
use of com.google.common.util.concurrent.Service in project cdap by caskdata.
the class SystemMetadataAuditPublishTest method setup.
@BeforeClass
public static void setup() {
cConf = CConfiguration.create();
cConf.setBoolean(Constants.Audit.ENABLED, true);
Injector injector = AppFabricTestHelper.getInjector(cConf, new AbstractModule() {
@Override
protected void configure() {
bind(MetadataStore.class).to(DefaultMetadataStore.class);
install(new AuditModule().getInMemoryModules());
}
});
auditPublisher = injector.getInstance(InMemoryAuditPublisher.class);
namespaceAdmin = injector.getInstance(NamespaceAdmin.class);
scheduler = injector.getInstance(Scheduler.class);
if (scheduler instanceof Service) {
((Service) scheduler).startAndWait();
}
}
use of com.google.common.util.concurrent.Service in project cdap by caskdata.
the class DefaultPreviewManager method start.
@Override
public ApplicationId start(NamespaceId namespace, AppRequest<?> appRequest) throws Exception {
ApplicationId previewApp = namespace.app(PREFIX + System.currentTimeMillis());
Injector injector = createPreviewInjector(previewApp);
PreviewRunner runner = injector.getInstance(PreviewRunner.class);
if (runner instanceof Service) {
((Service) runner).startAndWait();
}
try {
runner.startPreview(new PreviewRequest<>(getProgramIdFromRequest(previewApp, appRequest), appRequest));
} catch (Exception e) {
if (runner instanceof Service) {
stopQuietly((Service) runner);
}
removePreviewDir(previewApp);
throw e;
}
appInjectors.put(previewApp, injector);
return previewApp;
}
Aggregations