Search in sources :

Example 36 with Executor

use of java.util.concurrent.Executor in project hazelcast by hazelcast.

the class AbstractInvocationFuture_AndThenTest method whenDefaultExecutor.

@Test
public void whenDefaultExecutor() {
    Executor defaultExecutor = mock(Executor.class);
    TestFuture future = new TestFuture(defaultExecutor, logger);
    final ExecutionCallback callback = mock(ExecutionCallback.class);
    future.andThen(callback);
    future.complete(value);
    verify(defaultExecutor).execute(any(Runnable.class));
}
Also used : Executor(java.util.concurrent.Executor) ExecutionCallback(com.hazelcast.core.ExecutionCallback) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 37 with Executor

use of java.util.concurrent.Executor in project flink by apache.

the class CassandraTupleWriteAheadSinkTest method testAckLoopExitOnException.

@Test(timeout = 20000)
public void testAckLoopExitOnException() throws Exception {
    final AtomicReference<Runnable> runnableFuture = new AtomicReference<>();
    final ClusterBuilder clusterBuilder = new ClusterBuilder() {

        private static final long serialVersionUID = 4624400760492936756L;

        @Override
        protected Cluster buildCluster(Cluster.Builder builder) {
            try {
                BoundStatement boundStatement = mock(BoundStatement.class);
                when(boundStatement.setDefaultTimestamp(any(long.class))).thenReturn(boundStatement);
                PreparedStatement preparedStatement = mock(PreparedStatement.class);
                when(preparedStatement.bind(Matchers.anyVararg())).thenReturn(boundStatement);
                ResultSetFuture future = mock(ResultSetFuture.class);
                when(future.get()).thenThrow(new RuntimeException("Expected exception."));
                doAnswer(new Answer<Void>() {

                    @Override
                    public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
                        synchronized (runnableFuture) {
                            runnableFuture.set((((Runnable) invocationOnMock.getArguments()[0])));
                            runnableFuture.notifyAll();
                        }
                        return null;
                    }
                }).when(future).addListener(any(Runnable.class), any(Executor.class));
                Session session = mock(Session.class);
                when(session.prepare(anyString())).thenReturn(preparedStatement);
                when(session.executeAsync(any(BoundStatement.class))).thenReturn(future);
                Cluster cluster = mock(Cluster.class);
                when(cluster.connect()).thenReturn(session);
                return cluster;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    // Our asynchronous executor thread
    new Thread(new Runnable() {

        @Override
        public void run() {
            synchronized (runnableFuture) {
                while (runnableFuture.get() == null) {
                    try {
                        runnableFuture.wait();
                    } catch (InterruptedException e) {
                    // ignore interrupts
                    }
                }
            }
            runnableFuture.get().run();
        }
    }).start();
    CheckpointCommitter cc = mock(CheckpointCommitter.class);
    final CassandraTupleWriteAheadSink<Tuple0> sink = new CassandraTupleWriteAheadSink<>("abc", TupleTypeInfo.of(Tuple0.class).createSerializer(new ExecutionConfig()), clusterBuilder, cc);
    OneInputStreamOperatorTestHarness<Tuple0, Tuple0> harness = new OneInputStreamOperatorTestHarness(sink);
    harness.getEnvironment().getTaskConfiguration().setBoolean("checkpointing", true);
    harness.setup();
    sink.open();
    // we should leave the loop and return false since we've seen an exception
    assertFalse(sink.sendValues(Collections.singleton(new Tuple0()), 0L));
    sink.close();
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) CheckpointCommitter(org.apache.flink.streaming.runtime.operators.CheckpointCommitter) Executor(java.util.concurrent.Executor) Cluster(com.datastax.driver.core.Cluster) AtomicReference(java.util.concurrent.atomic.AtomicReference) PreparedStatement(com.datastax.driver.core.PreparedStatement) OneInputStreamOperatorTestHarness(org.apache.flink.streaming.util.OneInputStreamOperatorTestHarness) Tuple0(org.apache.flink.api.java.tuple.Tuple0) InvocationOnMock(org.mockito.invocation.InvocationOnMock) BoundStatement(com.datastax.driver.core.BoundStatement) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Example 38 with Executor

use of java.util.concurrent.Executor in project flink by apache.

the class TaskAsyncCallTest method createTask.

private static Task createTask() throws Exception {
    LibraryCacheManager libCache = mock(LibraryCacheManager.class);
    when(libCache.getClassLoader(any(JobID.class))).thenReturn(ClassLoader.getSystemClassLoader());
    ResultPartitionManager partitionManager = mock(ResultPartitionManager.class);
    ResultPartitionConsumableNotifier consumableNotifier = mock(ResultPartitionConsumableNotifier.class);
    PartitionProducerStateChecker partitionProducerStateChecker = mock(PartitionProducerStateChecker.class);
    Executor executor = mock(Executor.class);
    NetworkEnvironment networkEnvironment = mock(NetworkEnvironment.class);
    when(networkEnvironment.getResultPartitionManager()).thenReturn(partitionManager);
    when(networkEnvironment.getDefaultIOMode()).thenReturn(IOManager.IOMode.SYNC);
    when(networkEnvironment.createKvStateTaskRegistry(any(JobID.class), any(JobVertexID.class))).thenReturn(mock(TaskKvStateRegistry.class));
    JobInformation jobInformation = new JobInformation(new JobID(), "Job Name", new SerializedValue<>(new ExecutionConfig()), new Configuration(), Collections.<BlobKey>emptyList(), Collections.<URL>emptyList());
    TaskInformation taskInformation = new TaskInformation(new JobVertexID(), "Test Task", 1, 1, CheckpointsInOrderInvokable.class.getName(), new Configuration());
    return new Task(jobInformation, taskInformation, new ExecutionAttemptID(), new AllocationID(), 0, 0, Collections.<ResultPartitionDeploymentDescriptor>emptyList(), Collections.<InputGateDeploymentDescriptor>emptyList(), 0, new TaskStateHandles(), mock(MemoryManager.class), mock(IOManager.class), networkEnvironment, mock(BroadcastVariableManager.class), mock(TaskManagerActions.class), mock(InputSplitProvider.class), mock(CheckpointResponder.class), libCache, mock(FileCache.class), new TestingTaskManagerRuntimeInfo(), mock(TaskMetricGroup.class), consumableNotifier, partitionProducerStateChecker, executor);
}
Also used : StatefulTask(org.apache.flink.runtime.jobgraph.tasks.StatefulTask) Configuration(org.apache.flink.configuration.Configuration) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) TaskKvStateRegistry(org.apache.flink.runtime.query.TaskKvStateRegistry) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) Executor(java.util.concurrent.Executor) TestingTaskManagerRuntimeInfo(org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo) BroadcastVariableManager(org.apache.flink.runtime.broadcast.BroadcastVariableManager) PartitionProducerStateChecker(org.apache.flink.runtime.io.network.netty.PartitionProducerStateChecker) ResultPartitionConsumableNotifier(org.apache.flink.runtime.io.network.partition.ResultPartitionConsumableNotifier) InputSplitProvider(org.apache.flink.runtime.jobgraph.tasks.InputSplitProvider) JobInformation(org.apache.flink.runtime.executiongraph.JobInformation) TaskInformation(org.apache.flink.runtime.executiongraph.TaskInformation) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) IOManager(org.apache.flink.runtime.io.disk.iomanager.IOManager) TaskMetricGroup(org.apache.flink.runtime.metrics.groups.TaskMetricGroup) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) LibraryCacheManager(org.apache.flink.runtime.execution.librarycache.LibraryCacheManager) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) FileCache(org.apache.flink.runtime.filecache.FileCache) TaskStateHandles(org.apache.flink.runtime.state.TaskStateHandles) NetworkEnvironment(org.apache.flink.runtime.io.network.NetworkEnvironment) JobID(org.apache.flink.api.common.JobID)

