ClusterElderManager { public InternalDistributedMember getElderId() throws DistributedSystemDisconnectedException { if (clusterDistributionManager.isCloseInProgress()) { throw new DistributedSystemDisconnectedException( "no valid elder when system is shutting down", clusterDistributionManager.getRootCause()); } clusterDistributionManager.getSystem().getCancelCriterion().checkCancelInProgress(null); return getElderCandidate(); } ClusterElderManager(ClusterDistributionManager clusterDistributionManager);  ClusterElderManager(ClusterDistributionManager clusterDistributionManager,
      Supplier<ElderState> elderStateSupplier); InternalDistributedMember getElderId(); boolean isElder(); ElderState getElderState(boolean waitToBecomeElder); boolean waitForElder(final InternalDistributedMember desiredElder);  }
@Test public void getElderIdReturnsOldestMember() { ClusterElderManager clusterElderManager = new ClusterElderManager(clusterDistributionManager); when(clusterDistributionManager.getViewMembers()).thenReturn(Arrays.asList(member1, member2)); assertThat(clusterElderManager.getElderId()).isEqualTo(member1); }
@Test public void getElderIdWithNoMembers() { ClusterElderManager clusterElderManager = new ClusterElderManager(clusterDistributionManager); when(clusterDistributionManager.getViewMembers()).thenReturn(Arrays.asList()); assertThat(clusterElderManager.getElderId()).isNull(); }
@Test public void getElderIdIgnoresAdminMembers() { ClusterElderManager clusterElderManager = new ClusterElderManager(clusterDistributionManager); when(member1.getVmKind()).thenReturn(ClusterDistributionManager.ADMIN_ONLY_DM_TYPE); when(clusterDistributionManager.getViewMembers()).thenReturn(Arrays.asList(member1, member2)); assertThat(clusterElderManager.getElderId()).isEqualTo(member2); }
@Test public void getElderIdIgnoresSurpriseMembers() { ClusterElderManager clusterElderManager = new ClusterElderManager(clusterDistributionManager); when(distribution.isSurpriseMember(eq(member1))).thenReturn(true); when(clusterDistributionManager.getViewMembers()).thenReturn(Arrays.asList(member1, member2)); assertThat(clusterElderManager.getElderId()).isEqualTo(member2); }