Skip to content

Commit

Permalink
Remove duplications (#2925)
Browse files Browse the repository at this point in the history
  • Loading branch information
violetagg committed Oct 5, 2023
1 parent 69af8bc commit ac7f7ba
Showing 1 changed file with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import io.netty.handler.ssl.util.SelfSignedCertificate;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import reactor.core.publisher.Hooks;
Expand All @@ -54,29 +56,40 @@ class ContextPropagationTest {
static final ConnectionProvider provider = ConnectionProvider.create("testContextPropagation", 1);
static final ContextRegistry registry = ContextRegistry.getInstance();

static SelfSignedCertificate ssc;

HttpServer baseServer;
DisposableServer disposableServer;
SelfSignedCertificate ssc;
Http2SslContextSpec serverCtx;


@BeforeAll
static void createSelfSignedCertificate() throws Exception {
ssc = new SelfSignedCertificate();
}

@AfterAll
static void disposePool() {
provider.disposeLater()
.block(Duration.ofSeconds(30));
}

@ParameterizedTest
@MethodSource("httpClientCombinations")
void testContextPropagation(HttpClient client) throws Exception {
ssc = new SelfSignedCertificate();
Http2SslContextSpec serverCtxHttp = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
HttpServer server =
@BeforeEach
void setUp() {
serverCtx = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
baseServer =
HttpServer.create()
.wiretap(true)
.httpRequestDecoder(spec -> spec.h2cMaxContentLength(256))
.handle((in, out) -> out.send(in.receive().retain()));
}

server = client.configuration().sslProvider() != null ?
server.secure(spec -> spec.sslContext(serverCtxHttp)).protocol(HttpProtocol.HTTP11, HttpProtocol.H2) :
server.protocol(HttpProtocol.HTTP11, HttpProtocol.H2C);
@ParameterizedTest
@MethodSource("httpClientCombinations")
void testContextPropagation(HttpClient client) {
HttpServer server = client.configuration().sslProvider() != null ?
baseServer.secure(spec -> spec.sslContext(serverCtx)).protocol(HttpProtocol.HTTP11, HttpProtocol.H2) :
baseServer.protocol(HttpProtocol.HTTP11, HttpProtocol.H2C);

disposableServer = server.bindNow();

Expand Down Expand Up @@ -108,25 +121,17 @@ void testContextPropagation(HttpClient client) throws Exception {

@ParameterizedTest
@MethodSource("httpClientCombinations")
void testAutomaticContextPropagation(HttpClient client) throws Exception {
void testAutomaticContextPropagation(HttpClient client) {
String reactorCoreVersionMinor = System.getProperty("reactorCoreVersionMinor");
String contextPropagationVersionMicro = System.getProperty("contextPropagationVersionMicro");

boolean enableAutomaticContextPropagation =
reactorCoreVersionMinor != null && !reactorCoreVersionMinor.isEmpty() && Integer.parseInt(reactorCoreVersionMinor) >= 6 && // 3.6.x
contextPropagationVersionMicro != null && !contextPropagationVersionMicro.isEmpty() && Integer.parseInt(contextPropagationVersionMicro) >= 5; // 1.0.5 or above

ssc = new SelfSignedCertificate();
Http2SslContextSpec serverCtxHttp = Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey());
HttpServer server =
HttpServer.create()
.wiretap(true)
.httpRequestDecoder(spec -> spec.h2cMaxContentLength(256))
.handle((in, out) -> out.send(in.receive().retain()));

server = client.configuration().sslProvider() != null ?
server.secure(spec -> spec.sslContext(serverCtxHttp)).protocol(HttpProtocol.HTTP11, HttpProtocol.H2) :
server.protocol(HttpProtocol.HTTP11, HttpProtocol.H2C);
HttpServer server = client.configuration().sslProvider() != null ?
baseServer.secure(spec -> spec.sslContext(serverCtx)).protocol(HttpProtocol.HTTP11, HttpProtocol.H2) :
baseServer.protocol(HttpProtocol.HTTP11, HttpProtocol.H2C);

disposableServer = server.bindNow();

Expand Down

0 comments on commit ac7f7ba

Please sign in to comment.