use of com.aws.greengrass.integrationtests.ipc.IPCTestUtils.DEFAULT_IPC_API_TIMEOUT_SECONDS in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentServiceIntegrationTest method GIVEN_device_deployment_not_started_WHEN_new_deployment_THEN_first_deployment_cancelled.
@Test
void GIVEN_device_deployment_not_started_WHEN_new_deployment_THEN_first_deployment_cancelled() throws Exception {
CountDownLatch cdlDeployNonDisruptable = new CountDownLatch(1);
CountDownLatch cdlDeployRedSignal = new CountDownLatch(1);
CountDownLatch cdlRedeployNonDisruptable = new CountDownLatch(1);
Consumer<GreengrassLogMessage> listener = m -> {
if (m.getMessage() != null) {
if (m.getMessage().contains("Current deployment finished") && m.getContexts().get("DeploymentId").equals("deployNonDisruptable")) {
cdlDeployNonDisruptable.countDown();
}
if (m.getMessage().contains("Discarding device deployment") && m.getContexts().get("DEPLOYMENT_ID").equals("deployRedSignal")) {
cdlDeployRedSignal.countDown();
}
if (m.getMessage().contains("Current deployment finished") && m.getContexts().get("DeploymentId").equals("redeployNonDisruptable")) {
cdlRedeployNonDisruptable.countDown();
}
}
};
try (AutoCloseable l = TestUtils.createCloseableLogListener(listener)) {
submitSampleJobDocument(DeploymentServiceIntegrationTest.class.getResource("FleetConfigWithNonDisruptableService.json").toURI(), "deployNonDisruptable", DeploymentType.SHADOW);
CountDownLatch nonDisruptableServiceServiceLatch = new CountDownLatch(1);
kernel.getContext().addGlobalStateChangeListener((service, oldState, newState) -> {
if (service.getName().equals("NonDisruptableService") && newState.equals(State.RUNNING)) {
nonDisruptableServiceServiceLatch.countDown();
}
});
assertTrue(nonDisruptableServiceServiceLatch.await(30, TimeUnit.SECONDS));
try (EventStreamRPCConnection connection = IPCTestUtils.getEventStreamRpcConnection(kernel, "NonDisruptableService")) {
GreengrassCoreIPCClient ipcEventStreamClient = new GreengrassCoreIPCClient(connection);
ipcEventStreamClient.subscribeToComponentUpdates(new SubscribeToComponentUpdatesRequest(), Optional.of(new StreamResponseHandler<ComponentUpdatePolicyEvents>() {
@Override
public void onStreamEvent(ComponentUpdatePolicyEvents streamEvent) {
if (streamEvent.getPreUpdateEvent() != null) {
try {
DeferComponentUpdateRequest deferComponentUpdateRequest = new DeferComponentUpdateRequest();
deferComponentUpdateRequest.setRecheckAfterMs(TimeUnit.SECONDS.toMillis(60));
deferComponentUpdateRequest.setMessage("Test");
ipcEventStreamClient.deferComponentUpdate(deferComponentUpdateRequest, Optional.empty()).getResponse().get(DEFAULT_IPC_API_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
}
}
}
@Override
public boolean onStreamError(Throwable error) {
logger.atError().setCause(error).log("Caught error stream when subscribing for component " + "updates");
return false;
}
@Override
public void onStreamClosed() {
}
}));
assertTrue(cdlDeployNonDisruptable.await(30, TimeUnit.SECONDS));
submitSampleJobDocument(DeploymentServiceIntegrationTest.class.getResource("FleetConfigWithRedSignalService.json").toURI(), "deployRedSignal", DeploymentType.SHADOW);
submitSampleJobDocument(DeploymentServiceIntegrationTest.class.getResource("FleetConfigWithNonDisruptableService.json").toURI(), "redeployNonDisruptable", DeploymentType.SHADOW);
assertTrue(cdlRedeployNonDisruptable.await(15, TimeUnit.SECONDS));
assertTrue(cdlDeployRedSignal.await(1, TimeUnit.SECONDS));
}
}
}
Aggregations