    @Override
    public boolean run()
    {
        try
        {
            File storeDir = config.get( ServerInternalSettings.legacy_db_location );

            FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
            try ( PageCache pageCache = StandalonePageCacheFactory.createPageCache( fileSystem, config ) )
            {
                StoreVersionCheck storeVersionCheck = new StoreVersionCheck(
                        pageCache );
                if ( new CurrentDatabase( storeVersionCheck ).storeFilesAtCurrentVersion( storeDir ) )
                {
                    return true;
                }

                UpgradableDatabase upgradableDatabase = new UpgradableDatabase( storeVersionCheck );
                if ( !upgradableDatabase.storeFilesUpgradeable( storeDir ) )
                {
                    return true;
                }

                try
                {
                    new StoreMigrationTool().run( fileSystem, storeDir,
                            new Config( dbConfig ), logProvider, monitor );
                }
                catch ( UpgradeNotAllowedByConfigurationException e )
                {
                    log.error( e.getMessage() );
                    failureMessage = e.getMessage();
                    return false;
                }
                catch ( StoreUpgrader.UnableToUpgradeException e )
                {
                    log.error( "Unable to upgrade store", e );
                    return false;
                }
            }
            return true;
        }
        catch ( Exception e )
        {
            log.error( "Unknown error", e );
            return false;
        }
    }

    @Override
    public boolean run()
    {
        try
        {
            File storeDir = config.get( ServerInternalSettings.legacy_db_location );

            if ( new CurrentDatabase(new StoreVersionCheck( new DefaultFileSystemAbstraction() ) ).storeFilesAtCurrentVersion( storeDir ) )
            {
                return true;
            }

            FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
            UpgradableDatabase upgradableDatabase = new UpgradableDatabase( new StoreVersionCheck( fileSystem ) );
            if ( !upgradableDatabase.storeFilesUpgradeable( storeDir ) )
            {
                return true;
            }

            try
            {
                new StoreMigrationTool().run( fileSystem, storeDir,
                        new Config( dbConfig ), logProvider, monitor );
            }
            catch ( UpgradeNotAllowedByConfigurationException e )
            {
                log.error( e.getMessage() );
                failureMessage = e.getMessage();
                return false;
            }
            catch ( StoreUpgrader.UnableToUpgradeException e )
            {
                log.error( "Unable to upgrade store", e );
                return false;
            }
            return true;
        }
        catch ( Exception e )
        {
            log.error( "Unknown error", e );
            return false;
        }
    }

Try With Resources try(PageCache pageCache=StandalonePageCacheFactory.createPageCache(fileSystem,config)) in method public run() : boolean from class org.neo4j.server.preflight.PerformUpgradeIfNecessary


    @Override
    public Iterator<PropertyContainer> iterator()
    {
        // TODO Don't loop through them all up front
        LinkedList<PropertyContainer> entities = new LinkedList<>();
        TraversalBranch branch = start;
        while ( branch.length() > 0 )
        {
            entities.addFirst( branch.endNode() );
            entities.addFirst( branch.lastRelationship() );
            branch = branch.parent();
        }
        entities.addFirst( branch.endNode() );
        if ( cachedStartNode == null )
            cachedStartNode = branch.endNode();
        if ( end.length() > 0 )
        {
            entities.add( end.lastRelationship() );
            branch = end.parent();
            while ( branch.length() > 0 )
            {
                entities.add( branch.endNode() );
                entities.add( branch.lastRelationship() );
                branch = branch.parent();
            }
            entities.add( branch.endNode() );
        }
        return entities.iterator();
    }

    @Override
    public Iterator<PropertyContainer> iterator()
    {
        // TODO Don't loop through them all up front
        LinkedList<PropertyContainer> entities = new LinkedList<PropertyContainer>();
        TraversalBranch branch = start;
        while ( branch.length() > 0 )
        {
            entities.addFirst( branch.endNode() );
            entities.addFirst( branch.lastRelationship() );
            branch = branch.parent();
        }
        entities.addFirst( branch.endNode() );
        if ( cachedStartNode == null )
            cachedStartNode = branch.endNode();
        if ( end.length() > 0 )
        {
            entities.add( end.lastRelationship() );
            branch = end.parent();
            while ( branch.length() > 0 )
            {
                entities.add( branch.endNode() );
                entities.add( branch.lastRelationship() );
                branch = branch.parent();
            }
            entities.add( branch.endNode() );
        }
        return entities.iterator();
    }

Replace Generic With Diamond LinkedList<PropertyContainer> with LinkedList<> in method public iterator() : Iterator<PropertyContainer> from class org.neo4j.kernel.BidirectionalTraversalBranchPath


        public Configuration build()
        {
            return fromMap( new HashMap<>( config ) );
        }

        public Configuration build()
        {
            return fromMap( new HashMap<String, String>( config ) );
        }

Replace Generic With Diamond HashMap<String,String> with HashMap<> in method public build() : Configuration from class org.neo4j.perftest.enterprise.util.Configuration.Builder


        @Override
        public void visitDeletedNode( long id )
        {
            try ( StoreStatement statement = storeLayer.acquireStatement() )
            {
                counts.incrementNodeCount( ANY_LABEL, -1 );
                PrimitiveIntIterator labels = storeLayer.nodeGetLabels( statement, id );
                if ( labels.hasNext() )
                {
                    final int[] removed = PrimitiveIntCollections.asArray( labels );
                    for ( int label : removed )
                    {
                        counts.incrementNodeCount( label, -1 );
                    }
                    storeLayer.nodeVisitDegrees( statement, id, new DegreeVisitor()
                    {
                        @Override
                        public void visitDegree( int type, int outgoing, int incoming )
                        {
                            for ( int label : removed )
                            {
                                updateRelationshipsCountsFromDegrees( type, label, -outgoing, -incoming );
                            }
                        }
                    } );
                }
            }
            catch ( EntityNotFoundException e )
            {
                // this should not happen, but I guess it means the node we deleted did not exist...?
            }
            recordState.nodeDelete( id );
        }

        @Override
        public void visitDeletedNode( long id )
        {
            try
            {
                counts.incrementNodeCount( ANY_LABEL, -1 );
                PrimitiveIntIterator labels = storeLayer.nodeGetLabels( id );
                if ( labels.hasNext() )
                {
                    final int[] removed = PrimitiveIntCollections.asArray( labels );
                    for ( int label : removed )
                    {
                        counts.incrementNodeCount( label, -1 );
                    }
                    storeLayer.nodeVisitDegrees( id, new DegreeVisitor()
                    {
                        @Override
                        public void visitDegree( int type, int outgoing, int incoming )
                        {
                            for ( int label : removed )
                            {
                                updateRelationshipsCountsFromDegrees( type, label, -outgoing, -incoming );
                            }
                        }
                    } );
                }
            }
            catch ( EntityNotFoundException e )
            {
                // this should not happen, but I guess it means the node we deleted did not exist...?
            }
            recordState.nodeDelete( id );
        }

Try With Resources try(StoreStatement statement=storeLayer.acquireStatement()) in method public visitDeletedNode(id long) : void from class org.neo4j.kernel.impl.api.KernelTransactionImplementation.TransactionToRecordStateVisitor


        @Override
        protected void generateInitialData( GraphDatabaseService graphDb )
        {
            try (org.neo4j.graphdb.Transaction tx = graphDb.beginTx())
            {
                Node node1 = set( graphDb.createNode() );
                Node node2 = set( graphDb.createNode(), property( "key", "value" ) );
                node1.createRelationshipTo( node2, DynamicRelationshipType.withName( "C" ) );
                tx.success();
            }
        }

        @Override
        protected void generateInitialData( GraphDatabaseService graphDb )
        {
            org.neo4j.graphdb.Transaction tx = graphDb.beginTx();
            try
            {
                Node node1 = set( graphDb.createNode() );
                Node node2 = set( graphDb.createNode(), property( "key", "value" ) );
                node1.createRelationshipTo( node2, DynamicRelationshipType.withName( "C" ) );
                tx.success();
            }
            finally
            {
                tx.finish();
            }
        }

Try With Resources try(org.neo4j.graphdb.Transaction tx=graphDb.beginTx()) in method protected generateInitialData(graphDb GraphDatabaseService) : void from class org.neo4j.consistency.ConsistencyCheckServiceIntegrationTest.fixture.new GraphStoreFixture


    private StoreAccess createStoreWithOneHighDegreeNodeAndSeveralDegreeTwoNodes( int nDegreeTwoNodes )
    {
        File storeDirectory = storeLocation.graphDbDir();
        GraphDatabaseService database = new TestGraphDatabaseFactory().newEmbeddedDatabase( storeDirectory );

        try ( Transaction transaction = database.beginTx() )
        {
            Node denseNode = database.createNode();
            for ( int i = 0; i < nDegreeTwoNodes; i++ )
            {
                Node degreeTwoNode = database.createNode();
                Node leafNode = database.createNode();
                if ( i % 2 == 0 )
                {
                    denseNode.createRelationshipTo( degreeTwoNode, TestRelationshipType.CONNECTED );
                }
                else
                {
                    degreeTwoNode.createRelationshipTo( denseNode, TestRelationshipType.CONNECTED );
                }
                degreeTwoNode.createRelationshipTo( leafNode, TestRelationshipType.CONNECTED );
            }
            transaction.success();
        }
        database.shutdown();
        PageCache pageCache = pageCacheRule.getPageCache( new DefaultFileSystemAbstraction() );
        return new StoreAccess( pageCache, storeDirectory );
    }

    private StoreAccess createStoreWithOneHighDegreeNodeAndSeveralDegreeTwoNodes( int nDegreeTwoNodes )
    {
        File storeDirectory = storeLocation.graphDbDir();
        GraphDatabaseService database = new TestGraphDatabaseFactory().newEmbeddedDatabase( storeDirectory );
        Transaction transaction = database.beginTx();
        try
        {
            Node denseNode = database.createNode();
            for ( int i = 0; i < nDegreeTwoNodes; i++ )
            {
                Node degreeTwoNode = database.createNode();
                Node leafNode = database.createNode();
                if ( i % 2 == 0 )
                {
                    denseNode.createRelationshipTo( degreeTwoNode, TestRelationshipType.CONNECTED );
                }
                else
                {
                    degreeTwoNode.createRelationshipTo( denseNode, TestRelationshipType.CONNECTED );
                }
                degreeTwoNode.createRelationshipTo( leafNode, TestRelationshipType.CONNECTED );
            }
            transaction.success();
        }
        finally
        {
            transaction.finish();
        }
        database.shutdown();
        PageCache pageCache = pageCacheRule.getPageCache( new DefaultFileSystemAbstraction() );
        return new StoreAccess( pageCache, storeDirectory );
    }

