use of org.neo4j.kernel.impl.util.Neo4jJobScheduler in project neo4j by neo4j.
the class TestMasterCommittingAtSlave method newPropagator.
private TransactionPropagator newPropagator(int slaveCount, int replication, SlavePriority slavePriority, boolean... failingSlaves) throws Exception {
slaves = instantiateSlaves(slaveCount, failingSlaves);
Config config = Config.embeddedDefaults(MapUtil.stringMap(HaSettings.tx_push_factor.name(), "" + replication, ClusterSettings.server_id.name(), "" + MasterServerId));
Neo4jJobScheduler scheduler = cleanup.add(new Neo4jJobScheduler());
TransactionPropagator result = new TransactionPropagator(TransactionPropagator.from(config, slavePriority), NullLog.getInstance(), new Slaves() {
@Override
public Iterable<Slave> getSlaves() {
return slaves;
}
}, new CommitPusher(scheduler));
// Life
try {
scheduler.init();
scheduler.start();
result.init();
result.start();
} catch (Throwable e) {
throw Exceptions.launderedException(e);
}
return result;
}
use of org.neo4j.kernel.impl.util.Neo4jJobScheduler in project neo4j by neo4j.
the class ConnectionInfoIT method hzTest.
@Test
public void hzTest() throws Throwable {
// given
testSocket = bindPort("0.0.0.0", 4243);
//when
AssertableLogProvider logProvider = new AssertableLogProvider();
AssertableLogProvider userLogProvider = new AssertableLogProvider();
HazelcastDiscoveryServiceFactory hzFactory = new HazelcastDiscoveryServiceFactory();
Config config = embeddedDefaults(stringMap(discovery_listen_address.name(), ":" + testSocket.getLocalPort(), CausalClusteringSettings.initial_discovery_members.name(), "localhost:" + testSocket.getLocalPort(), new BoltConnector("bolt").enabled.name(), "true", new HttpConnector("http").enabled.name(), "true"));
Neo4jJobScheduler jobScheduler = new Neo4jJobScheduler();
jobScheduler.init();
CoreTopologyService coreTopologyService = hzFactory.coreTopologyService(config, new MemberId(UUID.randomUUID()), jobScheduler, logProvider, userLogProvider);
try {
coreTopologyService.init();
coreTopologyService.start();
}//then
catch (Throwable throwable) {
//expected
}
logProvider.assertContainsMessageContaining("Hazelcast was unable to start with setting");
userLogProvider.assertContainsMessageContaining("Hazelcast was unable to start with setting");
}
use of org.neo4j.kernel.impl.util.Neo4jJobScheduler in project neo4j by neo4j.
the class IndexSamplingJobTrackerTest method shouldWaitForAllJobsToFinish.
@Test(timeout = 5_000)
public void shouldWaitForAllJobsToFinish() throws Throwable {
// Given
when(config.jobLimit()).thenReturn(2);
JobScheduler jobScheduler = new Neo4jJobScheduler();
jobScheduler.init();
final IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(config, jobScheduler);
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
WaitingIndexSamplingJob job1 = new WaitingIndexSamplingJob(indexId11, latch1);
WaitingIndexSamplingJob job2 = new WaitingIndexSamplingJob(indexId22, latch1);
jobTracker.scheduleSamplingJob(job1);
jobTracker.scheduleSamplingJob(job2);
Future<?> stopping = Executors.newSingleThreadExecutor().submit(() -> {
latch2.countDown();
try {
jobTracker.awaitAllJobs(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
// When
latch2.await();
assertFalse(stopping.isDone());
latch1.countDown();
stopping.get(10, SECONDS);
// Then
assertTrue(stopping.isDone());
assertNull(stopping.get());
assertTrue(job1.executed);
assertTrue(job2.executed);
}
use of org.neo4j.kernel.impl.util.Neo4jJobScheduler in project neo4j by neo4j.
the class IndexSamplingJobTrackerTest method shouldNotAcceptMoreJobsThanAllowed.
@Test
public void shouldNotAcceptMoreJobsThanAllowed() throws Throwable {
// given
when(config.jobLimit()).thenReturn(1);
JobScheduler jobScheduler = new Neo4jJobScheduler();
jobScheduler.init();
final IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(config, jobScheduler);
final DoubleLatch latch = new DoubleLatch();
final DoubleLatch waitingLatch = new DoubleLatch();
// when
assertTrue(jobTracker.canExecuteMoreSamplingJobs());
jobTracker.scheduleSamplingJob(new IndexSamplingJob() {
@Override
public void run() {
latch.startAndWaitForAllToStart();
latch.waitForAllToFinish();
}
@Override
public long indexId() {
return indexId12;
}
});
// then
latch.waitForAllToStart();
assertFalse(jobTracker.canExecuteMoreSamplingJobs());
final AtomicBoolean waiting = new AtomicBoolean(false);
new Thread(() -> {
waiting.set(true);
waitingLatch.startAndWaitForAllToStart();
jobTracker.waitUntilCanExecuteMoreSamplingJobs();
waiting.set(false);
waitingLatch.finish();
}).start();
waitingLatch.waitForAllToStart();
assertTrue(waiting.get());
latch.finish();
waitingLatch.waitForAllToFinish();
assertFalse(waiting.get());
// eventually we accept new jobs
while (!jobTracker.canExecuteMoreSamplingJobs()) {
Thread.yield();
}
}
use of org.neo4j.kernel.impl.util.Neo4jJobScheduler in project neo4j by neo4j.
the class NonUniqueIndexTests method newEmbeddedGraphDatabaseWithSlowJobScheduler.
private GraphDatabaseService newEmbeddedGraphDatabaseWithSlowJobScheduler() {
GraphDatabaseFactoryState graphDatabaseFactoryState = new GraphDatabaseFactoryState();
graphDatabaseFactoryState.setUserLogProvider(NullLogService.getInstance().getUserLogProvider());
return new GraphDatabaseFacadeFactory(DatabaseInfo.COMMUNITY, CommunityEditionModule::new) {
@Override
protected PlatformModule createPlatform(File storeDir, Config config, Dependencies dependencies, GraphDatabaseFacade graphDatabaseFacade) {
return new PlatformModule(storeDir, config, databaseInfo, dependencies, graphDatabaseFacade) {
@Override
protected Neo4jJobScheduler createJobScheduler() {
return newSlowJobScheduler();
}
@Override
protected LogService createLogService(LogProvider userLogProvider) {
return NullLogService.getInstance();
}
};
}
}.newFacade(directory.graphDbDir(), Config.embeddedDefaults(), graphDatabaseFactoryState.databaseDependencies());
}
Aggregations