Java Code Examples for org.apache.flink.util.ExceptionUtils#findThrowableWithMessage()
The following examples show how to use
org.apache.flink.util.ExceptionUtils#findThrowableWithMessage() .
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: FlinkPulsarITest.java From pulsar-flink with Apache License 2.0 | 6 votes |
@Test public void testRunFailedOnWrongServiceUrl() { try { Properties props = MapUtils.toProperties(Collections.singletonMap(TOPIC_SINGLE_OPTION_KEY, "tp")); StreamExecutionEnvironment see = StreamExecutionEnvironment.getExecutionEnvironment(); see.getConfig().disableSysoutLogging(); see.setRestartStrategy(RestartStrategies.noRestart()); see.setParallelism(1); FlinkPulsarSource<String> source = new FlinkPulsarSource<String>("sev", "admin", new SimpleStringSchema(), props).setStartFromEarliest(); DataStream<String> stream = see.addSource(source); stream.print(); see.execute("wrong service url"); } catch (Exception e) { final Optional<Throwable> optionalThrowable = ExceptionUtils.findThrowableWithMessage(e, "authority component is missing"); assertTrue(optionalThrowable.isPresent()); assertTrue(optionalThrowable.get() instanceof PulsarClientException); } }
Example 2
Source File: StreamOperatorWrapperTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testClosingOperatorWithException() { AbstractStreamOperator streamOperator = new AbstractStreamOperator<Void>() { @Override public void close() throws Exception { throw new Exception("test exception at closing"); } }; StreamOperatorWrapper<?, ?> operatorWrapper = new StreamOperatorWrapper<>( streamOperator, Optional.ofNullable(streamOperator.getProcessingTimeService()), containingTask.getMailboxExecutorFactory().createExecutor(Integer.MAX_VALUE - 1)); try { operatorWrapper.close(containingTask.getActionExecutor()); fail("should throw an exception"); } catch (Throwable t) { Optional<Throwable> optional = ExceptionUtils.findThrowableWithMessage(t, "test exception at closing"); assertTrue(optional.isPresent()); } }
Example 3
Source File: KafkaConsumerTestBase.java From flink with Apache License 2.0 | 5 votes |
/** * Test that ensures the KafkaConsumer is properly failing if the topic doesnt exist * and a wrong broker was specified. * * @throws Exception */ public void runFailOnNoBrokerTest() throws Exception { try { Properties properties = new Properties(); StreamExecutionEnvironment see = StreamExecutionEnvironment.getExecutionEnvironment(); see.getConfig().disableSysoutLogging(); see.setRestartStrategy(RestartStrategies.noRestart()); see.setParallelism(1); // use wrong ports for the consumers properties.setProperty("bootstrap.servers", "localhost:80"); properties.setProperty("group.id", "test"); properties.setProperty("request.timeout.ms", "3000"); // let the test fail fast properties.setProperty("socket.timeout.ms", "3000"); properties.setProperty("session.timeout.ms", "2000"); properties.setProperty("fetch.max.wait.ms", "2000"); properties.setProperty("heartbeat.interval.ms", "1000"); properties.putAll(secureProps); FlinkKafkaConsumerBase<String> source = kafkaServer.getConsumer("doesntexist", new SimpleStringSchema(), properties); DataStream<String> stream = see.addSource(source); stream.print(); see.execute("No broker test"); } catch (JobExecutionException jee) { if (kafkaServer.getVersion().equals("0.9") || kafkaServer.getVersion().equals("0.10") || kafkaServer.getVersion().equals("0.11") || kafkaServer.getVersion().equals("2.0")) { final Optional<TimeoutException> optionalTimeoutException = ExceptionUtils.findThrowable(jee, TimeoutException.class); assertTrue(optionalTimeoutException.isPresent()); final TimeoutException timeoutException = optionalTimeoutException.get(); assertEquals("Timeout expired while fetching topic metadata", timeoutException.getMessage()); } else { final Optional<Throwable> optionalThrowable = ExceptionUtils.findThrowableWithMessage(jee, "Unable to retrieve any partitions"); assertTrue(optionalThrowable.isPresent()); assertTrue(optionalThrowable.get() instanceof RuntimeException); } } }
Example 4
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 5 votes |
private Optional<Throwable> findMissingFileException(SqlExecutionException e, String filename) { Optional<Throwable> throwableWithMessage; // for "batch" sources throwableWithMessage = ExceptionUtils.findThrowableWithMessage( e, "File " + filename + " does not exist or the user running Flink"); if (!throwableWithMessage.isPresent()) { // for "streaming" sources (the Blink runner always uses a streaming source throwableWithMessage = ExceptionUtils.findThrowableWithMessage( e, "The provided file path " + filename + " does not exist"); } return throwableWithMessage; }
Example 5
Source File: BulkSlotProviderImplTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testBulkSlotAllocationTimeoutsIfUnfulfillable() { final Exception exception = allocateSlotsAndWaitForTimeout(); final Optional<Throwable> cause = ExceptionUtils.findThrowableWithMessage( exception, "Slot request bulk is not fulfillable!"); assertThat(cause.isPresent(), is(true)); assertThat(cause.get(), instanceOf(TimeoutException.class)); }