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

Replace WireMock with okhttp3:mockwebserver #291

Merged
merged 1 commit into from
Mar 27, 2024
Merged
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
17 changes: 9 additions & 8 deletions gateway-ha/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<dep.jdbi.version>3.44.0</dep.jdbi.version>
<dep.jeasy.version>4.1.0</dep.jeasy.version>
<dep.mockito.version>5.8.0</dep.mockito.version>
<dep.okhttp3.version>3.14.9</dep.okhttp3.version>
<dep.mysqlconnector.version>8.0.33</dep.mysqlconnector.version>
</properties>

Expand Down Expand Up @@ -70,7 +71,7 @@
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.14.9</version>
<version>${dep.okhttp3.version}</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -417,6 +418,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<version>${dep.okhttp3.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down Expand Up @@ -479,13 +487,6 @@
<artifactId>trino</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>3.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*/
package io.trino.gateway.ha;

import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import io.airlift.log.Logger;
import io.trino.gateway.ha.config.DataStoreConfiguration;
import io.trino.gateway.ha.persistence.JdbcConnectionManager;
Expand All @@ -23,6 +21,8 @@
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import org.javalite.activejdbc.Base;
import org.jdbi.v3.core.Jdbi;

Expand All @@ -33,6 +33,8 @@
import java.util.Random;
import java.util.Scanner;

import static com.google.common.net.HttpHeaders.CONTENT_ENCODING;
import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -57,16 +59,14 @@ public static void seedRequiredData(TestConfig testConfig)
}

public static void prepareMockBackend(
WireMockServer backend, String endPoint, String expectedResonse)
MockWebServer backend, int customBackendPort, String expectedResonse)
throws IOException
{
backend.start();
backend.stubFor(
WireMock.post(endPoint)
.willReturn(
WireMock.aResponse()
.withBody(expectedResonse)
.withHeader("Content-Encoding", "plain")
.withStatus(200)));
backend.start(customBackendPort);
backend.enqueue(new MockResponse()
.setBody(expectedResonse)
.addHeader(CONTENT_ENCODING, PLAIN_TEXT_UTF_8)
.setResponseCode(200));
}

public static TestConfig buildGatewayConfigAndSeedDb(int routerPort, String configFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
package io.trino.gateway.ha;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import io.trino.gateway.ha.config.ProxyBackendConfiguration;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand All @@ -43,8 +43,7 @@ public class TestGatewayHaMultipleBackend
final int routerPort = 20000 + (int) (Math.random() * 1000);
final int customBackendPort = 21000 + (int) (Math.random() * 1000);

private final WireMockServer customBackend =
new WireMockServer(WireMockConfiguration.options().port(customBackendPort));
private final MockWebServer customBackend = new MockWebServer();

private final OkHttpClient httpClient = new OkHttpClient();

Expand All @@ -60,7 +59,7 @@ public void setup()
int backend1Port = adhocTrino.getMappedPort(8080);
int backend2Port = scheduledTrino.getMappedPort(8080);

HaGatewayTestUtils.prepareMockBackend(customBackend, CUSTOM_PATH, CUSTOM_RESPONSE);
HaGatewayTestUtils.prepareMockBackend(customBackend, customBackendPort, CUSTOM_RESPONSE);

// seed database
HaGatewayTestUtils.TestConfig testConfig =
Expand Down Expand Up @@ -94,6 +93,9 @@ public void testCustomPath()
.build();
Response response1 = httpClient.newCall(request1).execute();
assertThat(response1.body().string()).isEqualTo(CUSTOM_RESPONSE);
RecordedRequest recordedRequest = customBackend.takeRequest();
assertThat(recordedRequest.getRequestLine()).contains("POST");
assertThat(recordedRequest.getPath()).isEqualTo(CUSTOM_PATH);

Request request2 =
new Request.Builder()
Expand Down
Loading