com.amazonaws.services.kinesis.clientlibrary.exceptions.ShutdownException Java Examples
The following examples show how to use
com.amazonaws.services.kinesis.clientlibrary.exceptions.ShutdownException.
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: TestKinesisRecordProcessor.java From samza with Apache License 2.0 | 6 votes |
static Map<KinesisRecordProcessor, List<Record>> generateRecords(int numRecordsPerShard, List<KinesisRecordProcessor> processors) { Map<KinesisRecordProcessor, List<Record>> processorRecordMap = new HashMap<>(); processors.forEach(processor -> { try { // Create records and call process records IRecordProcessorCheckpointer checkpointer = Mockito.mock(IRecordProcessorCheckpointer.class); doNothing().when(checkpointer).checkpoint(anyString()); doNothing().when(checkpointer).checkpoint(); ProcessRecordsInput processRecordsInput = Mockito.mock(ProcessRecordsInput.class); when(processRecordsInput.getCheckpointer()).thenReturn(checkpointer); when(processRecordsInput.getMillisBehindLatest()).thenReturn(1000L); List<Record> inputRecords = createRecords(numRecordsPerShard); processorRecordMap.put(processor, inputRecords); when(processRecordsInput.getRecords()).thenReturn(inputRecords); processor.processRecords(processRecordsInput); } catch (ShutdownException | InvalidStateException ex) { throw new RuntimeException(ex); } }); return processorRecordMap; }
Example #2
Source File: StreamSetsRecordProcessor.java From datacollector with Apache License 2.0 | 6 votes |
private void retryCheckpoint(IRecordProcessorCheckpointer checkpointer, Record checkpointRecord) throws InvalidStateException, ShutdownException, InterruptedException { if (throttleMaxRetries > 0) { LOG.debug("Retry checkpointing batch at record: {}", checkpointRecord.toString()); int retryCount = 0; boolean success = false; while (retryCount < throttleMaxRetries && !success) { Thread.sleep(throttleWaitTime); try { checkpointer.checkpoint(checkpointRecord); success = true; } catch (ThrottlingException te) {} retryCount++; } if (success) { LOG.debug("Successfully checkpointed at record {}, after {} retries.", checkpointRecord.toString(), retryCount); } else { LOG.debug("Could not checkpoint batch at record {} after {} retries.", checkpointRecord.toString(), retryCount); } } }
Example #3
Source File: MyRecordProcessor.java From aws-big-data-blog with Apache License 2.0 | 6 votes |
@Override public void processRecords(List<Record> records, IRecordProcessorCheckpointer checkpointer) { LOG.info(String.format("Received %s Records", records.size())); // add a call to your business logic here! // // myLinkedClasses.doSomething(records) // // try { checkpointer.checkpoint(); } catch (KinesisClientLibDependencyException | InvalidStateException | ThrottlingException | ShutdownException e) { e.printStackTrace(); super.shutdown(checkpointer, ShutdownReason.ZOMBIE); } }
Example #4
Source File: KinesisConnectorRecordProcessor.java From amazon-kinesis-connectors with Apache License 2.0 | 6 votes |
@Override public void shutdown(IRecordProcessorCheckpointer checkpointer, ShutdownReason reason) { LOG.info("Shutting down record processor with shardId: " + shardId + " with reason " + reason); if (isShutdown) { LOG.warn("Record processor for shardId: " + shardId + " has been shutdown multiple times."); return; } switch (reason) { case TERMINATE: emit(checkpointer, transformToOutput(buffer.getRecords())); try { checkpointer.checkpoint(); } catch (KinesisClientLibDependencyException | InvalidStateException | ThrottlingException | ShutdownException e) { LOG.error(e); } break; case ZOMBIE: break; default: throw new IllegalStateException("invalid shutdown reason"); } emitter.shutdown(); isShutdown = true; }
Example #5
Source File: KinesisConnectorRecordProcessorTests.java From amazon-kinesis-connectors with Apache License 2.0 | 6 votes |
/** * Test process records with ITransformerBase should throw exception. */ @Test(expected = RuntimeException.class) @SuppressWarnings("unchecked") public void testBadTransformer() throws ThrottlingException, ShutdownException, IOException, KinesisClientLibDependencyException, InvalidStateException { // Test Variables String shardId = "shardId"; int numRecords = 5; // Override existing transformer with a collection transformer ITransformerBase<Object,Object> baseTransformer = control.createMock(ITransformerBase.class); // Initialize class under test KinesisConnectorRecordProcessor<Object, Object> kcrp = new KinesisConnectorRecordProcessor<Object, Object>( buffer, filter, emitter, baseTransformer, configuration); kcrp.initialize(shardId); // call method, expect exception thrown kcrp.processRecords(getDummyRecordList(numRecords), checkpointer); }
Example #6
Source File: StreamSetsRecordProcessor.java From datacollector with Apache License 2.0 | 5 votes |
/** * We don't checkpoint on SHUTDOWN_REQUESTED because we currently always * checkpoint each batch in {@link #processRecords}. * * @param shutdownInput {@inheritDoc} */ @Override public void shutdown(ShutdownInput shutdownInput) { LOG.info("Shutting down record processor for shard: {}", shardId); if (ShutdownReason.TERMINATE.equals(shutdownInput.getShutdownReason())) { // Shard is closed / finished processing. Checkpoint all processing up to here. try { shutdownInput.getCheckpointer().checkpoint(); LOG.debug("Checkpointed due to record processor shutdown request."); } catch (InvalidStateException | ShutdownException e) { LOG.error("Error checkpointing batch: {}", e.toString(), e); } } }
Example #7
Source File: KinesisConnectorRecordProcessorTests.java From amazon-kinesis-connectors with Apache License 2.0 | 5 votes |
/** * expect buffer flush, emit and checkpoint to happen on ShutdownReason.TERMINATE */ @Test public void testShutdownTerminate() throws IOException, KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException { // reset the control to mock new behavior control.reset(); // expect flush cycle. // Get records from buffer, emit, clear, then checkpoint EasyMock.expect(buffer.getRecords()).andReturn(Collections.emptyList()); EasyMock.expect(emitter.emit(EasyMock.anyObject(UnmodifiableBuffer.class))).andReturn( Collections.emptyList()); buffer.getLastSequenceNumber(); EasyMock.expectLastCall().andReturn(null); buffer.clear(); EasyMock.expectLastCall(); checkpointer.checkpoint(); EasyMock.expectLastCall(); // expect shutdown to be called on emitter emitter.shutdown(); EasyMock.expectLastCall(); // Prepare controller for method call control.replay(); KinesisConnectorRecordProcessor<Object, Object> kcrp = new KinesisConnectorRecordProcessor<Object, Object>( buffer, filter, emitter, transformer, configuration); kcrp.shutdown(checkpointer, ShutdownReason.TERMINATE); control.verify(); }
Example #8
Source File: DynamoDBTableReplicator.java From podyn with Apache License 2.0 | 4 votes |
protected IRecordProcessor createStreamProcessor() { return new IRecordProcessor() { @Override public void initialize(InitializationInput initializationInput) { } public List<Record> extractDynamoStreamRecords(List<com.amazonaws.services.kinesis.model.Record> kinesisRecords) { List<Record> dynamoRecords = new ArrayList<>(kinesisRecords.size()); for(com.amazonaws.services.kinesis.model.Record kinesisRecord : kinesisRecords) { if (kinesisRecord instanceof RecordAdapter) { Record dynamoRecord = ((RecordAdapter) kinesisRecord).getInternalObject(); dynamoRecords.add(dynamoRecord); } } return dynamoRecords; } @Override public void processRecords(ProcessRecordsInput processRecordsInput) { List<Record> records = extractDynamoStreamRecords(processRecordsInput.getRecords()); DynamoDBTableReplicator.this.processRecords(records); checkpoint(processRecordsInput.getCheckpointer()); } @Override public void shutdown(ShutdownInput shutdownInput) { if (shutdownInput.getShutdownReason() == ShutdownReason.TERMINATE) { checkpoint(shutdownInput.getCheckpointer()); } } void checkpoint(IRecordProcessorCheckpointer checkpointer) { try { checkpointer.checkpoint(); } catch (KinesisClientLibDependencyException|InvalidStateException|ThrottlingException|ShutdownException e) { LOG.warn(e); } } }; }
Example #9
Source File: TestKinesisSystemConsumer.java From samza with Apache License 2.0 | 4 votes |
/** * Helper to simulate and test the life-cycle of record processing from a kinesis stream with a given number of shards * 1. Creation of record processors. * 2. Initialization of record processors. * 3. Processing records via record processors. * 4. Calling checkpoint on record processors. * 5. Shutting down (due to re-assignment or lease expiration) record processors. */ private void testProcessRecordsHelper(String system, String stream, int numShards, int numRecordsPerShard) throws InterruptedException, NoSuchFieldException, IllegalAccessException { KinesisConfig kConfig = new KinesisConfig(new MapConfig()); // Create consumer KinesisSystemConsumer consumer = new KinesisSystemConsumer(system, kConfig, new NoOpMetricsRegistry()); initializeMetrics(consumer, stream); List<SystemStreamPartition> ssps = new LinkedList<>(); IntStream.range(0, numShards) .forEach(p -> { SystemStreamPartition ssp = new SystemStreamPartition(system, stream, new Partition(p)); ssps.add(ssp); }); ssps.forEach(ssp -> consumer.register(ssp, SYSTEM_CONSUMER_REGISTER_OFFSET)); // Create Kinesis record processor factory IRecordProcessorFactory factory = consumer.createRecordProcessorFactory(stream); // Create and initialize Kinesis record processor Map<String, KinesisRecordProcessor> processorMap = createAndInitProcessors(factory, numShards); List<KinesisRecordProcessor> processorList = new ArrayList<>(processorMap.values()); // Generate records to Kinesis record processor Map<KinesisRecordProcessor, List<Record>> inputRecordMap = generateRecords(numRecordsPerShard, processorList); // Verification steps // Read events from the BEM queue Map<SystemStreamPartition, List<IncomingMessageEnvelope>> messages = readEvents(new HashSet<>(ssps), consumer, numRecordsPerShard); if (numRecordsPerShard > 0) { Assert.assertEquals(messages.size(), numShards); } else { // No input records and hence no messages Assert.assertEquals(messages.size(), 0); return; } Map<SystemStreamPartition, KinesisRecordProcessor> sspToProcessorMap = getProcessorMap(consumer); ssps.forEach(ssp -> { try { KinesisRecordProcessor processor = sspToProcessorMap.get(ssp); // Verify that the read messages are received in order and are the same as input records Assert.assertEquals(messages.get(ssp).size(), numRecordsPerShard); List<IncomingMessageEnvelope> envelopes = messages.get(ssp); List<Record> inputRecords = inputRecordMap.get(processor); verifyRecords(envelopes, inputRecords, processor.getShardId()); // Call checkpoint on consumer and verify that the checkpoint is called with the right offset IncomingMessageEnvelope lastEnvelope = envelopes.get(envelopes.size() - 1); consumer.afterCheckpoint(Collections.singletonMap(ssp, lastEnvelope.getOffset())); ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class); verify(getCheckpointer(processor)).checkpoint(argument.capture()); Assert.assertEquals(inputRecords.get(inputRecords.size() - 1).getSequenceNumber(), argument.getValue()); // Call shutdown (with ZOMBIE reason) on processor and verify if shutdown freed the ssp mapping shutDownProcessor(processor, ShutdownReason.ZOMBIE); Assert.assertFalse(sspToProcessorMap.containsValue(processor)); Assert.assertTrue(isSspAvailable(consumer, ssp)); } catch (NoSuchFieldException | IllegalAccessException | InvalidStateException | ShutdownException ex) { throw new RuntimeException(ex); } }); }
Example #10
Source File: KinesisConnectorRecordProcessorTests.java From amazon-kinesis-connectors with Apache License 2.0 | 4 votes |
/** * Test process records under normal conditions. */ @Test @SuppressWarnings("unchecked") public void testProcessRecords() throws ThrottlingException, ShutdownException, IOException, KinesisClientLibDependencyException, InvalidStateException { // Test Variables Object dummyRecord = new Object(); int numRecords = 5; String shardId = "shardId"; // reset the control to mock new behavior control.reset(); // Transformer Behavior: // transform numRecords records into dummyRecord objects EasyMock.expect(transformer.toClass(EasyMock.anyObject(Record.class))).andReturn(dummyRecord); EasyMock.expectLastCall().times(numRecords -1).andReturn(dummyRecord); // Filter Behavior: // return true for all records EasyMock.expect(filter.keepRecord(dummyRecord)).andReturn(true); EasyMock.expectLastCall().times(numRecords -1).andReturn(true); // Mock arguments Object o = EasyMock.anyObject(); int buf = EasyMock.anyInt(); // Buffer Behavior: // consume numRecords dummy records buffer.consumeRecord(o, buf, EasyMock.anyObject(String.class)); EasyMock.expectLastCall().times(numRecords); buffer.getLastSequenceNumber(); EasyMock.expectLastCall().andReturn(DEFAULT_SEQUENCE_NUMBER); buffer.clear(); EasyMock.expectLastCall(); // check full buffer and return true EasyMock.expect(buffer.shouldFlush()).andReturn(true); // call buffer.getRecords List<Object> objects = new ArrayList<>(); Object item = new Object(); objects.add(item); EasyMock.expect(buffer.getRecords()).andReturn(objects); EasyMock.expect(transformer.fromClass(item)).andReturn(item); // Emitter behavior: // one call to emit EasyMock.expect(emitter.emit(EasyMock.anyObject(UnmodifiableBuffer.class))).andReturn( Collections.emptyList()); // Checkpointer Behavior: // one call to checkpoint checkpointer.checkpoint(DEFAULT_SEQUENCE_NUMBER); EasyMock.expectLastCall(); // Initialize class under test KinesisConnectorRecordProcessor<Object, Object> kcrp = new KinesisConnectorRecordProcessor<Object, Object>( buffer, filter, emitter, transformer, configuration); kcrp.initialize(shardId); // Prepare controller for method call control.replay(); // call method kcrp.processRecords(getDummyRecordList(numRecords), checkpointer); control.verify(); }
Example #11
Source File: KinesisConnectorRecordProcessorTests.java From amazon-kinesis-connectors with Apache License 2.0 | 4 votes |
/** * Test emitter throws exception upon processing. */ @Test @SuppressWarnings("unchecked") public void testFailRecords() throws IOException, KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException { Object dummyRecord = new Object(); int numRecords = 5; String shardId = "shardId"; // reset the control to mock new behavior control.reset(); // Transformer Behavior: // transform numRecords records into dummyRecord objects EasyMock.expect(transformer.toClass(EasyMock.anyObject(Record.class))).andReturn(dummyRecord); EasyMock.expectLastCall().times(numRecords - 1).andReturn(dummyRecord); // Filter Behavior: // return true for all records EasyMock.expect(filter.keepRecord(dummyRecord)).andReturn(true); EasyMock.expectLastCall().times(numRecords -1).andReturn(true); // Mock arguments Object o = EasyMock.anyObject(); int buf = EasyMock.anyInt(); String seq = EasyMock.anyObject(String.class); // Buffer Behavior: // consume numRecords dummy records buffer.consumeRecord(o, buf, seq); EasyMock.expectLastCall().times(numRecords); // check full buffer and return true EasyMock.expect(buffer.shouldFlush()).andReturn(true); // call buffer.getRecords EasyMock.expect(buffer.getRecords()).andReturn(Collections.emptyList()); // Emitter behavior: // one call to emit EasyMock.expect(emitter.emit(EasyMock.anyObject(UnmodifiableBuffer.class))).andThrow( new IOException()); emitter.fail(EasyMock.anyObject(List.class)); EasyMock.expectLastCall(); // Initialize class under test KinesisConnectorRecordProcessor<Object, Object> kcrp = new KinesisConnectorRecordProcessor<Object, Object>( buffer, filter, emitter, transformer, configuration); kcrp.initialize(shardId); // Prepare controller for method call control.replay(); // call method kcrp.processRecords(getDummyRecordList(numRecords), checkpointer); control.verify(); }
Example #12
Source File: KinesisConnectorRecordProcessorTests.java From amazon-kinesis-connectors with Apache License 2.0 | 4 votes |
/** * Test process records under normal conditions but with batch processor. */ @Test @SuppressWarnings("unchecked") public void testProcessBatchedRecords() throws ThrottlingException, ShutdownException, IOException, KinesisClientLibDependencyException, InvalidStateException { // Test Variables Object dummyRecord1 = new Object(); Object dummyRecord2= new Object(); List<Object> dummyCollection = new ArrayList<>(); dummyCollection.add(dummyRecord1); dummyCollection.add(dummyRecord2); // 5 Kinesis records, with 2 objects per. So 10 total records int numRecords = 5; int numTotalRecords = numRecords * 2; String shardId = "shardId"; // Override existing transformer with a collection transformer ICollectionTransformer<Object,Object> collectionTransformer = control.createMock(ICollectionTransformer.class); // reset the control to mock new behavior control.reset(); // Transformer Behavior: // transform numRecords records into dummyRecord objects EasyMock.expect(collectionTransformer.toClass(EasyMock.anyObject(Record.class))).andReturn(dummyCollection); EasyMock.expectLastCall().times(numRecords -1).andReturn(dummyCollection); // Filter Behavior: // return true for all records EasyMock.expect(filter.keepRecord(dummyRecord1)).andReturn(true); EasyMock.expectLastCall().times(numRecords -1).andReturn(true); EasyMock.expect(filter.keepRecord(dummyRecord2)).andReturn(true); EasyMock.expectLastCall().times(numRecords -1).andReturn(true); // Mock arguments Object o = EasyMock.anyObject(); int buf = EasyMock.anyInt(); // Buffer Behavior: // consume numRecords dummy records buffer.consumeRecord(o, buf, EasyMock.anyObject(String.class)); EasyMock.expectLastCall().times(numTotalRecords); buffer.getLastSequenceNumber(); EasyMock.expectLastCall().andReturn(DEFAULT_SEQUENCE_NUMBER); buffer.clear(); EasyMock.expectLastCall(); // check full buffer and return true EasyMock.expect(buffer.shouldFlush()).andReturn(true); // call buffer.getRecords EasyMock.expect(buffer.getRecords()).andReturn(Collections.emptyList()); // Emitter behavior: // one call to emit EasyMock.expect(emitter.emit(EasyMock.anyObject(UnmodifiableBuffer.class))).andReturn( Collections.emptyList()); // Checkpointer Behavior: // one call to checkpoint checkpointer.checkpoint(DEFAULT_SEQUENCE_NUMBER); EasyMock.expectLastCall(); // Initialize class under test KinesisConnectorRecordProcessor<Object, Object> kcrp = new KinesisConnectorRecordProcessor<Object, Object>( buffer, filter, emitter, collectionTransformer, configuration); kcrp.initialize(shardId); // Prepare controller for method call control.replay(); // call method kcrp.processRecords(getDummyRecordList(numRecords), checkpointer); control.verify(); }
Example #13
Source File: KinesisConnectorRecordProcessorTests.java From amazon-kinesis-connectors with Apache License 2.0 | 4 votes |
/** * Test retry logic only retries unprocessed/failed records */ @Test public void testRetryBehavior() throws IOException, KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException { // Test Variables Object dummyRecord1 = new Object(); Object dummyRecord2= new Object(); List<Object> objectsAsList = new ArrayList<Object>(); objectsAsList.add(dummyRecord1); objectsAsList.add(dummyRecord2); List<Object> singleObjectAsList = new ArrayList<Object>(); singleObjectAsList.add(dummyRecord1); String shardId = "shardId"; Properties props = new Properties(); // set backoff interval to 0 to speed up test props.setProperty(KinesisConnectorConfiguration.PROP_BACKOFF_INTERVAL, String.valueOf(0)); // set retry limit to allow for retry below props.setProperty(KinesisConnectorConfiguration.PROP_RETRY_LIMIT, String.valueOf(2)); configuration = new KinesisConnectorConfiguration(props, new DefaultAWSCredentialsProviderChain()); // reset the control to mock new behavior control.reset(); // set expectations for each record EasyMock.expect(transformer.toClass(EasyMock.anyObject(Record.class))).andReturn(dummyRecord1); EasyMock.expect(filter.keepRecord(dummyRecord1)).andReturn(true); buffer.consumeRecord(dummyRecord1, DEFAULT_RECORD_BYTE_SIZE, DEFAULT_SEQUENCE_NUMBER); EasyMock.expect(transformer.toClass(EasyMock.anyObject(Record.class))).andReturn(dummyRecord2); EasyMock.expect(filter.keepRecord(dummyRecord2)).andReturn(true); buffer.consumeRecord(dummyRecord2, DEFAULT_RECORD_BYTE_SIZE, DEFAULT_SEQUENCE_NUMBER); EasyMock.expect(buffer.shouldFlush()).andReturn(true); // call Buffer.getRecords EasyMock.expect(buffer.getRecords()).andReturn(objectsAsList); // Transform back EasyMock.expect(transformer.fromClass(dummyRecord1)).andReturn(dummyRecord1); EasyMock.expect(transformer.fromClass(dummyRecord2)).andReturn(dummyRecord2); // Emitter behavior: // one call to emit which fails (test a transient issue), and then returns empty on second call // uses the original list (i.e. emitItems) UnmodifiableBuffer<Object> unmodBuffer = new UnmodifiableBuffer<>(buffer, objectsAsList); EasyMock.expect(emitter.emit(EasyMock.eq(unmodBuffer))).andReturn(singleObjectAsList); // uses the returned list (i.e. unprocessed) unmodBuffer = new UnmodifiableBuffer<>(buffer, singleObjectAsList); EasyMock.expect(emitter.emit(EasyMock.eq(unmodBuffer))).andReturn(Collections.emptyList()); // Done, so expect buffer clear and checkpoint buffer.getLastSequenceNumber(); EasyMock.expectLastCall().andReturn(DEFAULT_SEQUENCE_NUMBER); buffer.clear(); EasyMock.expectLastCall(); checkpointer.checkpoint(DEFAULT_SEQUENCE_NUMBER); EasyMock.expectLastCall(); // Initialize class under test KinesisConnectorRecordProcessor<Object, Object> kcrp = new KinesisConnectorRecordProcessor<Object, Object>( buffer, filter, emitter, transformer, configuration); kcrp.initialize(shardId); // Prepare controller for method call control.replay(); // call method kcrp.processRecords(getDummyRecordList(objectsAsList.size()), checkpointer); control.verify(); }
Example #14
Source File: KinesisConnectorRecordProcessorTests.java From amazon-kinesis-connectors with Apache License 2.0 | 4 votes |
/** * Test fail called when all retries done. */ @Test public void testFailAfterRetryLimitReached() throws IOException, KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException { // Test Variables Object dummyRecord1 = new Object(); Object dummyRecord2= new Object(); List<Object> objectsAsList = new ArrayList<Object>(); objectsAsList.add(dummyRecord1); objectsAsList.add(dummyRecord2); List<Object> singleObjectAsList = new ArrayList<Object>(); singleObjectAsList.add(dummyRecord1); String shardId = "shardId"; Properties props = new Properties(); // set backoff interval to 0 to speed up test props.setProperty(KinesisConnectorConfiguration.PROP_BACKOFF_INTERVAL, String.valueOf(0)); // set retry limit to allow for retry below (1) props.setProperty(KinesisConnectorConfiguration.PROP_RETRY_LIMIT, String.valueOf(1)); configuration = new KinesisConnectorConfiguration(props, new DefaultAWSCredentialsProviderChain()); // reset the control to mock new behavior control.reset(); // set expectations for each record EasyMock.expect(transformer.toClass(EasyMock.anyObject(Record.class))).andReturn(dummyRecord1); EasyMock.expect(filter.keepRecord(dummyRecord1)).andReturn(true); buffer.consumeRecord(dummyRecord1, DEFAULT_RECORD_BYTE_SIZE, DEFAULT_SEQUENCE_NUMBER); EasyMock.expect(transformer.toClass(EasyMock.anyObject(Record.class))).andReturn(dummyRecord2); EasyMock.expect(filter.keepRecord(dummyRecord2)).andReturn(true); buffer.consumeRecord(dummyRecord2, DEFAULT_RECORD_BYTE_SIZE, DEFAULT_SEQUENCE_NUMBER); EasyMock.expect(buffer.shouldFlush()).andReturn(true); // call Buffer.getRecords EasyMock.expect(buffer.getRecords()).andReturn(objectsAsList); // Transform back EasyMock.expect(transformer.fromClass(dummyRecord1)).andReturn(dummyRecord1); EasyMock.expect(transformer.fromClass(dummyRecord2)).andReturn(dummyRecord2); // Emitter behavior: // one call to emit which fails (test a transient issue), and then returns empty on second call // uses the original list (i.e. emitItems) UnmodifiableBuffer<Object> unmodBuffer = new UnmodifiableBuffer<>(buffer, objectsAsList); EasyMock.expect(emitter.emit(EasyMock.eq(unmodBuffer))).andReturn(singleObjectAsList); // only one retry, so now we should expect fail to be called. emitter.fail(singleObjectAsList); // Done, so expect buffer clear and checkpoint buffer.getLastSequenceNumber(); EasyMock.expectLastCall().andReturn(DEFAULT_SEQUENCE_NUMBER); buffer.clear(); EasyMock.expectLastCall(); checkpointer.checkpoint(DEFAULT_SEQUENCE_NUMBER); EasyMock.expectLastCall(); // Initialize class under test KinesisConnectorRecordProcessor<Object, Object> kcrp = new KinesisConnectorRecordProcessor<Object, Object>( buffer, filter, emitter, transformer, configuration); kcrp.initialize(shardId); // Prepare controller for method call control.replay(); // call method kcrp.processRecords(getDummyRecordList(objectsAsList.size()), checkpointer); control.verify(); }