@Test public void testFetchActiveFlowsExecutorAssigned() throws Exception { final List<ExecutableFlow> flows = createExecutions(); final Map<Integer, Pair<ExecutionReference, ExecutableFlow>> activeFlows = this.fetchActiveFlowDao .fetchActiveFlows(); assertFound(activeFlows, flows.get(0), true); assertNotFound(activeFlows, flows.get(1), "Returned a queued execution"); assertFound(activeFlows, flows.get(2), true); assertNotFound(activeFlows, flows.get(3), "Returned an execution with a finished status"); assertFound(activeFlows, flows.get(4), false); assertTwoFlowSame(activeFlows.get(flows.get(0).getExecutionId()).getSecond(), flows.get(0)); }
@Test public void testAdvancedFilter() throws Exception { createTestProject(); final ExecutableFlow flow = createTestFlow(); this.executionFlowDao.uploadExecutableFlow(flow); final List<ExecutableFlow> flowList1 = this.executionFlowDao .fetchFlowHistory("exectest1", "", "", 0, -1, -1, 0, 16); assertThat(flowList1.size()).isEqualTo(1); final ExecutableFlow fetchFlow = this.executionFlowDao.fetchExecutableFlow(flow.getExecutionId()); assertTwoFlowSame(flowList1.get(0), fetchFlow); }
@Test public void fetchFlowHistory() throws Exception { final ExecutableFlow flow = createTestFlow(); this.executionFlowDao.uploadExecutableFlow(flow); final List<ExecutableFlow> flowList1 = this.executionFlowDao.fetchFlowHistory(0, 2); assertThat(flowList1.size()).isEqualTo(1); final List<ExecutableFlow> flowList2 = this.executionFlowDao .fetchFlowHistory(flow.getProjectId(), flow.getId(), 0, 2); assertThat(flowList2.size()).isEqualTo(1); final ExecutableFlow fetchFlow = this.executionFlowDao.fetchExecutableFlow(flow.getExecutionId()); assertTwoFlowSame(flowList1.get(0), flowList2.get(0)); assertTwoFlowSame(flowList1.get(0), fetchFlow); }
@Test public void testFetchActiveFlowByExecId() throws Exception { final List<ExecutableFlow> flows = createExecutions(); assertTwoFlowSame( this.fetchActiveFlowDao.fetchActiveFlowByExecId(flows.get(0).getExecutionId()).getSecond(), flows.get(0)); assertThat(this.fetchActiveFlowDao.fetchActiveFlowByExecId(flows.get(1).getExecutionId())) .isNull(); assertTwoFlowSame( this.fetchActiveFlowDao.fetchActiveFlowByExecId(flows.get(2).getExecutionId()).getSecond(), flows.get(2)); assertThat(this.fetchActiveFlowDao.fetchActiveFlowByExecId(flows.get(3).getExecutionId())) .isNull(); assertTwoFlowSame( this.fetchActiveFlowDao.fetchActiveFlowByExecId(flows.get(4).getExecutionId()).getSecond(), flows.get(4)); }
private List<ExecutableFlow> createExecutions() throws Exception { final Executor executor = this.executorDao.addExecutor("test", 1); final ExecutableFlow flow1 = createExecutionAndAssign(Status.PREPARING, executor); // flow2 is not assigned final ExecutableFlow flow2 = createExecution(Status.PREPARING); final ExecutableFlow flow3 = createExecutionAndAssign(Status.RUNNING, executor); flow3.setStartTime(System.currentTimeMillis() + 1); this.executionFlowDao.updateExecutableFlow(flow3); final ExecutableFlow flow4 = createExecutionAndAssign(Status.SUCCEEDED, executor); flow4.setStartTime(System.currentTimeMillis() - 2); flow4.setEndTime(System.currentTimeMillis() - 1); this.executionFlowDao.updateExecutableFlow(flow4); final Executor executor2 = this.executorDao.addExecutor("test2", 2); // flow5 is assigned to an executor that is then removed final ExecutableFlow flow5 = createExecutionAndAssign(Status.RUNNING, executor2); flow5.setStartTime(System.currentTimeMillis() + 1); this.executionFlowDao.updateExecutableFlow(flow5); this.executorDao.removeExecutor(executor2.getHost(), executor2.getPort()); return ImmutableList.of(flow1, flow2, flow3, flow4, flow5); }
private void assertTwoFlowSame(final ExecutableFlow flow1, final ExecutableFlow flow2) { assertTwoFlowSame(flow1, flow2, true); }
private ExecutableFlow createExecutionAndAssign(final Status status, final Executor executor) throws Exception { final ExecutableFlow flow = createExecution(status); this.assignExecutor.assignExecutor(executor.getId(), flow.getExecutionId()); return flow; }
@Test public void testFetchEmptyRecentlyFinishedFlows() throws Exception { final ExecutableFlow flow1 = createTestFlow(); this.executionFlowDao.uploadExecutableFlow(flow1); flow1.setStatus(Status.SUCCEEDED); flow1.setEndTime(DateTimeUtils.currentTimeMillis()); this.executionFlowDao.updateExecutableFlow(flow1); //Todo jamiesjc: use java8.java.time api instead of jodatime //Mock flow finished time to be 2 min ago. DateTimeUtils.setCurrentMillisOffset(-FLOW_FINISHED_TIME.toMillis()); flow1.setEndTime(DateTimeUtils.currentTimeMillis()); this.executionFlowDao.updateExecutableFlow(flow1); //Fetch recently finished flows within 1 min. Should be empty. final List<ExecutableFlow> flows = this.executionFlowDao .fetchRecentlyFinishedFlows(RECENTLY_FINISHED_LIFETIME); assertThat(flows.size()).isEqualTo(0); }
@Test public void testFetchRecentlyFinishedFlows() throws Exception { final ExecutableFlow flow1 = createTestFlow(); this.executionFlowDao.uploadExecutableFlow(flow1); flow1.setStatus(Status.SUCCEEDED); flow1.setEndTime(System.currentTimeMillis()); this.executionFlowDao.updateExecutableFlow(flow1); //Flow just finished. Fetch recently finished flows immediately. Should get it. final List<ExecutableFlow> flows = this.executionFlowDao.fetchRecentlyFinishedFlows( RECENTLY_FINISHED_LIFETIME); assertThat(flows.size()).isEqualTo(1); assertTwoFlowSame(flow1, flows.get(0)); }
@Test public void testFetchUnfinishedFlows() throws Exception { final List<ExecutableFlow> flows = createExecutions(); final Map<Integer, Pair<ExecutionReference, ExecutableFlow>> unfinishedFlows = this.fetchActiveFlowDao.fetchUnfinishedFlows(); assertFound(unfinishedFlows, flows.get(0), true); assertFound(unfinishedFlows, flows.get(1), false); assertFound(unfinishedFlows, flows.get(2), true); assertNotFound(unfinishedFlows, flows.get(3), "Returned an execution with a finished status"); assertFound(unfinishedFlows, flows.get(4), false); assertTwoFlowSame(unfinishedFlows.get(flows.get(0).getExecutionId()).getSecond(), flows.get(0)); }
@Test public void testUploadAndFetchExecutionFlows() throws Exception { final ExecutableFlow flow = createTestFlow(); this.executionFlowDao.uploadExecutableFlow(flow); final ExecutableFlow fetchFlow = this.executionFlowDao.fetchExecutableFlow(flow.getExecutionId()); assertThat(flow).isNotSameAs(fetchFlow); assertTwoFlowSame(flow, fetchFlow); }
@Test public void testFetchUnfinishedFlowsMetadata() throws Exception { final List<ExecutableFlow> flows = createExecutions(); final Map<Integer, Pair<ExecutionReference, ExecutableFlow>> unfinishedFlows = this.fetchActiveFlowDao.fetchUnfinishedFlowsMetadata(); assertFound(unfinishedFlows, flows.get(0), true); assertFound(unfinishedFlows, flows.get(1), false); assertFound(unfinishedFlows, flows.get(2), true); assertNotFound(unfinishedFlows, flows.get(3), "Returned an execution with a finished status"); assertFound(unfinishedFlows, flows.get(4), false); assertTwoFlowSame(unfinishedFlows.get(flows.get(0).getExecutionId()).getSecond(), flows.get(0), false); assertTwoFlowSame(unfinishedFlows.get(flows.get(1).getExecutionId()).getSecond(), flows.get(1), false); assertTwoFlowSame(unfinishedFlows.get(flows.get(2).getExecutionId()).getSecond(), flows.get(2), false); }
@Test public void testFetchQueuedFlows() throws Exception { final ExecutableFlow flow = createTestFlow(); flow.setStatus(Status.PREPARING); this.executionFlowDao.uploadExecutableFlow(flow); final ExecutableFlow flow2 = TestUtils.createTestExecutableFlow("exectest1", "exec2"); flow2.setStatus(Status.PREPARING); this.executionFlowDao.uploadExecutableFlow(flow2); final List<Pair<ExecutionReference, ExecutableFlow>> fetchedQueuedFlows = this.executionFlowDao .fetchQueuedFlows(); assertThat(fetchedQueuedFlows.size()).isEqualTo(2); final Pair<ExecutionReference, ExecutableFlow> fetchedFlow1 = fetchedQueuedFlows.get(0); final Pair<ExecutionReference, ExecutableFlow> fetchedFlow2 = fetchedQueuedFlows.get(1); assertTwoFlowSame(flow, fetchedFlow1.getSecond()); assertTwoFlowSame(flow2, fetchedFlow2.getSecond()); }
final ExecutableFlow flow1 = createTestFlow(); flow1.setStartTime(dateUtil.dateStrToLong("2018-09-01 10:00:00")); this.executionFlowDao.uploadExecutableFlow(flow1); final ExecutableFlow flow2 = createTestFlow(); flow2.setStartTime(dateUtil.dateStrToLong("2018-09-01 09:00:00")); this.executionFlowDao.uploadExecutableFlow(flow2); final ExecutableFlow flow3 = createTestFlow(); flow3.setStartTime(dateUtil.dateStrToLong("2018-09-01 09:00:00")); this.executionFlowDao.uploadExecutableFlow(flow3); final ExecutableFlow flow4 = createTestFlow(); flow4.setStartTime(dateUtil.dateStrToLong("2018-09-01 08:00:00")); this.executionFlowDao.uploadExecutableFlow(flow4); assertTwoFlowSame(flowList.get(i), expected.get(i));
@Test public void testUpdateExecutableFlow() throws Exception { final ExecutableFlow flow = createTestFlow(); this.executionFlowDao.uploadExecutableFlow(flow); final ExecutableFlow fetchFlow = this.executionFlowDao.fetchExecutableFlow(flow.getExecutionId()); fetchFlow.setEndTime(System.currentTimeMillis()); fetchFlow.setStatus(Status.SUCCEEDED); this.executionFlowDao.updateExecutableFlow(fetchFlow); final ExecutableFlow fetchFlow2 = this.executionFlowDao.fetchExecutableFlow(flow.getExecutionId()); assertTwoFlowSame(fetchFlow, fetchFlow2); }