use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class MasterInfoServiceTest method shouldReportMasterAsGenerallyAvailableForTransactionProcessing.
@Test
public void shouldReportMasterAsGenerallyAvailableForTransactionProcessing() throws Exception {
// given
HighlyAvailableGraphDatabase database = mock(HighlyAvailableGraphDatabase.class);
when(database.role()).thenReturn("master");
MasterInfoService service = new MasterInfoService(null, database);
// when
Response response = service.isAvailable();
// then
assertEquals(200, response.getStatus());
assertEquals("master", String.valueOf(response.getEntity()));
}
use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class MasterInfoServiceTest method shouldReportSlaveAsGenerallyAvailableForTransactionProcessing.
@Test
public void shouldReportSlaveAsGenerallyAvailableForTransactionProcessing() throws Exception {
// given
HighlyAvailableGraphDatabase database = mock(HighlyAvailableGraphDatabase.class);
when(database.role()).thenReturn("slave");
MasterInfoService service = new MasterInfoService(null, database);
// when
Response response = service.isAvailable();
// then
assertEquals(200, response.getStatus());
assertEquals("slave", String.valueOf(response.getEntity()));
}
use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class MasterInfoServiceTest method masterShouldRespond200AndTrueWhenMaster.
@Test
public void masterShouldRespond200AndTrueWhenMaster() throws Exception {
// given
HighlyAvailableGraphDatabase database = mock(HighlyAvailableGraphDatabase.class);
when(database.role()).thenReturn("master");
MasterInfoService service = new MasterInfoService(null, database);
// when
Response response = service.isMaster();
// then
assertEquals(200, response.getStatus());
assertEquals("true", String.valueOf(response.getEntity()));
}
use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class IndexOperationsIT method put_if_absent_works_across_instances.
@Test
public void put_if_absent_works_across_instances() throws Exception {
// GIVEN
// -- two instances, each begin a transaction
String key = "key2", value = "value2";
HighlyAvailableGraphDatabase db1 = cluster.getMaster(), db2 = cluster.getAnySlave();
long node = createNode(db1, key, value, false);
cluster.sync();
OtherThreadExecutor<HighlyAvailableGraphDatabase> w1 = new OtherThreadExecutor<>("w1", db1);
OtherThreadExecutor<HighlyAvailableGraphDatabase> w2 = new OtherThreadExecutor<>("w2", db2);
Transaction tx1 = w1.execute(new BeginTx());
Transaction tx2 = w2.execute(new BeginTx());
// WHEN
// -- second instance does putIfAbsent --> null
assertNull(w2.execute(new PutIfAbsent(node, key, value)));
// -- get a future to first instance putIfAbsent. Wait for it to go and await the lock
Future<Node> w1Future = w1.executeDontWait(new PutIfAbsent(node, key, value));
w1.waitUntilWaiting();
// -- second instance completes tx
w2.execute(new FinishTx(tx2, true));
tx2.success();
tx2.close();
// THEN
// -- first instance can complete the future with a non-null result
assertNotNull(w1Future.get());
w1.execute(new FinishTx(tx1, true));
// -- assert the index has got one entry and both instances have the same data
assertNodeAndIndexingExists(db1, node, key, value);
assertNodeAndIndexingExists(db2, node, key, value);
cluster.sync();
assertNodeAndIndexingExists(cluster.getAnySlave(db1, db2), node, key, value);
w2.close();
w1.close();
}
use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.
the class HaKernelDataTest method shouldReturnHaGraphDbFromKernelData.
@Test
public void shouldReturnHaGraphDbFromKernelData() throws Exception {
// given
HighlyAvailableGraphDatabase haGraphDb = ha.getResource();
KernelData kernelData = haGraphDb.getDependencyResolver().resolveDependency(KernelData.class);
// then
assertSame(kernelData.graphDatabase(), haGraphDb);
}
Aggregations