Search in sources :

Example 6 with Tuple2

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);
}
Also used : Callable(java.util.concurrent.Callable) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) ExecutionContext(scala.concurrent.ExecutionContext) Tuple2(scala.Tuple2) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with Tuple2

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) {
    }
}
Also used : ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) IOException(java.io.IOException) PartitionNotFoundException(org.apache.flink.runtime.io.network.partition.PartitionNotFoundException) PartitionNotFoundException(org.apache.flink.runtime.io.network.partition.PartitionNotFoundException) Timer(java.util.Timer) TimerTask(java.util.TimerTask) Tuple2(scala.Tuple2) InvocationOnMock(org.mockito.invocation.InvocationOnMock) BufferAvailabilityListener(org.apache.flink.runtime.io.network.partition.BufferAvailabilityListener) BufferProvider(org.apache.flink.runtime.io.network.buffer.BufferProvider) Test(org.junit.Test)

Example 8 with Tuple2

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);
}
Also used : Tuple2(scala.Tuple2) PartitionRequestClient(org.apache.flink.runtime.io.network.netty.PartitionRequestClient) Test(org.junit.Test)

Example 9 with Tuple2

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) {
    }
}
Also used : Tuple2(scala.Tuple2) PartitionRequestClient(org.apache.flink.runtime.io.network.netty.PartitionRequestClient) ProducerFailedException(org.apache.flink.runtime.io.network.partition.ProducerFailedException) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with Tuple2

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) {
    }
}
Also used : Tuple2(scala.Tuple2) PartitionRequestClient(org.apache.flink.runtime.io.network.netty.PartitionRequestClient) ProducerFailedException(org.apache.flink.runtime.io.network.partition.ProducerFailedException) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Tuple2 (scala.Tuple2)181 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)57 ArrayList (java.util.ArrayList)43 IOException (java.io.IOException)32 Test (org.junit.Test)32 INDArray (org.nd4j.linalg.api.ndarray.INDArray)28 JavaPairRDD (org.apache.spark.api.java.JavaPairRDD)23 List (java.util.List)22 Function (org.apache.spark.api.java.function.Function)19 File (java.io.File)18 Collectors (java.util.stream.Collectors)18 GATKException (org.broadinstitute.hellbender.exceptions.GATKException)18 Configuration (org.apache.hadoop.conf.Configuration)17 UserException (org.broadinstitute.hellbender.exceptions.UserException)17 Broadcast (org.apache.spark.broadcast.Broadcast)16 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)16 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)16 SparkConf (org.apache.spark.SparkConf)15 JavaRDD (org.apache.spark.api.java.JavaRDD)15 VisibleForTesting (com.google.common.annotations.VisibleForTesting)14