Example 39 with Executor

use of java.util.concurrent.Executor in project flink by apache.

the class TaskTest method createTask.

private Task createTask(Class<? extends AbstractInvokable> invokable, LibraryCacheManager libCache, Configuration config, ExecutionConfig execConfig) throws IOException {
    ResultPartitionManager partitionManager = mock(ResultPartitionManager.class);
    ResultPartitionConsumableNotifier consumableNotifier = mock(ResultPartitionConsumableNotifier.class);
    PartitionProducerStateChecker partitionProducerStateChecker = mock(PartitionProducerStateChecker.class);
    Executor executor = mock(Executor.class);
    NetworkEnvironment network = mock(NetworkEnvironment.class);
    when(network.getResultPartitionManager()).thenReturn(partitionManager);
    when(network.getDefaultIOMode()).thenReturn(IOManager.IOMode.SYNC);
    when(network.createKvStateTaskRegistry(any(JobID.class), any(JobVertexID.class))).thenReturn(mock(TaskKvStateRegistry.class));
    return createTask(invokable, libCache, network, consumableNotifier, partitionProducerStateChecker, executor, config, execConfig);
}
Also used : Executor(java.util.concurrent.Executor) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) NetworkEnvironment(org.apache.flink.runtime.io.network.NetworkEnvironment) TaskKvStateRegistry(org.apache.flink.runtime.query.TaskKvStateRegistry) PartitionProducerStateChecker(org.apache.flink.runtime.io.network.netty.PartitionProducerStateChecker) ResultPartitionManager(org.apache.flink.runtime.io.network.partition.ResultPartitionManager) ResultPartitionConsumableNotifier(org.apache.flink.runtime.io.network.partition.ResultPartitionConsumableNotifier) JobID(org.apache.flink.api.common.JobID)

