Skip to content

Commit

Permalink
Unit tests to check backend configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushbilala committed Oct 21, 2021
1 parent eeb028f commit 2fc034a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.lyft.data.gateway.ha;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.lyft.data.gateway.ha.config.ProxyBackendConfiguration;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
Expand All @@ -24,6 +26,7 @@ public class TestGatewayHaMulipleBackend {
new WireMockServer(WireMockConfiguration.options().port(backend1Port));
private WireMockServer scheduledBackend =
new WireMockServer(WireMockConfiguration.options().port(backend2Port));
private final OkHttpClient httpClient = new OkHttpClient();

@BeforeClass(alwaysRun = true)
public void setup() throws Exception {
Expand All @@ -47,7 +50,6 @@ public void setup() throws Exception {
@Test
public void testQueryDeliveryToMultipleRoutingGroups() throws Exception {
// Default request should be routed to adhoc backend
OkHttpClient httpClient = new OkHttpClient();
RequestBody requestBody =
RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "SELECT 1");
Request request1 =
Expand Down Expand Up @@ -79,6 +81,28 @@ public void testQueryDeliveryToMultipleRoutingGroups() throws Exception {
Assert.assertEquals(response3.body().string(), EXPECTED_RESPONSE1);
}

@Test
public void testBackendConfiguration() throws Exception {
Request request = new Request.Builder()
.url("http://localhost:" + routerPort + "/entity/GATEWAY_BACKEND")
.method("GET", null)
.build();
Response response = httpClient.newCall(request).execute();

final ObjectMapper objectMapper = new ObjectMapper();
ProxyBackendConfiguration[] backendConfiguration =
objectMapper.readValue(response.body().string(), ProxyBackendConfiguration[].class);

Assert.assertNotNull(backendConfiguration);
Assert.assertEquals(2, backendConfiguration.length);
Assert.assertTrue(backendConfiguration[0].isActive());
Assert.assertTrue(backendConfiguration[1].isActive());
Assert.assertEquals("adhoc", backendConfiguration[0].getRoutingGroup());
Assert.assertEquals("scheduled", backendConfiguration[1].getRoutingGroup());
Assert.assertEquals("externalUrl", backendConfiguration[0].getExternalUrl());
Assert.assertEquals("externalUrl", backendConfiguration[1].getExternalUrl());
}

@AfterClass(alwaysRun = true)
public void cleanup() {
adhocBackend.stop();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.lyft.data.gateway.ha;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.lyft.data.gateway.ha.config.ProxyBackendConfiguration;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
Expand Down Expand Up @@ -49,6 +51,25 @@ public void testRequestDelivery() throws Exception {
Assert.assertEquals(EXPECTED_RESPONSE, response.body().string());
}

@Test
public void testBackendConfiguration() throws Exception {
Request request = new Request.Builder()
.url("http://localhost:" + routerPort + "/entity/GATEWAY_BACKEND")
.method("GET", null)
.build();
Response response = httpClient.newCall(request).execute();

final ObjectMapper objectMapper = new ObjectMapper();
ProxyBackendConfiguration[] backendConfiguration =
objectMapper.readValue(response.body().string(), ProxyBackendConfiguration[].class);

Assert.assertNotNull(backendConfiguration);
Assert.assertEquals(1, backendConfiguration.length);
Assert.assertTrue(backendConfiguration[0].isActive());
Assert.assertEquals("adhoc", backendConfiguration[0].getRoutingGroup());
Assert.assertEquals("externalUrl", backendConfiguration[0].getExternalUrl());
}

@AfterClass(alwaysRun = true)
public void cleanup() {
backend.stop();
Expand Down

0 comments on commit 2fc034a

Please sign in to comment.