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));
}
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();
}
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);
}
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);
}
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);
}
}
Aggregations