@Test public void shouldCallStopDatabaseAndNotifyEventBusWithWaitingForPermanentStatus() throws Exception { when(resourceConnector.getDatabaseServerStatus(authenticatedContext, dbStack)).thenReturn(ExternalDatabaseStatus.UPDATE_IN_PROGRESS); when(statusCheckFactory.newPollPermanentExternalDatabaseStateTask(authenticatedContext, dbStack)) .thenReturn(externalDatabaseStatusPollTask); when(externalDatabaseStatusSyncPollingScheduler.schedule(externalDatabaseStatusPollTask)).thenReturn(ExternalDatabaseStatus.STARTED); victim.accept(anEvent()); verify(resourceConnector).stopDatabaseServer(authenticatedContext, dbStack); verify(eventBus).notify(eq(StopDatabaseServerSuccess.class.getSimpleName().toUpperCase()), Mockito.any(Event.class)); }
@Override public void accept(Event<StopDatabaseServerRequest> event) { LOGGER.debug("Received event: {}", event); StopDatabaseServerRequest request = event.getData(); CloudContext cloudContext = request.getCloudContext(); try { CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant()); AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential()); ExternalDatabaseStatus status = connector.resources().getDatabaseServerStatus(ac, request.getDbStack()); if (status != null && status.isTransient()) { LOGGER.debug("Database server '{}' is in '{}' status. Start waiting for a permanent status.", request.getDbStack(), status); PollTask<ExternalDatabaseStatus> task = statusCheckFactory.newPollPermanentExternalDatabaseStateTask(ac, request.getDbStack()); status = externalDatabaseStatusPollingScheduler.schedule(task); } if (status != STOPPED) { LOGGER.debug("Database server '{}' is in '{}' status. Calling for '{}' status.", request.getDbStack(), status, STOPPED); connector.resources().stopDatabaseServer(ac, request.getDbStack()); } else { LOGGER.debug("Database server '{}' is already in '{}' status.", request.getDbStack(), STOPPED); } RedbeamsEvent success = new StopDatabaseServerSuccess(request.getResourceId()); eventBus.notify(success.selector(), new Event<>(event.getHeaders(), success)); LOGGER.debug("Stopping the database server successfully finished for {}", cloudContext); } catch (Exception e) { StopDatabaseServerFailed failure = new StopDatabaseServerFailed(request.getResourceId(), e); LOGGER.warn("Error stopping the database server:", e); eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure)); } }
StopDatabaseServerHandler implements EventHandler<StopDatabaseServerRequest> { @Override public void accept(Event<StopDatabaseServerRequest> event) { LOGGER.debug("Received event: {}", event); StopDatabaseServerRequest request = event.getData(); CloudContext cloudContext = request.getCloudContext(); try { CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant()); AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential()); ExternalDatabaseStatus status = connector.resources().getDatabaseServerStatus(ac, request.getDbStack()); if (status != null && status.isTransient()) { LOGGER.debug("Database server '{}' is in '{}' status. Start waiting for a permanent status.", request.getDbStack(), status); PollTask<ExternalDatabaseStatus> task = statusCheckFactory.newPollPermanentExternalDatabaseStateTask(ac, request.getDbStack()); status = externalDatabaseStatusPollingScheduler.schedule(task); } if (status != STOPPED) { LOGGER.debug("Database server '{}' is in '{}' status. Calling for '{}' status.", request.getDbStack(), status, STOPPED); connector.resources().stopDatabaseServer(ac, request.getDbStack()); } else { LOGGER.debug("Database server '{}' is already in '{}' status.", request.getDbStack(), STOPPED); } RedbeamsEvent success = new StopDatabaseServerSuccess(request.getResourceId()); eventBus.notify(success.selector(), new Event<>(event.getHeaders(), success)); LOGGER.debug("Stopping the database server successfully finished for {}", cloudContext); } catch (Exception e) { StopDatabaseServerFailed failure = new StopDatabaseServerFailed(request.getResourceId(), e); LOGGER.warn("Error stopping the database server:", e); eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure)); } } }
StopDatabaseServerHandler implements EventHandler<StopDatabaseServerRequest> { @Override public void accept(Event<StopDatabaseServerRequest> event) { LOGGER.debug("Received event: {}", event); StopDatabaseServerRequest request = event.getData(); CloudContext cloudContext = request.getCloudContext(); try { CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant()); AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential()); ExternalDatabaseStatus status = connector.resources().getDatabaseServerStatus(ac, request.getDbStack()); if (status != null && status.isTransient()) { LOGGER.debug("Database server '{}' is in '{}' status. Start waiting for a permanent status.", request.getDbStack(), status); PollTask<ExternalDatabaseStatus> task = statusCheckFactory.newPollPermanentExternalDatabaseStateTask(ac, request.getDbStack()); status = externalDatabaseStatusPollingScheduler.schedule(task); } if (status != STOPPED) { LOGGER.debug("Database server '{}' is in '{}' status. Calling for '{}' status.", request.getDbStack(), status, STOPPED); connector.resources().stopDatabaseServer(ac, request.getDbStack()); } else { LOGGER.debug("Database server '{}' is already in '{}' status.", request.getDbStack(), STOPPED); } RedbeamsEvent success = new StopDatabaseServerSuccess(request.getResourceId()); eventBus.notify(success.selector(), new Event<>(event.getHeaders(), success)); LOGGER.debug("Stopping the database server successfully finished for {}", cloudContext); } catch (Exception e) { StopDatabaseServerFailed failure = new StopDatabaseServerFailed(request.getResourceId(), e); LOGGER.warn("Error stopping the database server:", e); eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure)); } }  }
StopDatabaseServerHandler implements EventHandler<StopDatabaseServerRequest> { @Override public void accept(Event<StopDatabaseServerRequest> event) { LOGGER.debug("Received event: {}", event); StopDatabaseServerRequest request = event.getData(); CloudContext cloudContext = request.getCloudContext(); try { CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant()); AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential()); ExternalDatabaseStatus status = connector.resources().getDatabaseServerStatus(ac, request.getDbStack()); if (status != null && status.isTransient()) { LOGGER.debug("Database server '{}' is in '{}' status. Start waiting for a permanent status.", request.getDbStack(), status); PollTask<ExternalDatabaseStatus> task = statusCheckFactory.newPollPermanentExternalDatabaseStateTask(ac, request.getDbStack()); status = externalDatabaseStatusPollingScheduler.schedule(task); } if (status != STOPPED) { LOGGER.debug("Database server '{}' is in '{}' status. Calling for '{}' status.", request.getDbStack(), status, STOPPED); connector.resources().stopDatabaseServer(ac, request.getDbStack()); } else { LOGGER.debug("Database server '{}' is already in '{}' status.", request.getDbStack(), STOPPED); } RedbeamsEvent success = new StopDatabaseServerSuccess(request.getResourceId()); eventBus.notify(success.selector(), new Event<>(event.getHeaders(), success)); LOGGER.debug("Stopping the database server successfully finished for {}", cloudContext); } catch (Exception e) { StopDatabaseServerFailed failure = new StopDatabaseServerFailed(request.getResourceId(), e); LOGGER.warn("Error stopping the database server:", e); eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure)); } }  @Override String selector(); @Override void accept(Event<StopDatabaseServerRequest> event); }
StopDatabaseServerHandler implements EventHandler<StopDatabaseServerRequest> { @Override public void accept(Event<StopDatabaseServerRequest> event) { LOGGER.debug("Received event: {}", event); StopDatabaseServerRequest request = event.getData(); CloudContext cloudContext = request.getCloudContext(); try { CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant()); AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential()); ExternalDatabaseStatus status = connector.resources().getDatabaseServerStatus(ac, request.getDbStack()); if (status != null && status.isTransient()) { LOGGER.debug("Database server '{}' is in '{}' status. Start waiting for a permanent status.", request.getDbStack(), status); PollTask<ExternalDatabaseStatus> task = statusCheckFactory.newPollPermanentExternalDatabaseStateTask(ac, request.getDbStack()); status = externalDatabaseStatusPollingScheduler.schedule(task); } if (status != STOPPED) { LOGGER.debug("Database server '{}' is in '{}' status. Calling for '{}' status.", request.getDbStack(), status, STOPPED); connector.resources().stopDatabaseServer(ac, request.getDbStack()); } else { LOGGER.debug("Database server '{}' is already in '{}' status.", request.getDbStack(), STOPPED); } RedbeamsEvent success = new StopDatabaseServerSuccess(request.getResourceId()); eventBus.notify(success.selector(), new Event<>(event.getHeaders(), success)); LOGGER.debug("Stopping the database server successfully finished for {}", cloudContext); } catch (Exception e) { StopDatabaseServerFailed failure = new StopDatabaseServerFailed(request.getResourceId(), e); LOGGER.warn("Error stopping the database server:", e); eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure)); } }  @Override String selector(); @Override void accept(Event<StopDatabaseServerRequest> event);  }