Skip to content

Commit

Permalink
Add jdk client buffering test (#5280)
Browse files Browse the repository at this point in the history
* Add jdk client buffering test

Signed-off-by: jansupol <jan.supol@oracle.com>
  • Loading branch information
jansupol authored Mar 22, 2023
1 parent 18903fd commit e40b9ac
Showing 1 changed file with 39 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -32,14 +32,22 @@
import org.glassfish.jersey.apache5.connector.Apache5ConnectorProvider;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.HttpUrlConnectorProvider;
import org.glassfish.jersey.client.RequestEntityProcessing;
import org.glassfish.jersey.client.spi.ConnectorProvider;
import org.glassfish.jersey.grizzly.connector.GrizzlyConnectorProvider;
import org.glassfish.jersey.jdk.connector.JdkConnectorProvider;
import org.glassfish.jersey.logging.LoggingFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.function.Supplier;
import java.util.stream.Stream;

/**
* Tests chunk encoding and possibility of buffering the entity.
Expand All @@ -65,56 +73,42 @@ public String getBuffered(@HeaderParam("content-length") String contentLenght,
}
}

@Test
public void testApacheConnector() {
testWithBuffering(getApacheConnectorConfig());
testWithChunkEncodingWithoutPropertyDefinition(getApacheConnectorConfig());
testWithChunkEncodingWithPropertyDefinition(getApacheConnectorConfig());
testWithChunkEncodingPerRequest(getApacheConnectorConfig());
testDefaultOption(getApacheConnectorConfig(), RequestEntityProcessing.CHUNKED);
}

@Test
public void testApache5Connector() {
testWithBuffering(getApache5ConnectorConfig());
testWithChunkEncodingWithoutPropertyDefinition(getApache5ConnectorConfig());
testWithChunkEncodingWithPropertyDefinition(getApache5ConnectorConfig());
testWithChunkEncodingPerRequest(getApache5ConnectorConfig());
testDefaultOption(getApache5ConnectorConfig(), RequestEntityProcessing.CHUNKED);
public static Stream<Arguments> clientConfigs() {
return Stream.of(
Arguments.of(new TestArguments(() -> new ApacheConnectorProvider(), RequestEntityProcessing.CHUNKED)),
Arguments.of(new TestArguments(() -> new Apache5ConnectorProvider(), RequestEntityProcessing.CHUNKED)),
Arguments.of(new TestArguments(() -> new GrizzlyConnectorProvider(), RequestEntityProcessing.CHUNKED)),
Arguments.of(new TestArguments(() -> new HttpUrlConnectorProvider(), RequestEntityProcessing.BUFFERED)),
Arguments.of(new TestArguments(() -> new JdkConnectorProvider(), RequestEntityProcessing.BUFFERED))
);
}

@Test
public void testGrizzlyConnector() {
testWithBuffering(getGrizzlyConnectorConfig());
testWithChunkEncodingWithoutPropertyDefinition(getGrizzlyConnectorConfig());
testWithChunkEncodingWithPropertyDefinition(getGrizzlyConnectorConfig());
testWithChunkEncodingPerRequest(getGrizzlyConnectorConfig());
testDefaultOption(getGrizzlyConnectorConfig(), RequestEntityProcessing.CHUNKED);
}

@Test
public void testHttpUrlConnector() {
testWithBuffering(getHttpUrlConnectorConfig());
testWithChunkEncodingWithoutPropertyDefinition(getHttpUrlConnectorConfig());
testWithChunkEncodingWithPropertyDefinition(getHttpUrlConnectorConfig());
testWithChunkEncodingPerRequest(getHttpUrlConnectorConfig());
testDefaultOption(getHttpUrlConnectorConfig(), RequestEntityProcessing.BUFFERED);
}
private static final class TestArguments {
private final Supplier<ConnectorProvider> connectorProviderSupplier;
private final RequestEntityProcessing defaultProcessing;

private ClientConfig getApacheConnectorConfig() {
return new ClientConfig().connectorProvider(new ApacheConnectorProvider());
}
private TestArguments(Supplier<ConnectorProvider> connectorProviderSupplier, RequestEntityProcessing defaultProcessing) {
this.connectorProviderSupplier = connectorProviderSupplier;
this.defaultProcessing = defaultProcessing;
}

private ClientConfig getApache5ConnectorConfig() {
return new ClientConfig().connectorProvider(new Apache5ConnectorProvider());
}
private ClientConfig clientConfig() {
return new ClientConfig().connectorProvider(connectorProviderSupplier.get());
}

private ClientConfig getGrizzlyConnectorConfig() {
return new ClientConfig().connectorProvider(new GrizzlyConnectorProvider());
private RequestEntityProcessing defaultProcessing() {
return defaultProcessing;
}
}

private ClientConfig getHttpUrlConnectorConfig() {
return new ClientConfig();
@ParameterizedTest
@MethodSource("clientConfigs")
public void testConnector(TestArguments arguments) {
testWithBuffering(arguments.clientConfig());
testWithChunkEncodingWithoutPropertyDefinition(arguments.clientConfig());
testWithChunkEncodingWithPropertyDefinition(arguments.clientConfig());
testWithChunkEncodingPerRequest(arguments.clientConfig());
testDefaultOption(arguments.clientConfig(), arguments.defaultProcessing());
}

private void testDefaultOption(ClientConfig cc, RequestEntityProcessing mode) {
Expand Down

0 comments on commit e40b9ac

Please sign in to comment.