Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2002-2014 "Neo Technology," Network Engine for Objects in Lund AB [http://neotechnology.com] This file is part of Neo4j. Neo4j is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 package visibility;
 
 
 import org.junit.Test;
 
 
 import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertThat;
 
 {
     private static final String INDEX_NAME = "foo";
     private static final String INDEX_KEY = "bar";
     private static final String INDEX_VALUE = "baz";
     private static final String PROPERTY_NAME = "quux";
     private static final int PROPERTY_VALUE = 42;
 
 
     @Before
     public void setUp() throws Exception
     {
     }
 
     @Test
     public void shouldNotMakeIndexWritesVisibleUntilCommit() throws Exception
     {
         Node commonNode;
         try(Transaction tx = .beginTx())
         {
             commonNode = .createNode();
             tx.success();
         }
 
         try(Transaction transaction = .beginTx())
         {
             // index write first so that that datastore is added first
             .index().forNodes ).addcommonNode );
             commonNode.setProperty );
 
             assertNodeIsUnchangedOutsideThisTransaction(commonNode);
 
             transaction.success();
 
             assertNodeIsUnchangedOutsideThisTransaction(commonNode);
         }
 
         assertNodeIsIndexed(commonNode);
         assertNodeHasBeenUpdatedcommonNode );
     }
 
     private void assertNodeIsNotIndexedOutsideThisTransaction() throws Exception
     {
         final Collection<Exceptionproblems = new HashSet<>();
 
         Thread thread = new Threadnew Runnable()
         {
             @Override
             public void run()
             {
                 try(Transaction ignored = .beginTx())
                 {
                     assertThat.index().forNodes ).get,
                              ).size(), is( 0 ) );
                 }
                 catch ( Throwable t )
                 {
                     problems.addnew Exceptiont ) );
                 }
             }
        } );
        thread.start();
        thread.join();
        if ( problems.size() > 0 )
        {
            throw problems.iterator().next();
        }
    }
    private void assertNodeIsUnchangedOutsideThisTransactionfinal Node commonNode ) throws Exception
    {
        final Collection<Exceptionproblems = new HashSet<>();
        Thread thread = new Threadnew Runnable()
        {
            @Override
            public void run()
            {
                try(Transaction ignored = .beginTx())
                {
                    assertThatcommonNode.hasProperty ), isfalse ) );
                }
                catch ( Throwable t )
                {
                    problems.addnew Exceptiont ) );
                }
            }
        } );
        thread.start();
        thread.join();
        if ( problems.size() > 0 )
        {
            throw problems.iterator().next();
        }
    }
    private void assertNodeIsIndexed(final Node commonNodethrows Exception
    {
        final Collection<Exceptionproblems = new HashSet<>();
        Thread thread = new Threadnew Runnable()
        {
            @Override
            public void run()
            {
                try(Transaction ignored = .beginTx())
                {
                    Node node = .index().forNodes ).get,
                             ).getSingle();
                    assertThatnodeiscommonNode) );
                }
                catch ( Throwable t )
                {
                    problems.addnew Exceptiont ) );
                }
            }
        } );
        thread.start();
        thread.join();
        if ( problems.size() > 0 )
        {
            throw problems.iterator().next();
        }
    }
    private void assertNodeHasBeenUpdatedfinal Node commonNode ) throws Exception
    {
        final Collection<Exceptionproblems = new HashSet<>();
        Thread thread = new Threadnew Runnable()
        {
            @Override
            public void run()
            {
                try(Transaction ignored = .beginTx())
                {
                    assertThat( (IntegercommonNode.getProperty ),
                            is ) );
                }
                catch ( Throwable t )
                {
                    problems.addnew Exceptiont ) );
                }
            }
        } );
        thread.start();
        thread.join();
        if ( problems.size() > 0 )
        {
            throw problems.iterator().next();
        }
    }
New to GrepCode? Check out our FAQ X