private void assertFatalError(Class<? extends RuntimeException> cause) { assertTrue(transactionManager.hasError()); try { transactionManager.beginAbort(); fail("Should have raised " + cause.getSimpleName()); } catch (KafkaException e) { assertTrue(cause.isAssignableFrom(e.getCause().getClass())); assertTrue(transactionManager.hasError()); } // Transaction abort cannot clear fatal error state try { transactionManager.beginAbort(); fail("Should have raised " + cause.getSimpleName()); } catch (KafkaException e) { assertTrue(cause.isAssignableFrom(e.getCause().getClass())); assertTrue(transactionManager.hasError()); } }
private void assertAbortableError(Class<? extends RuntimeException> cause) { try { transactionManager.beginCommit(); fail("Should have raised " + cause.getSimpleName()); } catch (KafkaException e) { assertTrue(cause.isAssignableFrom(e.getCause().getClass())); assertTrue(transactionManager.hasError()); } assertTrue(transactionManager.hasError()); transactionManager.beginAbort(); assertFalse(transactionManager.hasError()); }
@Test public void shouldThrowOnSendIfProducerGotFenced() { buildMockProducer(true); producer.initTransactions(); producer.fenceProducer(); try { producer.send(null); fail("Should have thrown as producer is fenced off"); } catch (KafkaException e) { assertTrue("The root cause of the exception should be ProducerFenced", e.getCause() instanceof ProducerFencedException); } }
fail("Expected an InvalidConfigurationException"); } catch (KafkaException e) { assertEquals(InvalidConfigurationException.class, e.getCause().getClass());
Runnable guardFailures(final Runnable delegate) { return () -> { try { delegate.run(); } catch (InterruptException e) { // Interrupts are normal on shutdown, intentionally swallow } catch (KafkaException e) { if (e.getCause() instanceof ConfigException) e = (KafkaException) e.getCause(); LOG.error("Kafka worker exited with exception", e); failure.set(CheckResult.failed(e)); } catch (RuntimeException e) { LOG.error("Kafka worker exited with exception", e); failure.set(CheckResult.failed(e)); } catch (Error e) { LOG.error("Kafka worker exited with error", e); failure.set(CheckResult.failed(new RuntimeException(e))); } }; } }
throw (ProducerFencedException) kafkaException.getCause(); } else { throw new StreamsException(
@Test public void TestConsumerProperties() throws ParseException { //Added test on this check to ensure consumer properties are set and not reset between. if (null != kafkaInput.getConsumerProps().get("security.protocol")) { try { kafkaInput.definePartitions(null, null); } catch (KafkaException e) { //Ensures the properties of the consumer are set/not reset. Assert.assertEquals( expectedException(), e.getCause().getMessage()); } } } }