assertEquals("Clear should erase our history", 0, producer.history().size());
}
@Test
public void testManualCompletion() throws Exception {
MockProducer producer = new MockProducer(false);
ProducerRecord record1 = new ProducerRecord("topic", "key1".getBytes(), "value1".getBytes());
ProducerRecord record2 = new ProducerRecord("topic", "key2".getBytes(), "value2".getBytes());
Future<RecordMetadata> md1 = producer.send(record1);
assertFalse("Send shouldn't have completed", md1.isDone());
Future<RecordMetadata> md2 = producer.send(record2);
assertFalse("Send shouldn't have completed", md2.isDone());
assertTrue("Complete the first request", producer.completeNext());
assertFalse("Requst should be successful", isError(md1));
assertFalse("Second request still incomplete", md2.isDone());
IllegalArgumentException e = new IllegalArgumentException("blah");
assertTrue("Complete the second request with an error", producer.errorNext(e));
try {
md2.get();
fail("Expected error to be thrown");
} catch (ExecutionException err) {
assertEquals(e, err.getCause());
}
assertFalse("No more requests to complete", producer.completeNext());
}