Skip to content
Snippets Groups Projects
Commit edfa3bd5 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-4392 throw exception when command finished with error

parent 971bbcc7
No related branches found
No related tags found
No related merge requests found
package de.ozgcloud.apilib.common.command.grpc;
import de.itvsh.kop.common.errorhandling.TechnicalException;
import de.itvsh.ozg.pluto.grpc.command.CommandServiceGrpc.CommandServiceBlockingStub;
import de.itvsh.ozg.pluto.grpc.command.GrpcGetCommandRequest;
import de.ozgcloud.apilib.common.callcontext.OzgCloudCallContextAttachingInterceptor;
......@@ -7,6 +8,7 @@ import de.ozgcloud.apilib.common.callcontext.OzgCloudCallContextProvider;
import de.ozgcloud.apilib.common.command.OzgCloudCommand;
import de.ozgcloud.apilib.common.command.OzgCloudCommandId;
import de.ozgcloud.apilib.common.command.OzgCloudCommandService;
import de.ozgcloud.apilib.common.command.OzgCloudCommandStatus;
import lombok.RequiredArgsConstructor;
import net.devh.boot.grpc.client.inject.GrpcClient;
......@@ -48,6 +50,9 @@ public class GrpcOzgCloudCommandService implements OzgCloudCommandService {
}
}
}
if (command.getStatus() == OzgCloudCommandStatus.ERROR) {
throw new TechnicalException("Command (id=%s) failed: %s".formatted(command.getId(), command.getErrorMessage()));
}
return command;
}
......
......@@ -4,12 +4,14 @@ import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import de.itvsh.kop.common.errorhandling.TechnicalException;
import de.itvsh.ozg.pluto.grpc.command.CommandServiceGrpc.CommandServiceBlockingStub;
import de.ozgcloud.apilib.common.callcontext.OzgCloudCallContextProvider;
import de.ozgcloud.apilib.common.command.OzgCloudCommand;
......@@ -55,6 +57,23 @@ class GrpcOzgCloudCommandServiceTest {
verify(service).waitUntilDone(created);
}
@Test
void shouldTerminateByTimeout() {
var command = OzgCloudCommandTestFactory.createBuilder().status(OzgCloudCommandStatus.PENDING).build();
doReturn(command).when(service).reloadCommand(any());
service.waitUntilDone(command);
Mockito.verify(service, Mockito.times(2)).reloadCommand(command.getId());
}
@Test
void shouldThrowException() {
var command = OzgCloudCommandTestFactory.createBuilder().status(OzgCloudCommandStatus.ERROR).build();
Assertions.assertThrows(TechnicalException.class, () -> service.waitUntilDone(command));
}
@Nested
class Create {
......@@ -100,14 +119,4 @@ class GrpcOzgCloudCommandServiceTest {
}
}
@Test
void shouldTerminateByTimeout() {
var command = OzgCloudCommandTestFactory.createBuilder().status(OzgCloudCommandStatus.PENDING).build();
doReturn(command).when(service).reloadCommand(any());
service.waitUntilDone(command);
Mockito.verify(service, Mockito.times(2)).reloadCommand(command.getId());
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment