use of org.springframework.integration.aws.support.AwsRequestFailureException in project spring-integration-aws by spring-projects.
the class KinesisProducingMessageHandlerTests method testKinesisMessageHandler.
@Test
@SuppressWarnings("unchecked")
public void testKinesisMessageHandler() {
Message<?> message = MessageBuilder.withPayload("message").build();
try {
this.kinesisSendChannel.send(message);
} catch (Exception e) {
assertThat(e).isInstanceOf(MessageHandlingException.class);
assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
assertThat(e.getMessage()).contains("'stream' must not be null for sending a Kinesis record");
}
this.kinesisMessageHandler.setStream("foo");
try {
this.kinesisSendChannel.send(message);
} catch (Exception e) {
assertThat(e).isInstanceOf(MessageHandlingException.class);
assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
assertThat(e.getMessage()).contains("'partitionKey' must not be null for sending a Kinesis record");
}
message = MessageBuilder.fromMessage(message).setHeader(AwsHeaders.PARTITION_KEY, "fooKey").setHeader(AwsHeaders.SEQUENCE_NUMBER, "10").build();
this.kinesisSendChannel.send(message);
Message<?> success = this.successChannel.receive(10000);
assertThat(success.getHeaders().get(AwsHeaders.PARTITION_KEY)).isEqualTo("fooKey");
assertThat(success.getHeaders().get(AwsHeaders.SEQUENCE_NUMBER)).isEqualTo("10");
assertThat(success.getPayload()).isEqualTo("message");
message = MessageBuilder.fromMessage(message).setHeader(AwsHeaders.PARTITION_KEY, "fooKey").setHeader(AwsHeaders.SEQUENCE_NUMBER, "10").build();
this.kinesisSendChannel.send(message);
Message<?> failed = this.errorChannel.receive(10000);
AwsRequestFailureException putRecordFailure = (AwsRequestFailureException) failed.getPayload();
assertThat(putRecordFailure.getCause().getMessage()).isEqualTo("putRecordRequestEx");
assertThat(((PutRecordRequest) putRecordFailure.getRequest()).getStreamName()).isEqualTo("foo");
assertThat(((PutRecordRequest) putRecordFailure.getRequest()).getPartitionKey()).isEqualTo("fooKey");
assertThat(((PutRecordRequest) putRecordFailure.getRequest()).getSequenceNumberForOrdering()).isEqualTo("10");
assertThat(((PutRecordRequest) putRecordFailure.getRequest()).getExplicitHashKey()).isNull();
assertThat(((PutRecordRequest) putRecordFailure.getRequest()).getData()).isEqualTo(ByteBuffer.wrap("message".getBytes()));
message = new GenericMessage<>(new PutRecordsRequest().withStreamName("myStream").withRecords(new PutRecordsRequestEntry().withData(ByteBuffer.wrap("test".getBytes())).withPartitionKey("testKey")));
this.kinesisSendChannel.send(message);
success = this.successChannel.receive(10000);
assertThat(((PutRecordsRequest) success.getPayload()).getRecords()).containsExactlyInAnyOrder(new PutRecordsRequestEntry().withData(ByteBuffer.wrap("test".getBytes())).withPartitionKey("testKey"));
message = new GenericMessage<>(new PutRecordsRequest().withStreamName("myStream").withRecords(new PutRecordsRequestEntry().withData(ByteBuffer.wrap("test".getBytes())).withPartitionKey("testKey")));
this.kinesisSendChannel.send(message);
failed = this.errorChannel.receive(10000);
AwsRequestFailureException putRecordsFailure = (AwsRequestFailureException) failed.getPayload();
assertThat(putRecordsFailure.getCause().getMessage()).isEqualTo("putRecordsRequestEx");
assertThat(((PutRecordsRequest) putRecordsFailure.getRequest()).getStreamName()).isEqualTo("myStream");
assertThat(((PutRecordsRequest) putRecordsFailure.getRequest()).getRecords()).containsExactlyInAnyOrder(new PutRecordsRequestEntry().withData(ByteBuffer.wrap("test".getBytes())).withPartitionKey("testKey"));
}
Aggregations