Skip to content

Commit 5f781f1

Browse files
millemsdagnir
authored andcommitted
Attempting to test.
1 parent 20dc5f5 commit 5f781f1

File tree

16 files changed

+630
-12
lines changed

16 files changed

+630
-12
lines changed

http-clients/netty-nio-client/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@
9797
</dependency>
9898

9999
<!--Test Dependencies-->
100+
<dependency>
101+
<groupId>software.amazon.awssdk</groupId>
102+
<artifactId>test-server</artifactId>
103+
<version>${awsjavasdk.version}</version>
104+
<scope>test</scope>
105+
</dependency>
100106
<dependency>
101107
<groupId>com.github.tomakehurst</groupId>
102108
<artifactId>wiremock</artifactId>

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/http2/GoAwayException.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
package software.amazon.awssdk.http.nio.netty.internal.http2;
1717

18-
1918
import io.netty.buffer.ByteBuf;
2019
import java.io.IOException;
2120
import java.nio.charset.StandardCharsets;

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/http2/Http2ToHttpInboundAdapter.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,11 @@
2525
import io.netty.handler.codec.http2.Http2Error;
2626
import io.netty.handler.codec.http2.Http2Exception;
2727
import io.netty.handler.codec.http2.Http2Frame;
28-
import io.netty.handler.codec.http2.Http2GoAwayFrame;
2928
import io.netty.handler.codec.http2.Http2HeadersFrame;
3029
import io.netty.handler.codec.http2.Http2ResetFrame;
3130
import io.netty.handler.codec.http2.HttpConversionUtil;
3231
import java.io.IOException;
33-
import java.nio.charset.StandardCharsets;
34-
3532
import software.amazon.awssdk.annotations.SdkInternalApi;
36-
import software.amazon.awssdk.utils.BinaryUtils;
3733

