use of java.util.concurrent.Executor in project flink by apache.
the class TerminalStateDeadlockTest method testProvokeDeadlock.
// ------------------------------------------------------------------------
@Test
public void testProvokeDeadlock() {
try {
final JobID jobId = resource.getJobID();
final JobVertexID vid1 = new JobVertexID();
final JobVertexID vid2 = new JobVertexID();
final List<JobVertex> vertices;
{
JobVertex v1 = new JobVertex("v1", vid1);
JobVertex v2 = new JobVertex("v2", vid2);
v1.setParallelism(1);
v2.setParallelism(1);
v1.setInvokableClass(DummyInvokable.class);
v2.setInvokableClass(DummyInvokable.class);
vertices = Arrays.asList(v1, v2);
}
final Scheduler scheduler = new Scheduler(TestingUtils.defaultExecutionContext());
final Executor executor = Executors.newFixedThreadPool(4);
// try a lot!
for (int i = 0; i < 20000; i++) {
final TestExecGraph eg = new TestExecGraph(jobId);
eg.attachJobGraph(vertices);
final Execution e1 = eg.getJobVertex(vid1).getTaskVertices()[0].getCurrentExecutionAttempt();
final Execution e2 = eg.getJobVertex(vid2).getTaskVertices()[0].getCurrentExecutionAttempt();
initializeExecution(e1);
initializeExecution(e2);
execGraphStateField.set(eg, JobStatus.FAILING);
execGraphSlotProviderField.set(eg, scheduler);
Runnable r1 = new Runnable() {
@Override
public void run() {
e1.cancelingComplete();
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
e2.cancelingComplete();
}
};
executor.execute(r1);
executor.execute(r2);
eg.waitTillDone();
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of java.util.concurrent.Executor in project flink by apache.
the class StreamTaskTest method createTask.
public static Task createTask(Class<? extends AbstractInvokable> invokable, StreamConfig taskConfig, Configuration taskManagerConfig) throws Exception {
LibraryCacheManager libCache = mock(LibraryCacheManager.class);
when(libCache.getClassLoader(any(JobID.class))).thenReturn(StreamTaskTest.class.getClassLoader());
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));
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, invokable.getName(), taskConfig.getConfiguration());
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), network, mock(BroadcastVariableManager.class), mock(TaskManagerActions.class), mock(InputSplitProvider.class), mock(CheckpointResponder.class), libCache, mock(FileCache.class), new TestingTaskManagerRuntimeInfo(taskManagerConfig, new String[] { System.getProperty("java.io.tmpdir") }), new UnregisteredTaskMetricsGroup(), consumableNotifier, partitionProducerStateChecker, executor);
}
use of java.util.concurrent.Executor in project disruptor by LMAX-Exchange.
the class WorkerPoolTest method shouldProcessOnlyOnceItHasBeenPublished.
@SuppressWarnings("unchecked")
@Test
public void shouldProcessOnlyOnceItHasBeenPublished() throws Exception {
Executor executor = Executors.newCachedThreadPool(DaemonThreadFactory.INSTANCE);
WorkerPool<AtomicLong> pool = new WorkerPool<AtomicLong>(new AtomicLongEventFactory(), new FatalExceptionHandler(), new AtomicLongWorkHandler(), new AtomicLongWorkHandler());
RingBuffer<AtomicLong> ringBuffer = pool.start(executor);
ringBuffer.next();
ringBuffer.next();
Thread.sleep(1000);
assertThat(ringBuffer.get(0).get(), is(0L));
assertThat(ringBuffer.get(1).get(), is(0L));
}
use of java.util.concurrent.Executor in project neo4j by neo4j.
the class ClusterContextTest method testElectionVersionIsResetWhenElectorChangesFromMeToOther.
@Test
public void testElectionVersionIsResetWhenElectorChangesFromMeToOther() throws Exception {
final String coordinatorRole = "coordinator";
final InstanceId me = new InstanceId(1);
final InstanceId winner = new InstanceId(2);
final InstanceId elector = new InstanceId(2);
HeartbeatContext heartbeatContext = mock(HeartbeatContext.class);
when(heartbeatContext.getFailed()).thenReturn(Collections.<InstanceId>emptySet());
Config config = mock(Config.class);
when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
MultiPaxosContext multiPaxosContext = new MultiPaxosContext(me, Iterables.<ElectionRole, ElectionRole>iterable(new ElectionRole(coordinatorRole)), mock(ClusterConfiguration.class), new Executor() {
@Override
public void execute(Runnable command) {
command.run();
}
}, NullLogProvider.getInstance(), mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(AcceptorInstanceStore.class), mock(Timeouts.class), mock(ElectionCredentialsProvider.class), config);
ClusterContext context = multiPaxosContext.getClusterContext();
ElectionContext electionContext = multiPaxosContext.getElectionContext();
ClusterListener listener = mock(ClusterListener.class);
context.setLastElectorVersion(5);
context.setLastElector(me);
context.addClusterListener(listener);
long expectedVersion = electionContext.newConfigurationStateChange().getVersion();
context.elected(coordinatorRole, winner, me, expectedVersion);
verify(listener, times(1)).elected(coordinatorRole, winner, null);
context.elected(coordinatorRole, winner, elector, 2);
verify(listener, times(2)).elected(coordinatorRole, winner, null);
context.elected(coordinatorRole, winner, elector, 3);
verify(listener, times(3)).elected(coordinatorRole, winner, null);
context.elected(coordinatorRole, winner, elector, 2);
verifyNoMoreInteractions(listener);
}
use of java.util.concurrent.Executor in project netty by netty.
the class LocalChannelTest method localChannelRaceCondition.
@Test
public void localChannelRaceCondition() throws Exception {
final CountDownLatch closeLatch = new CountDownLatch(1);
final EventLoopGroup clientGroup = new DefaultEventLoopGroup(1) {
@Override
protected EventLoop newChild(Executor threadFactory, Object... args) throws Exception {
return new SingleThreadEventLoop(this, threadFactory, true) {
@Override
protected void run() {
for (; ; ) {
Runnable task = takeTask();
if (task != null) {
/* Only slow down the anonymous class in LocalChannel#doRegister() */
if (task.getClass().getEnclosingClass() == LocalChannel.class) {
try {
closeLatch.await();
} catch (InterruptedException e) {
throw new Error(e);
}
}
task.run();
updateLastExecutionTime();
}
if (confirmShutdown()) {
break;
}
}
}
};
}
};
Channel sc = null;
Channel cc = null;
try {
ServerBootstrap sb = new ServerBootstrap();
sc = sb.group(group2).channel(LocalServerChannel.class).childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.close();
closeLatch.countDown();
}
}).bind(TEST_ADDRESS).sync().channel();
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(clientGroup).channel(LocalChannel.class).handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
/* Do nothing */
}
});
ChannelFuture future = bootstrap.connect(sc.localAddress());
assertTrue("Connection should finish, not time out", future.await(200));
cc = future.channel();
} finally {
closeChannel(cc);
closeChannel(sc);
clientGroup.shutdownGracefully(0, 0, SECONDS).await();
}
}
Aggregations