use of io.cdap.cdap.AppWithServices in project cdap by caskdata.
the class DefaultStoreTest method testServiceDeletion.
@Test
public void testServiceDeletion() {
// Store the application specification
AbstractApplication app = new AppWithServices();
ApplicationSpecification appSpec = Specifications.from(app);
ApplicationId appId = NamespaceId.DEFAULT.app(appSpec.getName());
store.addApplication(appId, appSpec);
AbstractApplication newApp = new AppWithNoServices();
// get the delete program specs after deploying AppWithNoServices
List<ProgramSpecification> programSpecs = store.getDeletedProgramSpecifications(appId, Specifications.from(newApp));
// verify the result.
Assert.assertEquals(1, programSpecs.size());
Assert.assertEquals("NoOpService", programSpecs.get(0).getName());
}
use of io.cdap.cdap.AppWithServices in project cdap by caskdata.
the class DefaultStoreTest method testHistoryDeletion.
@Test
public void testHistoryDeletion() {
// Deploy two apps, write some history for programs
// Remove application using accountId, AppId and verify
// Remove all from accountId and verify
ApplicationSpecification spec = Specifications.from(new AllProgramsApp());
NamespaceId namespaceId = new NamespaceId("testDeleteAll");
ApplicationId appId1 = namespaceId.app(spec.getName());
store.addApplication(appId1, spec);
spec = Specifications.from(new AppWithServices());
ApplicationId appId2 = namespaceId.app(spec.getName());
store.addApplication(appId2, spec);
ProgramId mapreduceProgramId1 = appId1.mr("NoOpMR");
ProgramId workflowProgramId1 = appId1.workflow("NoOpWorkflow");
ArtifactId artifactId = appId1.getNamespaceId().artifact("testArtifact", "1.0").toApiArtifactId();
ProgramId serviceId = appId2.service(AppWithServices.SERVICE_NAME);
Assert.assertNotNull(store.getApplication(appId1));
Assert.assertNotNull(store.getApplication(appId2));
long now = System.currentTimeMillis();
ProgramRunId mapreduceProgramRunId1 = mapreduceProgramId1.run(RunIds.generate(now - 1000));
setStartAndRunning(mapreduceProgramRunId1, artifactId);
store.setStop(mapreduceProgramRunId1, now, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId));
RunId runId = RunIds.generate(now - 1000);
setStartAndRunning(workflowProgramId1.run(runId.getId()), artifactId);
store.setStop(workflowProgramId1.run(runId.getId()), now, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId));
ProgramRunId serviceRunId = serviceId.run(RunIds.generate(now - 1000));
setStartAndRunning(serviceRunId, artifactId);
store.setStop(serviceRunId, now, ProgramController.State.COMPLETED.getRunStatus(), AppFabricTestHelper.createSourceId(++sourceId));
verifyRunHistory(mapreduceProgramId1, 1);
verifyRunHistory(workflowProgramId1, 1);
verifyRunHistory(serviceId, 1);
// removing application
store.removeApplication(appId1);
Assert.assertNull(store.getApplication(appId1));
Assert.assertNotNull(store.getApplication(appId2));
verifyRunHistory(mapreduceProgramId1, 0);
verifyRunHistory(workflowProgramId1, 0);
// Check to see if the history of second app is not deleted
verifyRunHistory(serviceId, 1);
// remove all
store.removeAll(namespaceId);
verifyRunHistory(serviceId, 0);
}
use of io.cdap.cdap.AppWithServices in project cdap by caskdata.
the class DefaultStoreTest method testServiceInstances.
@Test
public void testServiceInstances() {
ApplicationSpecification appSpec = Specifications.from(new AppWithServices());
ApplicationId appId = NamespaceId.DEFAULT.app(appSpec.getName());
store.addApplication(appId, appSpec);
// Test setting of service instances
ProgramId programId = appId.program(ProgramType.SERVICE, "NoOpService");
int count = store.getServiceInstances(programId);
Assert.assertEquals(1, count);
store.setServiceInstances(programId, 10);
count = store.getServiceInstances(programId);
Assert.assertEquals(10, count);
ApplicationSpecification newSpec = store.getApplication(appId);
Assert.assertNotNull(newSpec);
Map<String, ServiceSpecification> services = newSpec.getServices();
Assert.assertEquals(1, services.size());
ServiceSpecification serviceSpec = services.get("NoOpService");
Assert.assertEquals(10, serviceSpec.getInstances());
}
Aggregations