3834
/**
3935
* Converts {@link Http2Frame}s to {@link HttpObject}s. Ignores the majority of {@link Http2Frame}s like PING

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/http2/MultiplexedChannelRecord.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ MultiplexedChannelRecord acquire(Promise<Channel> channelPromise) {
103103
* streams newer than the last-stream-id on the go-away frame.
104104
*/
105105
public void goAway(Http2GoAwayFrame frame) {
106+
System.out.println("Got GOAWAY: " + frame);
106107
this.goAway = true;
107108
doInEventLoop(connection.eventLoop(), () -> {
108109
GoAwayException exception = new GoAwayException(frame.errorCode(), frame.content());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.http.nio.netty;
17+
18+
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
19+
20+
import io.reactivex.Flowable;
21+
import java.net.URI;
22+
import java.nio.ByteBuffer;
23+
import java.util.Optional;
24+
import java.util.concurrent.CompletableFuture;
25+
import org.junit.AfterClass;
26+
import org.junit.BeforeClass;
27+
import org.junit.Test;
28+
import org.reactivestreams.Publisher;
29+
import org.reactivestreams.Subscriber;
30+
import software.amazon.awssdk.http.Protocol;
31+
import software.amazon.awssdk.http.SdkHttpMethod;
32+
import software.amazon.awssdk.http.SdkHttpRequest;
33+
import software.amazon.awssdk.http.SdkHttpResponse;
34+
import software.amazon.awssdk.http.async.AsyncExecuteRequest;
35+
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
36+
import software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler;
37+
import software.amazon.awssdk.http.async.SdkHttpContentPublisher;
38+
import software.amazon.awssdk.testserver.MockH2Server;
39+
import software.amazon.awssdk.utils.Logger;
40+
41+
public class GoAwayFrameMockServerTest {
42+
private static final Logger log = Logger.loggerFor(GoAwayFrameMockServerTest.class);
43+
private static MockH2Server server;
44+
45+
@BeforeClass
46+
public static void setup() throws Exception {
47+
server = new MockH2Server(false);
48+
server.start();
49+
}
50+
51+
@AfterClass
52+
public static void teardown() throws Exception {
53+
server.stop();
54+
}
55+
56+
@Test(timeout = 10_000)
57+
public void test() throws InterruptedException {
58+
SdkAsyncHttpClient client = NettyNioAsyncHttpClient.builder().protocol(Protocol.HTTP2).build();
59+
60+
URI serverUri = server.getHttpUri();
61+
CompletableFuture<Void> call = startCall(client, serverUri);
62+
// Thread.sleep(1_000);
63+
// CompletableFuture<Void> call2 = startCall(client, serverUri);
64+
65+
// TODO: Ensure the first call worked, but the second one didn't
66+
call.join();
67+
// assertThatThrownBy(call2::join).isNotNull();
68+
}
69+
70+
private CompletableFuture<Void> startCall(SdkAsyncHttpClient client, URI serverUri) {
71+
return client.execute(AsyncExecuteRequest.builder()
72+
.request(SdkHttpRequest.builder()
73+
.protocol(serverUri.getScheme())
74+
.host(serverUri.getHost())
75+
.port(serverUri.getPort())
76+
.method(SdkHttpMethod.POST)
77+
.encodedPath("/")
78+
.putHeader("host", serverUri.getHost() + ":" + serverUri.getPort())
79+
.build())
80+
.requestContentPublisher(junkStream(100))
81+
.fullDuplex(true)
82+
.responseHandler(dataIgnoringResponseHandler())
83+
.build());
84+
}
85+
86+
public SdkHttpContentPublisher junkStream(long length) {
87+
Flowable<ByteBuffer> publisher = Flowable.generate(e -> e.onNext(ByteBuffer.wrap(new byte[]{'X'})));
88+
return new SdkHttpContentPublisher() {
89+
@Override
90+
public Optional<Long> contentLength() {
91+
return Optional.of(length);
92+
}
93+
94+
@Override
95+
public void subscribe(Subscriber<? super ByteBuffer> s) {
96+
publisher.take(length).subscribe(s);
97+
}
98+
};
99+
}
100+
101+
public SdkAsyncHttpResponseHandler dataIgnoringResponseHandler() {
102+
return new SdkAsyncHttpResponseHandler() {
103+
@Override
104+
public void onHeaders(SdkHttpResponse headers) {
105+
log.info(() -> "onHeaders");
106+
}
107+
108+
@Override
109+
public void onStream(Publisher<ByteBuffer> stream) {
110+
// Read the response payload
111+
Flowable.fromPublisher(stream).subscribe(b -> {});
112+
log.info(() -> "onStream");
113+
}
114+
115+
@Override
116+
public void onError(Throwable error) {
117+
log.error(() -> "Error on response: " + error.getMessage(), error);
118+
}
119+
};
120+
}
121+
}

http-clients/netty-nio-client/src/test/java/software/amazon/awssdk/http/nio/netty/internal/http2/Http2MultiplexedChannelPoolTest.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@
2121
import io.netty.channel.pool.ChannelPool;
2222
import io.netty.channel.socket.SocketChannel;
2323
import io.netty.channel.socket.nio.NioSocketChannel;
24+
import io.netty.handler.codec.http2.DefaultHttp2GoAwayFrame;
25+
import io.netty.util.Attribute;
2426
import io.netty.util.concurrent.DefaultPromise;
2527
import io.netty.util.concurrent.Promise;
28+
import java.net.InetAddress;
29+
import java.net.InetSocketAddress;
30+
import java.net.SocketAddress;
31+
import java.util.concurrent.ExecutionException;
32+
import java.util.concurrent.TimeUnit;
33+
import java.util.concurrent.TimeoutException;
2634
import org.junit.AfterClass;
2735
import org.junit.BeforeClass;
2836
import org.junit.Test;
@@ -31,8 +39,12 @@
3139

3240
import java.util.Collections;
3341
import java.util.concurrent.CompletableFuture;
42+
import software.amazon.awssdk.http.Protocol;
43+
import software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey;
3444

3545
import static org.assertj.core.api.Assertions.assertThat;
46+
import static org.mockito.Matchers.eq;
47+
import static org.mockito.internal.verification.VerificationModeFactory.times;
3648

3749
/**
3850
* Tests for {@link Http2MultiplexedChannelPool}.
@@ -62,7 +74,7 @@ public void closeWaitsForConnectionToBeReleasedBeforeClosingConnectionPool() thr
6274
Promise<Void> releasePromise = Mockito.spy(new DefaultPromise<>(loopGroup.next()));
6375
Mockito.doCallRealMethod().when(releasePromise).await();
6476
releasePromise.setSuccess(null);
65-
Mockito.when(connectionPool.release(Mockito.eq(channel))).thenReturn(releasePromise);
77+
Mockito.when(connectionPool.release(eq(channel))).thenReturn(releasePromise);
6678

6779
MultiplexedChannelRecord record = new MultiplexedChannelRecord(channelPromise,
6880
channel,
@@ -102,13 +114,13 @@ public void interruptDuringClosePreservesFlag() throws InterruptedException {
102114
ChannelPool connectionPool = Mockito.mock(ChannelPool.class);
103115
Promise<Void> releasePromise = Mockito.spy(new DefaultPromise<>(loopGroup.next()));
104116

105-
Mockito.when(connectionPool.release(Mockito.eq(channel))).thenReturn(releasePromise);
117+
Mockito.when(connectionPool.release(eq(channel))).thenReturn(releasePromise);
106118

107119
MultiplexedChannelRecord record = new MultiplexedChannelRecord(channelPromise,
108-
channel,
109-
8,
110-
(ch, rec) -> {
111-
});
120+
channel,
121+
8,
122+
(ch, rec) -> {
123+
});
112124
Http2MultiplexedChannelPool h2Pool = new Http2MultiplexedChannelPool(connectionPool, loopGroup.next(), 2, Collections.singletonList(record));
113125

114126
CompletableFuture<Boolean> interrupteFlagPreserved = new CompletableFuture<>();

http-clients/netty-nio-client/src/test/resources/log4j.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# permissions and limitations under the License.
1414
#
1515

16-
log4j.rootLogger=ERROR, A1
16+
log4j.rootLogger=DEBUG, A1
1717
log4j.appender.A1=org.apache.log4j.ConsoleAppender
1818
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
1919

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
<module>test/module-path-tests</module>
7979
<module>test/tests-coverage-reporting</module>
8080
<module>test/stability-tests</module>
81+
<module>test/test-server</module>
8182
</modules>
8283
<scm>
8384
<url>https://github.com/aws/aws-sdk-java-v2.git</url>

test/test-server/pom.xml

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<!--
2+
~ Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License").
5+
~ You may not use this file except in compliance with the License.
6+
~ A copy of the License is located at
7+
~
8+
~ http://aws.amazon.com/apache2.0
9+
~
10+
~ or in the "license" file accompanying this file. This file is distributed
11+
~ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
~ express or implied. See the License for the specific language governing
13+
~ permissions and limitations under the License.
14+
-->
15+
16+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
18+
<modelVersion>4.0.0</modelVersion>
19+
<parent>
20+
<groupId>software.amazon.awssdk</groupId>
21+
<artifactId>aws-sdk-java-pom</artifactId>
22+
<version>2.9.22-SNAPSHOT</version>
23+
<relativePath>../../pom.xml</relativePath>
24+
</parent>
25+
26+
<artifactId>test-server</artifactId>
27+
<packaging>jar</packaging>
28+
29+
<name>AWS Java SDK :: Test :: Test Servers</name>
30+
<description>Contains low-level test servers for validating client functionality</description>
31+
32+
<properties>
33+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34+
<javac.target>1.8</javac.target>
35+
</properties>
36+
37+
<dependencies>
38+
<dependency>
39+
<groupId>org.eclipse.jetty</groupId>
40+
<artifactId>jetty-servlet</artifactId>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.eclipse.jetty</groupId>
44+
<artifactId>jetty-server</artifactId>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.eclipse.jetty.http2</groupId>
48+
<artifactId>http2-server</artifactId>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.eclipse.jetty</groupId>
52+
<artifactId>jetty-alpn-java-server</artifactId>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.eclipse.jetty.http2</groupId>
56+
<artifactId>http2-hpack</artifactId>
57+
</dependency>
58+
</dependencies>
59+
60+
<dependencyManagement>
61+
<dependencies>
62+
<dependency>
63+
<groupId>software.amazon.awssdk</groupId>
64+
<artifactId>bom-internal</artifactId>
65+
<version>${awsjavasdk.version}</version>
66+
<type>pom</type>
67+
<scope>import</scope>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.eclipse.jetty</groupId>
71+
<artifactId>jetty-bom</artifactId>
72+
<version>9.4.19.v20190610</version>
73+
<type>pom</type>
74+
<scope>import</scope>
75+
</dependency>
76+
</dependencies>
77+
</dependencyManagement>
78+
79+
<!-- <build>-->
80+
<!-- <resources>-->
81+
<!-- <resource>-->
82+
<!-- <directory>src/main/resources</directory>-->
83+
<!-- </resource>-->
84+
<!-- </resources>-->
85+
<!-- <pluginManagement>-->
86+
<!-- <plugins>-->
87+
<!-- <plugin>-->
88+
<!-- <groupId>org.apache.maven.plugins</groupId>-->
89+
<!-- <artifactId>maven-compiler-plugin</artifactId>-->
90+
<!-- <version>3.1</version>-->
91+
<!-- Override the configuration in the parent-->
92+
<!-- <configuration combine.self="override">-->
93+
<!-- <compilerVersion>${javac.target}</compilerVersion>-->
94+
<!-- <source>${javac.target}</source>-->
95+
<!-- <target>${javac.target}</target>-->
96+
<!-- </configuration>-->
97+
<!-- <executions>-->
98+
<!-- <execution>-->
99+
<!-- <id>compile</id>-->
100+
<!-- <phase>none</phase>-->
101+
<!-- </execution>-->
102+
<!-- </executions>-->
103+
<!-- <inherited>false</inherited>-->
104+
<!-- </plugin>-->
105+
<!-- <plugin>-->
106+
<!-- <artifactId>maven-clean-plugin</artifactId>-->
107+
<!-- <version>2.5</version>-->
108+
<!-- </plugin>-->
109+
<!-- <plugin>-->
110+
<!-- <artifactId>maven-deploy-plugin</artifactId>-->
111+
<!-- <version>2.8.1</version>-->
112+
<!-- </plugin>-->
113+
<!-- <plugin>-->
114+
<!-- <artifactId>maven-install-plugin</artifactId>-->
115+
<!-- <version>2.5.1</version>-->
116+
<!-- </plugin>-->
117+
<!-- <plugin>-->
118+
<!-- <artifactId>maven-jar-plugin</artifactId>-->
119+
<!-- <version>2.4</version>-->
120+
<!-- </plugin>-->
121+
<!-- <plugin>-->
122+
<!-- <artifactId>maven-javadoc-plugin</artifactId>-->
123+
<!-- <version>2.9.1</version>-->
124+
<!-- </plugin>-->
125+
<!-- <plugin>-->
126+
<!-- <artifactId>maven-resources-plugin</artifactId>-->
127+
<!-- <version>2.6</version>-->
128+
<!-- </plugin>-->
129+
<!-- <plugin>-->
130+
<!-- <artifactId>maven-site-plugin</artifactId>-->
131+
<!-- <version>3.3</version>-->
132+
<!-- </plugin>-->
133+
<!-- <plugin>-->
134+
<!-- <artifactId>maven-source-plugin</artifactId>-->
135+
<!-- <version>2.2.1</version>-->
136+
<!-- </plugin>-->
137+
<!-- <plugin>-->
138+
<!-- <artifactId>maven-surefire-plugin</artifactId>-->
139+
<!-- <version>2.17</version>-->
140+
<!-- </plugin>-->
141+
<!-- </plugins>-->
142+
<!-- </pluginManagement>-->
143+
<!-- <plugins>-->
144+
<!-- <plugin>-->
145+
<!-- <groupId>org.apache.maven.plugins</groupId>-->
146+
<!-- <artifactId>maven-compiler-plugin</artifactId>-->
147+
<!-- </plugin>-->
148+
<!-- </plugins>-->
149+
<!-- </build>-->
150+
151+
</project>

0 commit comments

Comments
 (0)