use of co.cask.cdap.test.ApplicationManager in project cdap by caskdata.
the class TestFrameworkTestRun method testServiceManager.
@Test
public void testServiceManager() throws Exception {
ApplicationManager applicationManager = deployApplication(FilterAppWithNewFlowAPI.class);
final ServiceManager countService = applicationManager.getServiceManager("CountService");
countService.setInstances(2);
Assert.assertEquals(0, countService.getProvisionedInstances());
Assert.assertEquals(2, countService.getRequestedInstances());
Assert.assertFalse(countService.isRunning());
List<RunRecord> history = countService.getHistory();
Assert.assertEquals(0, history.size());
countService.start();
countService.waitForStatus(true);
Assert.assertEquals(2, countService.getProvisionedInstances());
// requesting with ProgramRunStatus.KILLED returns empty list
history = countService.getHistory(ProgramRunStatus.KILLED);
Assert.assertEquals(0, history.size());
// requesting with either RUNNING or ALL will return one record
Tasks.waitFor(1, new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return countService.getHistory(ProgramRunStatus.RUNNING).size();
}
}, 5, TimeUnit.SECONDS);
history = countService.getHistory(ProgramRunStatus.RUNNING);
Assert.assertEquals(ProgramRunStatus.RUNNING, history.get(0).getStatus());
history = countService.getHistory(ProgramRunStatus.ALL);
Assert.assertEquals(1, history.size());
Assert.assertEquals(ProgramRunStatus.RUNNING, history.get(0).getStatus());
}
use of co.cask.cdap.test.ApplicationManager in project cdap by caskdata.
the class TestFrameworkTestRun method testAppFromArtifact.
@Test
public void testAppFromArtifact() throws Exception {
ArtifactId artifactId = NamespaceId.DEFAULT.artifact("cfg-app", "1.0.0-SNAPSHOT");
addAppArtifact(artifactId, ConfigTestApp.class);
ApplicationId appId = NamespaceId.DEFAULT.app("AppFromArtifact");
AppRequest<ConfigTestApp.ConfigClass> createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new ConfigTestApp.ConfigClass("testStream", "testDataset"));
ApplicationManager appManager = deployApplication(appId, createRequest);
testAppConfig(appId.getApplication(), appManager, createRequest.getConfig());
}
use of co.cask.cdap.test.ApplicationManager in project cdap by caskdata.
the class TestFrameworkTestRun method testByteCodeClassLoader.
@Category(XSlowTests.class)
@Test
public void testByteCodeClassLoader() throws Exception {
// This test verify bytecode generated classes ClassLoading
ApplicationManager appManager = deployApplication(testSpace, ClassLoaderTestApp.class);
FlowManager flowManager = appManager.getFlowManager("BasicFlow").start();
// Wait for at least 10 records being generated
RuntimeMetrics flowMetrics = flowManager.getFlowletMetrics("Sink");
flowMetrics.waitForProcessed(10, 5000, TimeUnit.MILLISECONDS);
flowManager.stop();
ServiceManager serviceManager = appManager.getServiceManager("RecordQuery").start();
URL serviceURL = serviceManager.getServiceURL(15, TimeUnit.SECONDS);
Assert.assertNotNull(serviceURL);
// Query record
URL url = new URL(serviceURL, "query?type=public");
HttpRequest request = HttpRequest.get(url).build();
HttpResponse response = HttpRequests.execute(request);
Assert.assertEquals(200, response.getResponseCode());
long count = Long.parseLong(response.getResponseBodyAsString());
serviceManager.stop();
// Verify the record count with dataset
DataSetManager<KeyValueTable> recordsManager = getDataset(testSpace.dataset("records"));
KeyValueTable records = recordsManager.get();
Assert.assertTrue(count == Bytes.toLong(records.read("PUBLIC")));
}
use of co.cask.cdap.test.ApplicationManager in project cdap by caskdata.
the class TestFrameworkTestRun method testWorkerInstances.
@Category(SlowTests.class)
@Test
public void testWorkerInstances() throws Exception {
ApplicationManager applicationManager = deployApplication(testSpace, AppUsingGetServiceURL.class);
WorkerManager workerManager = applicationManager.getWorkerManager(AppUsingGetServiceURL.PINGING_WORKER).start();
workerManager.waitForStatus(true);
// Should be 5 instances when first started.
workerInstancesCheck(workerManager, 5);
// Test increasing instances.
workerManager.setInstances(10);
workerInstancesCheck(workerManager, 10);
// Test decreasing instances.
workerManager.setInstances(2);
workerInstancesCheck(workerManager, 2);
// Test requesting same number of instances.
workerManager.setInstances(2);
workerInstancesCheck(workerManager, 2);
WorkerManager lifecycleWorkerManager = applicationManager.getWorkerManager(AppUsingGetServiceURL.LIFECYCLE_WORKER);
lifecycleWorkerManager.setInstances(3);
lifecycleWorkerManager.start().waitForStatus(true);
workerInstancesCheck(lifecycleWorkerManager, 3);
for (int i = 0; i < 3; i++) {
kvTableKeyCheck(testSpace, AppUsingGetServiceURL.WORKER_INSTANCES_DATASET, Bytes.toBytes(String.format("init.%d", i)));
}
// Set 5 instances for the LifecycleWorker
lifecycleWorkerManager.setInstances(5);
workerInstancesCheck(lifecycleWorkerManager, 5);
// Make sure all the keys have been written before stopping the worker
for (int i = 0; i < 5; i++) {
kvTableKeyCheck(testSpace, AppUsingGetServiceURL.WORKER_INSTANCES_DATASET, Bytes.toBytes(String.format("init.%d", i)));
}
lifecycleWorkerManager.stop();
lifecycleWorkerManager.waitForStatus(false);
if (workerManager.isRunning()) {
workerManager.stop();
}
workerManager.waitForStatus(false);
// Should be same instances after being stopped.
workerInstancesCheck(lifecycleWorkerManager, 5);
workerInstancesCheck(workerManager, 2);
// Assert the LifecycleWorker dataset writes
// 3 workers should have started with 3 total instances. 2 more should later start with 5 total instances.
assertWorkerDatasetWrites(Bytes.toBytes("init"), Bytes.stopKeyForPrefix(Bytes.toBytes("init.2")), 3, 3);
assertWorkerDatasetWrites(Bytes.toBytes("init.3"), Bytes.stopKeyForPrefix(Bytes.toBytes("init")), 2, 5);
// Test that the worker had 5 instances when stopped, and each knew that there were 5 instances
byte[] startRow = Bytes.toBytes("stop");
assertWorkerDatasetWrites(startRow, Bytes.stopKeyForPrefix(startRow), 5, 5);
}
use of co.cask.cdap.test.ApplicationManager in project cdap by caskdata.
the class TestFrameworkTestRun method testWorkerStop.
@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");
workerManager.start();
workerManager.waitForStatus(false, 30, 1);
}
Aggregations