use of java.util.concurrent.Executor in project neo4j by neo4j.
the class ClusterContextImplTest method shouldKeepTrackOfInstancesWeHaveContacted.
@Test
public void shouldKeepTrackOfInstancesWeHaveContacted() throws Exception {
// Given
InstanceId me = new InstanceId(1);
InstanceId joiningOne = new InstanceId(2);
InstanceId joiningTwo = new InstanceId(3);
CommonContextState commonContextState = mock(CommonContextState.class, RETURNS_MOCKS);
Timeouts timeouts = mock(Timeouts.class);
Executor executor = mock(Executor.class);
HeartbeatContext heartbeatContext = mock(HeartbeatContext.class);
ClusterContext context = new ClusterContextImpl(me, commonContextState, NullLogProvider.getInstance(), timeouts, executor, mock(ObjectOutputStreamFactory.class), mock(ObjectInputStreamFactory.class), mock(LearnerContext.class), heartbeatContext, mock(Config.class));
ClusterMessage.ConfigurationRequestState requestOne = mock(ClusterMessage.ConfigurationRequestState.class);
when(requestOne.getJoiningId()).thenReturn(joiningOne);
ClusterMessage.ConfigurationRequestState requestTwo = mock(ClusterMessage.ConfigurationRequestState.class);
when(requestTwo.getJoiningId()).thenReturn(joiningTwo);
// When
// Instance two contacts us but we are not in the header
context.addContactingInstance(requestOne, "4, 5");
// Then we haven't contacted instance 2
assertFalse(context.haveWeContactedInstance(requestOne));
// When
// Instance 2 reports that we have contacted it after all
context.addContactingInstance(requestOne, "4, 5, 1");
// Then
assertTrue(context.haveWeContactedInstance(requestOne));
// When
// Instance 3 says we have contacted it
context.addContactingInstance(requestTwo, "2, 5, 1");
// Then
assertTrue(context.haveWeContactedInstance(requestTwo));
// When
// For some reason we are not in the header of 3 in subsequent responses (a delayed one, for example)
context.addContactingInstance(requestTwo, "2, 5");
// Then
// The state should still keep the fact we've contacted it already
assertTrue(context.haveWeContactedInstance(requestTwo));
}
use of java.util.concurrent.Executor in project neo4j by neo4j.
the class MultiPaxosContextTest method shouldDeepClone.
@Test
public void shouldDeepClone() throws Exception {
// Given
ObjectStreamFactory objStream = new ObjectStreamFactory();
AcceptorInstanceStore acceptorInstances = mock(AcceptorInstanceStore.class);
Executor executor = mock(Executor.class);
Timeouts timeouts = mock(Timeouts.class);
ClusterConfiguration clusterConfig = new ClusterConfiguration("myCluster", NullLogProvider.getInstance());
ElectionCredentialsProvider electionCredentials = mock(ElectionCredentialsProvider.class);
Config config = mock(Config.class);
when(config.get(ClusterSettings.max_acceptors)).thenReturn(10);
MultiPaxosContext ctx = new MultiPaxosContext(new InstanceId(1), Collections.<ElectionRole>emptyList(), clusterConfig, executor, NullLogProvider.getInstance(), objStream, objStream, acceptorInstances, timeouts, electionCredentials, config);
// When
MultiPaxosContext snapshot = ctx.snapshot(NullLogProvider.getInstance(), timeouts, executor, acceptorInstances, objStream, objStream, electionCredentials);
// Then
assertEquals(ctx, snapshot);
}
use of java.util.concurrent.Executor in project zipkin by openzipkin.
the class LazyTest method get_memoizes.
@Test(timeout = 1000L)
public void get_memoizes() throws InterruptedException {
int getCount = 1000;
AtomicInteger value = new AtomicInteger();
Lazy<Integer> lazyInt = new Lazy<Integer>() {
final AtomicInteger val = new AtomicInteger();
@Override
protected Integer compute() {
return val.incrementAndGet();
}
};
CountDownLatch latch = new CountDownLatch(getCount);
Executor exec = Executors.newFixedThreadPool(10);
for (int i = 0; i < getCount; i++) {
exec.execute(() -> {
// if lazy computes multiple times, the result of lazyInt.get() > 1
value.getAndAdd(lazyInt.get());
latch.countDown();
});
}
latch.await();
assertThat(value.get()).isEqualTo(getCount);
}
use of java.util.concurrent.Executor in project dev-summit-architecture-demo by yigit.
the class AutoCancelAsyncTaskTest method unregisterAfterCompletion.
@Test
public void unregisterAfterCompletion() {
Executor mockExecutor = new Executor() {
@Override
public void execute(Runnable command) {
command.run();
}
};
LifecycleProvider provider = mock(LifecycleProvider.class);
doNothing().when(provider).addLifecycleListener(any(LifecycleListener.class));
AutoCancelAsyncTask<Void, Void> task = new AutoCancelAsyncTask<Void, Void>(provider) {
@Override
protected void onResult(Void aVoid) {
}
@Override
protected Void onDoInBackground(Void... params) {
return null;
}
};
task.executeOnExecutor(mockExecutor);
verify(provider).removeLifecycleListener(any(LifecycleListener.class));
}
use of java.util.concurrent.Executor in project java-chassis by ServiceComb.
the class MockUtil method mockMicroserviceMetaManager.
public void mockMicroserviceMetaManager() {
new MockUp<MicroserviceMetaManager>() {
@Mock
public SchemaMeta ensureFindSchemaMeta(String schemaId) {
SchemaMeta schemaMeta = Mockito.mock(SchemaMeta.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
Mockito.when(schemaMeta.ensureFindOperation(null)).thenReturn(operationMeta);
Method method = this.getClass().getMethods()[0];
Mockito.when(operationMeta.getMethod()).thenReturn(method);
OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
Executor lExecutor = Mockito.mock(Executor.class);
Mockito.when(operationMeta.getExecutor()).thenReturn(lExecutor);
return schemaMeta;
}
};
}
Aggregations