use of java.util.concurrent.ExecutionException in project flink by apache.
the class AsyncWaitOperatorTest method testAsyncTimeout.
@Test
public void testAsyncTimeout() throws Exception {
final long timeout = 10L;
final AsyncWaitOperator<Integer, Integer> operator = new AsyncWaitOperator<>(new LazyAsyncFunction(), timeout, 2, AsyncDataStream.OutputMode.ORDERED);
final Environment mockEnvironment = mock(Environment.class);
final Configuration taskConfiguration = new Configuration();
final ExecutionConfig executionConfig = new ExecutionConfig();
final TaskMetricGroup metricGroup = new UnregisteredTaskMetricsGroup();
final TaskManagerRuntimeInfo taskManagerRuntimeInfo = new TestingTaskManagerRuntimeInfo();
final TaskInfo taskInfo = new TaskInfo("foobarTask", 1, 0, 1, 1);
when(mockEnvironment.getTaskConfiguration()).thenReturn(taskConfiguration);
when(mockEnvironment.getExecutionConfig()).thenReturn(executionConfig);
when(mockEnvironment.getMetricGroup()).thenReturn(metricGroup);
when(mockEnvironment.getTaskManagerInfo()).thenReturn(taskManagerRuntimeInfo);
when(mockEnvironment.getTaskInfo()).thenReturn(taskInfo);
when(mockEnvironment.getUserClassLoader()).thenReturn(AsyncWaitOperatorTest.class.getClassLoader());
final OneInputStreamOperatorTestHarness<Integer, Integer> testHarness = new OneInputStreamOperatorTestHarness<>(operator, IntSerializer.INSTANCE, mockEnvironment);
final long initialTime = 0L;
final ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>();
testHarness.open();
testHarness.setProcessingTime(initialTime);
synchronized (testHarness.getCheckpointLock()) {
testHarness.processElement(new StreamRecord<>(1, initialTime));
testHarness.setProcessingTime(initialTime + 5L);
testHarness.processElement(new StreamRecord<>(2, initialTime + 5L));
}
// trigger the timeout of the first stream record
testHarness.setProcessingTime(initialTime + timeout + 1L);
// allow the second async stream record to be processed
LazyAsyncFunction.countDown();
// wait until all async collectors in the buffer have been emitted out.
synchronized (testHarness.getCheckpointLock()) {
testHarness.close();
}
expectedOutput.add(new StreamRecord<>(2, initialTime + 5L));
TestHarnessUtil.assertOutputEquals("Output with watermark was not correct.", expectedOutput, testHarness.getOutput());
ArgumentCaptor<Throwable> argumentCaptor = ArgumentCaptor.forClass(Throwable.class);
verify(mockEnvironment).failExternally(argumentCaptor.capture());
Throwable failureCause = argumentCaptor.getValue();
Assert.assertNotNull(failureCause.getCause());
Assert.assertTrue(failureCause.getCause() instanceof ExecutionException);
Assert.assertNotNull(failureCause.getCause().getCause());
Assert.assertTrue(failureCause.getCause().getCause() instanceof TimeoutException);
}
use of java.util.concurrent.ExecutionException in project flink by apache.
the class EmitterTest method testEmitterWithExceptions.
/**
* Tests that the emitter handles exceptions occurring in the {@link AsyncCollector} correctly.
*/
@Test
public void testEmitterWithExceptions() throws Exception {
Object lock = new Object();
List<StreamElement> list = new ArrayList<>();
Output<StreamRecord<Integer>> output = new CollectorOutput<>(list);
List<StreamElement> expected = Arrays.asList(new StreamRecord<>(1, 0L), new Watermark(3L));
OperatorActions operatorActions = mock(OperatorActions.class);
final int capacity = 3;
StreamElementQueue queue = new OrderedStreamElementQueue(capacity, executor, operatorActions);
final Emitter<Integer> emitter = new Emitter<>(lock, output, queue, operatorActions);
final Thread emitterThread = new Thread(emitter);
emitterThread.start();
final Exception testException = new Exception("Test exception");
try {
StreamRecordQueueEntry<Integer> record1 = new StreamRecordQueueEntry<>(new StreamRecord<>(1, 0L));
StreamRecordQueueEntry<Integer> record2 = new StreamRecordQueueEntry<>(new StreamRecord<>(2, 1L));
WatermarkQueueEntry watermark1 = new WatermarkQueueEntry(new Watermark(3L));
queue.put(record1);
queue.put(record2);
queue.put(watermark1);
record2.collect(testException);
record1.collect(Arrays.asList(1));
synchronized (lock) {
while (!queue.isEmpty()) {
lock.wait();
}
}
Assert.assertEquals(expected, list);
ArgumentCaptor<Throwable> argumentCaptor = ArgumentCaptor.forClass(Throwable.class);
verify(operatorActions).failOperator(argumentCaptor.capture());
Throwable failureCause = argumentCaptor.getValue();
Assert.assertNotNull(failureCause.getCause());
Assert.assertTrue(failureCause.getCause() instanceof ExecutionException);
Assert.assertNotNull(failureCause.getCause().getCause());
Assert.assertEquals(testException, failureCause.getCause().getCause());
} finally {
emitter.stop();
emitterThread.interrupt();
}
}
use of java.util.concurrent.ExecutionException in project hadoop by apache.
the class ValueQueue method getAtMost.
/**
* This removes the "num" values currently at the head of the Queue for the
* provided key. Will immediately fire the Queue filler function if key
* does not exist
* How many values are actually returned is governed by the
* <code>SyncGenerationPolicy</code> specified by the user.
* @param keyName String key name
* @param num Minimum number of values to return.
* @return List<E> values returned
* @throws IOException
* @throws ExecutionException
*/
public List<E> getAtMost(String keyName, int num) throws IOException, ExecutionException {
LinkedBlockingQueue<E> keyQueue = keyQueues.get(keyName);
// Using poll to avoid race condition..
LinkedList<E> ekvs = new LinkedList<E>();
try {
for (int i = 0; i < num; i++) {
readLock(keyName);
E val = keyQueue.poll();
readUnlock(keyName);
// figure out how many new values need to be generated synchronously
if (val == null) {
// Synchronous call to get remaining values
int numToFill = 0;
switch(policy) {
case ATLEAST_ONE:
numToFill = (ekvs.size() < 1) ? 1 : 0;
break;
case LOW_WATERMARK:
numToFill = Math.min(num, (int) (lowWatermark * numValues)) - ekvs.size();
break;
case ALL:
numToFill = num - ekvs.size();
break;
}
// Synchronous fill if not enough values found
if (numToFill > 0) {
refiller.fillQueueForKey(keyName, ekvs, numToFill);
}
// Asynch task to fill > lowWatermark
if (i <= (int) (lowWatermark * numValues)) {
submitRefillTask(keyName, keyQueue);
}
return ekvs;
}
ekvs.add(val);
}
} catch (Exception e) {
throw new IOException("Exception while contacting value generator ", e);
}
return ekvs;
}
use of java.util.concurrent.ExecutionException in project flink by apache.
the class SlotPoolRpcTest method testSlotAllocationNoResourceManager.
// ------------------------------------------------------------------------
// tests
// ------------------------------------------------------------------------
@Test
public void testSlotAllocationNoResourceManager() throws Exception {
final JobID jid = new JobID();
final SlotPool pool = new SlotPool(rpcService, jid, SystemClock.getInstance(), Time.days(1), Time.days(1), // this is the timeout for the request tested here
Time.milliseconds(100));
pool.start(UUID.randomUUID());
Future<SimpleSlot> future = pool.allocateSlot(mock(ScheduledUnit.class), DEFAULT_TESTING_PROFILE, null);
try {
future.get(4, TimeUnit.SECONDS);
fail("We expected a ExecutionException.");
} catch (ExecutionException e) {
assertEquals(NoResourceAvailableException.class, e.getCause().getClass());
} catch (TimeoutException e) {
fail("future timed out rather than being failed");
} catch (Exception e) {
fail("wrong exception: " + e);
}
}
use of java.util.concurrent.ExecutionException in project flink by apache.
the class RetryingRegistrationTest method testPropagateFailures.
@Test
public void testPropagateFailures() throws Exception {
final String testExceptionMessage = "testExceptionMessage";
// RPC service that fails with exception upon the connection
RpcService rpc = mock(RpcService.class);
when(rpc.connect(anyString(), any(Class.class))).thenThrow(new RuntimeException(testExceptionMessage));
TestRetryingRegistration registration = new TestRetryingRegistration(rpc, "testaddress", UUID.randomUUID());
registration.startRegistration();
Future<?> future = registration.getFuture();
assertTrue(future.isDone());
try {
future.get();
fail("We expected an ExecutionException.");
} catch (ExecutionException e) {
assertEquals(testExceptionMessage, e.getCause().getMessage());
}
}
Aggregations