use of software.amazon.eventstream.MessageDecoder in project aws-sdk-java-v2 by aws.
the class Aws4EventStreamSignerTest method testEventStreamSigning.
@Test
public void testEventStreamSigning() {
TestVector testVector = generateTestVector();
SdkHttpFullRequest.Builder request = testVector.httpFullRequest();
AwsBasicCredentials credentials = AwsBasicCredentials.create("access", "secret");
SdkHttpFullRequest signedRequest = SignerTestUtils.signRequest(signer, request.build(), credentials, "demo", signingClock(), "us-east-1");
AsyncRequestBody transformedPublisher = SignerTestUtils.signAsyncRequest(signer, signedRequest, testVector.requestBodyPublisher(), credentials, "demo", signingClock(), "us-east-1");
TestSubscriber testSubscriber = TestSubscriber.create();
Flowable.fromPublisher(transformedPublisher).flatMap(new Function<ByteBuffer, Publisher<?>>() {
Queue<Message> messages = new LinkedList<>();
MessageDecoder decoder = new MessageDecoder(message -> messages.offer(message));
@Override
public Publisher<?> apply(ByteBuffer byteBuffer) throws Exception {
decoder.feed(byteBuffer.array());
List<Message> messageList = new ArrayList<>();
while (!messages.isEmpty()) {
messageList.add(messages.poll());
}
return Flowable.fromIterable(messageList);
}
}).subscribe(testSubscriber);
testSubscriber.assertNoErrors();
testSubscriber.assertComplete();
testSubscriber.assertValueSequence(testVector.expectedMessagePublisher().blockingIterable());
}
use of software.amazon.eventstream.MessageDecoder in project aws-sdk-java-v2 by aws.
the class Aws4EventStreamSignerTest method testBackPressure.
/**
* Test that without demand from subscriber, trailing empty frame is not delivered
*/
@Test
public void testBackPressure() {
TestVector testVector = generateTestVector();
SdkHttpFullRequest.Builder request = testVector.httpFullRequest();
AwsBasicCredentials credentials = AwsBasicCredentials.create("access", "secret");
SdkHttpFullRequest signedRequest = SignerTestUtils.signRequest(signer, request.build(), credentials, "demo", signingClock(), "us-east-1");
AsyncRequestBody transformedPublisher = SignerTestUtils.signAsyncRequest(signer, signedRequest, testVector.requestBodyPublisher(), credentials, "demo", signingClock(), "us-east-1");
Subscriber<Object> subscriber = Mockito.spy(new Subscriber<Object>() {
@Override
public void onSubscribe(Subscription s) {
// Only request the number of request body (excluding trailing empty frame)
s.request(testVector.requestBody().size());
}
@Override
public void onNext(Object o) {
}
@Override
public void onError(Throwable t) {
fail("onError should never been called");
}
@Override
public void onComplete() {
fail("onComplete should never been called");
}
});
Flowable.fromPublisher(transformedPublisher).flatMap(new Function<ByteBuffer, Publisher<?>>() {
Queue<Message> messages = new LinkedList<>();
MessageDecoder decoder = new MessageDecoder(message -> messages.offer(message));
@Override
public Publisher<?> apply(ByteBuffer byteBuffer) throws Exception {
decoder.feed(byteBuffer.array());
List<Message> messageList = new ArrayList<>();
while (!messages.isEmpty()) {
messageList.add(messages.poll());
}
return Flowable.fromIterable(messageList);
}
}).subscribe(subscriber);
// The number of events equal to the size of request body (excluding trailing empty frame)
verify(subscriber, times(testVector.requestBody().size())).onNext(any());
// subscriber is not terminated (no onError/onComplete) since trailing empty frame is not delivered yet
verify(subscriber, never()).onError(any());
verify(subscriber, never()).onComplete();
}
use of software.amazon.eventstream.MessageDecoder in project aws-sdk-java-v2 by aws.
the class EventStreamAws4SignerTest method readMessages.
private List<Message> readMessages(AsyncRequestBody signedBody) {
MessageDecoder decoder = new MessageDecoder();
Flowable.fromPublisher(signedBody).blockingForEach(x -> decoder.feed(x.array()));
return decoder.getDecodedMessages();
}
use of software.amazon.eventstream.MessageDecoder in project aws-sdk-java-v2 by aws.
the class EventMarshallingTest method setup.
@Before
public void setup() {
when(mockHttpClient.execute(any(AsyncExecuteRequest.class))).thenAnswer(this::mockExecute);
client = EventStreamRestJsonAsyncClient.builder().region(Region.US_WEST_2).credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("akid", "skid"))).httpClient(mockHttpClient).build();
marshalledEvents = new ArrayList<>();
chunkDecoder = new MessageDecoder();
eventDecoder = new MessageDecoder();
}
Aggregations