Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor cleanup in TestGatewayHaSingleBackend #496

Merged
merged 4 commits into from
Sep 30, 2024
Merged
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 @@ -30,7 +30,7 @@
import org.junit.jupiter.params.provider.MethodSource;
import org.testcontainers.containers.TrinoContainer;

import java.util.stream.Stream;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.testcontainers.utility.MountableFile.forClasspathResource;
Expand Down Expand Up @@ -62,55 +62,57 @@ public void setup()
"trino1", "http://localhost:" + backendPort, "externalUrl", true, "adhoc", routerPort);
}

public Stream<OkHttpClient> getOkHttpClient()
{
OkHttpClient.Builder http1Builder = new OkHttpClient.Builder();
http1Builder.protocols(ImmutableList.of(Protocol.HTTP_1_1));
OkHttpClient.Builder http2Builder = new OkHttpClient.Builder();
http2Builder.protocols(ImmutableList.of(Protocol.H2_PRIOR_KNOWLEDGE));
return Stream.of(http1Builder.build(), http2Builder.build());
}

@ParameterizedTest
@MethodSource("getOkHttpClient")
public void testRequestDelivery(OkHttpClient httpClient)
@MethodSource("protocols")
public void testRequestDelivery(Protocol protocol)
throws Exception
{
OkHttpClient httpClient = new OkHttpClient.Builder().protocols(ImmutableList.of(protocol)).build();

RequestBody requestBody =
RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "SELECT 1");
RequestBody.create("SELECT 1", MediaType.parse("application/json; charset=utf-8"));
Request request =
new Request.Builder()
.url("http://localhost:" + routerPort + "/v1/statement")
.addHeader("X-Trino-User", "test")
.addHeader("Host", "test.host.com")
.post(requestBody)
.build();
Response response = httpClient.newCall(request).execute();
String responseBody = response.body().string();
assertThat(responseBody).contains("nextUri");
assertThat(responseBody).contains("test.host.com");
try (Response response = httpClient.newCall(request).execute()) {
assertThat(response.body()).isNotNull();
String responseBody = response.body().string();
assertThat(responseBody).contains("nextUri");
assertThat(responseBody).contains("test.host.com");
}
}

@ParameterizedTest
@MethodSource("getOkHttpClient")
public void testBackendConfiguration(OkHttpClient httpClient)
@MethodSource("protocols")
public void testBackendConfiguration(Protocol protocol)
throws Exception
{
OkHttpClient httpClient = new OkHttpClient.Builder().protocols(ImmutableList.of(protocol)).build();

Request request = new Request.Builder()
.url("http://localhost:" + routerPort + "/entity/GATEWAY_BACKEND")
.addHeader("Host", "test.host.com")
.method("GET", null)
.build();
Response response = httpClient.newCall(request).execute();

final ObjectMapper objectMapper = new ObjectMapper();
ProxyBackendConfiguration[] backendConfiguration =
objectMapper.readValue(response.body().string(), ProxyBackendConfiguration[].class);
try (Response response = httpClient.newCall(request).execute()) {
final ObjectMapper objectMapper = new ObjectMapper();
assertThat(response.body()).isNotNull();
ProxyBackendConfiguration[] backendConfiguration = objectMapper.readValue(response.body().string(), ProxyBackendConfiguration[].class);
assertThat(backendConfiguration).hasSize(1);
assertThat(backendConfiguration[0].isActive()).isTrue();
assertThat(backendConfiguration[0].getRoutingGroup()).isEqualTo("adhoc");
assertThat(backendConfiguration[0].getExternalUrl()).isEqualTo("externalUrl");
}
}

assertThat(backendConfiguration).hasSize(1);
assertThat(backendConfiguration[0].isActive()).isTrue();
assertThat(backendConfiguration[0].getRoutingGroup()).isEqualTo("adhoc");
assertThat(backendConfiguration[0].getExternalUrl()).isEqualTo("externalUrl");
List<Protocol> protocols()
{
return ImmutableList.of(Protocol.HTTP_1_1, Protocol.H2_PRIOR_KNOWLEDGE);
}

@AfterAll
Expand Down