Add test for NSX plugin that simulates a live lock

This commit is contained in:
Miguel Ferreira 2015-12-02 14:53:26 +01:00
parent 2093c33ebd
commit d248e61a31
1 changed files with 42 additions and 0 deletions

View File

@ -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 "));
}
}
}