Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2002-2014 "Neo Technology," Network Engine for Objects in Lund AB [http://neotechnology.com] This file is part of Neo4j. Neo4j is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 package upgrade;
 
 import java.io.File;
 import java.util.Set;
 
 import org.junit.Test;
 
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 import static org.neo4j.graphdb.Direction.OUTGOING;
 import static org.neo4j.graphdb.DynamicLabel.label;
 import static org.neo4j.graphdb.factory.GraphDatabaseSettings.allow_store_upgrade;
 import static org.neo4j.helpers.collection.IteratorUtil.asSet;
 import static org.neo4j.helpers.collection.IteratorUtil.count;
 import static org.neo4j.helpers.collection.IteratorUtil.single;
 import static org.neo4j.tooling.GlobalGraphOperations.at;
 
 {
     private static final Label referenceNode = label"ReferenceNode" );
 
     private static enum Types implements RelationshipType
     {
         DENSE,
         SPARSE,
         OTHER,
         FOURTH;
     }
 
     private static enum Properties
     {
         BYTE( (byte)10 ),
         SHORT( (short)345 ),
         INT( 123456 ),
         LONG( 12345678901L ),
         CHAR( 'N' ),
         FLOAT( 123.456F ),
         DOUBLE( 123.456789D ),
         SHORT_STRING( "short" ),
         LONG_STRING( "super-duper long string that will have to spill over into a dynamic record !#ยค%&/()=," ),
         INT_ARRAY( new int[] {12345, 67890, 123456789, 1, 2, 3, 4, 5} )
         {
             @Override
             public void assertValueEqualsObject otherValue )
             {
                 assertArrayEquals( (int[]) , (int[]) otherValue );
             }
         },
         STRING_ARRAY( new String[] { "First""Second""Third""Fourth" } )
         {
             @Override
             public void assertValueEqualsObject otherValue )
             {
                 assertArrayEquals( (Object[]) , (Object[]) otherValue );
             }
         };
 
         protected final Object value;
 
         private PropertiesObject value )
         {
             this. = value;
        }
        public Object getValue()
        {
            return ;
        }
        public void assertValueEqualsObject otherValue )
        {
            assertEqualsotherValue );
        }
    }
    private File dir;
    @Before
    public void before() throws Exception
    {
         = AbstractNeo4jTestCase.unzipgetClass(), "0.A.1-db.zip" );
    }
    @Test
    @Ignore"Used for creating the dataset, using the previous store version" )
    public void createDb()
    {
                TargetDirectory.forTestgetClass() ).makeGraphDbDir().getPath() );
        try
        {
            try ( Transaction tx = db.beginTx() )
            {
                Node refNode = db.createNode );
                // Create 10 dense nodes
                for ( int i = 0; i < 10; i++ )
                {
                    createDenseNodedbrefNode );
                }
                // And 10 sparse nodes
                for ( int i = 0; i < 10; i++ )
                {
                    createSparseNodedbrefNode );
                }
                tx.success();
            }
        }
        finally
        {
            db.shutdown();
        }
    }
    private void createSparseNodeGraphDatabaseService dbNode refNode )
    {
        Node node = db.createNode();
        refNode.createRelationshipTonode. );
        createRelationshipsdbnode, 3, . );
        setPropertiesnode );
    }
    private void createDenseNodeGraphDatabaseService dbNode refNode )
    {
        Node node = db.createNode();
        refNode.createRelationshipTonode. );
        createRelationshipsdbnode, 100, . );
        createRelationshipsdbnode, 2, . );
        setPropertiesnode );
    }
    private void createRelationshipsGraphDatabaseService dbNode nodeint countRelationshipType type )
    {
        for ( int i = 0; i < counti++ )
        {
            node.createRelationshipTodb.createNode(), type );
        }
    }
    private void setPropertiesNode node )
    {
        for ( Properties properties : Properties.values() )
        {
            node.setPropertyproperties.name(), properties.getValue() );
        }
    }
    @Test
    public void migrateDbWithDenseNodes() throws Exception
    {
                .setConfig"true" ).newGraphDatabase();
        try ( Transaction tx = db.beginTx() )
        {
            Node refNode = singleatdb ).getAllNodesWithLabel ) );
            int sparseCount = 0;
            for ( Relationship relationship : refNode.getRelationships. ) )
            {
                verifySparseNodedbrelationship.getEndNode() );
                sparseCount++;
            }
            int denseCount = 0;
            for ( Relationship relationship : refNode.getRelationships. ) )
            {
                verifyDenseNodedbrelationship.getEndNode() );
                denseCount++;
            }
            assertEquals( 10, sparseCount );
            assertEquals( 10, denseCount );
            tx.success();
        }
        db.shutdown();
    }
    private void verifyDenseNodeGraphDatabaseService dbNode node )
    {
        assertEquals( 102, countnode.getRelationships ) ) );
        assertEquals( 100, countnode.getRelationships. ) ) );
        assertEquals( 2, countnode.getRelationships. ) ) );
        verifyPropertiesnode );
        verifyDenseRepresentationdbnodetrue );
    }
    private void verifySparseNodeGraphDatabaseService dbNode node )
    {
        assertEquals( 3, countnode.getRelationships ) ) );
        verifyPropertiesnode );
        verifyDenseRepresentationdbnodefalse );
    }
    private void verifyPropertiesNode node )
    {
        Set<Stringkeys = asSetnode.getPropertyKeys() );
        for ( Properties property : Properties.values() )
        {
            assertTruekeys.removeproperty.name() ) );
            property.assertValueEqualsnode.getPropertyproperty.name() ) );
        }
        assertTruekeys.isEmpty() );
    }
    private void verifyDenseRepresentationGraphDatabaseService dbNode nodeboolean dense )
    {
        NeoStore neoStore = ((GraphDatabaseAPIdb).getDependencyResolver().resolveDependency(
                NeoStoreProvider.class ).evaluate();
        NodeRecord record = neoStore.getNodeStore().getRecordnode.getId() );
        assertEqualsdenserecord.isDense() );
    }
New to GrepCode? Check out our FAQ X