### Question:
HAManager { public long selectSlaveId(SortedSet<Long> ids) { long slaveId = -1; if (ids.size() - 1 == ids.last()) { slaveId = ids.last() + 1; } else { long preId = 0; for (long id : ids) { if (id == MixAll.MASTER_ID) { continue; } if (id - preId > 1) { slaveId = preId + 1; break; } preId++; } if (slaveId == -1) { slaveId = ids.last() + 1; } } return slaveId; } HAManager();  HAManager(NamesrvController namesrvController); void start(); void shutdown(); boolean changeToSlave(String clusterName, String brokerName, String brokerAddr); long selectSlaveId(SortedSet<Long> ids); void enableBrokerRoleSwitch(String clusterName, String brokerName); RoleChangeInfo selectNewMaster(String cluster, String brokerName);  }### Answer:
@Test public void testSelectSlaveId() { HAManager haManager = new HAManager(); Assert.assertEquals(2, haManager.selectSlaveId(new TreeSet<Long>(Arrays.asList(0l, 1l)))); Assert.assertEquals(1, haManager.selectSlaveId(new TreeSet<Long>(Arrays.asList(0l, 2l)))); Assert.assertEquals(1, haManager.selectSlaveId(new TreeSet<Long>(Arrays.asList(0l, 2l, 4l)))); Assert.assertEquals(2, haManager.selectSlaveId(new TreeSet<Long>(Arrays.asList(1l)))); Assert.assertEquals(1, haManager.selectSlaveId(new TreeSet<Long>(Arrays.asList(2l)))); }