-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HTTP-42-BatchRequest - add support for batch request processing in HT…
…TP sink #8 tests Signed-off-by: Krzysztof Chmielewski <[email protected]>
- Loading branch information
1 parent
b78ff43
commit 7a865ea
Showing
7 changed files
with
284 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 23 additions & 1 deletion
24
...getindata/connectors/http/internal/sink/httpclient/PerRequestRequestSubmitterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,33 @@ | ||
package com.getindata.connectors.http.internal.sink.httpclient; | ||
|
||
import java.util.Properties; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
import org.apache.flink.util.concurrent.ExecutorThreadFactory; | ||
|
||
import com.getindata.connectors.http.internal.utils.JavaNetHttpClientFactory; | ||
import com.getindata.connectors.http.internal.utils.ThreadUtils; | ||
|
||
public class PerRequestRequestSubmitterFactory implements RequestSubmitterFactory { | ||
|
||
// TODO Add this property to config. Make sure to add note in README.md that will describe that | ||
// any value greater than one will break order of messages. | ||
int HTTP_CLIENT_THREAD_POOL_SIZE = 1; | ||
|
||
@Override | ||
public RequestSubmitter createSubmitter(Properties properties, String[] headersAndValues) { | ||
return new PerRequestSubmitter(properties, headersAndValues); | ||
|
||
ExecutorService httpClientExecutor = | ||
Executors.newFixedThreadPool( | ||
HTTP_CLIENT_THREAD_POOL_SIZE, | ||
new ExecutorThreadFactory( | ||
"http-sink-client-per-request-worker", ThreadUtils.LOGGING_EXCEPTION_HANDLER)); | ||
|
||
return new PerRequestSubmitter( | ||
properties, | ||
headersAndValues, | ||
JavaNetHttpClientFactory.createClient(properties, httpClientExecutor) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
.../getindata/connectors/http/internal/sink/httpclient/BatchRequestSubmitterFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.getindata.connectors.http.internal.sink.httpclient; | ||
|
||
import java.util.Properties; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import com.getindata.connectors.http.internal.config.ConfigException; | ||
import com.getindata.connectors.http.internal.config.HttpConnectorConfigConstants; | ||
|
||
class BatchRequestSubmitterFactoryTest { | ||
|
||
@ParameterizedTest | ||
@ValueSource(ints = {0, -1}) | ||
public void shouldThrowIfInvalidDefaultSize(int invalidArgument) { | ||
assertThrows( | ||
IllegalArgumentException.class, | ||
() -> new BatchRequestSubmitterFactory(invalidArgument) | ||
); | ||
} | ||
|
||
@Test | ||
public void shouldCreateSubmitterWithDefaultBatchSize() { | ||
|
||
int defaultBatchSize = 10; | ||
BatchRequestSubmitter submitter = new BatchRequestSubmitterFactory(defaultBatchSize) | ||
.createSubmitter(new Properties(), new String[0]); | ||
|
||
assertThat(submitter.getBatchSize()).isEqualTo(defaultBatchSize); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"1", "2"}) | ||
public void shouldCreateSubmitterWithCustomBatchSize(String batchSize) { | ||
|
||
Properties properties = new Properties(); | ||
properties.setProperty( | ||
HttpConnectorConfigConstants.SINK_HTTP_BATCH_REQUEST_SIZE, | ||
batchSize | ||
); | ||
|
||
BatchRequestSubmitter submitter = new BatchRequestSubmitterFactory(10) | ||
.createSubmitter(properties, new String[0]); | ||
|
||
assertThat(submitter.getBatchSize()).isEqualTo(Integer.valueOf(batchSize)); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"0", "-1"}) | ||
public void shouldThrowIfBatchSizeToSmall(String invalidBatchSize) { | ||
|
||
Properties properties = new Properties(); | ||
properties.setProperty( | ||
HttpConnectorConfigConstants.SINK_HTTP_BATCH_REQUEST_SIZE, | ||
invalidBatchSize | ||
); | ||
|
||
BatchRequestSubmitterFactory factory = new BatchRequestSubmitterFactory(10); | ||
|
||
assertThrows( | ||
ConfigException.class, | ||
() -> factory.createSubmitter(properties, new String[0]) | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = {"1.1", "2,2", "hello"}) | ||
public void shouldThrowIfInvalidBatchSize(String invalidBatchSize) { | ||
|
||
Properties properties = new Properties(); | ||
properties.setProperty( | ||
HttpConnectorConfigConstants.SINK_HTTP_BATCH_REQUEST_SIZE, | ||
invalidBatchSize | ||
); | ||
|
||
BatchRequestSubmitterFactory factory = new BatchRequestSubmitterFactory(10); | ||
|
||
assertThrows( | ||
ConfigException.class, | ||
() -> factory.createSubmitter(properties, new String[0]) | ||
); | ||
} | ||
|
||
|
||
|
||
} |
Oops, something went wrong.