Try With Resources try(Transaction transaction=database.beginTx()) in method private createStoreWithOneHighDegreeNodeAndSeveralDegreeTwoNodes(nDegreeTwoNodes int) : StoreAccess from class org.neo4j.consistency.repair.RelationshipChainExplorerTest


    @Test
    public void addingALabelUsingAValidIdentifierShouldSucceed() throws Exception
    {
        // Given
        GraphDatabaseService graphDatabase = dbRule.getGraphDatabaseService();
        Node myNode = null;

        // When
        try ( Transaction tx = graphDatabase.beginTx() )
        {
            myNode = graphDatabase.createNode();
            myNode.addLabel( Labels.MY_LABEL );

            tx.success();
        }

        // Then
        assertThat( "Label should have been added to node", myNode, inTx( graphDatabase, hasLabel( Labels.MY_LABEL ) ) );
    }

    @Test
    public void addingALabelUsingAValidIdentifierShouldSucceed() throws Exception
    {
        // Given
        GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService();
        Node myNode = null;

        // When
        Transaction tx = beansAPI.beginTx();
        try
        {
            myNode = beansAPI.createNode();
            myNode.addLabel( Labels.MY_LABEL );

            tx.success();
        }
        finally
        {
            tx.finish();
        }

        // Then
        assertThat( "Label should have been added to node", myNode, inTx( beansAPI, hasLabel( Labels.MY_LABEL ) ) );
    }

Try With Resources try(Transaction tx=graphDatabase.beginTx()) in method public addingALabelUsingAValidIdentifierShouldSucceed() : void from class org.neo4j.graphdb.LabelsAcceptanceTest


    @Test
    public void addingALabelThatAlreadyExistsBehavesAsNoOp() throws Exception
    {
        // Given
        GraphDatabaseService graphDatabase = dbRule.getGraphDatabaseService();
        Node myNode = null;

        // When
        try (Transaction tx = graphDatabase.beginTx())
        {
            myNode = graphDatabase.createNode();
            myNode.addLabel( Labels.MY_LABEL );
            myNode.addLabel( Labels.MY_LABEL );

            tx.success();
        }

        // Then
        assertThat( "Label should have been added to node", myNode, inTx( graphDatabase, hasLabel( Labels.MY_LABEL ) ) );
    }

    @Test
    public void addingALabelThatAlreadyExistsBehavesAsNoOp() throws Exception
    {
        // Given
        GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService();
        Node myNode = null;

        // When
        Transaction tx = beansAPI.beginTx();
        try
        {
            myNode = beansAPI.createNode();
            myNode.addLabel( Labels.MY_LABEL );
            myNode.addLabel( Labels.MY_LABEL );

            tx.success();
        }
        finally
        {
            tx.finish();
        }

        // Then
        assertThat( "Label should have been added to node", myNode, inTx( beansAPI, hasLabel( Labels.MY_LABEL ) ) );
    }

Try With Resources try(Transaction tx=graphDatabase.beginTx()) in method public addingALabelThatAlreadyExistsBehavesAsNoOp() : void from class org.neo4j.graphdb.LabelsAcceptanceTest


    @Test
    public void oversteppingMaxNumberOfLabelsShouldFailGracefully() throws Exception
    {
        // Given
        GraphDatabaseService graphDatabase = beansAPIWithNoMoreLabelIds();

        // When
        try (Transaction tx = graphDatabase.beginTx())
        {
            graphDatabase.createNode().addLabel( Labels.MY_LABEL );
            fail( "Should have thrown exception" );
        }
        catch ( ConstraintViolationException ex )
        {   // Happy
        }

        graphDatabase.shutdown();
    }

    @Test
    public void oversteppingMaxNumberOfLabelsShouldFailGracefully() throws Exception
    {
        // Given
        GraphDatabaseService beansAPI = beansAPIWithNoMoreLabelIds();

        // When
        Transaction tx = beansAPI.beginTx();
        try
        {
            beansAPI.createNode().addLabel( Labels.MY_LABEL );
            fail( "Should have thrown exception" );
        }
        catch ( ConstraintViolationException ex )
        {   // Happy
        }
        finally
        {
            tx.finish();
        }

        beansAPI.shutdown();
    }

Try With Resources try(Transaction tx=graphDatabase.beginTx()) in method public oversteppingMaxNumberOfLabelsShouldFailGracefully() : void from class org.neo4j.graphdb.LabelsAcceptanceTest


    @Test
    public void createNodeWithLabels() throws Exception
    {
        // GIVEN
        GraphDatabaseService db = dbRule.getGraphDatabaseService();

        // WHEN
        Node node = null;
        try (Transaction tx = db.beginTx())
        {
            node = db.createNode( Labels.values() );
            tx.success();
        }

        // THEN
        assertThat( node, inTx( db, hasLabels( asEnumNameSet( Labels.class ) ) ));
    }

    @Test
    public void createNodeWithLabels() throws Exception
    {
        // GIVEN
        GraphDatabaseService db = dbRule.getGraphDatabaseService();

        // WHEN
        Node node = null;
        Transaction tx = db.beginTx();
        try
        {
            node = db.createNode( Labels.values() );
            tx.success();
        }
        finally
        {
            tx.finish();
        }

        // THEN
        assertThat( node, inTx( db, hasLabels( asEnumNameSet( Labels.class ) ) ));
    }

Try With Resources try(Transaction tx=db.beginTx()) in method public createNodeWithLabels() : void from class org.neo4j.graphdb.LabelsAcceptanceTest


    @Test
    public void removingNonExistentLabel() throws Exception
    {
        // Given
        GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService();
        Label label = Labels.MY_LABEL;

        // When
        Node myNode;
        try (Transaction tx = beansAPI.beginTx())
        {
            myNode = beansAPI.createNode();
            myNode.removeLabel( label );
            tx.success();
        }

        // THEN
        assertThat( myNode, not( inTx( beansAPI, hasLabel( label ) ) ) );
    }

    @Test
    public void removingNonExistentLabel() throws Exception
    {
        // Given
        GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService();
        Label label = Labels.MY_LABEL;

        // When
        Transaction tx = beansAPI.beginTx();
        Node myNode;
        try
        {
            myNode = beansAPI.createNode();
            myNode.removeLabel( label );
            tx.success();
        }
        finally
        {
            tx.finish();
        }

        // THEN
        assertThat( myNode, not( inTx( beansAPI, hasLabel( label ) ) ) );
    }

Try With Resources try(Transaction tx=beansAPI.beginTx()) in method public removingNonExistentLabel() : void from class org.neo4j.graphdb.LabelsAcceptanceTest


    @Test
    public void removingExistingLabelFromUnlabeledNode() throws Exception
    {
        // Given
        GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService();
        Label label = Labels.MY_LABEL;
        createNode( beansAPI, label );
        Node myNode = createNode( beansAPI );

        // When
        try (Transaction tx = beansAPI.beginTx())
        {
            myNode.removeLabel( label );
            tx.success();
        }

        // THEN
        assertThat( myNode, not( inTx( beansAPI, hasLabel( label ) ) ) ) ;
    }

    @Test
    public void removingExistingLabelFromUnlabeledNode() throws Exception
    {
        // Given
        GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService();
        Label label = Labels.MY_LABEL;
        createNode( beansAPI, label );
        Node myNode = createNode( beansAPI );

        // When
        Transaction tx = beansAPI.beginTx();
        try
        {
            myNode.removeLabel( label );
            tx.success();
        }
        finally
        {
            tx.finish();
        }

        // THEN
        assertThat( myNode, not( inTx( beansAPI, hasLabel( label ) ) ) ) ;
    }

