Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
public class ZaasSchemeTransformRest implements ZaasSchemeTransform {

private static final String HEADER_SERVICE_ID = "X-Service-Id";
private static final String SERVICE_IS_UNAVAILABLE_MESSAGE = "There are no instance of ZAAS available";
private static final String SERVICE_IS_UNAVAILABLE_MESSAGE = "There are no instances of ZAAS available";

private static final ObjectWriter WRITER = new ObjectMapper().writer();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected Mono<T> invoke(
) {
Iterator<ServiceInstance> i = robinRound.getIterator(serviceInstances);
if (!i.hasNext()) {
throw new ServiceNotAccessibleException("There are no instance of ZAAS available");
throw new ServiceNotAccessibleException("There are no instances of ZAAS available");
}

return requestWithHa(i, requestCreator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ class GivenZaas extends AcceptanceTestWithMockServices {
@MockitoSpyBean
private ReactiveDiscoveryClient reactiveDiscoveryClient;

private AtomicInteger counter = new AtomicInteger(0);
private AtomicInteger queryCounter = new AtomicInteger(0);
private AtomicInteger loginCounter = new AtomicInteger(0);

@BeforeAll
void setup() {
Expand All @@ -167,12 +168,13 @@ void setup() {
.responseCode(204)
.assertion(he -> assertEquals("Basic dXNlcjpwYXNz", he.getRequestHeaders().getFirst(HttpHeaders.AUTHORIZATION)))
.assertion(he -> assertEquals("POST", he.getRequestMethod()))
.assertion(he -> loginCounter.incrementAndGet())
.and()
.addEndpoint("/zaas/api/v1/auth/query")
.responseCode(200)
.assertion(he -> {
assertNotNull(he);
counter.incrementAndGet();
queryCounter.incrementAndGet();
})
.contentType(APPLICATION_JSON)
.body("{\"status\":\"valid\"}")
Expand All @@ -194,7 +196,7 @@ String login() {
}

@Test
void whenOneZaasUnresponsive_thenQueryDoesNotFail() {
void whenTwoZaasUnresponsive_thenQueryDoesNotFail() {
var token = login();

// 2 out of 3 instances will fail
Expand All @@ -221,8 +223,32 @@ void whenOneZaasUnresponsive_thenQueryDoesNotFail() {
.statusCode(SC_OK);
}

assertEquals(50, counter.get());
assertEquals(50, queryCounter.get());
}

@Test
void whenTwoZaasUnresponsive_thenLoginDoesNotFail() {
// 2 out of 3 instances will fail
when(discoveryClient.getInstances(CoreService.ZAAS.getServiceId()))
.thenReturn(List.of(
buildZaasInfo(randomPort()),
buildZaasInfo(zaasService.getPort()),
buildZaasInfo(randomPort())
));

when(reactiveDiscoveryClient.getInstances(CoreService.ZAAS.getServiceId()))
.thenReturn(Flux.just(
buildZaasInfo(randomPort()),
buildZaasInfo(zaasService.getPort()),
buildZaasInfo(randomPort())
));

System.out.println("test");
for (int i = 0; i < 50; i ++) {
login();
}

assertEquals(50, loginCounter.get());
}

private int randomPort() {
Expand Down
Loading