forked from eldersantos/community
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a failing test case for a data visibility issue for newly creat…
…ed primitives
- Loading branch information
Showing
1 changed file
with
145 additions
and
0 deletions.
There are no files selected for viewing
145 changes: 145 additions & 0 deletions
145
neo4j/src/test/java/visibility/TestPropertyReadOnNewEntityBeforeLockRelease.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/** | ||
* Copyright (c) 2002-2011 "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 java.util.concurrent.CountDownLatch; | ||
|
||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.neo4j.graphdb.Node; | ||
import org.neo4j.graphdb.Transaction; | ||
import org.neo4j.kernel.AbstractGraphDatabase; | ||
import org.neo4j.kernel.impl.core.LockReleaser; | ||
import org.neo4j.test.AbstractSubProcessTestBase; | ||
import org.neo4j.test.subprocess.BreakPoint; | ||
import org.neo4j.test.subprocess.DebugInterface; | ||
import org.neo4j.test.subprocess.DebuggedThread; | ||
import org.neo4j.test.subprocess.KillSubProcess; | ||
|
||
@Ignore( "fix not available yet" ) | ||
@SuppressWarnings( "serial" ) | ||
public class TestPropertyReadOnNewEntityBeforeLockRelease extends AbstractSubProcessTestBase | ||
{ | ||
private final CountDownLatch latch1 = new CountDownLatch( 1 ), latch2 = new CountDownLatch( 1 ); | ||
|
||
@Test | ||
public void shouldBeAbleToReadPropertiesFromNewNodeReturnedFromIndex() throws Exception | ||
{ | ||
runInThread( new CreateData() ); | ||
latch1.await(); | ||
run( new ReadData() ); | ||
latch2.await(); | ||
} | ||
|
||
private static class CreateData implements Task | ||
{ | ||
@Override | ||
public void run( AbstractGraphDatabase graphdb ) | ||
{ | ||
Transaction tx = graphdb.beginTx(); | ||
try | ||
{ | ||
Node node = graphdb.createNode(); | ||
node.setProperty( "value", "present" ); | ||
graphdb.index().forNodes( "nodes" ).add( node, "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 run( AbstractGraphDatabase graphdb ) | ||
{ | ||
Node node = graphdb.index().forNodes( "nodes" ).get( "value", "present" ).getSingle(); | ||
assertNotNull( "did not get the node from the index", node ); | ||
assertEquals( "present", node.getProperty( "value" ) ); | ||
resumeThread(); | ||
} | ||
} | ||
|
||
private volatile DebuggedThread thread; | ||
private final BreakPoint lockReleaserCommit = new BreakPoint( LockReleaser.class, "commit" ) | ||
{ | ||
@Override | ||
protected void callback( DebugInterface debug ) throws KillSubProcess | ||
{ | ||
thread = debug.thread().suspend( this ); | ||
this.disable(); | ||
latch1.countDown(); | ||
} | ||
}, enableBreakPoints = new BreakPoint( TestPropertyReadOnNewEntityBeforeLockRelease.class, "enableBreakPoints" ) | ||
{ | ||
@Override | ||
protected void callback( DebugInterface debug ) throws KillSubProcess | ||
{ | ||
lockReleaserCommit.enable(); | ||
this.disable(); | ||
} | ||
}, resumeThread = new BreakPoint( TestPropertyReadOnNewEntityBeforeLockRelease.class, "resumeThread" ) | ||
{ | ||
@Override | ||
protected void callback( DebugInterface debug ) throws KillSubProcess | ||
{ | ||
thread.resume(); | ||
this.disable(); | ||
} | ||
}, done = new BreakPoint( TestPropertyReadOnNewEntityBeforeLockRelease.class, "done" ) | ||
{ | ||
@Override | ||
protected void callback( DebugInterface debug ) throws KillSubProcess | ||
{ | ||
latch2.countDown(); | ||
this.disable(); | ||
} | ||
}; | ||
|
||
@Override | ||
protected BreakPoint[] breakpoints( int id ) | ||
{ | ||
return new BreakPoint[] { lockReleaserCommit, enableBreakPoints.enable(), resumeThread, done.enable() }; | ||
} | ||
} |