use of com.aws.greengrass.builtin.services.configstore.ConfigStoreIPCEventStreamAgent in project aws-greengrass-nucleus by aws-greengrass.
the class IPCServicesTest method GIVEN_ConfigStoreEventStreamClient_WHEN_report_config_validation_status_THEN_inform_validation_requester.
@SuppressWarnings({ "PMD.CloseResource", "PMD.AvoidCatchingGenericException" })
@Test
void GIVEN_ConfigStoreEventStreamClient_WHEN_report_config_validation_status_THEN_inform_validation_requester() throws Exception {
LogConfig.getRootLogConfig().setLevel(Level.DEBUG);
CountDownLatch cdl = new CountDownLatch(1);
String authToken = IPCTestUtils.getAuthTokeForService(kernel, TEST_SERVICE_NAME);
try (EventStreamRPCConnection clientConnection = IPCTestUtils.connectToGGCOverEventStreamIPC(socketOptions, authToken, kernel)) {
CountDownLatch subscriptionLatch = new CountDownLatch(1);
Slf4jLogAdapter.addGlobalListener(m -> {
if (m.getMessage().contains("Config IPC subscribe to config validation request")) {
subscriptionLatch.countDown();
}
});
GreengrassCoreIPCClient greengrassCoreIPCClient = new GreengrassCoreIPCClient(clientConnection);
SubscribeToValidateConfigurationUpdatesRequest subscribe = new SubscribeToValidateConfigurationUpdatesRequest();
CompletableFuture<SubscribeToValidateConfigurationUpdatesResponse> fut = greengrassCoreIPCClient.subscribeToValidateConfigurationUpdates(subscribe, Optional.of(new StreamResponseHandler<ValidateConfigurationUpdateEvents>() {
@Override
public void onStreamEvent(ValidateConfigurationUpdateEvents events) {
assertNotNull(events);
assertNotNull(events.getValidateConfigurationUpdateEvent());
assertNotNull(events.getValidateConfigurationUpdateEvent().getConfiguration());
assertThat(events.getValidateConfigurationUpdateEvent().getConfiguration(), IsMapContaining.hasEntry("keyToValidate", "valueToValidate"));
cdl.countDown();
SendConfigurationValidityReportRequest reportRequest = new SendConfigurationValidityReportRequest();
ConfigurationValidityReport report = new ConfigurationValidityReport();
report.setStatus(ConfigurationValidityStatus.ACCEPTED);
report.setDeploymentId(events.getValidateConfigurationUpdateEvent().getDeploymentId());
reportRequest.setConfigurationValidityReport(report);
greengrassCoreIPCClient.sendConfigurationValidityReport(reportRequest, Optional.empty());
}
@Override
public boolean onStreamError(Throwable error) {
logger.atError().log("Received stream error.", error);
return false;
}
@Override
public void onStreamClosed() {
}
})).getResponse();
try {
fut.get(3, TimeUnit.SECONDS);
} catch (Exception e) {
logger.atError().setCause(e).log("Error when subscribing to component updates");
fail("Caught exception when subscribing to component updates");
}
assertTrue(subscriptionLatch.await(20, TimeUnit.SECONDS));
CompletableFuture<ConfigurationValidityReport> responseTracker = new CompletableFuture<>();
ConfigStoreIPCEventStreamAgent agent = kernel.getContext().get(ConfigStoreIPCEventStreamAgent.class);
agent.validateConfiguration("ServiceName", "A", Collections.singletonMap("keyToValidate", "valueToValidate"), responseTracker);
assertTrue(cdl.await(20, TimeUnit.SECONDS));
assertEquals(ConfigurationValidityStatus.ACCEPTED, responseTracker.get(20, TimeUnit.SECONDS).getStatus());
SendConfigurationValidityReportRequest reportRequest = new SendConfigurationValidityReportRequest();
ConfigurationValidityReport report = new ConfigurationValidityReport();
report.setStatus(ConfigurationValidityStatus.ACCEPTED);
reportRequest.setConfigurationValidityReport(report);
ExecutionException ex = assertThrows(ExecutionException.class, () -> greengrassCoreIPCClient.sendConfigurationValidityReport(reportRequest, Optional.empty()).getResponse().get(5, TimeUnit.SECONDS));
assertThat(ex.getCause().getMessage(), containsString("was null"));
}
}
Aggregations