LocatorClusterManagementService implements ClusterManagementService { @Override public <T extends AbstractConfiguration<R>, R extends RuntimeInfo> ClusterManagementGetResult<T, R> get( T config) { ClusterManagementListResult<T, R> list = list(config); List<EntityInfo<T, R>> result = list.getResult(); if (result.size() == 0) { raise(StatusCode.ENTITY_NOT_FOUND, config.getClass().getSimpleName() + " '" + config.getId() + "' does not exist."); } return new ClusterManagementGetResult<>(result.get(0)); } LocatorClusterManagementService(InternalCache cache,
      InternalConfigurationPersistenceService persistenceService); @VisibleForTesting  LocatorClusterManagementService(
      InternalCache cache,
      InternalConfigurationPersistenceService persistenceService,
      Map<Class, ConfigurationManager> managers,
      Map<Class, ConfigurationValidator> validators,
      MemberValidator memberValidator,
      CommonConfigurationValidator commonValidator,
      OperationManager operationManager); @Override ClusterManagementRealizationResult create(T config); @Override ClusterManagementRealizationResult delete(
      T config); @Override ClusterManagementRealizationResult update(
      T config); @Override ClusterManagementListResult<T, R> list(
      T filter); @Override ClusterManagementGetResult<T, R> get(
      T config); @Override ClusterManagementOperationResult<A, V> start(
      A op); @Override ClusterManagementListOperationsResult<A, V> list(
      A opType); @Override ClusterManagementOperationResult<A, V> get(
      A opType, String opId); @Override CompletableFuture<ClusterManagementOperationResult<A, V>> getFuture(
      A opType, String opId); boolean isConnected(); @Override void close(); @VisibleForTesting
  // the dlock service name used by the CMS
  static final String CMS_DLOCK_SERVICE_NAME; }
@Test public void getRebalanceWithNoOpThrows() { assertThatThrownBy(() -> service.get(rebalanceOperation, "123")) .isInstanceOf(ClusterManagementException.class); }
@Test public void getRebalance() { OperationState operationState = mock(OperationState.class); String locator = member.toString(); when(operationState.getLocator()).thenReturn(locator); when(operationManager.get(any())).thenReturn(operationState); ClusterManagementOperationResult<RebalanceOperation, RebalanceResult> result = service.get(rebalanceOperation, "456"); assertThat(result.getStatusCode()).isEqualTo(ClusterManagementResult.StatusCode.IN_PROGRESS); assertThat(result.getOperationResult()).isNull(); when(operationState.getOperationEnd()).thenReturn(new Date()); result = service.get(rebalanceOperation, "456"); assertThat(result.getStatusCode()).isEqualTo(ClusterManagementResult.StatusCode.OK); }
@Test public void getRebalanceWithOperationStateThrowableCorrectlySetsStatusMessage() { OperationState operationState = mock(OperationState.class); when(operationManager.get(any())).thenReturn(operationState); when(operationState.getOperationEnd()).thenReturn(new Date()); Throwable throwable = new NullPointerException("NPE"); when(operationState.getThrowable()).thenReturn(throwable); ClusterManagementOperationResult<RebalanceOperation, RebalanceResult> result = service.get(rebalanceOperation, "456"); assertThat(result.getStatusCode()).isEqualTo(ClusterManagementResult.StatusCode.ERROR); assertThat(result.getOperationResult()).isNull(); assertThat(result.getThrowable()).isSameAs(throwable); assertThat(result.getStatusMessage()).contains("NPE").contains("NullPointerException"); }
@Test public void getRebalanceStatusWhenLocatorIsOffline() { OperationState operationState = mock(OperationState.class); when(operationManager.get(any())).thenReturn(operationState); when(operationState.getOperationEnd()).thenReturn(new Date()); Throwable throwable = new RuntimeException("Locator that initiated the Rest API operation is offline:"); when(operationState.getThrowable()).thenReturn(throwable); ClusterManagementOperationResult result = service.get(rebalanceOperation, "456"); assertThat(result.getStatusCode()).isEqualTo(ClusterManagementResult.StatusCode.ERROR); assertThat(result.getStatusMessage()) .contains("Locator that initiated the Rest API operation is offline:"); }
@Test public void getRebalanceWithOperationResultThatFailedCorrectlySetsStatusMessage() { OperationState operationState = mock(OperationState.class); when(operationManager.get(any())).thenReturn(operationState); when(operationState.getOperationEnd()).thenReturn(new Date()); OperationResult operationResult = mock(OperationResult.class); when(operationResult.getSuccess()).thenReturn(false); when(operationResult.getStatusMessage()).thenReturn("Failure status message."); when(operationState.getResult()).thenReturn(operationResult); ClusterManagementOperationResult<RebalanceOperation, RebalanceResult> result = service.get(rebalanceOperation, "456"); assertThat(result.getStatusCode()).isEqualTo(ClusterManagementResult.StatusCode.ERROR); assertThat(result.getOperationResult()).isSameAs(operationResult); assertThat(result.getStatusMessage()).isEqualTo("Failure status message."); }
@Test public void getRebalanceWithOperationResultThatSucceededCorrectlySetsStatusMessage() { OperationState operationState = mock(OperationState.class); when(operationManager.get(any())).thenReturn(operationState); when(operationState.getOperationEnd()).thenReturn(new Date()); OperationResult operationResult = mock(OperationResult.class); when(operationResult.getSuccess()).thenReturn(true); when(operationResult.getStatusMessage()).thenReturn("Success status message."); when(operationState.getResult()).thenReturn(operationResult); ClusterManagementOperationResult<RebalanceOperation, RebalanceResult> result = service.get(rebalanceOperation, "456"); assertThat(result.getStatusCode()).isEqualTo(ClusterManagementResult.StatusCode.OK); assertThat(result.getOperationResult()).isSameAs(operationResult); assertThat(result.getStatusMessage()).isEqualTo("Success status message."); }
@Test public void getMember_whenNoMembers() { Member member = new Member(); ClusterManagementListResult<Member, MemberInformation> listResult = mock(ClusterManagementListResult.class); List<EntityGroupInfo<Member, MemberInformation>> entityGroupInfos = new ArrayList<>(); EntityGroupInfo<Member, MemberInformation> entityGroupInfo = mock(EntityGroupInfo.class); when(entityGroupInfo.getRuntimeInfo()).thenReturn(emptyList()); entityGroupInfos.add(entityGroupInfo); when(listResult.getEntityGroupInfo()).thenReturn(entityGroupInfos); assertThatThrownBy(() -> service.get(member)) .isInstanceOf(ClusterManagementException.class) .hasMessageContaining("ENTITY_NOT_FOUND"); }