|
18 | 18 | import static org.assertj.core.api.Assertions.assertThat; |
19 | 19 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
20 | 20 |
|
| 21 | +import java.io.BufferedOutputStream; |
21 | 22 | import java.io.ByteArrayInputStream; |
22 | 23 | import java.io.IOException; |
| 24 | +import java.io.OutputStream; |
23 | 25 | import java.util.concurrent.Executors; |
24 | 26 | import org.junit.jupiter.api.BeforeEach; |
25 | 27 | import org.junit.jupiter.api.Test; |
26 | 28 | import software.amazon.awssdk.core.ResponseBytes; |
27 | 29 | import software.amazon.awssdk.core.async.AsyncRequestBody; |
| 30 | +import software.amazon.awssdk.core.async.AsyncResponseTransformer; |
28 | 31 | import software.amazon.awssdk.core.interceptor.Context; |
29 | 32 | import software.amazon.awssdk.core.interceptor.ExecutionAttributes; |
30 | 33 | import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; |
@@ -97,6 +100,37 @@ public void streamingOutputOperation_syncClient_file_recordsMetadata() throws IO |
97 | 100 | assertThat(interceptor.userAgent()).contains("md/rt#f"); |
98 | 101 | } |
99 | 102 |
|
| 103 | + @Test |
| 104 | + public void streamingOutputOperation_syncClient_stream_recordsMetadata() throws IOException { |
| 105 | + callStreamingOutputOperation(syncClient(), ResponseTransformer.toOutputStream(new OutputStream() { |
| 106 | + @Override |
| 107 | + public void write(int b) throws IOException { |
| 108 | + |
| 109 | + } |
| 110 | + })); |
| 111 | + assertThat(interceptor.userAgent()).contains("md/rt#s"); |
| 112 | + } |
| 113 | + |
| 114 | + @Test |
| 115 | + public void streamingOutputOperation_asyncClient_bytes_recordsMetadata() { |
| 116 | + callStreamingOutputOperation(asyncClient(), AsyncResponseTransformer.toBytes()); |
| 117 | + assertThat(interceptor.userAgent()).contains("md/rt#b"); |
| 118 | + } |
| 119 | + |
| 120 | + @Test |
| 121 | + public void streamingOutputOperation_asyncClient_file_recordsMetadata() throws IOException { |
| 122 | + callStreamingOutputOperation(asyncClient(), AsyncResponseTransformer.toFile(new RandomTempFile(0))); |
| 123 | + assertThat(interceptor.userAgent()).contains("md/rt#f"); |
| 124 | + } |
| 125 | + |
| 126 | + @Test |
| 127 | + public void streamingOutputOperation_asyncClient_publisher_recordsMetadata() { |
| 128 | + callStreamingOutputOperation(asyncClient(), AsyncResponseTransformer.toPublisher()); |
| 129 | + assertThat(interceptor.userAgent()).contains("md/rt#p"); |
| 130 | + } |
| 131 | + |
| 132 | + |
| 133 | + |
100 | 134 | private ProtocolRestJsonWithConfigClient syncClient() { |
101 | 135 | return ProtocolRestJsonWithConfigClient |
102 | 136 | .builder() |
@@ -133,6 +167,12 @@ private static void callStreamingInputOperation(ProtocolRestJsonWithConfigAsyncC |
133 | 167 | }).hasMessageContaining("stop"); |
134 | 168 | } |
135 | 169 |
|
| 170 | + private void callStreamingOutputOperation( |
| 171 | + ProtocolRestJsonWithConfigAsyncClient client, AsyncResponseTransformer<StreamingOutputOperationResponse, ?> transformer) { |
| 172 | + assertThatThrownBy(() -> client.streamingOutputOperation(r -> {}, transformer).join()) |
| 173 | + .hasMessageContaining("stop"); |
| 174 | + } |
| 175 | + |
136 | 176 | public static class CapturingInterceptor implements ExecutionInterceptor { |
137 | 177 | private Context.BeforeTransmission context; |
138 | 178 | private ExecutionAttributes executionAttributes; |
|
0 commit comments