ClusterState { public Boolean exists(TaskID taskId) { try { getTask(taskId); } catch (IllegalArgumentException e) { return false; } return true; } ClusterState(@NotNull SerializableState zooKeeperStateDriver, @NotNull FrameworkState frameworkState); List<TaskInfo> getTaskList(); Integer getElasticNodeId(); Map<String, Task> getGuiTaskList(); ESTaskStatus getStatus(TaskID taskID); void addTask(ESTaskStatus esTask); void addTask(TaskInfo taskInfo); void removeTask(TaskInfo taskInfo); Boolean exists(TaskID taskId); TaskInfo getTask(TaskID taskID); TaskInfo getTask(Protos.ExecutorID executorID); void update(Protos.TaskStatus status); boolean taskInError(Protos.TaskStatus status); void destroy(); static final Logger LOGGER; static final String STATE_LIST; }
@Test public void shouldReturnTrueIfExists() throws IOException { ArrayList<Protos.TaskInfo> mock = Mockito.spy(new ArrayList<>()); Protos.TaskInfo defaultTaskInfo = ProtoTestUtil.getDefaultTaskInfo(); mock.add(defaultTaskInfo); when(state.get(anyString())).thenReturn(mock); assertTrue(clusterState.exists(defaultTaskInfo.getTaskId())); verify(state, atLeastOnce()).get(anyString()); }
@Test public void shouldReturnFalseIfNotExists() throws IOException { Protos.TaskInfo defaultTaskInfo = ProtoTestUtil.getDefaultTaskInfo(); assertFalse(clusterState.exists(defaultTaskInfo.getTaskId())); verify(state, times(1)).get(anyString()); }