use of scala.Tuple2 in project flink by apache.
the class FlinkFuture method thenCombineAsync.
@Override
public <U, R> Future<R> thenCombineAsync(final Future<U> other, final BiFunction<? super T, ? super U, ? extends R> biFunction, final Executor executor) {
Preconditions.checkNotNull(other);
Preconditions.checkNotNull(biFunction);
Preconditions.checkNotNull(executor);
final ExecutionContext executionContext = createExecutionContext(executor);
final scala.concurrent.Future<U> thatScalaFuture;
if (other instanceof FlinkFuture) {
thatScalaFuture = ((FlinkFuture<U>) other).scalaFuture;
} else {
thatScalaFuture = Futures.future(new Callable<U>() {
@Override
public U call() throws Exception {
try {
return other.get();
} catch (ExecutionException e) {
// unwrap the execution exception if the cause is an Exception
if (e.getCause() instanceof Exception) {
throw (Exception) e.getCause();
} else {
// it's an error or a throwable which we have to wrap for the moment
throw new FlinkFuture.ThrowableWrapperException(e.getCause());
}
}
}
}, executionContext);
}
scala.concurrent.Future<R> result = scalaFuture.zip(thatScalaFuture).map(new Mapper<Tuple2<T, U>, R>() {
@Override
public R apply(Tuple2<T, U> tuple2) {
return biFunction.apply(tuple2._1, tuple2._2);
}
}, executionContext);
return new FlinkFuture<>(result);
}
use of scala.Tuple2 in project flink by apache.
the class LocalInputChannelTest method testPartitionRequestExponentialBackoff.
@Test
public void testPartitionRequestExponentialBackoff() throws Exception {
// Config
Tuple2<Integer, Integer> backoff = new Tuple2<>(500, 3000);
// Start with initial backoff, then keep doubling, and cap at max.
int[] expectedDelays = { backoff._1(), 1000, 2000, backoff._2() };
// Setup
SingleInputGate inputGate = mock(SingleInputGate.class);
BufferProvider bufferProvider = mock(BufferProvider.class);
when(inputGate.getBufferProvider()).thenReturn(bufferProvider);
ResultPartitionManager partitionManager = mock(ResultPartitionManager.class);
LocalInputChannel ch = createLocalInputChannel(inputGate, partitionManager, backoff);
when(partitionManager.createSubpartitionView(eq(ch.partitionId), eq(0), eq(bufferProvider), any(BufferAvailabilityListener.class))).thenThrow(new PartitionNotFoundException(ch.partitionId));
Timer timer = mock(Timer.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
((TimerTask) invocation.getArguments()[0]).run();
return null;
}
}).when(timer).schedule(any(TimerTask.class), anyLong());
// Initial request
ch.requestSubpartition(0);
verify(partitionManager).createSubpartitionView(eq(ch.partitionId), eq(0), eq(bufferProvider), any(BufferAvailabilityListener.class));
// Request subpartition and verify that the actual requests are delayed.
for (long expected : expectedDelays) {
ch.retriggerSubpartitionRequest(timer, 0);
verify(timer).schedule(any(TimerTask.class), eq(expected));
}
// Exception after backoff is greater than the maximum backoff.
try {
ch.retriggerSubpartitionRequest(timer, 0);
ch.getNextBuffer();
fail("Did not throw expected exception.");
} catch (Exception expected) {
}
}
use of scala.Tuple2 in project flink by apache.
the class RemoteInputChannelTest method testRetriggerWithoutPartitionRequest.
@Test(expected = IllegalStateException.class)
public void testRetriggerWithoutPartitionRequest() throws Exception {
Tuple2<Integer, Integer> backoff = new Tuple2<Integer, Integer>(500, 3000);
PartitionRequestClient connClient = mock(PartitionRequestClient.class);
SingleInputGate inputGate = mock(SingleInputGate.class);
RemoteInputChannel ch = createRemoteInputChannel(inputGate, connClient, backoff);
ch.retriggerSubpartitionRequest(0);
}
use of scala.Tuple2 in project flink by apache.
the class RemoteInputChannelTest method testPartitionRequestSingleBackoff.
@Test
public void testPartitionRequestSingleBackoff() throws Exception {
// Config
Tuple2<Integer, Integer> backoff = new Tuple2<Integer, Integer>(500, 500);
// Setup
PartitionRequestClient connClient = mock(PartitionRequestClient.class);
SingleInputGate inputGate = mock(SingleInputGate.class);
RemoteInputChannel ch = createRemoteInputChannel(inputGate, connClient, backoff);
// No delay for first request
ch.requestSubpartition(0);
verify(connClient).requestSubpartition(eq(ch.partitionId), eq(0), eq(ch), eq(0));
// Initial delay for second request
ch.retriggerSubpartitionRequest(0);
verify(connClient).requestSubpartition(eq(ch.partitionId), eq(0), eq(ch), eq(backoff._1()));
// Exception after backoff is greater than the maximum backoff.
try {
ch.retriggerSubpartitionRequest(0);
ch.getNextBuffer();
fail("Did not throw expected exception.");
} catch (Exception expected) {
}
}
use of scala.Tuple2 in project flink by apache.
the class RemoteInputChannelTest method testPartitionRequestNoBackoff.
@Test
public void testPartitionRequestNoBackoff() throws Exception {
// Config
Tuple2<Integer, Integer> backoff = new Tuple2<Integer, Integer>(0, 0);
// Setup
PartitionRequestClient connClient = mock(PartitionRequestClient.class);
SingleInputGate inputGate = mock(SingleInputGate.class);
RemoteInputChannel ch = createRemoteInputChannel(inputGate, connClient, backoff);
// No delay for first request
ch.requestSubpartition(0);
verify(connClient).requestSubpartition(eq(ch.partitionId), eq(0), eq(ch), eq(0));
// Exception, because backoff is disabled.
try {
ch.retriggerSubpartitionRequest(0);
ch.getNextBuffer();
fail("Did not throw expected exception.");
} catch (Exception expected) {
}
}
Aggregations