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 static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
 
 import org.junit.Test;
 
 @SuppressWarnings"serial" )
 {
     private final CountDownLatch latch1 = new CountDownLatch( 1 ), latch2 = new CountDownLatch( 1 );
 
     @Test
     {
         runInThreadnew CreateData() );
         ..println("Awaiting first latch..");
         .await();
         ..println("Ok, reading..");
         runnew ReadData() );
         ..println("Awaiting second latch..");
         .await();
     }
 
     private static class CreateData implements Task
     {
         @Override
         public void runGraphDatabaseAPI graphdb )
         {
             Transaction tx = graphdb.beginTx();
             try
             {
                 Node node = graphdb.createNode();
                 node.setProperty"value""present" );
                 graphdb.index().forNodes"nodes" ).addnode"value""present" );
                 enableBreakPoints();
 
                 tx.success();
             }
             finally
             {
                 tx.finish();
             }
             done();
         }
     }
 
     static void enableBreakPoints()
     {
         // triggers breakpoint
     }
 
     static void done()
     {
         // triggers breakpoint
     }
 
     static void resumeThread()
     {
         // triggers breakpoint
     }
 
     private static class ReadData implements Task
     {
         @Override
         public void runGraphDatabaseAPI graphdb )
         {
             ..println("Fetching node");
            Node node = graphdb.index().forNodes"nodes" ).get"value""present" ).getSingle();
            ..println("Got node");
            assertNotNull"did not get the node from the index"node );
            assertEquals"present"node.getProperty"value" ) );
            ..println("Resuming thread");
            resumeThread();
        }
    }
    private volatile DebuggedThread thread;
    private final BreakPoint lockReleaserCommit = new BreakPointWritableTransactionState.class"commit" )
    {
        @Override
        protected void callbackDebugInterface debug ) throws KillSubProcess
        {
             = debug.thread().suspendthis );
            .enable();
            this.disable();
            .countDown();
        }
    }, enableBreakPoints = new BreakPointTestPropertyReadOnNewEntityBeforeLockRelease.class"enableBreakPoints" )
    {
        @Override
        protected void callbackDebugInterface debug ) throws KillSubProcess
        {
            .enable();
            this.disable();
        }
    }, resumeThread = new BreakPointTestPropertyReadOnNewEntityBeforeLockRelease.class"resumeThread" )
    {
        @Override
        protected void callbackDebugInterface debug ) throws KillSubProcess
        {
            .resume();
            this.disable();
        }
    }, done = new BreakPointTestPropertyReadOnNewEntityBeforeLockRelease.class"done" )
    {
        @Override
        protected void callbackDebugInterface debug ) throws KillSubProcess
        {
            .countDown();
            this.disable();
        }
    };
    @Override
    protected BreakPoint[] breakpointsint id )
    {
        return new BreakPoint[] { .enable(), .enable() };
    }

    
Version of the test case useful for manual debugging.
    public static void mainString... args ) throws Exception
    {
        final GraphDatabaseAPI graphdb = (GraphDatabaseAPInew GraphDatabaseFactory().
                                                  newEmbeddedDatabase"target/test-data/" + TestPropertyReadOnNewEntityBeforeLockRelease.class
                                                      .getName() + "/graphdb" );
        final CountDownLatch completion = new CountDownLatch( 2 );
        class TaskRunner implements Runnable
        {
            private final Task task;
            TaskRunnerTask task )
            {
                this. = task;
            }
            @Override
            public void run()
            {
                try
                {
                    .rungraphdb );
                }
                finally
                {
                    completion.countDown();
                }
            }
        }
        new Threadnew TaskRunnernew CreateData() ) ).start();
        new Threadnew TaskRunnernew ReadData() ) ).start();
        try
        {
            completion.await();
        }
        finally
        {
            graphdb.shutdown();
        }
    }
New to GrepCode? Check out our FAQ X