use of co.cask.cdap.AppWithServices in project cdap by caskdata.
the class DefaultStoreTest method testServiceInstances.
@Test
public void testServiceInstances() throws Exception {
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());
}
use of co.cask.cdap.AppWithServices in project cdap by caskdata.
the class DefaultStoreTest method testServiceDeletion.
@Test
public void testServiceDeletion() throws Exception {
// 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 co.cask.cdap.AppWithServices in project cdap by caskdata.
the class ProgramLifecycleHttpHandlerTest method testProgramSpecification.
/**
* Program specification tests through appfabric apis.
*/
@Test
public void testProgramSpecification() throws Exception {
// deploy WordCountApp in namespace1 and verify
HttpResponse response = deploy(WordCountApp.class, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
// deploy AppWithServices in namespace2 and verify
response = deploy(AppWithServices.class, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
// deploy AppWithWorkflow in namespace2 and verify
response = deploy(AppWithWorkflow.class, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
// deploy AppWithWorker in namespace1 and verify
response = deploy(AppWithWorker.class, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
// verify program specification
verifyProgramSpecification(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.FLOW.getCategoryName(), WORDCOUNT_FLOW_NAME);
verifyProgramSpecification(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.MAPREDUCE.getCategoryName(), WORDCOUNT_MAPREDUCE_NAME);
verifyProgramSpecification(TEST_NAMESPACE2, APP_WITH_SERVICES_APP_ID, ProgramType.SERVICE.getCategoryName(), APP_WITH_SERVICES_SERVICE_NAME);
verifyProgramSpecification(TEST_NAMESPACE2, APP_WITH_WORKFLOW_APP_ID, ProgramType.WORKFLOW.getCategoryName(), APP_WITH_WORKFLOW_WORKFLOW_NAME);
verifyProgramSpecification(TEST_NAMESPACE1, AppWithWorker.NAME, ProgramType.WORKER.getCategoryName(), AppWithWorker.WORKER);
// verify invalid namespace
Assert.assertEquals(404, getProgramSpecificationResponseCode(TEST_NAMESPACE1, APP_WITH_SERVICES_APP_ID, ProgramType.SERVICE.getCategoryName(), APP_WITH_SERVICES_SERVICE_NAME));
// verify invalid app
Assert.assertEquals(404, getProgramSpecificationResponseCode(TEST_NAMESPACE2, APP_WITH_SERVICES_APP_ID, ProgramType.WORKFLOW.getCategoryName(), APP_WITH_WORKFLOW_WORKFLOW_NAME));
// verify invalid program type
Assert.assertEquals(405, getProgramSpecificationResponseCode(TEST_NAMESPACE2, APP_WITH_SERVICES_APP_ID, "random", APP_WITH_WORKFLOW_WORKFLOW_NAME));
// verify invalid program type
Assert.assertEquals(404, getProgramSpecificationResponseCode(TEST_NAMESPACE2, AppWithWorker.NAME, ProgramType.WORKER.getCategoryName(), AppWithWorker.WORKER));
}
use of co.cask.cdap.AppWithServices in project cdap by caskdata.
the class ProgramLifecycleHttpHandlerTest method testProgramList.
/**
* Tests for program list calls
*/
@Test
public void testProgramList() throws Exception {
// test initial state
testListInitialState(TEST_NAMESPACE1, ProgramType.FLOW);
testListInitialState(TEST_NAMESPACE2, ProgramType.MAPREDUCE);
testListInitialState(TEST_NAMESPACE1, ProgramType.WORKFLOW);
testListInitialState(TEST_NAMESPACE2, ProgramType.SPARK);
testListInitialState(TEST_NAMESPACE1, ProgramType.SERVICE);
// deploy WordCountApp in namespace1 and verify
HttpResponse response = deploy(WordCountApp.class, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
// deploy AppWithServices in namespace2 and verify
response = deploy(AppWithServices.class, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
// verify list by namespace
verifyProgramList(TEST_NAMESPACE1, ProgramType.FLOW, 1);
verifyProgramList(TEST_NAMESPACE1, ProgramType.MAPREDUCE, 1);
verifyProgramList(TEST_NAMESPACE2, ProgramType.SERVICE, 1);
// verify list by app
verifyProgramList(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.FLOW, 1);
verifyProgramList(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.MAPREDUCE, 1);
verifyProgramList(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.WORKFLOW, 0);
verifyProgramList(TEST_NAMESPACE2, APP_WITH_SERVICES_APP_ID, ProgramType.SERVICE, 1);
// verify invalid namespace
Assert.assertEquals(404, getAppFDetailResponseCode(TEST_NAMESPACE1, APP_WITH_SERVICES_APP_ID, ProgramType.SERVICE.getCategoryName()));
// verify invalid app
Assert.assertEquals(404, getAppFDetailResponseCode(TEST_NAMESPACE1, "random", ProgramType.FLOW.getCategoryName()));
}
Aggregations