@Test public void shouldNotCallStartDatabaseButShouldNotifyEventBus() throws Exception { when(resourceConnector.getDatabaseServerStatus(authenticatedContext, dbStack)).thenReturn(ExternalDatabaseStatus.STARTED); victim.accept(anEvent()); verify(eventBus).notify(eq(StartDatabaseServerSuccess.class.getSimpleName().toUpperCase()), Mockito.any(Event.class)); verifyZeroInteractions(resourceConnector, statusCheckFactory, externalDatabaseStatusSyncPollingScheduler); }
@Override public void accept(Event<StartDatabaseServerRequest> event) { LOGGER.debug("Received event: {}", event); StartDatabaseServerRequest 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 != STARTED) { LOGGER.debug("Database server '{}' is in '{}' status. Calling for '{}' status.", request.getDbStack(), status, STARTED); connector.resources().startDatabaseServer(ac, request.getDbStack()); } else { LOGGER.debug("Database server '{}' is already in '{}' status.", request.getDbStack(), STARTED); } RedbeamsEvent success = new StartDatabaseServerSuccess(request.getResourceId()); eventBus.notify(success.selector(), new Event<>(event.getHeaders(), success)); LOGGER.debug("Starting the database server successfully finished for {}", cloudContext); } catch (Exception e) { StartDatabaseServerFailed failure = new StartDatabaseServerFailed(request.getResourceId(), e); LOGGER.warn("Error starting the database server:", e); eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure)); } }
StartDatabaseServerHandler implements EventHandler<StartDatabaseServerRequest> { @Override public void accept(Event<StartDatabaseServerRequest> event) { LOGGER.debug("Received event: {}", event); StartDatabaseServerRequest 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 != STARTED) { LOGGER.debug("Database server '{}' is in '{}' status. Calling for '{}' status.", request.getDbStack(), status, STARTED); connector.resources().startDatabaseServer(ac, request.getDbStack()); } else { LOGGER.debug("Database server '{}' is already in '{}' status.", request.getDbStack(), STARTED); } RedbeamsEvent success = new StartDatabaseServerSuccess(request.getResourceId()); eventBus.notify(success.selector(), new Event<>(event.getHeaders(), success)); LOGGER.debug("Starting the database server successfully finished for {}", cloudContext); } catch (Exception e) { StartDatabaseServerFailed failure = new StartDatabaseServerFailed(request.getResourceId(), e); LOGGER.warn("Error starting the database server:", e); eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure)); } } }
StartDatabaseServerHandler implements EventHandler<StartDatabaseServerRequest> { @Override public void accept(Event<StartDatabaseServerRequest> event) { LOGGER.debug("Received event: {}", event); StartDatabaseServerRequest 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 != STARTED) { LOGGER.debug("Database server '{}' is in '{}' status. Calling for '{}' status.", request.getDbStack(), status, STARTED); connector.resources().startDatabaseServer(ac, request.getDbStack()); } else { LOGGER.debug("Database server '{}' is already in '{}' status.", request.getDbStack(), STARTED); } RedbeamsEvent success = new StartDatabaseServerSuccess(request.getResourceId()); eventBus.notify(success.selector(), new Event<>(event.getHeaders(), success)); LOGGER.debug("Starting the database server successfully finished for {}", cloudContext); } catch (Exception e) { StartDatabaseServerFailed failure = new StartDatabaseServerFailed(request.getResourceId(), e); LOGGER.warn("Error starting the database server:", e); eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure)); } }  }
StartDatabaseServerHandler implements EventHandler<StartDatabaseServerRequest> { @Override public void accept(Event<StartDatabaseServerRequest> event) { LOGGER.debug("Received event: {}", event); StartDatabaseServerRequest 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 != STARTED) { LOGGER.debug("Database server '{}' is in '{}' status. Calling for '{}' status.", request.getDbStack(), status, STARTED); connector.resources().startDatabaseServer(ac, request.getDbStack()); } else { LOGGER.debug("Database server '{}' is already in '{}' status.", request.getDbStack(), STARTED); } RedbeamsEvent success = new StartDatabaseServerSuccess(request.getResourceId()); eventBus.notify(success.selector(), new Event<>(event.getHeaders(), success)); LOGGER.debug("Starting the database server successfully finished for {}", cloudContext); } catch (Exception e) { StartDatabaseServerFailed failure = new StartDatabaseServerFailed(request.getResourceId(), e); LOGGER.warn("Error starting the database server:", e); eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure)); } }  @Override String selector(); @Override void accept(Event<StartDatabaseServerRequest> event); }
StartDatabaseServerHandler implements EventHandler<StartDatabaseServerRequest> { @Override public void accept(Event<StartDatabaseServerRequest> event) { LOGGER.debug("Received event: {}", event); StartDatabaseServerRequest 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 != STARTED) { LOGGER.debug("Database server '{}' is in '{}' status. Calling for '{}' status.", request.getDbStack(), status, STARTED); connector.resources().startDatabaseServer(ac, request.getDbStack()); } else { LOGGER.debug("Database server '{}' is already in '{}' status.", request.getDbStack(), STARTED); } RedbeamsEvent success = new StartDatabaseServerSuccess(request.getResourceId()); eventBus.notify(success.selector(), new Event<>(event.getHeaders(), success)); LOGGER.debug("Starting the database server successfully finished for {}", cloudContext); } catch (Exception e) { StartDatabaseServerFailed failure = new StartDatabaseServerFailed(request.getResourceId(), e); LOGGER.warn("Error starting the database server:", e); eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure)); } }  @Override String selector(); @Override void accept(Event<StartDatabaseServerRequest> event);  }