Skip to content

Commit

Permalink
reintroduce the flaky test with some extra debugging to figure out wh…
Browse files Browse the repository at this point in the history
…at's going on
  • Loading branch information
Mark Needham committed Oct 25, 2016
1 parent 3445f03 commit 5dec65a
Showing 1 changed file with 48 additions and 1 deletion.
Expand Up @@ -23,17 +23,21 @@
import org.junit.Rule;
import org.junit.Test;

import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Stream;

import org.neo4j.causalclustering.core.CoreGraphDatabase;
import org.neo4j.causalclustering.core.consensus.roles.Role;
import org.neo4j.causalclustering.discovery.Cluster;
import org.neo4j.causalclustering.discovery.CoreClusterMember;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.ResourceIterable;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.security.WriteOperationsNotAllowedException;
import org.neo4j.helpers.collection.Iterables;
import org.neo4j.test.causalclustering.ClusterRule;

import static org.hamcrest.CoreMatchers.containsString;
Expand All @@ -43,6 +47,7 @@
import static org.neo4j.causalclustering.discovery.Cluster.dataMatchesEventually;
import static org.neo4j.function.Predicates.await;
import static org.neo4j.graphdb.Label.label;
import static org.neo4j.helpers.collection.Iterables.asList;
import static org.neo4j.helpers.collection.Iterables.count;

public class CoreReplicationIT
Expand Down Expand Up @@ -120,7 +125,7 @@ public void shouldNotAllowSchemaChangesFromAFollower() throws Exception
}

@Test
public void shouldNotAllowTokenCreationFromAFollower() throws Exception
public void shouldNotAllowTokenCreationFromAFollowerWithNoInitialTokens() throws Exception
{
// given
CoreClusterMember leader = cluster.coreTx( ( db, tx ) ->
Expand Down Expand Up @@ -148,6 +153,48 @@ public void shouldNotAllowTokenCreationFromAFollower() throws Exception
}
}

@Test
public void shouldNotAllowTokenCreationFromAFollower() throws Exception
{
// given
Label personLabel = Label.label( "Person" );

CoreClusterMember leader = cluster.coreTx( ( db, tx ) ->
{
db.createNode( personLabel );
tx.success();
} );

awaitForDataToBeApplied( leader );
dataMatchesEventually( leader, cluster.coreMembers() );

CoreClusterMember followerMember = cluster.getDbWithRole( Role.FOLLOWER );
CoreGraphDatabase follower = followerMember.database();

try(Transaction tx = follower.beginTx())
{
System.out.println( "all labels = " + asList( follower.getAllLabels() ) );

for ( Node node : follower.getAllNodes() )
{
System.out.println( "node = " + node + ", " + node.getLabels().toString());
}
}

// when
try ( Transaction tx = follower.beginTx() )
{
follower.findNodes(personLabel).next().setProperty( "name", "Mark" );
tx.success();
fail( "Should have thrown exception" );
}
catch ( WriteOperationsNotAllowedException ignored )
{
// expected
assertThat( ignored.getMessage(), containsString( "No write operations are allowed" ) );
}
}

private void awaitForDataToBeApplied( CoreClusterMember leader ) throws InterruptedException, TimeoutException
{
await( () -> countNodes(leader) > 0, 10, TimeUnit.SECONDS);
Expand Down

0 comments on commit 5dec65a

Please sign in to comment.