Search in sources :

Example 26 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.

the class UdcExtensionImplTest method shouldRecordSuccessesWhenThereIsAServer.

@Test
public void shouldRecordSuccessesWhenThereIsAServer() throws Exception {
    // first, set up the test server
    LocalTestServer server = new LocalTestServer(null, null);
    PingerHandler handler = new PingerHandler();
    server.register("/*", handler);
    server.start();
    final String hostname = server.getServiceHostName();
    final String serverAddress = hostname + ":" + server.getServicePort();
    Map<String, String> config = new HashMap<String, String>();
    config.put(UdcExtensionImpl.FIRST_DELAY_CONFIG_KEY, "100");
    config.put(UdcExtensionImpl.UDC_HOST_ADDRESS_KEY, serverAddress);
    EmbeddedGraphDatabase graphdb = createTempDatabase(config);
    assertGotSuccessWithRetry(IS_GREATER_THAN_ZERO);
    assertGotFailureWithRetry(IS_ZERO);
    destroy(graphdb);
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) HashMap(java.util.HashMap) LocalTestServer(org.apache.http.localserver.LocalTestServer) Test(org.junit.Test)

Example 27 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.

the class MultiJvmTest method shutdownDbsAndVerify.

@After
public void shutdownDbsAndVerify() throws Exception {
    shutdownDbs();
    GraphDatabaseService masterDb = new EmbeddedGraphDatabase(dbPath(0).getAbsolutePath());
    try {
        for (int i = 1; i < jvms.size(); i++) {
            GraphDatabaseService slaveDb = new EmbeddedGraphDatabase(dbPath(i).getAbsolutePath());
            try {
                verify(masterDb, slaveDb);
            } finally {
                slaveDb.shutdown();
            }
        }
    } finally {
        masterDb.shutdown();
    }
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) After(org.junit.After)

Example 28 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.

the class SingleJvmTest method verifyAndShutdownDbs.

@After
public void verifyAndShutdownDbs() {
    try {
        verify(master.getGraphDb(), haDbs.toArray(new GraphDatabaseService[haDbs.size()]));
    } finally {
        shutdownDbs();
    }
    GraphDatabaseService masterOfflineDb = new EmbeddedGraphDatabase(dbPath(0).getAbsolutePath());
    GraphDatabaseService[] slaveOfflineDbs = new GraphDatabaseService[haDbs.size()];
    for (int i = 1; i <= haDbs.size(); i++) {
        slaveOfflineDbs[i - 1] = new EmbeddedGraphDatabase(dbPath(i).getAbsolutePath());
    }
    try {
        verify(masterOfflineDb, slaveOfflineDbs);
    } finally {
        masterOfflineDb.shutdown();
        for (GraphDatabaseService db : slaveOfflineDbs) {
            db.shutdown();
        }
    }
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) After(org.junit.After)

Example 29 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.

the class TestRecovery method testAsLittleAsPossibleRecoveryScenario.

@Test
public void testAsLittleAsPossibleRecoveryScenario() throws Exception {
    GraphDatabaseService db = newGraphDbService();
    Index<Node> index = db.index().forNodes("my-index");
    db.beginTx();
    Node node = db.createNode();
    index.add(node, "key", "value");
    db.shutdown();
    // This doesn't seem to trigger recovery... it really should
    new EmbeddedGraphDatabase(getDbPath()).shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 30 with EmbeddedGraphDatabase

use of org.neo4j.kernel.EmbeddedGraphDatabase in project graphdb by neo4j-attic.

the class TestRecovery method testHardCoreRecovery.

@Ignore
@Test
public void testHardCoreRecovery() throws Exception {
    String path = "target/hcdb";
    Neo4jTestCase.deleteFileOrDirectory(new File(path));
    Process process = Runtime.getRuntime().exec(new String[] { "java", "-cp", System.getProperty("java.class.path"), Inserter.class.getName(), path });
    // Let it run for a while and then kill it, and wait for it to die
    Thread.sleep(6000);
    process.destroy();
    process.waitFor();
    GraphDatabaseService db = new EmbeddedGraphDatabase(path);
    assertTrue(db.index().existsForNodes("myIndex"));
    Index<Node> index = db.index().forNodes("myIndex");
    for (Node node : db.getAllNodes()) {
        for (String key : node.getPropertyKeys()) {
            String value = (String) node.getProperty(key);
            boolean found = false;
            for (Node indexedNode : index.get(key, value)) {
                if (indexedNode.equals(node)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                throw new IllegalStateException(node + " has property '" + key + "'='" + value + "', but not in index");
            }
        }
    }
    db.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Node(org.neo4j.graphdb.Node) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)84 Test (org.junit.Test)50 File (java.io.File)35 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)32 Node (org.neo4j.graphdb.Node)26 Transaction (org.neo4j.graphdb.Transaction)17 Relationship (org.neo4j.graphdb.Relationship)14 BeforeClass (org.junit.BeforeClass)13 HashMap (java.util.HashMap)7 BatchInserterImpl (org.neo4j.kernel.impl.batchinsert.BatchInserterImpl)6 RandomAccessFile (java.io.RandomAccessFile)5 BatchInserter (org.neo4j.kernel.impl.batchinsert.BatchInserter)5 BatchInserterIndex (org.neo4j.graphdb.index.BatchInserterIndex)4 TransactionManager (javax.transaction.TransactionManager)3 Before (org.junit.Before)3 DynamicRelationshipType (org.neo4j.graphdb.DynamicRelationshipType)3 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)3 BatchInserterIndexProvider (org.neo4j.graphdb.index.BatchInserterIndexProvider)3 IndexManager (org.neo4j.graphdb.index.IndexManager)3 Transaction (javax.transaction.Transaction)2