Skip to content

Commit

Permalink
HTTP-42-BatchRequest - add support for batch request processing in HT…
Browse files Browse the repository at this point in the history
…TP sink #5 tests

Signed-off-by: Krzysztof Chmielewski <[email protected]>
  • Loading branch information
kristoffSC committed Jun 22, 2023
1 parent 627b54a commit b327c31
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.getindata.connectors.http.internal.HttpsConnectionTestBase;
Expand All @@ -25,9 +26,15 @@

class JavaNetSinkHttpClientConnectionTest extends HttpsConnectionTestBase {

private RequestSubmitterFactory perRequestSubmitterFactory;

private RequestSubmitterFactory batchRequestSubmitterFactory;

@BeforeEach
public void setUp() {
super.setUp();
this.perRequestSubmitterFactory = new PerRequestRequestSubmitterFactory();
this.batchRequestSubmitterFactory = new BatchRequestSubmitterFactory(50);
}

@AfterEach
Expand All @@ -42,7 +49,17 @@ public void testHttpConnection() {
wireMockServer.start();
mockEndPoint(wireMockServer);

testSinkClientForConnection(new Properties(), "http://localhost:", SERVER_PORT);
testSinkClientForConnection(
new Properties(),
"http://localhost:",
SERVER_PORT,
perRequestSubmitterFactory);

testSinkClientForConnection(
new Properties(),
"http://localhost:",
SERVER_PORT,
batchRequestSubmitterFactory);
}

@Test
Expand All @@ -63,7 +80,17 @@ public void testHttpsConnectionWithSelfSignedCert() {

properties.setProperty(HttpConnectorConfigConstants.ALLOW_SELF_SIGNED, "true");

testSinkClientForConnection(properties, "https://localhost:", HTTPS_SERVER_PORT);
testSinkClientForConnection(
properties,
"https://localhost:",
HTTPS_SERVER_PORT,
perRequestSubmitterFactory);

testSinkClientForConnection(
properties,
"https://localhost:",
HTTPS_SERVER_PORT,
batchRequestSubmitterFactory);
}

@ParameterizedTest
Expand All @@ -89,7 +116,19 @@ public void testHttpsConnectionWithAddedCerts(String certName) {
trustedCert.getAbsolutePath()
);

testSinkClientForConnection(properties, "https://localhost:", HTTPS_SERVER_PORT);
testSinkClientForConnection(
properties,
"https://localhost:",
HTTPS_SERVER_PORT,
perRequestSubmitterFactory
);

testSinkClientForConnection(
properties,
"https://localhost:",
HTTPS_SERVER_PORT,
batchRequestSubmitterFactory
);
}

@ParameterizedTest
Expand Down Expand Up @@ -130,7 +169,19 @@ public void testMTlsConnection(String clientPrivateKeyName) {
clientPrivateKey.getAbsolutePath()
);

testSinkClientForConnection(properties, "https://localhost:", HTTPS_SERVER_PORT);
testSinkClientForConnection(
properties,
"https://localhost:",
HTTPS_SERVER_PORT,
perRequestSubmitterFactory
);

testSinkClientForConnection(
properties,
"https://localhost:",
HTTPS_SERVER_PORT,
batchRequestSubmitterFactory
);
}

@Test
Expand Down Expand Up @@ -173,7 +224,18 @@ public void testMTlsConnectionUsingKeyStore() {
serverTrustedCert.getAbsolutePath()
);

testSinkClientForConnection(properties, "https://localhost:", HTTPS_SERVER_PORT);
testSinkClientForConnection(
properties,
"https://localhost:",
HTTPS_SERVER_PORT,
perRequestSubmitterFactory
);

testSinkClientForConnection(properties,
"https://localhost:",
HTTPS_SERVER_PORT,
batchRequestSubmitterFactory
);
}


Expand Down Expand Up @@ -205,16 +267,26 @@ public void shouldThrowOnInvalidPath(
clientPrivateKey.getAbsolutePath()
);

// TODO HTTP-42 add test for PerRequest submitter
assertThrows(
RuntimeException.class,
() -> new JavaNetSinkHttpClient(
properties,
postRequestCallback,
headerPreprocessor,
new BatchRequestSubmitterFactory(50)
)
);
assertAll(() -> {
assertThrows(
RuntimeException.class,
() -> new JavaNetSinkHttpClient(
properties,
postRequestCallback,
headerPreprocessor,
perRequestSubmitterFactory
)
);
assertThrows(
RuntimeException.class,
() -> new JavaNetSinkHttpClient(
properties,
postRequestCallback,
headerPreprocessor,
batchRequestSubmitterFactory
)
);
});
}

@ParameterizedTest
Expand All @@ -233,22 +305,34 @@ public void shouldConnectWithBasicAuth(String authorizationHeaderValue) {
authorizationHeaderValue
);

testSinkClientForConnection(properties, "http://localhost:", SERVER_PORT);
testSinkClientForConnection(
properties,
"http://localhost:",
SERVER_PORT,
perRequestSubmitterFactory
);

testSinkClientForConnection(
properties,
"http://localhost:",
SERVER_PORT,
batchRequestSubmitterFactory
);
}

private void testSinkClientForConnection(
Properties properties,
String endpointUrl,
int httpsServerPort) {
int httpsServerPort,
RequestSubmitterFactory requestSubmitterFactory) {

try {
JavaNetSinkHttpClient client =
new JavaNetSinkHttpClient(
properties,
postRequestCallback,
headerPreprocessor,
// TODO HTTP-42 add test for PerRequest submitter
new BatchRequestSubmitterFactory(50));
requestSubmitterFactory);
HttpSinkRequestEntry requestEntry = new HttpSinkRequestEntry("GET", new byte[0]);
SinkHttpClientResponse response =
client.putRequests(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import java.net.http.HttpClient;
import java.util.Properties;

import java.util.stream.Stream;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.junit.jupiter.MockitoExtension;
Expand Down Expand Up @@ -56,22 +58,30 @@ public void setUp() {
when(httpClientBuilder.executor(any())).thenReturn(httpClientBuilder);
}

@Test
public void shouldBuildClientWithoutHeaders() {
private static Stream<Arguments> provideSubmitterFactory() {
return Stream.of(
Arguments.of(new PerRequestRequestSubmitterFactory()),
Arguments.of(new BatchRequestSubmitterFactory(50))
);
}

@ParameterizedTest
@MethodSource("provideSubmitterFactory")
public void shouldBuildClientWithoutHeaders(RequestSubmitterFactory requestSubmitterFactory) {

JavaNetSinkHttpClient client =
new JavaNetSinkHttpClient(
new Properties(),
postRequestCallback,
this.headerPreprocessor,
//TODO HTTP-42 add test for PerRequest submitter
new BatchRequestSubmitterFactory(50)
requestSubmitterFactory
);
assertThat(client.getHeadersAndValues()).isEmpty();
}

@Test
public void shouldBuildClientWithHeaders() {
@ParameterizedTest
@MethodSource("provideSubmitterFactory")
public void shouldBuildClientWithHeaders(RequestSubmitterFactory requestSubmitterFactory) {

// GIVEN
Properties properties = new Properties();
Expand All @@ -95,8 +105,7 @@ public void shouldBuildClientWithHeaders() {
properties,
postRequestCallback,
headerPreprocessor,
//TODO HTTP-42 add test for PerRequest submitter
new BatchRequestSubmitterFactory(50)
requestSubmitterFactory
);
String[] headersAndValues = client.getHeadersAndValues();
assertThat(headersAndValues).hasSize(6);
Expand Down

0 comments on commit b327c31

Please sign in to comment.