Example 40 with Executor

use of java.util.concurrent.Executor in project camel by apache.

the class CamelOutputStream method asyncInvokeFromWorkQueue.

protected void asyncInvokeFromWorkQueue(final org.apache.camel.Exchange exchange) throws IOException {
    Runnable runnable = new Runnable() {

        public void run() {
            try {
                syncInvoke(exchange);
            } catch (Throwable e) {
                ((PhaseInterceptorChain) outMessage.getInterceptorChain()).abort();
                outMessage.setContent(Exception.class, e);
                ((PhaseInterceptorChain) outMessage.getInterceptorChain()).unwind(outMessage);
                MessageObserver mo = outMessage.getInterceptorChain().getFaultObserver();
                if (mo == null) {
                    mo = outMessage.getExchange().get(MessageObserver.class);
                }
                mo.onMessage(outMessage);
            }
        }
    };
    try {
        Executor ex = outMessage.getExchange().get(Executor.class);
        if (ex != null) {
            outMessage.getExchange().put(Executor.class.getName() + ".USING_SPECIFIED", Boolean.TRUE);
            ex.execute(runnable);
        } else {
            WorkQueueManager mgr = outMessage.getExchange().get(Bus.class).getExtension(WorkQueueManager.class);
            AutomaticWorkQueue qu = mgr.getNamedWorkQueue("camel-cxf-conduit");
            if (qu == null) {
                qu = mgr.getAutomaticWorkQueue();
            }
            // need to set the time out somewhere
            qu.execute(runnable);
        }
    } catch (RejectedExecutionException rex) {
        if (!hasLoggedAsyncWarning) {
            LOG.warn("Executor rejected background task to retrieve the response.  Suggest increasing the workqueue settings.");
            hasLoggedAsyncWarning = true;
        }
        LOG.info("Executor rejected background task to retrieve the response, running on current thread.");
        syncInvoke(exchange);
    }
}
Also used : Bus(org.apache.cxf.Bus) MessageObserver(org.apache.cxf.transport.MessageObserver) Executor(java.util.concurrent.Executor) AutomaticWorkQueue(org.apache.cxf.workqueue.AutomaticWorkQueue) WorkQueueManager(org.apache.cxf.workqueue.WorkQueueManager) IOException(java.io.IOException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

Executor (java.util.concurrent.Executor)302 Test (org.junit.Test)127 ArrayList (java.util.ArrayList)35 CountDownLatch (java.util.concurrent.CountDownLatch)32 IOException (java.io.IOException)29 List (java.util.List)27 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)22 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)17 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 Map (java.util.Map)15 Timeouts (org.neo4j.cluster.timeout.Timeouts)15 ExecutorService (java.util.concurrent.ExecutorService)13 InstanceId (org.neo4j.cluster.InstanceId)13 Config (org.neo4j.kernel.configuration.Config)13 File (java.io.File)12 ObjectInputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory)12 ObjectOutputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory)12 HeartbeatContext (org.neo4j.cluster.protocol.heartbeat.HeartbeatContext)12 InetSocketAddress (java.net.InetSocketAddress)10