ClusterState { public Integer getElasticNodeId() { final List<Integer> idList = getElasticNodeIdList(); return IntStream.range(0, idList.size() + 1).filter(value -> !idList.contains(value)).findFirst().getAsInt(); } 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 shouldIncrementEsNodeId() throws IOException { assertEquals(0, clusterState.getElasticNodeId().intValue()); when(state.get(any())).thenReturn(Collections.singletonList(ProtoTestUtil.getTaskInfoExternalVolume(0))); assertEquals(1, clusterState.getElasticNodeId().intValue()); }
@Test public void shouldReplaceNodeId() throws IOException { when(state.get(any())).thenReturn(Collections.singletonList(ProtoTestUtil.getTaskInfoExternalVolume(1))); assertEquals(0, clusterState.getElasticNodeId().intValue()); when(state.get(any())).thenReturn(Arrays.asList(ProtoTestUtil.getTaskInfoExternalVolume(0), ProtoTestUtil.getTaskInfoExternalVolume(1))); assertEquals(2, clusterState.getElasticNodeId().intValue()); }