@Override public ProgramManager apply(ApplicationManager input) { return input.getWorkerManager(AppWithPartitionConsumers.WordCountWorker.NAME).start(); } }, false);
@Test public void testAdminWorker() throws Exception { testAdminProgram(appManager.getWorkerManager(AdminApp.WORKER_NAME)); }
@Test public void testTxPublishFetch() throws Exception { ApplicationManager appManager = deployWithArtifact(NAMESPACE, MessagingApp.class, artifactJar); MessagingAdmin messagingAdmin = getMessagingAdmin(NAMESPACE); final WorkerManager workerManager = appManager.getWorkerManager( MessagingApp.TransactionalMessagingWorker.class.getSimpleName()); // Run the TransactionalMessagingWorker twice, one with getting publisher/fetcher inside TX, one outside. for (boolean getInTx : Arrays.asList(true, false)) { messagingAdmin.createTopic(MessagingApp.TOPIC); workerManager.start(Collections.singletonMap("get.in.tx", Boolean.toString(getInTx))); // Wait for the worker to finish and verify that it completes successfully. int workerRunCount = getInTx ? 1 : 2; workerManager.waitForRuns(ProgramRunStatus.COMPLETED, workerRunCount, 60, TimeUnit.SECONDS); messagingAdmin.deleteTopic(MessagingApp.TOPIC); } }
@Test public void testWorkerStop() throws Exception { // Test to make sure the worker program's status goes to stopped after the run method finishes ApplicationManager manager = deployApplication(NoOpWorkerApp.class); WorkerManager workerManager = manager.getWorkerManager("NoOpWorker"); int numRuns = workerManager.getHistory().size(); workerManager.start(); Tasks.waitFor(numRuns + 1, () -> workerManager.getHistory().size(), 30, TimeUnit.SECONDS); workerManager.waitForStopped(30, TimeUnit.SECONDS); }
@Test public void testConcurrentRuns() throws Exception { ApplicationManager appManager = deployApplication(ConcurrentRunTestApp.class); WorkerManager workerManager = appManager.getWorkerManager(ConcurrentRunTestApp.TestWorker.class.getSimpleName()); workerManager.start(); // Start another time should fail as worker doesn't support concurrent run. workerManager.waitForRun(ProgramRunStatus.RUNNING, 10, TimeUnit.SECONDS); try { workerManager.start(); Assert.fail("Expected failure to start worker"); } catch (Exception e) { Assert.assertTrue(Throwables.getRootCause(e) instanceof ConflictException); } workerManager.waitForRun(ProgramRunStatus.RUNNING, 10, TimeUnit.SECONDS); workerManager.stop(); // Start the workflow File tmpDir = TEMP_FOLDER.newFolder(); File actionFile = new File(tmpDir, "action.file"); Map<String, String> args = Collections.singletonMap("action.file", actionFile.getAbsolutePath()); WorkflowManager workflowManager = appManager.getWorkflowManager( ConcurrentRunTestApp.TestWorkflow.class.getSimpleName()); // Starts two runs, both should succeed workflowManager.start(args); workflowManager.start(args); // Should get two active runs workflowManager.waitForRuns(ProgramRunStatus.RUNNING, 2, 10L, TimeUnit.SECONDS); // Touch the file to complete the workflow runs Files.touch(actionFile); workflowManager.waitForRuns(ProgramRunStatus.COMPLETED, 2, 10L, TimeUnit.SECONDS); }
WorkerManager workerManager = appManager.getWorkerManager("PartitionWorker") .start(ImmutableMap.of( "dataset.name", "tpfs", workerManager = appManager.getWorkerManager("PartitionWorker") .start(ImmutableMap.of( "dataset.name", "tpfs",
WorkerManager workerManager = appManager.getWorkerManager( ClusterNameTestApp.ClusterNameWorker.class.getSimpleName()).start(); key.set("worker.cluster.name");
@Category(SlowTests.class) @Test public void testGetServiceURL() throws Exception { ApplicationManager applicationManager = deployApplication(AppUsingGetServiceURL.class); ServiceManager centralServiceManager = applicationManager.getServiceManager(AppUsingGetServiceURL.CENTRAL_SERVICE).start(); centralServiceManager.waitForRun(ProgramRunStatus.RUNNING, 10, TimeUnit.SECONDS); WorkerManager pingingWorker = applicationManager.getWorkerManager(AppUsingGetServiceURL.PINGING_WORKER).start(); // Test service's getServiceURL ServiceManager serviceManager = applicationManager.getServiceManager(AppUsingGetServiceURL.FORWARDING).start(); serviceManager.waitForRun(ProgramRunStatus.RUNNING, 10, TimeUnit.SECONDS); String result = callServiceGet(serviceManager.getServiceURL(), "ping"); String decodedResult = new Gson().fromJson(result, String.class); // Verify that the service was able to hit the CentralService and retrieve the answer. Assert.assertEquals(AppUsingGetServiceURL.ANSWER, decodedResult); // Wait for the worker completed to make sure a value has been written to the dataset pingingWorker.waitForRun(ProgramRunStatus.COMPLETED, 30, TimeUnit.SECONDS); // Validate the value in the dataset by reading it via the service result = callServiceGet(serviceManager.getServiceURL(), "read/" + AppUsingGetServiceURL.DATASET_KEY); decodedResult = new Gson().fromJson(result, String.class); Assert.assertEquals(AppUsingGetServiceURL.ANSWER, decodedResult); serviceManager.stop(); centralServiceManager.stop(); serviceManager.waitForStopped(10, TimeUnit.SECONDS); centralServiceManager.waitForStopped(10, TimeUnit.SECONDS); }
@Category(SlowTests.class) @Test public void testAppWithWorker() throws Exception { ApplicationManager applicationManager = deployApplication(testSpace, AppWithWorker.class); LOG.info("Deployed."); WorkerManager manager = applicationManager.getWorkerManager(AppWithWorker.WORKER).start(); // Wait for initialize and run states Tasks.waitFor(true, new Callable<Boolean>() { @Override public Boolean call() throws Exception { DataSetManager<KeyValueTable> dataSetManager = getDataset(testSpace.dataset(AppWithWorker.DATASET)); KeyValueTable table = dataSetManager.get(); return AppWithWorker.INITIALIZE.equals(Bytes.toString(table.read(AppWithWorker.INITIALIZE))) && AppWithWorker.RUN.equals(Bytes.toString(table.read(AppWithWorker.RUN))); } }, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); manager.stop(); applicationManager.stopAll(); // Wait for stop state Tasks.waitFor(true, new Callable<Boolean>() { @Override public Boolean call() throws Exception { DataSetManager<KeyValueTable> dataSetManager = getDataset(testSpace.dataset(AppWithWorker.DATASET)); KeyValueTable table = dataSetManager.get(); return AppWithWorker.STOP.equals(Bytes.toString(table.read(AppWithWorker.STOP))); } }, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS); }
@Test public void testWorkerThrowingException() throws Exception { ApplicationManager appManager = deployApplication(AppWithExceptionThrowingWorker.class); final WorkerManager workerManager = appManager.getWorkerManager(AppWithExceptionThrowingWorker.WORKER_NAME); // Only one instance of the worker and it throws an exception. // ProgramRunStatus should go to FAILED state, except the one that throws in the destroy() method. testExceptionWorker(workerManager, 0, 0); // Test a case where worker completes without an exception. // There should be in total two completed runs. // One from the one that throws in destroy() in testExceptionWorker(), one from the next line. workerManager.start(); workerManager.waitForRuns(ProgramRunStatus.COMPLETED, 2, 5, TimeUnit.SECONDS); // Few of the instances of the worker will throw an exception, while others complete normally. Still the // ProgramRunStatus should go to FAILED state, , except for those that throws in the destroy() method. workerManager.setInstances(9); testExceptionWorker(workerManager, 2, 2); // Test a case where worker completes without an exception. // There should be four completed runs. // Two from throws that throws in destroy() in testExceptionWorker(), // one from the previous normal run, and one from next line. workerManager.start(); workerManager.waitForRuns(ProgramRunStatus.COMPLETED, 4, 10, TimeUnit.SECONDS); }
.getServiceManager(AppWithServices.DATASET_WORKER_SERVICE_NAME).start(args); WorkerManager datasetWorker = applicationManager.getWorkerManager(AppWithServices.DATASET_UPDATE_WORKER).start(args);
public void testWorkerInstances() throws Exception { ApplicationManager applicationManager = deployApplication(testSpace, AppUsingGetServiceURL.class); WorkerManager workerManager = applicationManager.getWorkerManager(AppUsingGetServiceURL.PINGING_WORKER).start(); workerManager.waitForRun(ProgramRunStatus.RUNNING, 10, TimeUnit.SECONDS); workerInstancesCheck(workerManager, 2); WorkerManager lifecycleWorkerManager = applicationManager.getWorkerManager(AppUsingGetServiceURL.LIFECYCLE_WORKER); lifecycleWorkerManager.setInstances(3); lifecycleWorkerManager.start().waitForRun(ProgramRunStatus.RUNNING, 10, TimeUnit.SECONDS);
ApplicationManager appManager = deployWithArtifact(NAMESPACE, MessagingApp.class, artifactJar); final WorkerManager workerManager = appManager.getWorkerManager( MessagingApp.MessagingWorker.class.getSimpleName()).start();
final WorkerManager workerManager = appManager.getWorkerManager(AppWithPlugin.WORKER); workerManager.start(); workerManager.waitForRun(ProgramRunStatus.COMPLETED, 10, TimeUnit.SECONDS);
ServiceManager serviceManager = appManager.getServiceManager(AppWithCustomTx.SERVICE) .start(txTimeoutArguments(txDefaulTimeoutService)); WorkerManager notxWorkerManager = appManager.getWorkerManager(AppWithCustomTx.WORKER_NOTX) .start(txTimeoutArguments(txDefaulTimeoutWorker)); WorkerManager txWorkerManager = appManager.getWorkerManager(AppWithCustomTx.WORKER_TX) .start(txTimeoutArguments(txDefaulTimeoutWorker)); WorkflowManager txWFManager = appManager.getWorkflowManager(AppWithCustomTx.WORKFLOW_TX)