software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException Java Examples
The following examples show how to use
software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SubscribeToShardUnmarshallingTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Test public void exceptionWithMessage_UnmarshalledCorrectly() throws Throwable { String errorCode = "ResourceNotFoundException"; AbortableInputStream content = new MessageWriter() .writeInitialResponse(new byte[0]) .writeException("{\"message\": \"foo\"}", errorCode) .toInputStream(); stubResponse(SdkHttpFullResponse.builder() .statusCode(200) .content(content) .putHeader("x-amzn-requestid", REQUEST_ID) .build()); try { subscribeToShard(); fail("Expected ResourceNotFoundException exception"); } catch (ResourceNotFoundException e) { assertThat(e.requestId()).isEqualTo(REQUEST_ID); assertThat(e.statusCode()).isEqualTo(500); assertThat(e.awsErrorDetails().errorCode()).isEqualTo(errorCode); assertThat(e.awsErrorDetails().errorMessage()).isEqualTo("foo"); assertThat(e.awsErrorDetails().serviceName()).isEqualTo("kinesis"); } }
Example #2
Source File: FanOutRecordsPublisher.java From amazon-kinesis-client with Apache License 2.0 | 6 votes |
private void handleFlowError(Throwable t, RecordFlow triggeringFlow) { if (t.getCause() instanceof ResourceNotFoundException) { log.debug( "{}: Could not call SubscribeToShard successfully because shard no longer exists. Marking shard for completion.", shardId); // The ack received for this onNext event will be ignored by the publisher as the global flow object should // be either null or renewed when the ack's flow identifier is evaluated. FanoutRecordsRetrieved response = new FanoutRecordsRetrieved( ProcessRecordsInput.builder().records(Collections.emptyList()).isAtShardEnd(true).build(), null, triggeringFlow != null ? triggeringFlow.getSubscribeToShardId() : shardId + "-no-flow-found"); subscriber.onNext(response); subscriber.onComplete(); } else { subscriber.onError(t); } }
Example #3
Source File: KinesisDataFetcher.java From amazon-kinesis-client with Apache License 2.0 | 6 votes |
/** * Get records from the current position in the stream (up to maxRecords). * * @return list of records of up to maxRecords size */ public DataFetcherResult getRecords() { if (!isInitialized) { throw new IllegalArgumentException("KinesisDataFetcher.records called before initialization."); } if (nextIterator != null) { try { return new AdvancingResult(getRecords(nextIterator)); } catch (ResourceNotFoundException e) { log.info("Caught ResourceNotFoundException when fetching records for shard {}", shardId); return TERMINAL_RESULT; } } else { return TERMINAL_RESULT; } }
Example #4
Source File: FanOutRecordsPublisherTest.java From amazon-kinesis-client with Apache License 2.0 | 6 votes |
@Test public void testResourceNotFoundForShard() { FanOutRecordsPublisher source = new FanOutRecordsPublisher(kinesisClient, SHARD_ID, CONSUMER_ARN); ArgumentCaptor<FanOutRecordsPublisher.RecordFlow> flowCaptor = ArgumentCaptor .forClass(FanOutRecordsPublisher.RecordFlow.class); ArgumentCaptor<RecordsRetrieved> inputCaptor = ArgumentCaptor.forClass(RecordsRetrieved.class); source.subscribe(subscriber); verify(kinesisClient).subscribeToShard(any(SubscribeToShardRequest.class), flowCaptor.capture()); FanOutRecordsPublisher.RecordFlow recordFlow = flowCaptor.getValue(); recordFlow.exceptionOccurred(new RuntimeException(ResourceNotFoundException.builder().build())); verify(subscriber).onSubscribe(any()); verify(subscriber, never()).onError(any()); verify(subscriber).onNext(inputCaptor.capture()); verify(subscriber).onComplete(); ProcessRecordsInput input = inputCaptor.getValue().processRecordsInput(); assertThat(input.isAtShardEnd(), equalTo(true)); assertThat(input.records().isEmpty(), equalTo(true)); }
Example #5
Source File: FanOutConsumerRegistrationTest.java From amazon-kinesis-client with Apache License 2.0 | 6 votes |
@Test(expected = DependencyException.class) public void testRegisterStreamConsumerThrottled() throws Exception { final CompletableFuture<DescribeStreamSummaryResponse> dssFuture = CompletableFuture .completedFuture(createDescribeStreamSummaryResponse()); final CompletableFuture<DescribeStreamConsumerResponse> dscFuture = CompletableFuture.supplyAsync(() -> { throw ResourceNotFoundException.builder().build(); }); final CompletableFuture<RegisterStreamConsumerResponse> rscFuture = CompletableFuture.supplyAsync(() -> { throw LimitExceededException.builder().build(); }); when(client.describeStreamSummary(any(DescribeStreamSummaryRequest.class))).thenReturn(dssFuture); when(client.describeStreamConsumer(any(DescribeStreamConsumerRequest.class))).thenReturn(dscFuture); when(client.registerStreamConsumer(any(RegisterStreamConsumerRequest.class))).thenReturn(rscFuture); try { consumerRegistration.getOrCreateStreamConsumerArn(); } finally { verify(client, times(RSC_RETRIES)) .registerStreamConsumer(any(RegisterStreamConsumerRequest.class)); } }
Example #6
Source File: KinesisDataFetcherTest.java From amazon-kinesis-client with Apache License 2.0 | 6 votes |
@Test public void testNonNullGetRecords() throws Exception { final String nextIterator = "TestIterator"; final ArgumentCaptor<GetShardIteratorRequest> iteratorCaptor = ArgumentCaptor .forClass(GetShardIteratorRequest.class); final ArgumentCaptor<GetRecordsRequest> recordsCaptor = ArgumentCaptor.forClass(GetRecordsRequest.class); final GetShardIteratorRequest expectedIteratorRequest = makeGetShardIteratorRequest( ShardIteratorType.LATEST.name()); final GetRecordsRequest expectedRecordsRequest = makeGetRecordsRequest(nextIterator); final CompletableFuture<GetRecordsResponse> future = mock(CompletableFuture.class); when(kinesisClient.getShardIterator(iteratorCaptor.capture())) .thenReturn(makeGetShardIteratorResonse(nextIterator)); when(kinesisClient.getRecords(recordsCaptor.capture())).thenReturn(future); when(future.get(anyLong(), any(TimeUnit.class))).thenThrow( new ExecutionException(ResourceNotFoundException.builder().message("Test Exception").build())); kinesisDataFetcher.initialize(SentinelCheckpoint.LATEST.toString(), INITIAL_POSITION_LATEST); DataFetcherResult dataFetcherResult = kinesisDataFetcher.getRecords(); assertNotNull(dataFetcherResult); assertEquals(expectedIteratorRequest.startingSequenceNumber(), iteratorCaptor.getValue().startingSequenceNumber()); assertEquals(expectedRecordsRequest.shardIterator(), recordsCaptor.getValue().shardIterator()); }
Example #7
Source File: KinesisIntegrationTests.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void testDescribeBogusStream() { try { client.describeStream(DescribeStreamRequest.builder().streamName("bogus-stream-name").build()); Assert.fail("Expected ResourceNotFoundException"); } catch (ResourceNotFoundException exception) { // Ignored or expected. } }
Example #8
Source File: KinesisIntegrationTests.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void testDeleteBogusStream() { try { client.deleteStream(DeleteStreamRequest.builder().streamName("bogus-stream-name").build()); Assert.fail("Expected ResourceNotFoundException"); } catch (ResourceNotFoundException exception) { // Ignored or expected. } }
Example #9
Source File: KinesisIntegrationTests.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void testGetIteratorForBogusStream() { try { client.getShardIterator(GetShardIteratorRequest.builder() .streamName("bogus-stream-name") .shardId("bogus-shard-id") .shardIteratorType(ShardIteratorType.LATEST) .build()); Assert.fail("Expected ResourceNotFoundException"); } catch (ResourceNotFoundException exception) { // Ignored or expected. } }
Example #10
Source File: KinesisStreamInfoProvider.java From synapse with Apache License 2.0 | 5 votes |
/** * Returns stream information for the given Kinesis stream. * * @param channelName the name of the stream * @return KinesisStreamInfo * @throws IllegalArgumentException if the stream does not exist */ public KinesisStreamInfo getStreamInfo(final String channelName) { try { final DescribeStreamRequest request = DescribeStreamRequest.builder().streamName(channelName).build(); DescribeStreamResponse response = kinesisAsyncClient.describeStream(request).join(); final KinesisStreamInfo.Builder streamInfoBuilder = builder() .withChannelName(channelName) .withArn(response.streamDescription().streamARN()); String lastSeenShardId = addShardInfoFromResponse(response, streamInfoBuilder); while (response.streamDescription().hasMoreShards()) { response = kinesisAsyncClient.describeStream(DescribeStreamRequest.builder() .streamName(channelName) .exclusiveStartShardId(lastSeenShardId) .build()) .join(); lastSeenShardId = addShardInfoFromResponse(response, streamInfoBuilder); } return streamInfoBuilder.build(); } catch (final ResourceNotFoundException e) { throw new IllegalArgumentException(format("Kinesis channel %s does not exist: %s", channelName, e.getMessage())); } }
Example #11
Source File: KinesisAppender.java From kinesis-logback-appender with Apache License 2.0 | 5 votes |
@Override protected void validateStreamName(KinesisAsyncClient client, String streamName) { DescribeStreamResponse describeResult; try { describeResult = getClient().describeStream(b -> b.streamName(streamName).build()).get(); StreamStatus streamStatus = describeResult.streamDescription().streamStatus(); if(!StreamStatus.ACTIVE.equals(streamStatus) && !StreamStatus.UPDATING.equals(streamStatus)) { setInitializationFailed(true); addError("Stream " + streamName + " is not ready (in active/updating status) for appender: " + name); } } catch(InterruptedException ie) { setInitializationFailed(true); addError("Interrupted while attempting to describe " + streamName, ie); } catch(ExecutionException ee) { setInitializationFailed(true); addError("Error executing the operation", ee); } catch(ResourceNotFoundException rnfe) { setInitializationFailed(true); addError("Stream " + streamName + " doesn't exist for appender: " + name, rnfe); } catch(AwsServiceException ase) { setInitializationFailed(true); addError("Error connecting to AWS to verify stream " + streamName + " for appender: " + name, ase); } }
Example #12
Source File: FanOutConsumerRegistration.java From amazon-kinesis-client with Apache License 2.0 | 5 votes |
private AWSExceptionManager createExceptionManager() { final AWSExceptionManager exceptionManager = new AWSExceptionManager(); exceptionManager.add(LimitExceededException.class, t -> t); exceptionManager.add(ResourceInUseException.class, t -> t); exceptionManager.add(ResourceNotFoundException.class, t -> t); exceptionManager.add(KinesisException.class, t -> t); return exceptionManager; }
Example #13
Source File: KinesisDataFetcher.java From amazon-kinesis-client with Apache License 2.0 | 5 votes |
private AWSExceptionManager createExceptionManager() { final AWSExceptionManager exceptionManager = new AWSExceptionManager(); exceptionManager.add(ResourceNotFoundException.class, t -> t); exceptionManager.add(KinesisException.class, t -> t); exceptionManager.add(SdkException.class, t -> t); return exceptionManager; }
Example #14
Source File: FanOutConsumerRegistrationTest.java From amazon-kinesis-client with Apache License 2.0 | 5 votes |
@Test public void testNewRegisterStreamConsumer() throws Exception { final CompletableFuture<DescribeStreamSummaryResponse> dssFuture = CompletableFuture .completedFuture(createDescribeStreamSummaryResponse()); final CompletableFuture<DescribeStreamConsumerResponse> failureResponse = CompletableFuture.supplyAsync(() -> { throw ResourceNotFoundException.builder().build(); }); final CompletableFuture<DescribeStreamConsumerResponse> intermidateResponse = CompletableFuture .completedFuture(createDescribeStreamConsumerResponse(ConsumerStatus.CREATING)); final CompletableFuture<DescribeStreamConsumerResponse> successResponse = CompletableFuture .completedFuture(createDescribeStreamConsumerResponse(ConsumerStatus.ACTIVE)); final CompletableFuture<RegisterStreamConsumerResponse> rscFuture = CompletableFuture .completedFuture(createRegisterStreamConsumerResponse()); when(client.describeStreamSummary(any(DescribeStreamSummaryRequest.class))).thenReturn(dssFuture); when(client.describeStreamConsumer(any(DescribeStreamConsumerRequest.class))).thenReturn(failureResponse) .thenReturn(intermidateResponse).thenReturn(successResponse); when(client.registerStreamConsumer(any(RegisterStreamConsumerRequest.class))).thenReturn(rscFuture); final long startTime = System.currentTimeMillis(); final String consumerArn = consumerRegistration.getOrCreateStreamConsumerArn(); final long endTime = System.currentTimeMillis(); assertThat(consumerArn, equalTo(CONSUMER_ARN)); assertThat(endTime - startTime, greaterThanOrEqualTo(2 * BACKOFF_MILLIS)); verify(client).registerStreamConsumer(any(RegisterStreamConsumerRequest.class)); }
Example #15
Source File: KinesisDataFetcherTest.java From amazon-kinesis-client with Apache License 2.0 | 5 votes |
@Test public void testGetRecordsWithResourceNotFoundException() throws Exception { final ArgumentCaptor<GetShardIteratorRequest> iteratorCaptor = ArgumentCaptor .forClass(GetShardIteratorRequest.class); final ArgumentCaptor<GetRecordsRequest> recordsCaptor = ArgumentCaptor.forClass(GetRecordsRequest.class); // Set up arguments used by proxy final String nextIterator = "TestShardIterator"; final GetShardIteratorRequest expectedIteratorRequest = makeGetShardIteratorRequest( ShardIteratorType.LATEST.name()); final GetRecordsRequest expectedRecordsRequest = makeGetRecordsRequest(nextIterator); final CompletableFuture<GetRecordsResponse> future = mock(CompletableFuture.class); // Set up proxy mock methods when(kinesisClient.getShardIterator(iteratorCaptor.capture())) .thenReturn(makeGetShardIteratorResonse(nextIterator)); when(kinesisClient.getRecords(recordsCaptor.capture())).thenReturn(future); when(future.get(anyLong(), any(TimeUnit.class))).thenThrow( new ExecutionException(ResourceNotFoundException.builder().message("Test Exception").build())); // Create data fectcher and initialize it with latest type checkpoint kinesisDataFetcher.initialize(SentinelCheckpoint.LATEST.toString(), INITIAL_POSITION_LATEST); final GetRecordsRetrievalStrategy getRecordsRetrievalStrategy = new SynchronousGetRecordsRetrievalStrategy( kinesisDataFetcher); try { // Call records of dataFetcher which will throw an exception getRecordsRetrievalStrategy.getRecords(MAX_RECORDS); } finally { // Test shard has reached the end assertTrue("Shard should reach the end", kinesisDataFetcher.isShardEndReached()); assertEquals(expectedIteratorRequest.startingSequenceNumber(), iteratorCaptor.getValue().startingSequenceNumber()); assertEquals(expectedRecordsRequest.shardIterator(), recordsCaptor.getValue().shardIterator()); } }
Example #16
Source File: KinesisShardDetectorTest.java From amazon-kinesis-client with Apache License 2.0 | 5 votes |
@Test(expected = ResourceNotFoundException.class) public void testListShardsResourceNotFound() { final CompletableFuture<ListShardsResponse> future = CompletableFuture.supplyAsync(() -> { throw ResourceNotFoundException.builder().build(); }); when(client.listShards(any(ListShardsRequest.class))).thenReturn(future); try { shardDetector.listShards(); } finally { verify(client).listShards(any(ListShardsRequest.class)); } }