diff options
Diffstat (limited to 'node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImplTest.java')
-rw-r--r-- | node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImplTest.java | 167 |
1 files changed, 92 insertions, 75 deletions
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImplTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImplTest.java index 7f2c584303b..2bc6561dbf9 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImplTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/configserver/orchestrator/OrchestratorImplTest.java @@ -6,11 +6,12 @@ import com.yahoo.vespa.hosted.node.admin.configserver.HttpException; import com.yahoo.vespa.orchestrator.restapi.wire.BatchOperationResult; import com.yahoo.vespa.orchestrator.restapi.wire.HostStateChangeDenialReason; import com.yahoo.vespa.orchestrator.restapi.wire.UpdateHostResponse; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.Optional; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; @@ -27,9 +28,9 @@ public class OrchestratorImplTest { private final OrchestratorImpl orchestrator = new OrchestratorImpl(configServerApi); @Test - public void testSuspendCall() { + void testSuspendCall() { when(configServerApi.put( - eq(OrchestratorImpl.ORCHESTRATOR_PATH_PREFIX_HOST_API + "/" + hostName+ "/suspended"), + eq(OrchestratorImpl.ORCHESTRATOR_PATH_PREFIX_HOST_API + "/" + hostName + "/suspended"), eq(Optional.empty()), eq(UpdateHostResponse.class), any() @@ -38,75 +39,87 @@ public class OrchestratorImplTest { orchestrator.suspend(hostName); } - @Test(expected=OrchestratorException.class) - public void testSuspendCallWithFailureReason() { - when(configServerApi.put( - eq(OrchestratorImpl.ORCHESTRATOR_PATH_PREFIX_HOST_API + "/" + hostName+ "/suspended"), - eq(Optional.empty()), - eq(UpdateHostResponse.class), - any() - )).thenReturn(new UpdateHostResponse(hostName, new HostStateChangeDenialReason("hostname", "fail"))); - - orchestrator.suspend(hostName); + @Test + void testSuspendCallWithFailureReason() { + assertThrows(OrchestratorException.class, () -> { + when(configServerApi.put( + eq(OrchestratorImpl.ORCHESTRATOR_PATH_PREFIX_HOST_API + "/" + hostName + "/suspended"), + eq(Optional.empty()), + eq(UpdateHostResponse.class), + any() + )).thenReturn(new UpdateHostResponse(hostName, new HostStateChangeDenialReason("hostname", "fail"))); + + orchestrator.suspend(hostName); + }); } - @Test(expected=OrchestratorNotFoundException.class) - public void testSuspendCallWithNotFound() { - when(configServerApi.put(any(String.class), any(), any(), any())) - .thenThrow(new HttpException.NotFoundException("Not Found")); + @Test + void testSuspendCallWithNotFound() { + assertThrows(OrchestratorNotFoundException.class, () -> { + when(configServerApi.put(any(String.class), any(), any(), any())) + .thenThrow(new HttpException.NotFoundException("Not Found")); - orchestrator.suspend(hostName); + orchestrator.suspend(hostName); + }); } - @Test(expected=RuntimeException.class) - public void testSuspendCallWithSomeOtherException() { - when(configServerApi.put(any(String.class), any(), any(), any())) - .thenThrow(new RuntimeException("Some parameter was wrong")); + @Test + void testSuspendCallWithSomeOtherException() { + assertThrows(RuntimeException.class, () -> { + when(configServerApi.put(any(String.class), any(), any(), any())) + .thenThrow(new RuntimeException("Some parameter was wrong")); - orchestrator.suspend(hostName); + orchestrator.suspend(hostName); + }); } @Test - public void testResumeCall() { + void testResumeCall() { when(configServerApi.delete( - OrchestratorImpl.ORCHESTRATOR_PATH_PREFIX_HOST_API + "/" + hostName+ "/suspended", + OrchestratorImpl.ORCHESTRATOR_PATH_PREFIX_HOST_API + "/" + hostName + "/suspended", UpdateHostResponse.class )).thenReturn(new UpdateHostResponse(hostName, null)); orchestrator.resume(hostName); } - @Test(expected=OrchestratorException.class) - public void testResumeCallWithFailureReason() { - when(configServerApi.delete( - OrchestratorImpl.ORCHESTRATOR_PATH_PREFIX_HOST_API + "/" + hostName+ "/suspended", - UpdateHostResponse.class - )).thenReturn(new UpdateHostResponse(hostName, new HostStateChangeDenialReason("hostname", "fail"))); - - orchestrator.resume(hostName); + @Test + void testResumeCallWithFailureReason() { + assertThrows(OrchestratorException.class, () -> { + when(configServerApi.delete( + OrchestratorImpl.ORCHESTRATOR_PATH_PREFIX_HOST_API + "/" + hostName + "/suspended", + UpdateHostResponse.class + )).thenReturn(new UpdateHostResponse(hostName, new HostStateChangeDenialReason("hostname", "fail"))); + + orchestrator.resume(hostName); + }); } - @Test(expected=OrchestratorNotFoundException.class) - public void testResumeCallWithNotFound() { - when(configServerApi.delete( - any(String.class), - any() - )).thenThrow(new HttpException.NotFoundException("Not Found")); - - orchestrator.resume(hostName); + @Test + void testResumeCallWithNotFound() { + assertThrows(OrchestratorNotFoundException.class, () -> { + when(configServerApi.delete( + any(String.class), + any() + )).thenThrow(new HttpException.NotFoundException("Not Found")); + + orchestrator.resume(hostName); + }); } - @Test(expected=RuntimeException.class) - public void testResumeCallWithSomeOtherException() { - when(configServerApi.put(any(String.class), any(), any(), any())) - .thenThrow(new RuntimeException("Some parameter was wrong")); + @Test + void testResumeCallWithSomeOtherException() { + assertThrows(RuntimeException.class, () -> { + when(configServerApi.put(any(String.class), any(), any(), any())) + .thenThrow(new RuntimeException("Some parameter was wrong")); - orchestrator.suspend(hostName); + orchestrator.suspend(hostName); + }); } @Test - public void testBatchSuspendCall() { + void testBatchSuspendCall() { String parentHostName = "host1.test.yahoo.com"; List<String> hostNames = List.of("a1.host1.test.yahoo.com", "a2.host1.test.yahoo.com"); @@ -120,36 +133,40 @@ public class OrchestratorImplTest { orchestrator.suspend(parentHostName, hostNames); } - @Test(expected=OrchestratorException.class) - public void testBatchSuspendCallWithFailureReason() { - String parentHostName = "host1.test.yahoo.com"; - List<String> hostNames = List.of("a1.host1.test.yahoo.com", "a2.host1.test.yahoo.com"); - String failureReason = "Failed to suspend"; - - when(configServerApi.put( - eq("/orchestrator/v1/suspensions/hosts/host1.test.yahoo.com?hostname=a1.host1.test.yahoo.com&hostname=a2.host1.test.yahoo.com"), - eq(Optional.empty()), - eq(BatchOperationResult.class), - any() - )).thenReturn(new BatchOperationResult(failureReason)); - - orchestrator.suspend(parentHostName, hostNames); + @Test + void testBatchSuspendCallWithFailureReason() { + assertThrows(OrchestratorException.class, () -> { + String parentHostName = "host1.test.yahoo.com"; + List<String> hostNames = List.of("a1.host1.test.yahoo.com", "a2.host1.test.yahoo.com"); + String failureReason = "Failed to suspend"; + + when(configServerApi.put( + eq("/orchestrator/v1/suspensions/hosts/host1.test.yahoo.com?hostname=a1.host1.test.yahoo.com&hostname=a2.host1.test.yahoo.com"), + eq(Optional.empty()), + eq(BatchOperationResult.class), + any() + )).thenReturn(new BatchOperationResult(failureReason)); + + orchestrator.suspend(parentHostName, hostNames); + }); } - @Test(expected=RuntimeException.class) - public void testBatchSuspendCallWithSomeException() { - String parentHostName = "host1.test.yahoo.com"; - List<String> hostNames = List.of("a1.host1.test.yahoo.com", "a2.host1.test.yahoo.com"); - String exceptionMessage = "Exception: Something crashed!"; - - when(configServerApi.put( - eq("/orchestrator/v1/suspensions/hosts/host1.test.yahoo.com?hostname=a1.host1.test.yahoo.com&hostname=a2.host1.test.yahoo.com"), - eq(Optional.empty()), - eq(BatchOperationResult.class), - any() - )).thenThrow(new RuntimeException(exceptionMessage)); - - orchestrator.suspend(parentHostName, hostNames); + @Test + void testBatchSuspendCallWithSomeException() { + assertThrows(RuntimeException.class, () -> { + String parentHostName = "host1.test.yahoo.com"; + List<String> hostNames = List.of("a1.host1.test.yahoo.com", "a2.host1.test.yahoo.com"); + String exceptionMessage = "Exception: Something crashed!"; + + when(configServerApi.put( + eq("/orchestrator/v1/suspensions/hosts/host1.test.yahoo.com?hostname=a1.host1.test.yahoo.com&hostname=a2.host1.test.yahoo.com"), + eq(Optional.empty()), + eq(BatchOperationResult.class), + any() + )).thenThrow(new RuntimeException(exceptionMessage)); + + orchestrator.suspend(parentHostName, hostNames); + }); } } |