Skip to content

Commit

Permalink
Forces the test to fail if any worker encounter an exception
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint committed Jun 13, 2012
1 parent c665994 commit bb1bc7b
Showing 1 changed file with 18 additions and 5 deletions.
Expand Up @@ -25,6 +25,7 @@
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.concurrent.atomic.AtomicReference;

import org.junit.Test;
import org.neo4j.graphdb.GraphDatabaseService;
Expand Down Expand Up @@ -68,7 +69,6 @@ class ThreadRunner implements Runnable
this.impl = impl;
}


private Node createNode()
{
Transaction tx = graphdb().beginTx();
Expand All @@ -90,19 +90,28 @@ public void run()
final Node lockNode = createNode();
final List<List<Node>> results = new ArrayList<List<Node>>();
final List<Thread> threads = new ArrayList<Thread>();
final AtomicReference<RuntimeException> failure = new AtomicReference<RuntimeException>();
for ( int i = 0; i < 10; i++ )
{
threads.add( new Thread()
{
@Override
public void run()
{
List<Node> subresult = new ArrayList<Node>();
for ( int j = 0; j < NUM_USERS; j++ )
try
{
List<Node> subresult = new ArrayList<Node>();
for ( int j = 0; j < NUM_USERS; j++ )
{
subresult.add( impl.getOrCreateUser( getUsername( j ), graphdb(), lockNode ) );
}
results.add( subresult );
}
catch ( RuntimeException e )
{
subresult.add( impl.getOrCreateUser( getUsername( j ), graphdb(), lockNode ) );
failure.compareAndSet( null, e );
throw e;
}
results.add( subresult );
}
} );
}
Expand All @@ -121,6 +130,10 @@ public void run()
e.printStackTrace();
}
}

if ( failure.get() != null )
throw failure.get();

List<Node> first = results.remove( 0 );
for ( List<Node> subresult : results )
{
Expand Down

0 comments on commit bb1bc7b

Please sign in to comment.