Try With Resources try(Transaction tx=beansAPI.beginTx()) in method public removingExistingLabelFromUnlabeledNode() : void from class org.neo4j.graphdb.LabelsAcceptanceTest


    @Test
    public void removingUncommittedLabel() throws Exception
    {
        // Given
        GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService();
        Label label = Labels.MY_LABEL;

        // When
        Node myNode;
        try (Transaction tx = beansAPI.beginTx())
        {
            myNode = beansAPI.createNode();
            myNode.addLabel( label );
            myNode.removeLabel( label );

            // THEN
            assertFalse( myNode.hasLabel( label ) );

            tx.success();
        }
    }

    @Test
    public void removingUncommittedLabel() throws Exception
    {
        // Given
        GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService();
        Label label = Labels.MY_LABEL;

        // When
        Transaction tx = beansAPI.beginTx();
        Node myNode;
        try
        {
            myNode = beansAPI.createNode();
            myNode.addLabel( label );
            myNode.removeLabel( label );

            // THEN
            assertFalse( myNode.hasLabel( label ) );

            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=beansAPI.beginTx()) in method public removingUncommittedLabel() : void from class org.neo4j.graphdb.LabelsAcceptanceTest


    @Test
    public void shouldBeAbleToListLabelsForANode() throws Exception
    {
        // GIVEN
        GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService();
        Node node = null;
        Set<String> expected = asSet( Labels.MY_LABEL.name(), Labels.MY_OTHER_LABEL.name() );
        try (Transaction tx = beansAPI.beginTx())
        {
            node = beansAPI.createNode();
            for ( String label : expected )
            {
                node.addLabel( label( label ) );
            }
            tx.success();
        }

        assertThat(node, inTx( beansAPI, hasLabels( expected ) ));
    }

    @Test
    public void shouldBeAbleToListLabelsForANode() throws Exception
    {
        // GIVEN
        GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService();
        Transaction tx = beansAPI.beginTx();
        Node node = null;
        Set<String> expected = asSet( Labels.MY_LABEL.name(), Labels.MY_OTHER_LABEL.name() );
        try
        {
            node = beansAPI.createNode();
            for ( String label : expected )
            {
                node.addLabel( label( label ) );
            }
            tx.success();
        }
        finally
        {
            tx.finish();
        }

        assertThat(node, inTx( beansAPI, hasLabels( expected ) ));
    }

Try With Resources try(Transaction tx=beansAPI.beginTx()) in method public shouldBeAbleToListLabelsForANode() : void from class org.neo4j.graphdb.LabelsAcceptanceTest


    @Test
    public void getNodesWithLabelsWithTxAddsAndRemoves() throws Exception
    {
        // GIVEN
        GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService();
        Node node1 = createNode( beansAPI, Labels.MY_LABEL, Labels.MY_OTHER_LABEL );
        Node node2 = createNode( beansAPI, Labels.MY_LABEL, Labels.MY_OTHER_LABEL );

        // WHEN
        Node node3 = null;
        Set<Node> nodesWithMyLabel = null, nodesWithMyOtherLabel = null;
        try (Transaction tx = beansAPI.beginTx())
        {
            node3 = beansAPI.createNode( Labels.MY_LABEL );
            node2.removeLabel( Labels.MY_LABEL );
            // extracted here to be asserted below
            nodesWithMyLabel = asSet( beansAPI.findNodes( Labels.MY_LABEL ) );
            nodesWithMyOtherLabel = asSet( beansAPI.findNodes( Labels.MY_OTHER_LABEL ) );
            tx.success();
        }

        // THEN
        assertEquals( asSet( node1, node3 ), nodesWithMyLabel );
        assertEquals( asSet( node1, node2 ), nodesWithMyOtherLabel );
    }

    @Test
    public void getNodesWithLabelsWithTxAddsAndRemoves() throws Exception
    {
        // GIVEN
        GraphDatabaseService beansAPI = dbRule.getGraphDatabaseService();
        Node node1 = createNode( beansAPI, Labels.MY_LABEL, Labels.MY_OTHER_LABEL );
        Node node2 = createNode( beansAPI, Labels.MY_LABEL, Labels.MY_OTHER_LABEL );

        // WHEN
        Transaction tx = beansAPI.beginTx();
        Node node3 = null;
        Set<Node> nodesWithMyLabel = null, nodesWithMyOtherLabel = null;
        try
        {
            node3 = beansAPI.createNode( Labels.MY_LABEL );
            node2.removeLabel( Labels.MY_LABEL );
            // extracted here to be asserted below
            nodesWithMyLabel = asSet( beansAPI.findNodes( Labels.MY_LABEL ) );
            nodesWithMyOtherLabel = asSet( beansAPI.findNodes( Labels.MY_OTHER_LABEL ) );
            tx.success();
        }
        finally
        {
            tx.finish();
        }

        // THEN
        assertEquals( asSet( node1, node3 ), nodesWithMyLabel );
        assertEquals( asSet( node1, node2 ), nodesWithMyOtherLabel );
    }

Try With Resources try(Transaction tx=beansAPI.beginTx()) in method public getNodesWithLabelsWithTxAddsAndRemoves() : void from class org.neo4j.graphdb.LabelsAcceptanceTest


    @Test
    public void shouldListLabels() throws Exception
    {
        // Given
        GraphDatabaseService db = dbRule.getGraphDatabaseService();
        GlobalGraphOperations globalOps = GlobalGraphOperations.at( db );
        createNode( db, Labels.MY_LABEL, Labels.MY_OTHER_LABEL );
        List<Label> labels = null;

        // When
        try (Transaction tx = db.beginTx())
        {
            labels = toList( globalOps.getAllLabels() );
        }

        // Then
        assertEquals( 2, labels.size() );
        assertThat( map( new Function<Label,String>()
        {
            @Override
            public String apply( Label label )
            {
                return label.name();
            }
        }, labels ), hasItems( Labels.MY_LABEL.name(), Labels.MY_OTHER_LABEL.name() ) );
    }

    @Test
    public void shouldListLabels() throws Exception
    {
        // Given
        GraphDatabaseService db = dbRule.getGraphDatabaseService();
        GlobalGraphOperations globalOps = GlobalGraphOperations.at( db );
        createNode( db, Labels.MY_LABEL, Labels.MY_OTHER_LABEL );
        List<Label> labels = null;

        // When
        Transaction tx = db.beginTx();
        try
        {
            labels = toList( globalOps.getAllLabels() );
        }
        finally
        {
            tx.finish();
        }

        // Then
        assertEquals( 2, labels.size() );
        assertThat( map( new Function<Label, String>()
        {
            @Override
            public String apply( Label label )
            {
                return label.name();
            }
        }, labels ), hasItems( Labels.MY_LABEL.name(), Labels.MY_OTHER_LABEL.name() ) );
    }

Try With Resources try(Transaction tx=db.beginTx()) in method public shouldListLabels() : void from class org.neo4j.graphdb.LabelsAcceptanceTest


    private Node createNode( GraphDatabaseService db, Label... labels )
    {
        try ( Transaction tx = db.beginTx() )
        {
            Node node = db.createNode( labels );
            tx.success();
            return node;
        }
    }

    private Node createNode( GraphDatabaseService db, Label... labels )
    {
        Transaction tx = db.beginTx();
        try
        {
            Node node = db.createNode( labels );
            tx.success();
            return node;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method private createNode(db GraphDatabaseService, labels Label...) : Node from class org.neo4j.graphdb.LabelsAcceptanceTest


    @Test
    public void addingAnIndexingRuleInNestedTxShouldSucceed() throws Exception
    {
        IndexDefinition index;

        // WHEN
        IndexDefinition indexDef;
        try (Transaction tx = db.beginTx())
        {
            try ( Transaction nestedTransaction = db.beginTx() )
            {
                indexDef = db.schema().indexFor( label ).on( propertyKey ).create();
                nestedTransaction.success();
            }

            index = indexDef;
            tx.success();
        }
        waitForIndex( db, indexDef );

        // THEN
        assertThat( getIndexes( db, label ), containsOnly( index ) );
    }

    @Test
    public void addingAnIndexingRuleInNestedTxShouldSucceed() throws Exception
    {
        IndexDefinition index;

        // WHEN
        Transaction tx = db.beginTx();
        IndexDefinition indexDef;
        try
        {
            Transaction tx1 = db.beginTx();
            try
            {
                indexDef = db.schema().indexFor( label ).on( propertyKey ).create();
                tx1.success();
            }
            finally
            {
                tx1.finish();
            }

            index = indexDef;
            tx.success();
        }
        finally
        {
            tx.finish();
        }
        waitForIndex( db, indexDef );

        // THEN
        assertThat( getIndexes( db, label ), containsOnly( index ) );
    }

Try With Resources try(Transaction tx=db.beginTx()) in method public addingAnIndexingRuleInNestedTxShouldSucceed() : void from class org.neo4j.graphdb.SchemaAcceptanceTest


    @Test
    public void shouldThrowConstraintViolationIfAskedToIndexSamePropertyAndLabelTwiceInSameTx() throws Exception
    {
        // WHEN
        try ( Transaction tx = db.beginTx() )
        {
            Schema schema = db.schema();
            schema.indexFor( label ).on( propertyKey ).create();
            try
            {
                schema.indexFor( label ).on( propertyKey ).create();
                fail( "Should not have validated" );
            }
            catch ( ConstraintViolationException e )
            {
                assertEquals( "There already exists an index for label 'MY_LABEL' on property 'my_property_key'.",
                              e.getMessage() );
            }
            tx.success();
        }
    }

    @Test
    public void shouldThrowConstraintViolationIfAskedToIndexSamePropertyAndLabelTwiceInSameTx() throws Exception
    {
        // WHEN
        Transaction tx = db.beginTx();
        try
        {
            Schema schema = db.schema();
            schema.indexFor( label ).on( propertyKey ).create();
            try
            {
                schema.indexFor( label ).on( propertyKey ).create();
                fail( "Should not have validated" );
            }
            catch ( ConstraintViolationException e )
            {
                assertEquals( "There already exists an index for label 'MY_LABEL' on property 'my_property_key'.",
                              e.getMessage() );
            }
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method public shouldThrowConstraintViolationIfAskedToIndexSamePropertyAndLabelTwiceInSameTx() : void from class org.neo4j.graphdb.SchemaAcceptanceTest


    @Test
    public void shouldThrowConstraintViolationIfAskedToCreateCompoundIndex() throws Exception
    {
        // WHEN
        try ( Transaction tx = db.beginTx() )
        {
            Schema schema = db.schema();
            schema.indexFor( label )
                    .on( "my_property_key" )
                    .on( "other_property" ).create();
            tx.success();
            fail( "Should not be able to create index on multiple propertyKey keys" );
        }
        catch ( UnsupportedOperationException e )
        {
            assertThat( e.getMessage(), containsString( "Compound indexes" ) );
        }
    }

    @Test
    public void shouldThrowConstraintViolationIfAskedToCreateCompoundIndex() throws Exception
    {
        // WHEN
        Transaction tx = db.beginTx();
        try
        {
            Schema schema = db.schema();
            schema.indexFor( label )
                    .on( "my_property_key" )
                    .on( "other_property" ).create();
            tx.success();
            fail( "Should not be able to create index on multiple propertyKey keys" );
        }
        catch ( UnsupportedOperationException e )
        {
            assertThat( e.getMessage(), containsString( "Compound indexes" ) );
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method public shouldThrowConstraintViolationIfAskedToCreateCompoundIndex() : void from class org.neo4j.graphdb.SchemaAcceptanceTest


    @Test
    public void shouldThrowConstraintViolationIfAskedToCreateCompoundConstraint() throws Exception
    {
        // WHEN
        try ( Transaction tx = db.beginTx() )
        {
            Schema schema = db.schema();
            schema.constraintFor( label )
                    .assertPropertyIsUnique( "my_property_key" )
                    .assertPropertyIsUnique( "other_property" ).create();
            tx.success();
            fail( "Should not be able to create constraint on multiple propertyKey keys" );
        }
        catch ( UnsupportedOperationException e )
        {
            assertThat( e.getMessage(), containsString( "can only create one unique constraint" ) );
        }
    }

    @Test
    public void shouldThrowConstraintViolationIfAskedToCreateCompoundConstraint() throws Exception
    {
        // WHEN
        Transaction tx = db.beginTx();
        try
        {
            Schema schema = db.schema();
            schema.constraintFor( label )
                    .assertPropertyIsUnique( "my_property_key" )
                    .assertPropertyIsUnique( "other_property" ).create();
            tx.success();
            fail( "Should not be able to create constraint on multiple propertyKey keys" );
        }
        catch ( UnsupportedOperationException e )
        {
            assertThat( e.getMessage(), containsString( "can only create one unique constraint" ) );
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method public shouldThrowConstraintViolationIfAskedToCreateCompoundConstraint() : void from class org.neo4j.graphdb.SchemaAcceptanceTest


    @Test
    public void droppingAnUnexistingIndexShouldGiveHelpfulExceptionInSameTransaction() throws Exception
    {
        // GIVEN
        IndexDefinition index = createIndex( db, label , propertyKey );

        // WHEN
        try ( Transaction tx = db.beginTx() )
        {
            index.drop();
            try
            {
                index.drop();
                fail( "Should not be able to drop index twice" );
            }
            catch ( ConstraintViolationException e )
            {
                assertThat( e.getMessage(), containsString( "Unable to drop index" ) );
            }
            tx.success();
        }

        // THEN
        assertThat( "Index should have been deleted", getIndexes( db, label ), not( contains( index ) ) );
    }

    @Test
    public void droppingAnUnexistingIndexShouldGiveHelpfulExceptionInSameTransaction() throws Exception
    {
        // GIVEN
        IndexDefinition index = createIndex( db, label , propertyKey );

        // WHEN
        Transaction tx = db.beginTx();
        try
        {
            index.drop();
            try
            {
                index.drop();
                fail( "Should not be able to drop index twice" );
            }
            catch ( ConstraintViolationException e )
            {
                assertThat( e.getMessage(), containsString( "Unable to drop index" ) );
            }
            tx.success();
        }
        finally
        {
            tx.finish();
        }

        // THEN
        assertThat( "Index should have been deleted", getIndexes( db, label ), not( contains( index ) ) );
    }

Try With Resources try(Transaction tx=db.beginTx()) in method public droppingAnUnexistingIndexShouldGiveHelpfulExceptionInSameTransaction() : void from class org.neo4j.graphdb.SchemaAcceptanceTest


    @Test
    public void awaitingIndexComingOnlineWorks()
    {
        // GIVEN

        // WHEN
        IndexDefinition index = createIndex( db, label, propertyKey );

        // PASS
        try ( Transaction tx = db.beginTx() )
        {
            db.schema().awaitIndexOnline( index, 1L, TimeUnit.MINUTES );

            // THEN
            assertEquals( Schema.IndexState.ONLINE, db.schema().getIndexState( index ) );
        }
    }

    @Test
    public void awaitingIndexComingOnlineWorks()
    {
        // GIVEN

        // WHEN
        IndexDefinition index = createIndex( db, label, propertyKey );

        // PASS
        Transaction tx = db.beginTx();
        try
        {
            db.schema().awaitIndexOnline( index, 1L, TimeUnit.MINUTES );

            // THEN
            assertEquals( Schema.IndexState.ONLINE, db.schema().getIndexState( index ) );
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method public awaitingIndexComingOnlineWorks() : void from class org.neo4j.graphdb.SchemaAcceptanceTest


    @Test
    public void awaitingAllIndexesComingOnlineWorks()
    {
        // GIVEN

        // WHEN
        IndexDefinition index = createIndex( db, label , propertyKey );
        createIndex( db, label , "other_property" );

        // PASS
        waitForIndex( db, index );
        try ( Transaction tx = db.beginTx() )
        {
            db.schema().awaitIndexesOnline( 1L, TimeUnit.MINUTES );

            // THEN
            assertEquals( Schema.IndexState.ONLINE, db.schema().getIndexState( index ) );
        }
    }

    @Test
    public void awaitingAllIndexesComingOnlineWorks()
    {
        // GIVEN

        // WHEN
        IndexDefinition index = createIndex( db, label , propertyKey );
        createIndex( db, label , "other_property" );

        // PASS
        waitForIndex( db, index );
        Transaction tx = db.beginTx();
        try
        {
            db.schema().awaitIndexesOnline( 1L, TimeUnit.MINUTES );

            // THEN
            assertEquals( Schema.IndexState.ONLINE, db.schema().getIndexState( index ) );
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method public awaitingAllIndexesComingOnlineWorks() : void from class org.neo4j.graphdb.SchemaAcceptanceTest


    @Test
    public void addingUniquenessConstraintWhenDuplicateDataExistsGivesNiceError() throws Exception
    {
        // GIVEN
        try ( Transaction transaction = db.beginTx() )
        {
            db.createNode( label ).setProperty( propertyKey, "value1" );
            db.createNode( label ).setProperty( propertyKey, "value1" );
            transaction.success();
        }

        // WHEN
        try
        {
            createConstraint( label, propertyKey );
            fail( "Expected exception to be thrown" );
        }
        catch ( ConstraintViolationException e )
        {
            assertEquals(
                format( "Unable to create CONSTRAINT ON ( my_label:MY_LABEL ) ASSERT my_label.my_property_key " +
                        "IS UNIQUE:%nMultiple nodes with label `MY_LABEL` have property `my_property_key` = " +
                        "'value1':%n" +
                        "  node(0)%n" +
                        "  node(1)" ), e.getMessage() );
        }
    }

    @Test
    public void addingUniquenessConstraintWhenDuplicateDataExistsGivesNiceError() throws Exception
    {
        // GIVEN
        Transaction transaction = db.beginTx();
        try {
            db.createNode( label ).setProperty( propertyKey, "value1" );
            db.createNode( label ).setProperty( propertyKey, "value1" );
            transaction.success();
        }
        finally
        {
            transaction.finish();
        }

        // WHEN
        try
        {
            createConstraint( label, propertyKey );
            fail( "Expected exception to be thrown" );
        }
        catch ( ConstraintViolationException e )
        {
            assertEquals(
                format( "Unable to create CONSTRAINT ON ( my_label:MY_LABEL ) ASSERT my_label.my_property_key " +
                        "IS UNIQUE:%nMultiple nodes with label `MY_LABEL` have property `my_property_key` = " +
                        "'value1':%n" +
                        "  node(0)%n" +
                        "  node(1)" ), e.getMessage() );
        }
    }

Try With Resources try(Transaction transaction=db.beginTx()) in method public addingUniquenessConstraintWhenDuplicateDataExistsGivesNiceError() : void from class org.neo4j.graphdb.SchemaAcceptanceTest


    private void dropConstraint( GraphDatabaseService db, ConstraintDefinition constraint )
    {
        try ( Transaction tx = db.beginTx() )
        {
            constraint.drop();
            tx.success();
        }
    }

    private void dropConstraint( GraphDatabaseService db, ConstraintDefinition constraint )
    {
        Transaction tx = db.beginTx();
        try
        {
            constraint.drop();
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method private dropConstraint(db GraphDatabaseService, constraint ConstraintDefinition) : void from class org.neo4j.graphdb.SchemaAcceptanceTest


    private ConstraintDefinition createConstraint( Label label, String prop )
    {
        try (Transaction tx = db.beginTx())
        {
            ConstraintDefinition constraint = db.schema().constraintFor( label ).assertPropertyIsUnique( prop ).create();
            tx.success();
            return constraint;
        }
    }

    private ConstraintDefinition createConstraint( Label label, String prop )
    {
        Transaction tx = db.beginTx();
        try
        {
            ConstraintDefinition constraint = db.schema().constraintFor( label ).assertPropertyIsUnique( prop ).create();
            tx.success();
            return constraint;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method private createConstraint(label Label, prop String) : ConstraintDefinition from class org.neo4j.graphdb.SchemaAcceptanceTest


    private void dropIndex( IndexDefinition index )
    {
        try ( Transaction tx = db.beginTx() )
        {
            index.drop();
            tx.success();
        }
    }

    private void dropIndex( IndexDefinition index )
    {
        Transaction tx = db.beginTx();
        try
        {
            index.drop();
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method private dropIndex(index IndexDefinition) : void from class org.neo4j.graphdb.SchemaAcceptanceTest


    private Node createNode( GraphDatabaseService db, String key, Object value, Label label )
    {
        try ( Transaction tx = db.beginTx() )
        {
            Node node = db.createNode( label );
            node.setProperty( key, value );
            tx.success();
            return node;
        }
    }

    private Node createNode( GraphDatabaseService db, String key, Object value, Label label )
    {
        Transaction tx = db.beginTx();
        try
        {
            Node node = db.createNode( label );
            node.setProperty( key, value );
            tx.success();
            return node;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method private createNode(db GraphDatabaseService, key String, value Object, label Label) : Node from class org.neo4j.graphdb.SchemaAcceptanceTest


    @Test
    public void shouldTimeoutWatingForIndexToComeOnline() throws Exception
    {
        // given
        GraphDatabaseService db = rule.getGraphDatabaseService();
        DoubleLatch latch = provider.installPopulationJobCompletionLatch();

        IndexDefinition index;
        try ( Transaction tx = db.beginTx() )
        {
            index = db.schema().indexFor( DynamicLabel.label( "Person" ) ).on( "name" ).create();
            tx.success();
        }

        latch.awaitStart();

        // when
        try ( Transaction tx = db.beginTx() )
        {
            // then
            db.schema().awaitIndexOnline( index, 1, TimeUnit.MILLISECONDS );

            fail( "Expected IllegalStateException to be thrown" );
        }
        catch ( IllegalStateException e )
        {
            // good
            assertThat( e.getMessage(), containsString( "come online" ) );
        }
        finally
        {
            latch.finish();
        }
    }

    @Test
    public void shouldTimeoutWatingForIndexToComeOnline() throws Exception
    {
        // given
        GraphDatabaseService db = rule.getGraphDatabaseService();
        DoubleLatch latch = provider.installPopulationJobCompletionLatch();

        Transaction tx = db.beginTx();
        IndexDefinition index = db.schema().indexFor( DynamicLabel.label( "Person" ) ).on( "name" ).create();
        tx.success();
        tx.finish();

        latch.awaitStart();
        tx = db.beginTx();

        // when
        try
        {
            // then
            db.schema().awaitIndexOnline( index, 1, TimeUnit.MILLISECONDS );

            fail( "Expected IllegalStateException to be thrown" );
        }
        catch ( IllegalStateException e )
        {
            // good
            assertThat( e.getMessage(), containsString( "come online" ) );
        }
        finally
        {
            tx.finish();
            latch.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method public shouldTimeoutWatingForIndexToComeOnline() : void from class org.neo4j.graphdb.SchemaIndexWaitingAcceptanceTest


    @Test
    public void shouldTimeoutWatingForAllIndexesToComeOnline() throws Exception
    {
        // given
        GraphDatabaseService db = rule.getGraphDatabaseService();
        DoubleLatch latch = provider.installPopulationJobCompletionLatch();

        try ( Transaction tx = db.beginTx() )
        {
            db.schema().indexFor( DynamicLabel.label( "Person" ) ).on( "name" ).create();
            tx.success();
        }

        latch.awaitStart();

        // when
        try ( Transaction tx = db.beginTx() )
        {
            // then
            db.schema().awaitIndexesOnline( 1, TimeUnit.MILLISECONDS );

            fail( "Expected IllegalStateException to be thrown" );
        }
        catch ( IllegalStateException e )
        {
            // good
            assertThat( e.getMessage(), containsString( "come online" ) );
        }
        finally
        {
            latch.finish();
        }
    }

    @Test
    public void shouldTimeoutWatingForAllIndexesToComeOnline() throws Exception
    {
        // given
        GraphDatabaseService db = rule.getGraphDatabaseService();
        DoubleLatch latch = provider.installPopulationJobCompletionLatch();

        Transaction tx = db.beginTx();
        db.schema().indexFor( DynamicLabel.label( "Person" ) ).on( "name" ).create();
        tx.success();
        tx.finish();

        latch.awaitStart();

        tx = db.beginTx();
        // when
        try
        {
            // then
            db.schema().awaitIndexesOnline( 1, TimeUnit.MILLISECONDS );

            fail( "Expected IllegalStateException to be thrown" );
        }
        catch ( IllegalStateException e )
        {
            // good
            assertThat( e.getMessage(), containsString( "come online" ) );
        }
        finally
        {
            latch.finish();
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method public shouldTimeoutWatingForAllIndexesToComeOnline() : void from class org.neo4j.graphdb.SchemaIndexWaitingAcceptanceTest


    private void dropIndex( IndexDefinition index, DoubleLatch populationCompletionLatch )
    {
        try ( Transaction tx = db.beginTx() )
        {
            index.drop();
            populationCompletionLatch.finish();
            tx.success();
        }
    }

    private void dropIndex( IndexDefinition index, DoubleLatch populationCompletionLatch )
    {
        Transaction tx = db.beginTx();
        try
        {
            index.drop();
            populationCompletionLatch.finish();
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method private dropIndex(index IndexDefinition, populationCompletionLatch DoubleLatch) : void from class org.neo4j.kernel.impl.api.index.IndexRestartIT


    @Test
    public void shouldNotBeAbleToCommitIfFailedTransactionContext() throws Exception
    {
        // WHEN
        Node node = null;
        int labelId = -1;
        TransactionFailureException expectedException = null;
        try ( Transaction transaction = db.beginTx() )
        {
            Statement statement = statementContextSupplier.get();
            node = db.createNode();
            labelId = statement.dataWriteOperations().labelGetOrCreateForName( "labello" );
            statement.dataWriteOperations().nodeAddLabel( node.getId(), labelId );
            statement.close();
            transaction.failure();
            transaction.success();
        }
        catch ( TransactionFailureException e )
        {
            expectedException = e;
        }
        finally
        {
            Assert.assertNotNull( "Should have failed", expectedException );
        }

        // THEN
        try (Transaction tx = db.beginTx())
        {
            Statement statement = statementContextSupplier.get();
            try
            {
                statement.readOperations().nodeHasLabel( node.getId(), labelId );
                fail( "should have thrown exception" );
            }
            catch ( EntityNotFoundException e )
            {
                // Yay!
            }
        }
    }

    @Test
    public void shouldNotBeAbleToCommitIfFailedTransactionContext() throws Exception
    {
        Transaction tx = db.beginTx();
        Statement statement = statementContextSupplier.get();

        // WHEN
        Node node = null;
        int labelId = -1;
        try
        {
            node = db.createNode();
            labelId = statement.dataWriteOperations().labelGetOrCreateForName( "labello" );
            statement.dataWriteOperations().nodeAddLabel( node.getId(), labelId );
            statement.close();
            tx.failure();
            tx.success();
            tx.finish();
            fail( "Should have failed" );
        }
        catch ( TransactionFailureException e )
        {   // Expected
        }

        // THEN
        tx = db.beginTx();
        statement = statementContextSupplier.get();
        try
        {
            statement.readOperations().nodeHasLabel( node.getId(), labelId );
            fail( "should have thrown exception" );
        }
        catch ( EntityNotFoundException e )
        {
            // Yay!
        }
        tx.finish();
    }

Try With Resources try(Transaction transaction=db.beginTx()) in method public shouldNotBeAbleToCommitIfFailedTransactionContext() : void from class org.neo4j.kernel.impl.api.integrationtest.KernelIT


    @Test
    public void shouldKillTransactionsOnShutdown() throws Throwable
    {
        // Given
        assumeThat(kernel, instanceOf( Kernel.class ));

        // Then
        try ( KernelTransaction tx = kernel.newTransaction() )
        {
            ((Kernel)kernel).stop();
            tx.acquireStatement().readOperations().nodeExists( 0l );
            fail("Should have been terminated.");
        }
        catch(TransactionTerminatedException e)
        {
            // Success
        }
    }

    @Test
    public void shouldKillTransactionsOnShutdown() throws Throwable
    {
        // Given
        assumeThat(kernel, instanceOf( Kernel.class ));
        KernelTransaction tx = kernel.newTransaction();

        // When
        ((Kernel)kernel).stop();

        // Then
        try
        {
            tx.acquireStatement().readOperations().nodeExists( 0l );
            fail("Should have been terminated.");
        }
        catch(TransactionTerminatedException e)
        {
            // Success
        }
        finally
        {
            tx.close();
        }
    }

Try With Resources try(KernelTransaction tx=kernel.newTransaction()) in method public shouldKillTransactionsOnShutdown() : void from class org.neo4j.kernel.impl.api.integrationtest.KernelIT


            @Override
            public Boolean doWork( Void nothing ) throws Exception
            {
                try ( Transaction tx = db.beginTx() )
                {
                    db.createNode( label( label ) ).setProperty( propertyKey, propertyValue );

                    tx.success();
                    return true;
                }
                catch ( ConstraintViolationException e )
                {
                    return false;
                }
            }

            @Override
            public Boolean doWork( Void nothing ) throws Exception
            {
                Transaction tx = db.beginTx();
                try
                {
                    db.createNode( label( label ) ).setProperty( propertyKey, propertyValue );

                    tx.success();
                    return true;
                }
                catch ( ConstraintViolationException e )
                {
                    return false;
                }
                finally
                {
                    tx.finish();
                }
            }

Try With Resources try(Transaction tx=db.beginTx()) in method public doWork(nothing Void) : Boolean from class org.neo4j.kernel.impl.api.integrationtest.UniquenessConstraintValidationConcurrencyIT.createNode.new OtherThreadExecutor.WorkerCommand<Void,Boolean>


        @Override
        public void run()
        {
            awaitStartSignal();
            while ( failure.get() == null && !stopSignal.get() )
            {
                try ( Transaction tx = db.beginTx() )
                {
                    // ArrayIndexOutOfBoundsException happens here
                    count( parentNode.getRelationships( RELTYPE, OUTGOING ) );

                    parentNode.createRelationshipTo( db.createNode(), RELTYPE );
                    tx.success();
                }
                catch ( Exception e )
                {
                    failure.compareAndSet( null, e );
                }
            }
        }

        @Override
        public void run()
        {
            awaitStartSignal();
            while ( failure.get() == null && !stopSignal.get() )
            {
                Transaction tx = db.beginTx();
                try
                {
                    // ArrayIndexOutOfBoundsException happens here
                    count( parentNode.getRelationships( RELTYPE, OUTGOING ) );

                    parentNode.createRelationshipTo( db.createNode(), RELTYPE );
                    tx.success();
                }
                catch ( Exception e )
                {
                    failure.compareAndSet( null, e );
                }
                finally
                {
                    tx.finish();
                }
            }
        }

Try With Resources try(Transaction tx=db.beginTx()) in method public run() : void from class org.neo4j.kernel.impl.core.ConcurrentCreateAndGetRelationshipsIT.Worker


    private Node createNode( GraphDatabaseService db )
    {
        try ( Transaction tx = db.beginTx() )
        {
            Node node = db.createNode();
            tx.success();
            return node;
        }
    }

    private Node createNode( GraphDatabaseService db )
    {
        Transaction tx = db.beginTx();
        try
        {
            Node node = db.createNode();
            tx.success();
            return node;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method private createNode(db GraphDatabaseService) : Node from class org.neo4j.kernel.impl.core.ConcurrentCreateAndGetRelationshipsIT


        @Override
        public void run()
        {
            while ( true )
            {
                try ( Transaction tx = db.beginTx() )
                {
                    doSomething();
                    tx.success();
                }
                catch ( Throwable t )
                {
                    t.printStackTrace(System.err);
                    System.err.flush();
                    // throw Exceptions.launderedException( t );
                }
            }
        }

        @Override
        public void run()
        {
            while ( true )
            {
                Transaction tx = db.beginTx();
                try
                {
                    doSomething();
                    tx.success();
                }
                catch ( Throwable t )
                {
                    t.printStackTrace(System.err);
                    System.err.flush();
                    // throw Exceptions.launderedException( t );
                }
                finally
                {
                    tx.finish();
                }
            }
        }

Try With Resources try(Transaction tx=db.beginTx()) in method public run() : void from class org.neo4j.kernel.impl.core.ConcurrentPropertyAccessIT.Worker


    private Node[] createInitialNodes()
    {
        Node[] nodes = new Node[100];
        try ( Transaction tx = db.beginTx() )
        {
            for ( int i = 0; i < nodes.length; i++ )
            {
                nodes[i] = db.createNode();
            }
            tx.success();
        }
        return nodes;
    }

    private Node[] createInitialNodes()
    {
        Node[] nodes = new Node[100];
        Transaction tx = db.beginTx();
        try
        {
            for ( int i = 0; i < nodes.length; i++ )
            {
                nodes[i] = db.createNode();
            }
            tx.success();
        }
        finally
        {
            tx.finish();
        }
        return nodes;
    }

Try With Resources try(Transaction tx=db.beginTx()) in method private createInitialNodes() : Node[] from class org.neo4j.kernel.impl.core.ConcurrentPropertyAccessIT


                @Override
                public void run()
                {
                    awaitStartSignalAndRandomTimeLonger( startSignal );
                    try ( Transaction transaction = db.beginTx() )
                    {
                        assertEquals( relCount, count( node.getRelationships() ) );
                    }
                    catch ( Throwable e )
                    {
                        errors.add( e );
                    }
                }

                @Override
                public void run()
                {
                    awaitStartSignalAndRandomTimeLonger( startSignal );
                    Transaction transaction = db.beginTx();
                    try
                    {
                        assertEquals( relCount, count( node.getRelationships() ) );
                    }
                    catch ( Throwable e )
                    {
                        errors.add( e );
                    }
                    finally {
                        transaction.finish();
                    }
                }

Try With Resources try(Transaction transaction=db.beginTx()) in method public run() : void from class org.neo4j.kernel.impl.core.TestConcurrentRelationshipChainLoadingIssue.tryOnce.submit.new Runnable


    private Node createNodeWithRelationships( GraphDatabaseAPI db )
    {
        Node node;
        try ( Transaction tx = db.beginTx() )
        {
            node = db.createNode();
            for ( int i = 0; i < relCount / 2; i++ )
            {
                node.createRelationshipTo( node, MyRelTypes.TEST );
            }
            for ( int i = 0; i < relCount / 2; i++ )
            {
                node.createRelationshipTo( node, MyRelTypes.TEST2 );
            }
            tx.success();
            return node;
        }
    }

    private Node createNodeWithRelationships( GraphDatabaseAPI db )
    {
        Transaction tx = db.beginTx();
        Node node;
        try
        {
            node = db.createNode();
            for ( int i = 0; i < relCount / 2; i++ )
            {
                node.createRelationshipTo( node, MyRelTypes.TEST );
            }
            for ( int i = 0; i < relCount / 2; i++ )
            {
                node.createRelationshipTo( node, MyRelTypes.TEST2 );
            }
            tx.success();
            return node;
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method private createNodeWithRelationships(db GraphDatabaseAPI) : Node from class org.neo4j.kernel.impl.core.TestConcurrentRelationshipChainLoadingIssue


    private void assertPropertyEqual( PropertyContainer primitive, String key,
        String value )
    {
        try ( Transaction tx = getGraphDb().beginTx() )
        {
            assertEquals( value, primitive.getProperty( key ) );
        }
    }

    private void assertPropertyEqual( PropertyContainer primitive, String key,
        String value )
    {
        Transaction tx = getGraphDb().beginTx();
        try
        {
            assertEquals( value, primitive.getProperty( key ) );
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=getGraphDb().beginTx()) in method private assertPropertyEqual(primitive PropertyContainer, key String, value String) : void from class org.neo4j.kernel.impl.core.TestIsolationBasic


    private void assertRelationshipCount( Node node, int count )
    {

        try ( Transaction tx = getGraphDb().beginTx() )
        {
            int actualCount = 0;
            for ( Relationship rel : node.getRelationships() )
            {
                actualCount++;
            }
            assertEquals( count, actualCount );
        }
    }

    private void assertRelationshipCount( Node node, int count )
    {
        Transaction tx = getGraphDb().beginTx();
        try
        {
            int actualCount = 0;
            for ( Relationship rel : node.getRelationships() )
            {
                actualCount++;
            }
            assertEquals( count, actualCount );
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=getGraphDb().beginTx()) in method private assertRelationshipCount(node Node, count int) : void from class org.neo4j.kernel.impl.core.TestIsolationBasic


        @Override
        public Object call()
            throws Exception
        {
            System.out.println( "Start changing data" );
            int totalDeadlocks = 0;
            try
            {
                for (int round = 0; round < 100; round++)
                {
                    int deadLocks = 0;
                    DeadlockDetectedException ex = null;
                    do
                    {
                        ex = null;
                        try ( Transaction tx = database.beginTx() )
                        {
                            for (int i = 0; i < count; i++)
                            {
                                Node node = database.getNodeById( i+1 );
                                int foo = (Integer) node.getProperty( "foo" );
                                node.setProperty( "foo", foo+1 );
                            }

                            tx.success();
                        }
                        catch( DeadlockDetectedException e )
                        {
                            System.out.println("Deadlock detected");
                            deadLocks = deadLocks+1;
                            ex = e;

                            if (deadLocks > 100)
                            {
                                totalDeadlocks += deadLocks;
                                throw e;
                            }
                        }
                    } while (ex != null);

                    totalDeadlocks += deadLocks;
                }
            }
            catch( Exception e )
            {
                e.printStackTrace();
                throw e;
            } finally
            {
                done.set( true );
                System.out.printf( "Done changing data. Detected %d deadlocks\n", totalDeadlocks );
            }

            return null;
        }

        @Override
        public Object call()
            throws Exception
        {
            System.out.println( "Start changing data" );
            int totalDeadlocks = 0;
            try
            {
                for (int round = 0; round < 100; round++)
                {
                    int deadLocks = 0;
                    DeadlockDetectedException ex = null;
                    do
                    {
                        ex = null;
                        Transaction tx = database.beginTx();
                        try
                        {
                            for (int i = 0; i < count; i++)
                            {
                                Node node = database.getNodeById( i+1 );
                                int foo = (Integer) node.getProperty( "foo" );
                                node.setProperty( "foo", foo+1 );
                            }

                            tx.success();
                        }
                        catch( DeadlockDetectedException e )
                        {
                            System.out.println("Deadlock detected");
                            deadLocks = deadLocks+1;
                            ex = e;

                            tx.failure();

                            if (deadLocks > 100)
                            {
                                totalDeadlocks += deadLocks;
                                throw e;
                            }
                        } finally
                        {
                            tx.finish();
                        }
                    } while (ex != null);

                    totalDeadlocks += deadLocks;
                }
            }
            catch( Exception e )
            {
                e.printStackTrace();
                throw e;
            } finally
            {
                done.set( true );
                System.out.printf( "Done changing data. Detected %d deadlocks\n", totalDeadlocks );
            }

            return null;
        }

Try With Resources try(Transaction tx=database.beginTx()) in method public call() : Object from class org.neo4j.kernel.impl.core.TestIsolationMultipleThreads.DataChanger


        @Override
        public void run()
        {
                System.out.println( "Start checking data" );
                double errors = 0;
                double total = 0;
                while(!done.get())
                {
                    try ( Transaction transaction = database.beginTx() )
                    {
                        int firstNode = getFirstValue();
                        int lastNode = getSecondValue();
                        if (firstNode - lastNode != 0)
                        {
                            errors++;
                        }
                        total++;

                        tx.success();
                    }
                }
                double percentage = (errors/total)*100.0;
                System.out.printf( "Done checking data, %1.0f errors found(%1.3f%%)\n", errors, percentage );
        }

        @Override
        public void run()
        {
                System.out.println( "Start checking data" );
                double errors = 0;
                double total = 0;
                while(!done.get())
                {
                    try
                    {
                        tx = database.beginTx();

                        int firstNode = getFirstValue();
                        int lastNode = getSecondValue();
                        if (firstNode - lastNode != 0)
                        {
                            errors++;
                        }
                        total++;

                        tx.success();
                    }
                    finally
                    {
                        tx.finish();
                    }
                }
                double percentage = (errors/total)*100.0;
                System.out.printf( "Done checking data, %1.0f errors found(%1.3f%%)\n", errors, percentage );
        }

Try With Resources try(Transaction transaction=database.beginTx()) in method public run() : void from class org.neo4j.kernel.impl.core.TestIsolationMultipleThreads.DataChecker


        @Override
        public void run()
        {
                System.out.println( "Start checking data" );
                int totalDiff = 0;
                while(!done.get())
                {
                    try ( Transaction tx = database.beginTx() )
                    {
                        int correctValue = -1;
                        int diff = 0;

                        for (int i = 0; i < count; i++)
                        {
                            int foo = getNodeValue( i );

                            if (correctValue == -1)
                                correctValue = foo;

                            diff = diff + foo - correctValue;
                        }

                        totalDiff += diff;
                        tx.success();
                    }
                    catch( Exception e )
                    {
                        e.printStackTrace();
                        tx.failure();
                    }

                }
                System.out.printf( "Done checking data, %d diff\n", totalDiff );
        }

        @Override
        public void run()
        {
                System.out.println( "Start checking data" );
                int totalDiff = 0;
                while(!done.get())
                {
                    try
                    {
                        int correctValue = -1;
                        int diff = 0;
                        tx = database.beginTx();

                        for (int i = 0; i < count; i++)
                        {
                            int foo = getNodeValue( i );

                            if (correctValue == -1)
                                correctValue = foo;

                            diff = diff + foo - correctValue;
                        }

                        totalDiff += diff;
                        tx.success();
                    }
                    catch( Exception e )
                    {
                        e.printStackTrace();
                        tx.failure();
                    } finally
                    {
                        tx.finish();
                    }

                }
                System.out.printf( "Done checking data, %d diff\n", totalDiff );
        }

Try With Resources try(Transaction tx=database.beginTx()) in method public run() : void from class org.neo4j.kernel.impl.core.TestIsolationMultipleThreads.DataChecker2


    private Relationship[] getRelationshipArray(
        Iterable<Relationship> relsIterable )
    {
        ArrayList<Relationship> relList = new ArrayList<>();
        for ( Relationship rel : relsIterable )
        {
            relList.add( rel );
        }
        return relList.toArray( new Relationship[relList.size()] );
    }

    private Relationship[] getRelationshipArray(
        Iterable<Relationship> relsIterable )
    {
        ArrayList<Relationship> relList = new ArrayList<Relationship>();
        for ( Relationship rel : relsIterable )
        {
            relList.add( rel );
        }
        return relList.toArray( new Relationship[relList.size()] );
    }

Replace Generic With Diamond ArrayList<Relationship> with ArrayList<> in method private getRelationshipArray(relsIterable Iterable<Relationship>) : Relationship[] from class org.neo4j.kernel.impl.core.TestNeo4jCacheAndPersistence


    @Test
    public void testLowGrabSize()
    {
        Map<String,String> config = new HashMap<>();
        config.put( "relationship_grab_size", "1" );
        File storeDir = getStorePath( "neo2" );
        deleteFileOrDirectory( storeDir );
        GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( config ).newGraphDatabase();

        Node node1, node2;
        try ( Transaction tx = graphDb.beginTx() )
        {
            node1 = graphDb.createNode();
            node2 = graphDb.createNode();
            node1.createRelationshipTo( node2, MyRelTypes.TEST );
            node2.createRelationshipTo( node1, MyRelTypes.TEST2 );
            node1.createRelationshipTo( node2, MyRelTypes.TEST_TRAVERSAL );
            tx.success();
        }

        try ( Transaction tx = graphDb.beginTx() )
        {
            RelationshipType types[] = new RelationshipType[] {
                MyRelTypes.TEST, MyRelTypes.TEST2, MyRelTypes.TEST_TRAVERSAL };

            assertEquals( 3, count( node1.getRelationships( types ) ) );

            assertEquals( 3, count( node1.getRelationships() ) );

            assertEquals( 3, count( node2.getRelationships( types ) ) );

            assertEquals( 3, count( node2.getRelationships() ) );

            assertEquals( 2, count( node1.getRelationships( OUTGOING ) ) );

            assertEquals( 1, count( node1.getRelationships( INCOMING ) ) );

            assertEquals( 1, count( node2.getRelationships( OUTGOING ) ) );

            assertEquals( 2, count( node2.getRelationships( INCOMING ) ) );

            tx.success();
        }
        graphDb.shutdown();
    }

    @Test
    public void testLowGrabSize()
    {
        Map<String,String> config = new HashMap<String,String>();
        config.put( "relationship_grab_size", "1" );
        File storeDir = getStorePath( "neo2" );
        deleteFileOrDirectory( storeDir );
        GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig( config ).newGraphDatabase();

        Node node1, node2;
        try ( Transaction tx = graphDb.beginTx() )
        {
            node1 = graphDb.createNode();
            node2 = graphDb.createNode();
            node1.createRelationshipTo( node2, MyRelTypes.TEST );
            node2.createRelationshipTo( node1, MyRelTypes.TEST2 );
            node1.createRelationshipTo( node2, MyRelTypes.TEST_TRAVERSAL );
            tx.success();
        }

        try ( Transaction tx = graphDb.beginTx() )
        {
            RelationshipType types[] = new RelationshipType[] {
                MyRelTypes.TEST, MyRelTypes.TEST2, MyRelTypes.TEST_TRAVERSAL };

            assertEquals( 3, count( node1.getRelationships( types ) ) );

            assertEquals( 3, count( node1.getRelationships() ) );

            assertEquals( 3, count( node2.getRelationships( types ) ) );

            assertEquals( 3, count( node2.getRelationships() ) );

            assertEquals( 2, count( node1.getRelationships( OUTGOING ) ) );

            assertEquals( 1, count( node1.getRelationships( INCOMING ) ) );

            assertEquals( 1, count( node2.getRelationships( OUTGOING ) ) );

            assertEquals( 2, count( node2.getRelationships( INCOMING ) ) );

            tx.success();
        }
        graphDb.shutdown();
    }

Replace Generic With Diamond HashMap<String,String> with HashMap<> in method public testLowGrabSize() : void from class org.neo4j.kernel.impl.core.TestNeo4jCacheAndPersistence


    @Test
    public void name() throws Exception
    {
        Node node = getGraphDb().createNode();
        node.setProperty( "name", "yo" );
        node.getProperty( "name" );
        commit();

        try ( Transaction tx = getGraphDb().beginTx() )
        {
            node.getProperty( "name" );
            tx.success();
        }
    }

    @Test
    public void name() throws Exception
    {
        Node node = getGraphDb().createNode();
        node.setProperty( "name", "yo" );
        node.getProperty( "name" );
        commit();

        Transaction tx = getGraphDb().beginTx();
        try
        {
            node.getProperty( "name" );
           tx.success();
        }
        finally
        {
            //noinspection deprecation
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=getGraphDb().beginTx()) in method public name() : void from class org.neo4j.kernel.impl.core.TestProperties


    @Test
    public void testSimple()
    {
        DbRepresentation someData = createSomeData();
        GraphDatabaseService readGraphDb = new TestGraphDatabaseFactory().setFileSystem( fs.get() )
                .newImpermanentDatabaseBuilder( PATH )
                .setConfig( GraphDatabaseSettings.read_only, Settings.TRUE )
                .newGraphDatabase();
        assertEquals( someData, DbRepresentation.of( readGraphDb ) );

        try (Transaction tx = readGraphDb.beginTx())
        {
            readGraphDb.createNode();

            tx.success();
        }
        catch ( TransactionFailureException e )
        {
            // good
            assertThat(e.getCause(), instanceOf( ReadOnlyDbException.class ));
        }
        readGraphDb.shutdown();
    }

    @Test
    public void testSimple()
    {
        DbRepresentation someData = createSomeData();
        GraphDatabaseService readGraphDb = new TestGraphDatabaseFactory().setFileSystem( fs.get() )
                .newImpermanentDatabaseBuilder( PATH )
                .setConfig( GraphDatabaseSettings.read_only, Settings.TRUE )
                .newGraphDatabase();
        assertEquals( someData, DbRepresentation.of( readGraphDb ) );

        Transaction tx = readGraphDb.beginTx();
        try
        {
            readGraphDb.createNode();

            tx.success();
            tx.close();

            fail( "expected exception" );
        }
        catch ( TransactionFailureException e )
        {
            // good
            assertThat(e.getCause(), instanceOf( ReadOnlyDbException.class ));
        }
        readGraphDb.shutdown();
    }

Try With Resources try(Transaction tx=readGraphDb.beginTx()) in method public testSimple() : void from class org.neo4j.kernel.impl.core.TestReadOnlyNeo4j


    @Test
    public void deleteRelationshipFromNotFullyLoadedNode() throws Exception
    {
        beginTx();
        Node node1 = db.createNode();
        Node node2 = db.createNode();
        Node node3 = db.createNode();
        RelationshipType type1 = DynamicRelationshipType.withName( "type1" );
        RelationshipType type2 = DynamicRelationshipType.withName( "type2" );
        // This will the last relationship in the chain
        node1.createRelationshipTo( node3, type1 );
        Collection<Relationship> type2Relationships = new HashSet<>();
        // Create exactly grabSize relationships and store them in a set
        for ( int i = 0; i < GRAB_SIZE; i++ )
        {
            type2Relationships.add( node1.createRelationshipTo( node2, type2 ) );
        }
        finishTx( true );

        /*
         * Here node1 has grabSize+1 relationships. The first grabSize to be loaded will be
         * the type2 ones to node2 and the one remaining will be the type1 to node3.
         */

        beginTx();
        node1 = db.getNodeById( node1.getId() );
        node2 = db.getNodeById( node2.getId() );
        node3 = db.getNodeById( node3.getId() );

        // Will load <grabsize> relationships, not all, and not relationships of
        // type1 since it's the last one (the 11'th) in the chain.
        node1.getRelationships().iterator().next();

        // Delete the non-grabbed (from node1 POV) relationship
        node3.getRelationships().iterator().next().delete();
        // Just making sure
        assertFalse( node3.getRelationships().iterator().hasNext() );

        /*
         *  Now all Relationships left on node1 should be of type2
         *  This also checks that deletes on relationships are visible in the same tx.
         */
        assertEquals( type2Relationships, addToCollection( node1.getRelationships(), new HashSet<Relationship>() ) );

        finishTx( true );
        beginTx();
        assertEquals( type2Relationships, addToCollection( node1.getRelationships(), new HashSet<Relationship>() ) );
        finishTx( false );
    }

    @Test
    public void deleteRelationshipFromNotFullyLoadedNode() throws Exception
    {
        beginTx();
        Node node1 = db.createNode();
        Node node2 = db.createNode();
        Node node3 = db.createNode();
        RelationshipType type1 = DynamicRelationshipType.withName( "type1" );
        RelationshipType type2 = DynamicRelationshipType.withName( "type2" );
        // This will the last relationship in the chain
        node1.createRelationshipTo( node3, type1 );
        Collection<Relationship> type2Relationships = new HashSet<Relationship>();
        // Create exactly grabSize relationships and store them in a set
        for ( int i = 0; i < GRAB_SIZE; i++ )
        {
            type2Relationships.add( node1.createRelationshipTo( node2, type2 ) );
        }
        finishTx( true );

        /*
         * Here node1 has grabSize+1 relationships. The first grabSize to be loaded will be
         * the type2 ones to node2 and the one remaining will be the type1 to node3.
         */

        beginTx();
        node1 = db.getNodeById( node1.getId() );
        node2 = db.getNodeById( node2.getId() );
        node3 = db.getNodeById( node3.getId() );

        // Will load <grabsize> relationships, not all, and not relationships of
        // type1 since it's the last one (the 11'th) in the chain.
        node1.getRelationships().iterator().next();

        // Delete the non-grabbed (from node1 POV) relationship
        node3.getRelationships().iterator().next().delete();
        // Just making sure
        assertFalse( node3.getRelationships().iterator().hasNext() );

        /*
         *  Now all Relationships left on node1 should be of type2
         *  This also checks that deletes on relationships are visible in the same tx.
         */
        assertEquals( type2Relationships, addToCollection( node1.getRelationships(), new HashSet<Relationship>() ) );

        finishTx( true );
        beginTx();
        assertEquals( type2Relationships, addToCollection( node1.getRelationships(), new HashSet<Relationship>() ) );
        finishTx( false );
    }

Replace Generic With Diamond HashSet<Relationship> with HashSet<> in method public deleteRelationshipFromNotFullyLoadedNode() : void from class org.neo4j.kernel.impl.core.TestRelationshipGrabSize


    private void createNodeWithBigArray( GraphDatabaseService db )
    {
        try ( Transaction tx = db.beginTx() )
        {
            Node node = db.createNode();
            node.setProperty( "prop", randomBigByteArray() );
            tx.success();
        }
    }

    private void createNodeWithBigArray( GraphDatabaseService db )
    {
        Transaction tx = db.beginTx();
        try
        {
            Node node = db.createNode();
            node.setProperty( "prop", randomBigByteArray() );
            tx.success();
        }
        finally
        {
            tx.finish();
        }
    }

Try With Resources try(Transaction tx=db.beginTx()) in method private createNodeWithBigArray(db GraphDatabaseService) : void from class org.neo4j.kernel.impl.store.LargeByteArraysIT


    @Test
    public void testEquals()
    {
        GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase();
        PropertyContainer graphProperties = properties( db );
        try ( Transaction tx = db.beginTx() )
        {
            graphProperties.setProperty( "test", "test" );
            tx.success();
        }

        assertEquals( graphProperties, properties( db ) );
        db.shutdown();
        db = (GraphDatabaseAPI) factory.newImpermanentDatabase();
        assertFalse( graphProperties.equals( properties( db ) ) );
        db.shutdown();
    }

    @Test
    public void testEquals()
    {
        GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase();
        PropertyContainer graphProperties = properties( db );
        Transaction tx = db.beginTx();
        try
        {
            graphProperties.setProperty( "test", "test" );
            tx.success();
        }
        finally
        {
            tx.finish();
        }

        assertEquals( graphProperties, properties( db ) );
        db.shutdown();
        db = (GraphDatabaseAPI) factory.newImpermanentDatabase();
        assertFalse( graphProperties.equals( properties( db ) ) );
        db.shutdown();
    }

Try With Resources try(Transaction tx=db.beginTx()) in method public testEquals() : void from class org.neo4j.kernel.impl.store.TestGraphProperties


    @Test
    public void concurrentlyCommittingTransactionsMustNotRotateOutLoggedCommandsOfFailingTransaction()
            throws Exception
    {
        final ClassGuardedAdversary adversary = new ClassGuardedAdversary(
                new CountingAdversary( 1, false ),
                "org.neo4j.kernel.impl.nioneo.xa.Command$RelationshipCommand" );
        adversary.disable();

        File storeDir = dir.graphDbDir();
        final Map<String,String> params = stringMap( GraphDatabaseSettings.pagecache_memory.name(), "8m" );
        final EmbeddedGraphDatabase db = new TestEmbeddedGraphDatabase( storeDir, params )
        {
            @Override
            protected void create( File storeDir, Map<String, String> params, GraphDatabaseFacadeFactory.Dependencies dependencies )
            {
                new CommunityFacadeFactory()
                {
                    @Override
                    protected PlatformModule createPlatform( File storeDir, Map<String, String> params, Dependencies dependencies, GraphDatabaseFacade graphDatabaseFacade )
                    {
                        return new PlatformModule( storeDir, params, dependencies, graphDatabaseFacade )
                        {
                            @Override
                            protected FileSystemAbstraction createFileSystemAbstraction()
                            {
                                return new AdversarialFileSystemAbstraction( adversary );
                            }
                        };
                    }
                }.newFacade( storeDir, params, dependencies, this );
            }
        };

        Node a, b, c, d;
        try ( Transaction tx = db.beginTx() )
        {
            a = db.createNode();
            b = db.createNode();
            c = db.createNode();
            d = db.createNode();
            tx.success();
        }

        adversary.enable();
        CountDownLatch latch = new CountDownLatch( 1 );
        Thread t1 = new Thread( createRelationship( db, a, b, latch ), "T1" );
        Thread t2 = new Thread( createRelationship( db, c, d, latch ), "T2" );
        t1.start();
        t2.start();
        // Wait for both threads to get going
        t1.join( 10 );
        t2.join( 10 );
        latch.countDown();

        // Wait for the transactions to finish
        t1.join( 25000 );
        t2.join( 25000 );
        db.shutdown();

        // We should observe the store in a consistent state
        EmbeddedGraphDatabase db2 = new TestEmbeddedGraphDatabase( storeDir, params );
        try ( Transaction tx = db2.beginTx() )
        {
            Node x = db2.getNodeById( a.getId() );
            Node y = db2.getNodeById( b.getId() );
            Node z = db2.getNodeById( c.getId() );
            Node w = db2.getNodeById( d.getId() );
            Iterator<Relationship> itrRelX = x.getRelationships().iterator();
            Iterator<Relationship> itrRelY = y.getRelationships().iterator();
            Iterator<Relationship> itrRelZ = z.getRelationships().iterator();
            Iterator<Relationship> itrRelW = w.getRelationships().iterator();

            if ( itrRelX.hasNext() != itrRelY.hasNext() )
            {
                fail( "Node x and y have inconsistent relationship counts" );
            }
            else if ( itrRelX.hasNext() )
            {
                Relationship rel = itrRelX.next();
                assertEquals( rel, itrRelY.next() );
                assertFalse( itrRelX.hasNext() );
                assertFalse( itrRelY.hasNext() );
            }

            if ( itrRelZ.hasNext() != itrRelW.hasNext() )
            {
                fail( "Node z and w have inconsistent relationship counts" );
            }
            else if ( itrRelZ.hasNext() )
            {
                Relationship rel = itrRelZ.next();
                assertEquals( rel, itrRelW.next() );
                assertFalse( itrRelZ.hasNext() );
                assertFalse( itrRelW.hasNext() );
            }
        }
        finally
        {
            db2.shutdown();
        }
    }

    @Test
    public void concurrentlyCommittingTransactionsMustNotRotateOutLoggedCommandsOfFailingTransaction()
            throws Exception
    {
        final ClassGuardedAdversary adversary = new ClassGuardedAdversary(
                new CountingAdversary( 1, false ),
                "org.neo4j.kernel.impl.nioneo.xa.Command$RelationshipCommand" );
        adversary.disable();

        File storeDir = dir.graphDbDir();
        final Map<String,String> params = stringMap( GraphDatabaseSettings.pagecache_memory.name(), "8m" );
        final EmbeddedGraphDatabase db = new TestEmbeddedGraphDatabase( storeDir, params )
        {
            @Override
            protected void create( File storeDir, Map<String, String> params, GraphDatabaseFacadeFactory.Dependencies dependencies )
            {
                new CommunityFacadeFactory()
                {
                    @Override
                    protected PlatformModule createPlatform( File storeDir, Map<String, String> params, Dependencies dependencies, GraphDatabaseFacade graphDatabaseFacade )
                    {
                        return new PlatformModule( storeDir, params, dependencies, graphDatabaseFacade )
                        {
                            @Override
                            protected FileSystemAbstraction createFileSystemAbstraction()
                            {
                                return new AdversarialFileSystemAbstraction( adversary );
                            }
                        };
                    }
                }.newFacade( storeDir, params, dependencies, this );
            }
        };

        Node a, b, c, d;
        Transaction tx = db.beginTx();
        try
        {
            a = db.createNode();
            b = db.createNode();
            c = db.createNode();
            d = db.createNode();
            tx.success();
        }
        finally
        {
            tx.finish();
        }

        adversary.enable();
        CountDownLatch latch = new CountDownLatch( 1 );
        Thread t1 = new Thread( createRelationship( db, a, b, latch ), "T1" );
        Thread t2 = new Thread( createRelationship( db, c, d, latch ), "T2" );
        t1.start();
        t2.start();
        // Wait for both threads to get going
        t1.join( 10 );
        t2.join( 10 );
        latch.countDown();

        // Wait for the transactions to finish
        t1.join( 25000 );
        t2.join( 25000 );
        db.shutdown();

        // We should observe the store in a consistent state
        EmbeddedGraphDatabase db2 = new TestEmbeddedGraphDatabase( storeDir, params );
        tx = db2.beginTx();
        try
        {
            Node x = db2.getNodeById( a.getId() );
            Node y = db2.getNodeById( b.getId() );
            Node z = db2.getNodeById( c.getId() );
            Node w = db2.getNodeById( d.getId() );
            Iterator<Relationship> itrRelX = x.getRelationships().iterator();
            Iterator<Relationship> itrRelY = y.getRelationships().iterator();
            Iterator<Relationship> itrRelZ = z.getRelationships().iterator();
            Iterator<Relationship> itrRelW = w.getRelationships().iterator();

            if ( itrRelX.hasNext() != itrRelY.hasNext() )
            {
                fail( "Node x and y have inconsistent relationship counts" );
            }
            else if ( itrRelX.hasNext() )
            {
                Relationship rel = itrRelX.next();
                assertEquals( rel, itrRelY.next() );
                assertFalse( itrRelX.hasNext() );
                assertFalse( itrRelY.hasNext() );
            }

            if ( itrRelZ.hasNext() != itrRelW.hasNext() )
            {
                fail( "Node z and w have inconsistent relationship counts" );
            }
            else if ( itrRelZ.hasNext() )
            {
                Relationship rel = itrRelZ.next();
                assertEquals( rel, itrRelW.next() );
                assertFalse( itrRelZ.hasNext() );
                assertFalse( itrRelW.hasNext() );
            }
        }
        finally
        {
            try
            {
                tx.finish();
            }
            finally
            {
                db2.shutdown();
            }
        }
    }

Try With Resources try(Transaction tx=db2.beginTx()) in method public concurrentlyCommittingTransactionsMustNotRotateOutLoggedCommandsOfFailingTransaction() : void from class org.neo4j.kernel.impl.transaction.PartialTransactionFailureIT


            @Override
            public void run()
            {
                try ( Transaction tx = db.beginTx() )
                {
                    x.createRelationshipTo( y, DynamicRelationshipType.withName( "r" ) );
                    tx.success();
                    latch.await();
                    db.getDependencyResolver().resolveDependency( LogRotation.class ).rotateLogFile();
                }
                catch ( Exception ignore )
                {
                    // We don't care about our transactions failing, as long as we
                    // can recover our database to a consistent state.
                }
            }

            @Override
            public void run()
            {
                Transaction tx = db.beginTx();
                try
                {
                    x.createRelationshipTo( y, DynamicRelationshipType.withName( "r" ) );
                    tx.success();
                    latch.await();
                    db.getDependencyResolver().resolveDependency( LogRotation.class ).rotateLogFile();
                    tx.finish();
                }
                catch ( Exception ignore )
                {
                    // We don't care about our transactions failing, as long as we
                    // can recover our database to a consistent state.
                }
            }

Try With Resources try(Transaction tx=db.beginTx()) in method public run() : void from class org.neo4j.kernel.impl.transaction.PartialTransactionFailureIT.createRelationship.new Runnable