Search in sources :

Example 1 with TestHighlyAvailableGraphDatabaseFactory

use of org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory in project neo4j by neo4j.

the class StartInstanceInAnotherJvm method main.

public static void main(String[] args) {
    File dir = new File(args[0]);
    GraphDatabaseAPI newSlave = (GraphDatabaseAPI) new TestHighlyAvailableGraphDatabaseFactory().newEmbeddedDatabaseBuilder(dir).setConfig(Args.parse(args).asMap()).newGraphDatabase();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TestHighlyAvailableGraphDatabaseFactory(org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory) File(java.io.File)

Example 2 with TestHighlyAvailableGraphDatabaseFactory

use of org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory in project neo4j by neo4j.

the class LabelScanStoreHaIT method setUp.

@Before
public void setUp() {
    KernelExtensionFactory<?> testExtension = labelScanStoreExtension(monitor);
    TestHighlyAvailableGraphDatabaseFactory factory = new TestHighlyAvailableGraphDatabaseFactory();
    factory.removeKernelExtensions(extension -> extension.getClass().getName().contains("LabelScan"));
    factory.addKernelExtension(testExtension);
    ClusterManager clusterManager = new ClusterManager.Builder(testDirectory.directory("root")).withDbFactory(factory).withSharedSetting(GraphDatabaseSettings.label_index, labelIndexSettingName()).withStoreDirInitializer((serverId, storeDir) -> {
        if (serverId == 1) {
            GraphDatabaseService db = new TestGraphDatabaseFactory().addKernelExtension(testExtension).newEmbeddedDatabaseBuilder(storeDir.getAbsoluteFile()).setConfig(GraphDatabaseSettings.label_index, labelIndexSettingName()).newGraphDatabase();
            try {
                createSomeLabeledNodes(db, new Label[] { Labels.First }, new Label[] { Labels.First, Labels.Second }, new Label[] { Labels.Second });
            } finally {
                db.shutdown();
            }
        }
    }).build();
    life.add(clusterManager);
    life.start();
    cluster = clusterManager.getCluster();
    cluster.await(allSeesAllAsAvailable());
    cluster.await(allAvailabilityGuardsReleased());
}
Also used : Label(org.neo4j.graphdb.Label) TestDirectory(org.neo4j.test.rule.TestDirectory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Iterators.count(org.neo4j.helpers.collection.Iterators.count) TestHighlyAvailableGraphDatabaseFactory(org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory) Rule(org.junit.Rule) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) ClusterManager.allSeesAllAsAvailable(org.neo4j.kernel.impl.ha.ClusterManager.allSeesAllAsAvailable) After(org.junit.After) KernelExtensionFactory(org.neo4j.kernel.extension.KernelExtensionFactory) ClusterManager.allAvailabilityGuardsReleased(org.neo4j.kernel.impl.ha.ClusterManager.allAvailabilityGuardsReleased) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) Transaction(org.neo4j.graphdb.Transaction) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestHighlyAvailableGraphDatabaseFactory(org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Label(org.neo4j.graphdb.Label) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Before(org.junit.Before)

Example 3 with TestHighlyAvailableGraphDatabaseFactory

use of org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory in project neo4j by neo4j.

the class SlaveUpgradeTest method haShouldFailToStartWithOldStore.

@Test
public void haShouldFailToStartWithOldStore() throws Exception {
    try {
        File dir = testDirectory.directory("haShouldFailToStartWithOldStore");
        MigrationTestUtils.find20FormatStoreDirectory(dir);
        new TestHighlyAvailableGraphDatabaseFactory().newEmbeddedDatabaseBuilder(dir).setConfig(ClusterSettings.server_id, "1").setConfig(ClusterSettings.initial_hosts, "localhost:9999").newGraphDatabase();
        fail("Should exit abnormally");
    } catch (Exception e) {
        Throwable rootCause = Exceptions.rootCause(e);
        assertThat(rootCause, instanceOf(UpgradeNotAllowedByConfigurationException.class));
    }
}
Also used : TestHighlyAvailableGraphDatabaseFactory(org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory) File(java.io.File) UpgradeNotAllowedByConfigurationException(org.neo4j.kernel.impl.storemigration.UpgradeNotAllowedByConfigurationException) Test(org.junit.Test)

Example 4 with TestHighlyAvailableGraphDatabaseFactory

use of org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory in project neo4j by neo4j.

the class ConflictingServerIdIT method testConflictingIdDoesNotSilentlyFail.

@Test
public void testConflictingIdDoesNotSilentlyFail() throws Exception {
    HighlyAvailableGraphDatabase master = null, dbWithId21 = null, dbWithId22 = null;
    try {
        GraphDatabaseBuilder masterBuilder = new TestHighlyAvailableGraphDatabaseFactory().newEmbeddedDatabaseBuilder(path(1)).setConfig(ClusterSettings.initial_hosts, "127.0.0.1:5002").setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + (5001 + 1)).setConfig(ClusterSettings.server_id, "" + 1).setConfig(HaSettings.ha_server, ":" + (8001 + 1)).setConfig(HaSettings.tx_push_factor, "0");
        master = (HighlyAvailableGraphDatabase) masterBuilder.newGraphDatabase();
        GraphDatabaseBuilder db21Builder = new TestHighlyAvailableGraphDatabaseFactory().newEmbeddedDatabaseBuilder(path(2)).setConfig(ClusterSettings.initial_hosts, "127.0.0.1:5002,127.0.0.1:5003").setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + (5001 + 2)).setConfig(ClusterSettings.server_id, "" + 2).setConfig(HaSettings.ha_server, ":" + (8001 + 2)).setConfig(HaSettings.tx_push_factor, "0");
        dbWithId21 = (HighlyAvailableGraphDatabase) db21Builder.newGraphDatabase();
        GraphDatabaseBuilder db22Builder = new TestHighlyAvailableGraphDatabaseFactory().newEmbeddedDatabaseBuilder(path(3)).setConfig(ClusterSettings.initial_hosts, "127.0.0.1:5002").setConfig(ClusterSettings.cluster_server, "127.0.0.1:" + (5001 + 3)).setConfig(ClusterSettings.server_id, // Conflicting with the above
        "" + 2).setConfig(HaSettings.ha_server, ":" + (8001 + 3)).setConfig(HaSettings.tx_push_factor, "0");
        try {
            dbWithId22 = (HighlyAvailableGraphDatabase) db22Builder.newGraphDatabase();
            fail("Should not be able to startup when a cluster already has my id");
        } catch (Exception e) {
        // awesome
        }
        assertTrue(master.isMaster());
        assertTrue(!dbWithId21.isMaster());
        try (Transaction transaction = dbWithId21.beginTx()) {
            transaction.success();
        }
    } finally {
        if (dbWithId21 != null) {
            dbWithId21.shutdown();
        }
        if (dbWithId22 != null) {
            dbWithId22.shutdown();
        }
        if (master != null) {
            master.shutdown();
        }
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) TestHighlyAvailableGraphDatabaseFactory(org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) Test(org.junit.Test)

