Search in sources :

Example 56 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class MasterInfoServiceTest method masterShouldRespond404AndFalseWhenSlave.

@Test
public void masterShouldRespond404AndFalseWhenSlave() throws Exception {
    // given
    HighlyAvailableGraphDatabase database = mock(HighlyAvailableGraphDatabase.class);
    when(database.role()).thenReturn("slave");
    MasterInfoService service = new MasterInfoService(null, database);
    // when
    Response response = service.isMaster();
    // then
    assertEquals(404, response.getStatus());
    assertEquals("false", String.valueOf(response.getEntity()));
}
Also used : Response(javax.ws.rs.core.Response) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) Test(org.junit.Test)

Example 57 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class MasterInfoServiceTest method shouldReportNonMasterOrSlaveAsUnavailableForTransactionProcessing.

@Test
public void shouldReportNonMasterOrSlaveAsUnavailableForTransactionProcessing() throws Exception {
    // given
    HighlyAvailableGraphDatabase database = mock(HighlyAvailableGraphDatabase.class);
    when(database.role()).thenReturn("unknown");
    MasterInfoService service = new MasterInfoService(null, database);
    // when
    Response response = service.isAvailable();
    // then
    assertEquals(404, response.getStatus());
    assertEquals("UNKNOWN", String.valueOf(response.getEntity()));
}
Also used : Response(javax.ws.rs.core.Response) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) Test(org.junit.Test)

Example 58 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class MasterInfoServiceTest method slaveShouldRespond404AndFalseWhenMaster.

@Test
public void slaveShouldRespond404AndFalseWhenMaster() throws Exception {
    // given
    HighlyAvailableGraphDatabase database = mock(HighlyAvailableGraphDatabase.class);
    when(database.role()).thenReturn("master");
    MasterInfoService service = new MasterInfoService(null, database);
    // when
    Response response = service.isSlave();
    // then
    assertEquals(404, response.getStatus());
    assertEquals("false", String.valueOf(response.getEntity()));
}
Also used : Response(javax.ws.rs.core.Response) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) Test(org.junit.Test)

Example 59 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class MasterInfoServiceTest method slaveShouldRespond200AndTrueWhenSlave.

@Test
public void slaveShouldRespond200AndTrueWhenSlave() throws Exception {
    // given
    HighlyAvailableGraphDatabase database = mock(HighlyAvailableGraphDatabase.class);
    when(database.role()).thenReturn("slave");
    MasterInfoService service = new MasterInfoService(null, database);
    // when
    Response response = service.isSlave();
    // 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 60 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class TestPullUpdates method pullUpdatesShellAppPullsUpdates.

@Test
public void pullUpdatesShellAppPullsUpdates() throws Throwable {
    ClusterManager.ManagedCluster cluster = clusterRule.withCluster(clusterOfSize(2)).withSharedSetting(HaSettings.pull_interval, "0").withSharedSetting(HaSettings.tx_push_factor, "0").withSharedSetting(ShellSettings.remote_shell_enabled, Settings.TRUE).withInstanceSetting(ShellSettings.remote_shell_port, oneBasedServerId -> oneBasedServerId >= 1 && oneBasedServerId <= 2 ? "" + (SHELL_PORT + oneBasedServerId) : null).startCluster();
    long commonNodeId = createNodeOnMaster(cluster);
    setProperty(cluster.getMaster(), commonNodeId, 1);
    callPullUpdatesViaShell(2);
    HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
    try (Transaction tx = slave.beginTx()) {
        assertEquals(1, slave.getNodeById(commonNodeId).getProperty("i"));
        tx.success();
    }
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) System.currentTimeMillis(java.lang.System.currentTimeMillis) Settings(org.neo4j.kernel.configuration.Settings) ShellLobby(org.neo4j.shell.ShellLobby) ClusterRule(org.neo4j.test.ha.ClusterRule) NotFoundException(org.neo4j.graphdb.NotFoundException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Node(org.neo4j.graphdb.Node) Assert.assertThat(org.junit.Assert.assertThat) ClusterManager.clusterOfSize(org.neo4j.kernel.impl.ha.ClusterManager.clusterOfSize) Future(java.util.concurrent.Future) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) Transaction(org.neo4j.graphdb.Transaction) ShellSettings(org.neo4j.shell.ShellSettings) Assert.assertNotNull(org.junit.Assert.assertNotNull) ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) LogService(org.neo4j.kernel.impl.logging.LogService) HaSettings(org.neo4j.kernel.ha.HaSettings) File(java.io.File) Executors(java.util.concurrent.Executors) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ClusterManager.masterAvailable(org.neo4j.kernel.impl.ha.ClusterManager.masterAvailable) CountDownLatch(java.util.concurrent.CountDownLatch) TestHighlyAvailableGraphDatabaseFactory(org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory) Rule(org.junit.Rule) ShellException(org.neo4j.shell.ShellException) ClusterManager.allSeesAllAsAvailable(org.neo4j.kernel.impl.ha.ClusterManager.allSeesAllAsAvailable) ShellClient(org.neo4j.shell.ShellClient) ClusterSettings(org.neo4j.cluster.ClusterSettings) ClusterManager.masterSeesSlavesAsAvailable(org.neo4j.kernel.impl.ha.ClusterManager.masterSeesSlavesAsAvailable) ClusterClient(org.neo4j.cluster.client.ClusterClient) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Assert.assertEquals(org.junit.Assert.assertEquals) Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) 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