use of com.hortonworks.streamline.streams.catalog.Topology in project streamline by hortonworks.
the class TopologyTestRunnerTest method runTest_withMismatchedExpectedOutputRecords.
@Test
public void runTest_withMismatchedExpectedOutputRecords() throws Exception {
Topology topology = createSimpleDAGInjectedTestTopology();
Long testCaseId = 1L;
TopologyTestRunCase testCase = new TopologyTestRunCase();
testCase.setId(testCaseId);
testCase.setTopologyId(topology.getId());
testCase.setName("testcase1");
testCase.setTimestamp(System.currentTimeMillis());
setTopologyCurrentVersionExpectation(topology);
setTopologyTestRunCaseExpectations(topology, testCase);
setTopologyTestRunCaseSinkMismatchedRecordsExpectations(topology, testCase);
setTopologyTestRunHistoryExpectations();
setSucceedTopologyActionsExpectations();
TopologyTestRunHistory resultHistory = topologyTestRunner.runTest(topologyActions, topology, testCase, null);
assertNotNull(resultHistory);
waitForTopologyTestRunToFinish(resultHistory);
new VerificationsInOrder() {
{
TopologyTestRunHistory runHistory;
// some fields are already modified after calling the method, so don't need to capture it
catalogService.addTopologyTestRunHistory(withInstanceOf(TopologyTestRunHistory.class));
times = 1;
catalogService.addOrUpdateTopologyTestRunHistory(anyLong, runHistory = withCapture());
times = 1;
assertEquals(topology.getId(), runHistory.getTopologyId());
assertEquals(topology.getVersionId(), runHistory.getVersionId());
assertTrue(runHistory.getFinished());
assertTrue(runHistory.getSuccess());
assertNotNull(runHistory.getStartTime());
assertNotNull(runHistory.getFinishTime());
assertTrue(runHistory.getFinishTime() - runHistory.getStartTime() >= 0);
assertTrue(isNotEmptyJson(runHistory.getExpectedOutputRecords()));
assertTrue(isNotEmptyJson(runHistory.getActualOutputRecords()));
assertFalse(runHistory.getMatched());
}
};
}
use of com.hortonworks.streamline.streams.catalog.Topology in project streamline by hortonworks.
the class TopologyTestRunnerTest method runTest_withTestCaseId.
@Test
public void runTest_withTestCaseId() throws Exception {
Topology topology = createSimpleDAGInjectedTestTopology();
Long topologyId = topology.getId();
Long testCaseId = 1L;
TopologyTestRunCase testCase = new TopologyTestRunCase();
testCase.setId(testCaseId);
testCase.setTopologyId(topology.getId());
testCase.setName("testcase1");
testCase.setTimestamp(System.currentTimeMillis());
setTopologyCurrentVersionExpectation(topology);
setTopologyTestRunCaseExpectations(topology, testCase);
setTopologyTestRunCaseSinkNotFoundExpectations(topology, testCase);
setTopologyTestRunHistoryExpectations();
setSucceedTopologyActionsExpectations();
long sourceCount = topology.getTopologyDag().getOutputComponents().stream().filter(c -> c instanceof StreamlineSource).count();
long sinkCount = topology.getTopologyDag().getInputComponents().stream().filter(c -> c instanceof StreamlineSink).count();
TopologyTestRunHistory resultHistory = topologyTestRunner.runTest(topologyActions, topology, testCase, null);
waitForTopologyTestRunToFinish(resultHistory);
assertNotNull(resultHistory);
assertTrue(resultHistory.getFinished());
assertTrue(resultHistory.getSuccess());
new VerificationsInOrder() {
{
catalogService.getTopologyTestRunCaseSourceBySourceId(testCaseId, anyLong);
times = (int) sourceCount;
catalogService.getTopologyTestRunCaseSinkBySinkId(testCaseId, anyLong);
times = (int) sinkCount;
TopologyTestRunHistory runHistory;
// some fields are already modified after calling the method, so don't need to capture it
catalogService.addTopologyTestRunHistory(withInstanceOf(TopologyTestRunHistory.class));
times = 1;
catalogService.addOrUpdateTopologyTestRunHistory(anyLong, runHistory = withCapture());
times = 1;
assertEquals(topology.getId(), runHistory.getTopologyId());
assertEquals(topology.getVersionId(), runHistory.getVersionId());
assertTrue(runHistory.getFinished());
assertTrue(runHistory.getSuccess());
assertNotNull(runHistory.getStartTime());
assertNotNull(runHistory.getFinishTime());
assertTrue(runHistory.getFinishTime() - runHistory.getStartTime() >= 0);
assertTrue(isEmptyJson(runHistory.getExpectedOutputRecords()));
assertTrue(isNotEmptyJson(runHistory.getActualOutputRecords()));
assertFalse(runHistory.getMatched());
}
};
}
use of com.hortonworks.streamline.streams.catalog.Topology in project streamline by hortonworks.
the class TopologyTestRunnerTest method runTest_withMatchedExpectedOutputRecords.
@Test
public void runTest_withMatchedExpectedOutputRecords() throws Exception {
Topology topology = createSimpleDAGInjectedTestTopology();
Long testCaseId = 1L;
TopologyTestRunCase testCase = new TopologyTestRunCase();
testCase.setId(testCaseId);
testCase.setTopologyId(topology.getId());
testCase.setName("testcase1");
testCase.setTimestamp(System.currentTimeMillis());
setTopologyCurrentVersionExpectation(topology);
setTopologyTestRunCaseExpectations(topology, testCase);
setTopologyTestRunCaseSinkExpectations(topology, testCase);
setTopologyTestRunHistoryExpectations();
setSucceedTopologyActionsExpectations();
TopologyTestRunHistory resultHistory = topologyTestRunner.runTest(topologyActions, topology, testCase, null);
assertNotNull(resultHistory);
waitForTopologyTestRunToFinish(resultHistory);
new VerificationsInOrder() {
{
TopologyTestRunHistory runHistory;
// some fields are already modified after calling the method, so don't need to capture it
catalogService.addTopologyTestRunHistory(withInstanceOf(TopologyTestRunHistory.class));
times = 1;
catalogService.addOrUpdateTopologyTestRunHistory(anyLong, runHistory = withCapture());
times = 1;
assertEquals(topology.getId(), runHistory.getTopologyId());
assertEquals(topology.getVersionId(), runHistory.getVersionId());
assertTrue(runHistory.getFinished());
assertTrue(runHistory.getSuccess());
assertNotNull(runHistory.getStartTime());
assertNotNull(runHistory.getFinishTime());
assertTrue(runHistory.getFinishTime() - runHistory.getStartTime() >= 0);
assertTrue(isNotEmptyJson(runHistory.getExpectedOutputRecords()));
assertTrue(isNotEmptyJson(runHistory.getActualOutputRecords()));
assertTrue(runHistory.getMatched());
}
};
}
use of com.hortonworks.streamline.streams.catalog.Topology in project streamline by hortonworks.
the class TopologyCatalogResource method getTopologyById.
@GET
@Path("/topologies/{topologyId}")
@Timed
public Response getTopologyById(@PathParam("topologyId") Long topologyId, @Context SecurityContext securityContext) {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, NAMESPACE, topologyId, READ);
Topology result = catalogService.getTopology(topologyId);
if (result != null) {
return WSUtils.respondEntity(result, OK);
}
throw EntityNotFoundException.byId(topologyId.toString());
}
use of com.hortonworks.streamline.streams.catalog.Topology in project streamline by hortonworks.
the class TopologyCatalogResource method addOrUpdateTopology.
@PUT
@Path("/topologies/{topologyId}")
@Timed
public Response addOrUpdateTopology(@PathParam("topologyId") Long topologyId, Topology topology, @Context SecurityContext securityContext) {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, NAMESPACE, topologyId, WRITE);
if (StringUtils.isEmpty(topology.getName())) {
throw BadRequestException.missingParameter(Topology.NAME);
}
if (StringUtils.isEmpty(topology.getConfig())) {
throw BadRequestException.missingParameter(Topology.CONFIG);
}
if (topology.getNamespaceId() == null) {
throw BadRequestException.missingParameter(Topology.NAMESPACE_ID);
}
Topology existingTopology = catalogService.getTopology(topologyId);
Topology result = catalogService.addOrUpdateTopology(topologyId, topology);
if (existingTopology != null) {
Long prevNamespaceId = existingTopology.getNamespaceId();
if (!result.getNamespaceId().equals(prevNamespaceId)) {
LOG.info("Determined namespace change on topology: " + topologyId);
// environment has changed: it should set 'reconfigure' to all components
catalogService.setReconfigureOnAllComponentsInTopology(result);
}
}
return WSUtils.respondEntity(result, OK);
}
Aggregations