use of org.neo4j.test.OnDemandJobScheduler in project neo4j by neo4j.
the class HazelcastClientTest method shouldNotReconnectWhileHazelcastRemainsAvailable.
@Test
public void shouldNotReconnectWhileHazelcastRemainsAvailable() throws Throwable {
// given
HazelcastConnector connector = mock(HazelcastConnector.class);
OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
HazelcastClient client = new HazelcastClient(connector, jobScheduler, NullLogProvider.getInstance(), config(), myself);
HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
when(connector.connectToHazelcast()).thenReturn(hazelcastInstance);
when(hazelcastInstance.getAtomicReference(anyString())).thenReturn(mock(IAtomicReference.class));
when(hazelcastInstance.getSet(anyString())).thenReturn(new HazelcastSet());
when(hazelcastInstance.getMultiMap(anyString())).thenReturn(new HazelcastMultiMap());
when(hazelcastInstance.getExecutorService(anyString())).thenReturn(new StubExecutorService());
com.hazelcast.core.Cluster cluster = mock(Cluster.class);
when(hazelcastInstance.getCluster()).thenReturn(cluster);
Set<Member> members = asSet(makeMember(1), makeMember(2));
when(cluster.getMembers()).thenReturn(members);
// when
client.start();
jobScheduler.runJob();
CoreTopology topology;
for (int i = 0; i < 5; i++) {
topology = client.coreServers();
assertEquals(members.size(), topology.members().size());
}
// then
verify(connector, times(1)).connectToHazelcast();
}
use of org.neo4j.test.OnDemandJobScheduler in project neo4j by neo4j.
the class HazelcastClientTest method shouldSwallowNPEFromHazelcast.
@Test
public void shouldSwallowNPEFromHazelcast() throws Throwable {
// given
Endpoint endpoint = mock(Endpoint.class);
when(endpoint.getUuid()).thenReturn("12345");
HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
when(hazelcastInstance.getLocalEndpoint()).thenReturn(endpoint);
when(hazelcastInstance.getMap(anyString())).thenReturn(new HazelcastMap());
when(hazelcastInstance.getMultiMap(anyString())).thenReturn(new HazelcastMultiMap());
doThrow(new NullPointerException("boom!!!")).when(hazelcastInstance).shutdown();
HazelcastConnector connector = mock(HazelcastConnector.class);
when(connector.connectToHazelcast()).thenReturn(hazelcastInstance);
OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
HazelcastClient hazelcastClient = new HazelcastClient(connector, jobScheduler, NullLogProvider.getInstance(), config(), myself);
hazelcastClient.start();
jobScheduler.runJob();
// when
hazelcastClient.stop();
// then no NPE has been thrown
}
use of org.neo4j.test.OnDemandJobScheduler in project neo4j by neo4j.
the class SegmentedRaftLogVerificationIT method createRaftLog.
@Override
protected RaftLog createRaftLog() throws Throwable {
FileSystemAbstraction fsa = fsRule.get();
File directory = new File(RAFT_LOG_DIRECTORY_NAME);
fsa.mkdir(directory);
long rotateAtSizeBytes = 128;
int readerPoolSize = 8;
LogProvider logProvider = getInstance();
CoreLogPruningStrategy pruningStrategy = new CoreLogPruningStrategyFactory(raft_log_pruning_strategy.getDefaultValue(), logProvider).newInstance();
SegmentedRaftLog newRaftLog = new SegmentedRaftLog(fsa, directory, rotateAtSizeBytes, new DummyRaftableContentSerializer(), logProvider, readerPoolSize, Clocks.systemClock(), new OnDemandJobScheduler(), pruningStrategy);
newRaftLog.init();
newRaftLog.start();
return newRaftLog;
}
use of org.neo4j.test.OnDemandJobScheduler in project neo4j by neo4j.
the class MembershipWaiterTest method shouldWaitUntilLeaderCommitIsAvailable.
@Test
public void shouldWaitUntilLeaderCommitIsAvailable() throws Exception {
OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
MembershipWaiter waiter = new MembershipWaiter(member(0), jobScheduler, () -> dbHealth, 500, NullLogProvider.getInstance());
InMemoryRaftLog raftLog = new InMemoryRaftLog();
raftLog.append(new RaftLogEntry(0, valueOf(0)));
ExposedRaftState raftState = RaftStateBuilder.raftState().votingMembers(member(0)).leaderCommit(0).entryLog(raftLog).commitIndex(0L).build().copy();
RaftMachine raft = mock(RaftMachine.class);
when(raft.state()).thenReturn(raftState);
CompletableFuture<Boolean> future = waiter.waitUntilCaughtUpMember(raft);
jobScheduler.runJob();
future.get(1, TimeUnit.SECONDS);
}
use of org.neo4j.test.OnDemandJobScheduler in project neo4j by neo4j.
the class SegmentedRaftLogContractTest method createRaftLog.
@Override
public RaftLog createRaftLog() {
File directory = new File(RAFT_LOG_DIRECTORY_NAME);
FileSystemAbstraction fileSystem = fsRule.get();
fileSystem.mkdir(directory);
LogProvider logProvider = getInstance();
CoreLogPruningStrategy pruningStrategy = new CoreLogPruningStrategyFactory("1 entries", logProvider).newInstance();
return life.add(new SegmentedRaftLog(fileSystem, directory, 1024, new DummyRaftableContentSerializer(), logProvider, 8, Clocks.fakeClock(), new OnDemandJobScheduler(), pruningStrategy));
}
Aggregations