/** * Complete the earliest uncompleted call successfully. * * @return true if there was an uncompleted call to complete */ public synchronized boolean completeNext() { return errorNext(null); }
@Test public void testSimpleWithError() { MockProducer<String, String> producer = new MockProducer<>(Cluster.empty(), false, null, null, null); KafkaBolt<String, String> bolt = makeBolt(producer); OutputCollector collector = mock(OutputCollector.class); TopologyContext context = mock(TopologyContext.class); Map<String, Object> conf = new HashMap<>(); bolt.prepare(conf, context, collector); String key = "KEY"; String value = "VALUE"; Tuple testTuple = createTestTuple(key, value); bolt.execute(testTuple); assertThat(producer.history().size(), is(1)); ProducerRecord<String, String> arg = producer.history().get(0); LOG.info("GOT {} ->", arg); LOG.info("{}, {}, {}", arg.topic(), arg.key(), arg.value()); assertThat(arg.topic(), is("MY_TOPIC")); assertThat(arg.key(), is(key)); assertThat(arg.value(), is(value)); // Force a send error KafkaException ex = new KafkaException(); producer.errorNext(ex); verify(collector).reportError(ex); verify(collector).fail(testTuple); }
producer.errorNext(ex); verify(customCallback).onCompletion(any(), eq(ex)); verify(collector).reportError(ex);
@Test public void testManualCompletion() throws Exception { buildMockProducer(false); 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()); Future<RecordMetadata> md3 = producer.send(record1); Future<RecordMetadata> md4 = producer.send(record2); assertTrue("Requests should not be completed.", !md3.isDone() && !md4.isDone()); producer.flush(); assertTrue("Requests should be completed.", md3.isDone() && md4.isDone()); }
/** * Complete the earliest uncompleted call successfully. * * @return true if there was an uncompleted call to complete */ public synchronized boolean completeNext() { return errorNext(null); }
mockProducer.errorNext( new InjectedErrorException("Injected Error #" + (errorsInjected + 1)));
.submit(() -> { RuntimeException exception = new RuntimeException("Async Producer Mock exception"); while (!mockProducer.errorNext(exception)) { Thread.sleep(100);