Package org.neo4j.kernel

Examples of org.neo4j.kernel.EmbeddedGraphDatabase


    private EmbeddedGraphDatabase graphDb;

    public @Before
    void createGraphDb()
    {
        graphDb = new EmbeddedGraphDatabase( getStorePath( "shutdown" ) );
    }
View Full Code Here


    @Test
    public void inabilityToStartFromOldFormatFromNonCleanShutdown() throws Exception
    {
        String storeDir = "target/var/oldlog";
        deleteFileOrDirectory( storeDir );
        GraphDatabaseService db = new EmbeddedGraphDatabase( storeDir );
        Transaction tx = db.beginTx();
        db.createNode();
        tx.success();
        tx.finish();
       
        Pair<Pair<File, File>, Pair<File, File>> copy = copyLogicalLog( storeDir );
        decrementLogFormat( copy.other().other() );
        db.shutdown();
        renameCopiedLogicalLog( storeDir );
       
        try
        {
            db = new EmbeddedGraphDatabase( storeDir );
            fail( "Shouldn't be able to do recovery (and upgrade log format version) on non-clean shutdown" );
        }
        catch ( Exception e )
        {   // Good
            e.printStackTrace();
View Full Code Here

        }
        inserter.shutdown();
        System.out.println( "Switch to embedded" );
       
        // Then create the rest with embedded graph db.
        GraphDatabaseService db = new EmbeddedGraphDatabase( PATH );
        Node firstNode = db.getNodeById( first );
        Transaction tx = db.beginTx();
        for ( ; i < 5000000000L; i++ )
        {
            Node secondNode = db.createNode();
            firstNode.createRelationshipTo( secondNode, TYPE );
            firstNode = secondNode;
            if ( i % 100000 == 0 )
            {
                tx.success();
                tx.finish();
                System.out.println( (i/1000000) + "M" );
                tx = db.beginTx();
            }
        }
       
        // Here we have a huge db. Loop through it and count chain length.
/*        long count = 0;
        Node node = db.getReferenceNode();
        while ( true )
        {
            Relationship relationship = node.getSingleRelationship( TYPE, Direction.OUTGOING );
            if ( relationship == null )
            {
                break;
            }
        }
        System.out.println( count );
        assertTrue( count > 4900000000L );*/
       
        db.shutdown();
    }
View Full Code Here

    }
   
    private DbRepresentation createSomeData()
    {
        DynamicRelationshipType type = withName( "KNOWS" );
        GraphDatabaseService db = new EmbeddedGraphDatabase( PATH );
        Transaction tx = db.beginTx();
        Node prevNode = db.getReferenceNode();
        for ( int i = 0; i < 100; i++ )
        {
            Node node = db.createNode();
            Relationship rel = prevNode.createRelationshipTo( node, type );
            node.setProperty( "someKey" + i%10, i%15 );
            rel.setProperty( "since", System.currentTimeMillis() );
        }
        tx.success();
        tx.finish();
        DbRepresentation result = DbRepresentation.of( db );
        db.shutdown();
        return result;
    }
View Full Code Here

    }

    @Test
    public void testReadOnlyOperationsAndNoTransaction()
    {
        GraphDatabaseService db = new EmbeddedGraphDatabase( PATH );

        Transaction tx = db.beginTx();
        Node node1 = db.createNode();
        Node node2 = db.createNode();
        Relationship rel = node1.createRelationshipTo( node2, withName( "TEST" ) );
        node1.setProperty( "key1", "value1" );
        rel.setProperty( "key1", "value1" );
        tx.success();
        tx.finish();
       
        // make sure write operations still throw exception
        try
        {
            db.createNode();
            fail( "Write operation and no transaction should throw exception" );
        }
        catch ( NotInTransactionException e )
        { // good
        }
        try
        {
            node1.createRelationshipTo( node2, withName( "TEST2" ) );
            fail( "Write operation and no transaction should throw exception" );
        }
        catch ( NotInTransactionException e )
        { // good
        }
        try
        {
            node1.setProperty( "key1", "value2" );
            fail( "Write operation and no transaction should throw exception" );
        }
        catch ( NotInTransactionException e )
        { // good
        }

        try
        {
            rel.removeProperty( "key1" );
            fail( "Write operation and no transaction should throw exception" );
        }
        catch ( NotInTransactionException e )
        { // good
        }
       
        // clear caches and try reads
        ((AbstractGraphDatabase)db).getConfig().getGraphDbModule().
            getNodeManager().clearCache();
       
        assertEquals( node1, db.getNodeById( node1.getId() ) );
        assertEquals( node2, db.getNodeById( node2.getId() ) );
        assertEquals( rel, db.getRelationshipById( rel.getId() ) );
        ((AbstractGraphDatabase)db).getConfig().getGraphDbModule().
            getNodeManager().clearCache();
       
        assertEquals( "value1", node1.getProperty( "key1" ) );
        Relationship loadedRel = node1.getSingleRelationship(
View Full Code Here

        deleteFileOrDirectory( new File( PATH ) );
    }
   
    private GraphDatabaseService newDb( String cacheType )
    {
        return new EmbeddedGraphDatabase( PATH, MapUtil.stringMap( Config.CACHE_TYPE, cacheType ) );
    }
View Full Code Here

    @Test
    public void testMultipleTxSameThread() throws Exception
    {
        String storePath = getStorePath( "test-neo2" );
        deleteFileOrDirectory( storePath );
        EmbeddedGraphDatabase neo2 = new EmbeddedGraphDatabase( storePath );
        TransactionManager tm = neo2.getConfig().getTxModule().getTxManager();
        tm.begin();
        Node refNode = neo2.getReferenceNode();
        Transaction tx1 = tm.suspend();
        tm.begin();
        refNode.setProperty( "test2", "test" );
        Transaction tx2 = tm.suspend();
        tm.resume( tx1 );
        CommitThread thread = new CommitThread( tm, tx2 );
        thread.start();
        // would wait for ever since tx2 has write lock but now we have other
        // thread thread that will commit tx2
        refNode.removeProperty( "test2" );
        assertTrue( thread.success() );
        tm.commit();
        neo2.shutdown();
    }
View Full Code Here

    @BeforeClass
    public static void startDb()
    {
        String storeDir = "target/var/examples";
        Neo4jAlgoTestCase.deleteFileOrDirectory( new File( storeDir ) );
        graphDb = new EmbeddedGraphDatabase( storeDir );
    }
View Full Code Here

   
    @Before
    public void doBefore()
    {
        AbstractNeo4jTestCase.deleteFileOrDirectory( new File( PATH ) );
        db = new EmbeddedGraphDatabase( PATH );
    }
View Full Code Here

   
    private long getSizeOfStringStore()
    {
        db.shutdown();
        long size = new File( PATH, "neostore.propertystore.db.strings" ).length();
        db = new EmbeddedGraphDatabase( PATH );
        return size;
    }
View Full Code Here

TOP

Related Classes of org.neo4j.kernel.EmbeddedGraphDatabase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.