From d248e61a3128fe285a18c9836d1c7d18b5b946e9 Mon Sep 17 00:00:00 2001 From: Miguel Ferreira Date: Wed, 2 Dec 2015 14:53:26 +0100 Subject: [PATCH] Add test for NSX plugin that simulates a live lock --- .../network/nicira/NiciraRestClientTest.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/NiciraRestClientTest.java b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/NiciraRestClientTest.java index 7fcab8001bb..3c5160cf958 100644 --- a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/NiciraRestClientTest.java +++ b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/NiciraRestClientTest.java @@ -20,6 +20,7 @@ package com.cloud.network.nicira; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.isEmptyOrNullString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; @@ -169,4 +170,45 @@ public class NiciraRestClientTest { verifyPrivate(client).invoke("execute", HttpRequestMatcher.eq(loginRequest), eq(401)); } } + + @Test + public void testExecuteLiveLockWhenControllerAllowsLoginAndFollowsWithUnauthorizedButDoesNotRediect() throws Exception { + when(mockResponse.getStatusLine()) + .thenReturn(HTTP_401_STATUSLINE) + .thenReturn(HTTP_200_STATUSLINE) + .thenReturn(HTTP_401_STATUSLINE) + .thenReturn(HTTP_200_STATUSLINE) + .thenReturn(HTTP_401_STATUSLINE) + .thenReturn(HTTP_200_STATUSLINE) + .thenReturn(HTTP_401_STATUSLINE) + .thenReturn(HTTP_200_STATUSLINE) + .thenReturn(HTTP_401_STATUSLINE); + when(httpClient.execute(eq(HTTP_HOST), HttpRequestMatcher.eq(request), eq(httpClientContext))) + .thenReturn(mockResponse) + .thenReturn(mockResponse) + .thenReturn(mockResponse) + .thenReturn(mockResponse) + .thenReturn(mockResponse); + when(httpClient.execute(eq(HTTP_HOST), HttpRequestMatcher.eq(loginRequest), eq(httpClientContext))) + .thenReturn(mockResponse) + .thenReturn(mockResponse) + .thenReturn(mockResponse) + .thenReturn(mockResponse); + final NiciraRestClient client = spy(NiciraRestClient.create() + .client(httpClient) + .clientContext(httpClientContext) + .hostname(LOCALHOST) + .username(ADMIN) + .password(ADMIN_PASSWORD) + .loginUrl(LOGIN_PATH) + .executionLimit(2) + .build()); + + try { + client.execute(request); + fail("Execution count should have been maxed out"); + } catch (final CloudstackRESTException e) { + assertThat(e.getMessage(), containsString("Reached max executions limit of ")); + } + } }