Skip to content

Commit

Permalink
fixed IT tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mynecker committed Nov 15, 2024
1 parent bd8931f commit 7647a60
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,13 @@ public void configPush(CommandRequest request) {
}
}
}
finalizeAndSendResponse(request);
} catch (Exception e) {
log.error("ConfigPush command not executed successfully", e);
attachErrorLogToCommand(attacheErrorToTerraformCommand, e, request);
// try to send the response to EP
// might have failed before sending the regular response to EP
// this attempt will most likely fail as well
finalizeAndSendResponse(request);
} finally {
cleanup(executionLogFilesToClean);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void execute(Command command, SempApiProvider sempApiProvider) {
*/

private void executeSempDeleteCommand(Command command, SempApiProvider sempApiProvider) throws ApiException, JsonProcessingException {
SempEntityType deletionEntityType = SempEntityType.valueOf((String) command.getParameters().get(SempDeleteCommandConstants.SEMP_DELETE_ENTITY_TYPE));
SempEntityType deletionEntityType = (SempEntityType) command.getParameters().get(SempDeleteCommandConstants.SEMP_DELETE_ENTITY_TYPE);
switch (deletionEntityType) {
case solaceAclProfile:
executeDeleteAclProfile(command, sempApiProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,14 @@ void failSendingResponseBackToEp() {
.build()));
doNothing().when(commandLogStreamingProcessor).streamLogsToEP(any(), any(), any());

RuntimeException thrownException = assertThrows(RuntimeException.class, () -> {
RuntimeException thrownException = assertThrows(RuntimeException.class, () -> {
commandManager.execute(message);
});
assertEquals("Error sending response back to EP", thrownException.getMessage());

ArgumentCaptor<CommandMessage> messageArgCaptor = ArgumentCaptor.forClass(CommandMessage.class);
verify(commandPublisher, times(2)).sendCommandResponse(messageArgCaptor.capture(), any());
// 3 attempts to send the response back to EP
verify(commandPublisher, times(3)).sendCommandResponse(messageArgCaptor.capture(), any());

// Check that we attempted to set Error in the response message
messageArgCaptor.getAllValues().forEach(commandMessage -> {
Expand Down Expand Up @@ -282,7 +283,7 @@ void testCommandManager() {
// This test verifies that unexpected exceptions are caught and the error is reported back to EP
// The caught exception is attached to the result of the first command in the bundle and the status is set to error
@Test
void failCommandManagerConfigPushDeleteTfState(){
void failCommandManagerConfigPushDeleteTfState() {
CommandMessage message = getCommandMessage("1");
when(messagingServiceDelegateService.getMessagingServiceClient(any())).thenReturn(
new SolaceHttpSemp(SempClient.builder()
Expand All @@ -297,12 +298,12 @@ void failCommandManagerConfigPushDeleteTfState(){
ArgumentCaptor<CommandMessage> responseCaptor = ArgumentCaptor.forClass(CommandMessage.class);
verify(commandPublisher, times(1)).sendCommandResponse(responseCaptor.capture(), topicVarsCaptor.capture());
assertEquals(JobStatus.error, responseCaptor.getValue().getStatus());
assertEquals("Failed removing Terraform state: Failed removing Terraform state directory",
assertEquals("Failed removing Terraform state directory",
responseCaptor.getValue().getCommandBundles().get(0).getCommands().get(0).getResult().getLogs().get(0).get("message"));
}

@Test
void testCommandManagerConfigPushDeleteTfState(){
void testCommandManagerConfigPushDeleteTfState() {
CommandMessage message = getCommandMessage("1");
when(messagingServiceDelegateService.getMessagingServiceClient(any())).thenReturn(
new SolaceHttpSemp(SempClient.builder()
Expand All @@ -323,7 +324,7 @@ void testCommandManagerConfigPushDeleteTfState(){

@Test
void verifyExitOnFailureIsRespectedWhenTrueAndIgnoreResultIsFalse() {
CommandMessage message = getCommandMessage("1", 2,4, true, false);
CommandMessage message = getCommandMessage("1", 2, 4, true, false);

doThrow(new RuntimeException("Error executing command")).when(terraformManager).execute(any(), any(), any());

Expand All @@ -346,7 +347,7 @@ void verifyExitOnFailureIsRespectedWhenTrueAndIgnoreResultIsFalse() {

@Test
void verifyExitOnFailureIsRespectedWhenTrueAndIgnoreResultIsTrue() {
CommandMessage message = getCommandMessage("1", 2,4, true, true);
CommandMessage message = getCommandMessage("1", 2, 4, true, true);

doThrow(new RuntimeException("Error executing command")).when(terraformManager).execute(any(), any(), any());

Expand All @@ -368,7 +369,7 @@ private static void verifyAllCommandsHaveErrorState(CommandMessage commandMessag

@Test
void verifyExitOnFailureIsRespectedWhenFalseAndIgnoreResultIsSetToFalse() {
CommandMessage message = getCommandMessage("1", 2,4, false, false);
CommandMessage message = getCommandMessage("1", 2, 4, false, false);

doThrow(new RuntimeException("Error executing command")).when(terraformManager).execute(any(), any(), any());

Expand Down Expand Up @@ -421,7 +422,7 @@ private CommandMessage getCommandMessage(String correlationIdSuffix) {
return getCommandMessage(correlationIdSuffix, 1, false, false);
}

private CommandMessage getCommandMessage(String correlationIdSuffix, int numberOfTfCommands,
private CommandMessage getCommandMessage(String correlationIdSuffix, int numberOfTfCommands,
boolean exitOnFailure, boolean ignoreResult) {
return getCommandMessage(correlationIdSuffix, 0, numberOfTfCommands, exitOnFailure, ignoreResult);
}
Expand Down Expand Up @@ -452,18 +453,20 @@ private CommandMessage getCommandMessage(String correlationIdSuffix, int numberO
private static List<Command> buildSempDeleteCommands(int numberOfCommands, boolean ignoreResult) {
return IntStream.range(0, numberOfCommands).mapToObj(i -> buildSempDeleteCommand(ignoreResult)).toList();
}

private static List<Command> buildTfCommands(int numberOfCommands, boolean ignoreResult) {
return IntStream.range(0, numberOfCommands).mapToObj(i -> buildTfCommand(ignoreResult)).toList();
}

private static Command buildSempDeleteCommand(boolean ignoreResult){
private static Command buildSempDeleteCommand(boolean ignoreResult) {
return Command.builder()
.commandType(CommandType.semp)
.ignoreResult(ignoreResult)
.body("someSempCommandPayload")
.command("delete")
.build();
}

private static Command buildTfCommand(boolean ignoreResult) {
return Command.builder()
.commandType(CommandType.terraform)
Expand Down

0 comments on commit 7647a60

Please sign in to comment.