use of co.cask.cdap.WordCountApp in project cdap by caskdata.
the class DefaultStoreTest method testHistoryDeletion.
@Test
public void testHistoryDeletion() throws Exception {
// 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 WordCountApp());
ApplicationId appId2 = namespaceId.app(spec.getName());
store.addApplication(appId2, spec);
ProgramId flowProgramId1 = appId1.flow("NoOpFlow");
ProgramId mapreduceProgramId1 = appId1.mr("NoOpMR");
ProgramId workflowProgramId1 = appId1.workflow("NoOpWorkflow");
ProgramId flowProgramId2 = appId2.flow("WordCountFlow");
Assert.assertNotNull(store.getApplication(appId1));
Assert.assertNotNull(store.getApplication(appId2));
long now = System.currentTimeMillis();
store.setStart(flowProgramId1, "flowRun1", now - 1000);
store.setStop(flowProgramId1, "flowRun1", now, ProgramController.State.COMPLETED.getRunStatus());
store.setStart(mapreduceProgramId1, "mrRun1", now - 1000);
store.setStop(mapreduceProgramId1, "mrRun1", now, ProgramController.State.COMPLETED.getRunStatus());
RunId runId = RunIds.generate(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(1000));
store.setStart(workflowProgramId1, runId.getId(), now - 1000);
store.setStop(workflowProgramId1, runId.getId(), now, ProgramController.State.COMPLETED.getRunStatus());
store.setStart(flowProgramId2, "flowRun2", now - 1000);
store.setStop(flowProgramId2, "flowRun2", now, ProgramController.State.COMPLETED.getRunStatus());
verifyRunHistory(flowProgramId1, 1);
verifyRunHistory(mapreduceProgramId1, 1);
verifyRunHistory(workflowProgramId1, 1);
verifyRunHistory(flowProgramId2, 1);
// removing application
store.removeApplication(appId1);
Assert.assertNull(store.getApplication(appId1));
Assert.assertNotNull(store.getApplication(appId2));
verifyRunHistory(flowProgramId1, 0);
verifyRunHistory(mapreduceProgramId1, 0);
verifyRunHistory(workflowProgramId1, 0);
// Check to see if the flow history of second app is not deleted
verifyRunHistory(flowProgramId2, 1);
// remove all
store.removeAll(namespaceId);
verifyRunHistory(flowProgramId2, 0);
}
use of co.cask.cdap.WordCountApp in project cdap by caskdata.
the class DefaultStoreTest method testRemoveAllApplications.
@Test
public void testRemoveAllApplications() throws Exception {
ApplicationSpecification spec = Specifications.from(new WordCountApp());
NamespaceId namespaceId = new NamespaceId("account1");
ApplicationId appId = namespaceId.app(spec.getName());
store.addApplication(appId, spec);
Assert.assertNotNull(store.getApplication(appId));
// removing flow
store.removeAllApplications(namespaceId);
Assert.assertNull(store.getApplication(appId));
}
use of co.cask.cdap.WordCountApp in project cdap by caskdata.
the class DefaultStoreTest method testSetFlowletInstances.
@Test
public void testSetFlowletInstances() throws Exception {
ApplicationSpecification spec = Specifications.from(new WordCountApp());
int initialInstances = spec.getFlows().get("WordCountFlow").getFlowlets().get("StreamSource").getInstances();
ApplicationId appId = NamespaceId.DEFAULT.app(spec.getName());
store.addApplication(appId, spec);
ProgramId programId = appId.flow("WordCountFlow");
store.setFlowletInstances(programId, "StreamSource", initialInstances + 5);
// checking that app spec in store was adjusted
ApplicationSpecification adjustedSpec = store.getApplication(appId);
Assert.assertNotNull(adjustedSpec);
Assert.assertEquals(initialInstances + 5, adjustedSpec.getFlows().get("WordCountFlow").getFlowlets().get("StreamSource").getInstances());
// checking that program spec in program jar was adjusted
ProgramDescriptor descriptor = store.loadProgram(programId);
Assert.assertNotNull(descriptor);
Assert.assertEquals(initialInstances + 5, descriptor.getApplicationSpecification().getFlows().get("WordCountFlow").getFlowlets().get("StreamSource").getInstances());
}
use of co.cask.cdap.WordCountApp in project cdap by caskdata.
the class ConfiguratorTest method testInMemoryConfigurator.
@Test
public void testInMemoryConfigurator() throws Exception {
LocationFactory locationFactory = new LocalLocationFactory(TMP_FOLDER.newFolder());
Location appJar = AppJarHelper.createDeploymentJar(locationFactory, WordCountApp.class);
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, WordCountApp.class.getSimpleName(), "1.0.0");
CConfiguration cConf = CConfiguration.create();
ArtifactRepository artifactRepo = new ArtifactRepository(conf, null, null, authorizer, new DummyProgramRunnerFactory(), new DefaultImpersonator(cConf, null), authEnforcer, authenticationContext);
// Create a configurator that is testable. Provide it a application.
try (CloseableClassLoader artifactClassLoader = artifactRepo.createArtifactClassLoader(appJar, new EntityImpersonator(artifactId.getNamespace().toEntityId(), new DefaultImpersonator(cConf, null)))) {
Configurator configurator = new InMemoryConfigurator(conf, Id.Namespace.DEFAULT, artifactId, WordCountApp.class.getName(), artifactRepo, artifactClassLoader, null, null, "");
// Extract response from the configurator.
ListenableFuture<ConfigResponse> result = configurator.config();
ConfigResponse response = result.get(10, TimeUnit.SECONDS);
Assert.assertNotNull(response);
// Deserialize the JSON spec back into Application object.
ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
ApplicationSpecification specification = adapter.fromJson(response.get());
Assert.assertNotNull(specification);
// Simple checks.
Assert.assertTrue(specification.getName().equals("WordCountApp"));
// # of flows.
Assert.assertTrue(specification.getFlows().size() == 1);
}
}
use of co.cask.cdap.WordCountApp in project cdap by caskdata.
the class SimpleQueueSpecificationGeneratorTest method testQueueSpecificationGenWithWordCount.
@Test
public void testQueueSpecificationGenWithWordCount() throws Exception {
ApplicationSpecification appSpec = Specifications.from(new WordCountApp());
ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
QueueSpecificationGenerator generator = new SimpleQueueSpecificationGenerator(NamespaceId.DEFAULT.app(newSpec.getName()));
table = generator.create(newSpec.getFlows().values().iterator().next());
Assert.assertEquals(get(FlowletConnection.Type.STREAM, "text", "StreamSource").iterator().next().getQueueName().toString(), String.format("stream:///%s/text", TEST_NAMESPACE_ID));
Assert.assertEquals(get(FlowletConnection.Type.FLOWLET, "StreamSource", "Tokenizer").iterator().next().getQueueName().toString(), String.format("queue:///%s/WordCountApp/WordCountFlow/StreamSource/queue", Id.Namespace.DEFAULT.getId()));
Assert.assertEquals(1, get(FlowletConnection.Type.FLOWLET, "Tokenizer", "CountByField").size());
}
Aggregations