Example 5 with TestHighlyAvailableGraphDatabaseFactory

use of org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory in project neo4j by neo4j.

the class RollingUpgradeIT method rollOver.

private void rollOver(LegacyDatabase legacyDb, int i, int masterServerId, int authorativeSlaveId) throws Exception {
    String storeDir = legacyDb.getStoreDir();
    if (i == 0) {
        storeDir += "new";
    }
    stop(i);
    File storeDirFile = new File(storeDir);
    debug("Starting " + i + " as current version");
    switch(authorativeSlaveId) {
        case -1:
            break;
        case -2:
            debug("At last master starting, deleting store so that it fetches from the new master");
            FileUtils.deleteRecursively(storeDirFile);
            break;
        default:
            debug("Consecutive slave starting, making it so that I will copy store from " + authorativeSlaveId);
            FileUtils.deleteRecursively(storeDirFile);
            storeDirFile.mkdirs();
            backup(authorativeSlaveId, storeDirFile);
            break;
    }
    startStandaloneDbToRunUpgrade(storeDirFile, i);
    // start that db up in this JVM
    newDbs[i] = (GraphDatabaseAPI) new TestHighlyAvailableGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDirFile).setConfig(config(i)).newGraphDatabase();
    debug("Started " + i + " as current version");
    legacyDbs[i] = null;
    // issue transaction and see that it propagates
    if (i != masterServerId) {
        // if the instance is not the old master, create on the old master
        legacyDbs[masterServerId].doComplexLoad(centralNode);
        debug("Node created on " + i);
    } else {
        doComplexLoad(newDbs[1], centralNode);
    }
    for (int j = 0; j < legacyDbs.length; j++) {
        if (legacyDbs[j] != null) {
            legacyDbs[j].verifyComplexLoad(centralNode);
            debug("Verified on legacy db " + j);
        }
    }
    for (int j = 0; j < newDbs.length; j++) {
        if (newDbs[j] != null) {
            assertTrue("Rolled over database " + j + " not available within 1 minute", newDbs[i].isAvailable(MINUTES.toMillis(1)));
            verifyComplexLoad(newDbs[j], centralNode);
            debug("Verified on new db " + j);
        }
    }
}
Also used : TestHighlyAvailableGraphDatabaseFactory(org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory) File(java.io.File)

Aggregations

TestHighlyAvailableGraphDatabaseFactory (org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory)13 File (java.io.File)10 Test (org.junit.Test)9 HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)4 Transaction (org.neo4j.graphdb.Transaction)3 IOException (java.io.IOException)2 TransactionTerminatedException (org.neo4j.graphdb.TransactionTerminatedException)2 TransientTransactionFailureException (org.neo4j.graphdb.TransientTransactionFailureException)2 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)2 URI (java.net.URI)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 After (org.junit.After)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1 InstanceId (org.neo4j.cluster.InstanceId)1 ClusterClient (org.neo4j.cluster.client.ClusterClient)1 ClusterListener (org.neo4j.cluster.protocol.cluster.ClusterListener)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1