@Override public void assignExecutor(final int executorId, final int executionId) throws ExecutorManagerException { this.assignExecutorDao.assignExecutor(executorId, executionId); }
@Override public void unassignExecutor(final int executionId) throws ExecutorManagerException { this.assignExecutorDao.unassignExecutor(executionId); }
@Test public void testAssignAndUnassignExecutor() throws Exception { final String host = "localhost"; final int port = 12345; final Executor executor = this.executorDao.addExecutor(host, port); final ExecutableFlow flow = TestUtils.createTestExecutableFlow("exectest1", "exec1"); this.executionFlowDao.uploadExecutableFlow(flow); this.assignExecutor.assignExecutor(executor.getId(), flow.getExecutionId()); final Executor fetchExecutor = this.executorDao .fetchExecutorByExecutionId(flow.getExecutionId()); assertThat(fetchExecutor).isEqualTo(executor); this.assignExecutor.unassignExecutor(flow.getExecutionId()); assertThat(this.executorDao.fetchExecutorByExecutionId(flow.getExecutionId())).isNull(); }
@Before public void setup() { this.executionFlowDao = new ExecutionFlowDao(dbOperator); this.executorDao = new ExecutorDao(dbOperator); this.assignExecutor = new AssignExecutorDao(dbOperator, this.executorDao); this.fetchActiveFlowDao = new FetchActiveFlowDao(dbOperator); this.executionJobDao = new ExecutionJobDao(dbOperator); this.loader = new JdbcProjectImpl(props, dbOperator); }
@Test public void testAssignExecutorInvalidExecution() throws Exception { final String host = "localhost"; final int port = 12345; final Executor executor = this.executorDao.addExecutor(host, port); // Make 99 a random non-existent execution id. assertThatThrownBy( () -> this.assignExecutor.assignExecutor(executor.getId(), 99)) .isInstanceOf(ExecutorManagerException.class) .hasMessageContaining("non-existent execution"); }
@Override public void unassignExecutor(final int executionId) throws ExecutorManagerException { this.assignExecutorDao.unassignExecutor(executionId); } }
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 testAssignExecutorInvalidExecutor() throws Exception { final ExecutableFlow flow = TestUtils.createTestExecutableFlow("exectest1", "exec1"); this.executionFlowDao.uploadExecutableFlow(flow); // Since we haven't inserted any executors, 1 should be non-existent executor id. assertThatThrownBy( () -> this.assignExecutor.assignExecutor(1, flow.getExecutionId())) .isInstanceOf(ExecutorManagerException.class) .hasMessageContaining("non-existent executor"); }
@Test public void testFetchActiveFlowsStatusChanged() throws Exception { final ExecutableFlow flow1 = TestUtils.createTestExecutableFlow("exectest1", "exec1"); this.executionFlowDao.uploadExecutableFlow(flow1); final Executor executor = this.executorDao.addExecutor("test", 1); this.assignExecutor.assignExecutor(executor.getId(), flow1.getExecutionId()); Map<Integer, Pair<ExecutionReference, ExecutableFlow>> activeFlows1 = this.fetchActiveFlowDao.fetchActiveFlows(); assertThat(activeFlows1.containsKey(flow1.getExecutionId())).isTrue(); // When flow status becomes SUCCEEDED/KILLED/FAILED, it should not be in active state flow1.setStatus(Status.SUCCEEDED); this.executionFlowDao.updateExecutableFlow(flow1); activeFlows1 = this.fetchActiveFlowDao.fetchActiveFlows(); assertThat(activeFlows1.containsKey(flow1.getExecutionId())).isFalse(); flow1.setStatus(Status.KILLED); this.executionFlowDao.updateExecutableFlow(flow1); activeFlows1 = this.fetchActiveFlowDao.fetchActiveFlows(); assertThat(activeFlows1.containsKey(flow1.getExecutionId())).isFalse(); flow1.setStatus(Status.FAILED); this.executionFlowDao.updateExecutableFlow(flow1); activeFlows1 = this.fetchActiveFlowDao.fetchActiveFlows(); assertThat(activeFlows1.containsKey(flow1.getExecutionId())).isFalse(); }
@Override public void assignExecutor(final int executorId, final int executionId) throws ExecutorManagerException { this.assignExecutorDao.assignExecutor(executorId, executionId); }