Search in sources :

Example 26 with HighlyAvailableGraphDatabase

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()));
}
Also used : Response(javax.ws.rs.core.Response) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) Test(org.junit.Test)

Example 27 with HighlyAvailableGraphDatabase

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()));
}
Also used : Response(javax.ws.rs.core.Response) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) Test(org.junit.Test)

Example 28 with HighlyAvailableGraphDatabase

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()));
}
Also used : Response(javax.ws.rs.core.Response) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) Test(org.junit.Test)

Example 29 with HighlyAvailableGraphDatabase

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();
}
Also used : OtherThreadExecutor(org.neo4j.test.OtherThreadExecutor) Transaction(org.neo4j.graphdb.Transaction) FinishTx(org.neo4j.ha.FinishTx) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) Node(org.neo4j.graphdb.Node) BeginTx(org.neo4j.ha.BeginTx) Test(org.junit.Test)

Example 30 with HighlyAvailableGraphDatabase

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);
}
Also used : HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) Test(org.junit.Test)

Aggregations

HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)80 Test (org.junit.Test)68 Transaction (org.neo4j.graphdb.Transaction)38 ClusterManager (org.neo4j.kernel.impl.ha.ClusterManager)24 Node (org.neo4j.graphdb.Node)22 ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)16 File (java.io.File)12 InstanceId (org.neo4j.cluster.InstanceId)10 Response (javax.ws.rs.core.Response)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 TransientTransactionFailureException (org.neo4j.graphdb.TransientTransactionFailureException)5 TestHighlyAvailableGraphDatabaseFactory (org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory)5 RepairKit (org.neo4j.kernel.impl.ha.ClusterManager.RepairKit)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 ClusterClient (org.neo4j.cluster.client.ClusterClient)4 TransactionTerminatedException (org.neo4j.graphdb.TransactionTerminatedException)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 IOException (java.io.IOException)3 URI (java.net.URI)3 ExecutionException (java.util.concurrent.ExecutionException)3