Skip to content

Commit

Permalink
Do not use ClusterRule as @ClassRule
Browse files Browse the repository at this point in the history
Logs are always deleted when using ClusterRule as a @ClassRule due to
limitation of the TestDirectory rule.  The problem is that if the
latter is used in a static context cannot see single test failures,
hence it will effectively delete the files on disk. This is
problematic when there are failures in CI and we need logs to
understand what happened for debugging purposes.

This commit fix such problems.
  • Loading branch information
davidegrohmann committed Aug 24, 2016
1 parent d124063 commit 3b87c22
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 92 deletions.
38 changes: 18 additions & 20 deletions enterprise/ha/src/test/java/jmx/HaBeanIT.java
Expand Up @@ -19,7 +19,7 @@
*/
package jmx;

import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

import java.net.URI;
Expand Down Expand Up @@ -47,17 +47,15 @@
import org.neo4j.management.Neo4jManager;
import org.neo4j.test.ha.ClusterRule;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import static java.util.concurrent.TimeUnit.SECONDS;

import static org.neo4j.kernel.configuration.Settings.STRING;
import static org.neo4j.kernel.configuration.Settings.setting;
import static org.neo4j.helpers.collection.Iterables.filter;
import static org.neo4j.helpers.collection.Iterables.first;
import static org.neo4j.kernel.configuration.Settings.STRING;
import static org.neo4j.kernel.configuration.Settings.setting;
import static org.neo4j.kernel.impl.ha.ClusterManager.instanceEvicted;
import static org.neo4j.kernel.impl.ha.ClusterManager.masterAvailable;
import static org.neo4j.kernel.impl.ha.ClusterManager.masterSeesMembers;
Expand All @@ -67,23 +65,12 @@

public class HaBeanIT
{
@ClassRule
public static final ClusterRule clusterRule = new ClusterRule( HaBeanIT.class )
@Rule
public final ClusterRule clusterRule = new ClusterRule( getClass() )
.withInstanceSetting( setting( "jmx.port", STRING, (String) null ), intBase( 9912 ) )
.withInstanceSetting( HaSettings.ha_server, stringWithIntBase( ":", 1136 ) )
.withInstanceSetting( GraphDatabaseSettings.forced_kernel_id, stringWithIntBase( "kernel", 0 ) );

public Neo4jManager beans( HighlyAvailableGraphDatabase db )
{
return new Neo4jManager( db.getDependencyResolver().resolveDependency( JmxKernelExtension
.class ).getSingleManagementBean( Kernel.class ) );
}

public HighAvailability ha( HighlyAvailableGraphDatabase db )
{
return beans( db ).getHighAvailabilityBean();
}

@Test
public void canGetHaBean() throws Throwable
{
Expand Down Expand Up @@ -298,7 +285,18 @@ public void failedMemberIsStillInMemberListAlthoughFailed() throws Throwable
}
}

public static URI getUriForScheme( final String scheme, Iterable<URI> uris )
private Neo4jManager beans( HighlyAvailableGraphDatabase db )
{
return new Neo4jManager( db.getDependencyResolver().resolveDependency( JmxKernelExtension
.class ).getSingleManagementBean( Kernel.class ) );
}

private HighAvailability ha( HighlyAvailableGraphDatabase db )
{
return beans( db ).getHighAvailabilityBean();
}

private static URI getUriForScheme( final String scheme, Iterable<URI> uris )
{
return first( filter( new Predicate<URI>()
{
Expand Down
14 changes: 6 additions & 8 deletions enterprise/ha/src/test/java/org/neo4j/ha/BackupHaIT.java
Expand Up @@ -19,8 +19,7 @@
*/
package org.neo4j.ha;

import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

Expand All @@ -38,14 +37,13 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

import static org.neo4j.backup.BackupEmbeddedIT.createSomeData;
import static org.neo4j.backup.BackupEmbeddedIT.runBackupToolFromOtherJvmToGetExitCode;

public class BackupHaIT
{
@ClassRule
public static ClusterRule clusterRule = new ClusterRule( BackupHaIT.class )
@Rule
public ClusterRule clusterRule = new ClusterRule( getClass() )
.withSharedSetting( OnlineBackupSettings.online_backup_enabled, Settings.TRUE )
.withInstanceSetting( OnlineBackupSettings.online_backup_server, new IntFunction<String>()
{
Expand All @@ -58,10 +56,10 @@ public String apply( int serverId )
@Rule
public final SuppressOutput suppressOutput = SuppressOutput.suppressAll();

private static File backupPath;
private File backupPath;

@BeforeClass
public static void setup() throws Exception
@Before
public void setup() throws Exception
{
backupPath = clusterRule.cleanDirectory( "backup-db" );
createSomeData( clusterRule.startCluster().getMaster() );
Expand Down
Expand Up @@ -19,11 +19,10 @@
*/
package org.neo4j.ha;

import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

import org.neo4j.graphdb.Transaction;
import org.neo4j.kernel.GraphDatabaseAPI;
import org.neo4j.kernel.ha.HaSettings;
import org.neo4j.kernel.ha.HighlyAvailableGraphDatabase;
import org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster;
Expand All @@ -34,16 +33,16 @@

public class TestClusterIndexDeletion
{
@ClassRule
public static ClusterRule clusterRule = new ClusterRule( TestClusterIndexDeletion.class )
@Rule
public ClusterRule clusterRule = new ClusterRule( getClass() )
.withSharedSetting( HaSettings.ha_server, ":6001-6005" )
.withSharedSetting( HaSettings.tx_push_factor, "2" );

@Test
public void givenClusterWithCreatedIndexWhenDeleteIndexOnMasterThenIndexIsDeletedOnSlave() throws Throwable
{
ManagedCluster cluster = clusterRule.startCluster();
GraphDatabaseAPI master = cluster.getMaster();
HighlyAvailableGraphDatabase master = cluster.getMaster();
try ( Transaction tx = master.beginTx() )
{
master.index().forNodes( "Test" );
Expand Down
Expand Up @@ -19,7 +19,7 @@
*/
package org.neo4j.ha;

import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

import java.util.concurrent.CountDownLatch;
Expand All @@ -42,13 +42,12 @@
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import static org.neo4j.kernel.impl.ha.ClusterManager.allSeesAllAsAvailable;

public class TestSlaveOnlyCluster
{
@ClassRule
public static ClusterRule clusterRule = new ClusterRule( TestSlaveOnlyCluster.class )
@Rule
public ClusterRule clusterRule = new ClusterRule( getClass() )
.withInstanceSetting( HaSettings.slave_only, new IntFunction<String>()
{
@Override
Expand Down
Expand Up @@ -21,8 +21,6 @@

import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;

Expand All @@ -41,7 +39,6 @@
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.TransactionFailureException;
import org.neo4j.graphdb.TransientTransactionFailureException;
import org.neo4j.helpers.collection.Iterables;
import org.neo4j.kernel.DeadlockDetectedException;
import org.neo4j.kernel.ha.HaSettings;
import org.neo4j.kernel.ha.HighlyAvailableGraphDatabase;
Expand All @@ -54,13 +51,11 @@

import static java.lang.System.currentTimeMillis;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import static org.neo4j.graphdb.DynamicLabel.label;
import static org.neo4j.helpers.collection.Iterables.filter;
import static org.neo4j.helpers.collection.IteratorUtil.first;
import static org.neo4j.helpers.collection.IteratorUtil.single;
import static org.neo4j.kernel.impl.ha.ClusterManager.allSeesAllAsAvailable;
import static org.neo4j.kernel.impl.ha.ClusterManager.masterAvailable;
Expand All @@ -70,8 +65,8 @@ public class TransactionConstraintsIT
{
private static final int SLAVE_ONLY_ID = 1;

@ClassRule
public static final ClusterRule clusterRule = new ClusterRule( TransactionConstraintsIT.class )
@Rule
public final ClusterRule clusterRule = new ClusterRule( getClass() )
.withSharedSetting( HaSettings.pull_interval, "0" )
.withInstanceSetting( HaSettings.slave_only, new IntFunction<String>()
{
Expand Down
Expand Up @@ -19,7 +19,6 @@
*/
package org.neo4j.ha;

import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

Expand All @@ -37,7 +36,6 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import static org.neo4j.graphdb.DynamicLabel.label;
import static org.neo4j.kernel.impl.api.integrationtest.UniquenessConstraintValidationConcurrencyIT.createNode;
import static org.neo4j.test.OtherThreadRule.isWaiting;
Expand All @@ -49,8 +47,8 @@ public class UniquenessConstraintValidationHAIT

@Rule
public final OtherThreadRule<Void> otherThread = new OtherThreadRule<>();
@ClassRule
public static final ClusterRule clusterRule = new ClusterRule( UniquenessConstraintValidationHAIT.class )
@Rule
public final ClusterRule clusterRule = new ClusterRule( getClass() )
.withInitialDataset( uniquenessConstraint( LABEL, PROPERTY_KEY ) );

@Test
Expand Down
Expand Up @@ -19,7 +19,7 @@
*/
package org.neo4j.kernel;

import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

import org.neo4j.graphdb.DynamicLabel;
Expand All @@ -34,15 +34,14 @@
import org.neo4j.test.ha.ClusterRule;

import static org.junit.Assert.assertEquals;

import static org.neo4j.register.Registers.newDoubleLongRegister;

public class HACountsPropagationTest
{
private static final int PULL_INTERVAL = 100;

@ClassRule
public static ClusterRule clusterRule = new ClusterRule( HACountsPropagationTest.class )
@Rule
public ClusterRule clusterRule = new ClusterRule( getClass() )
.withSharedSetting( HaSettings.pull_interval, PULL_INTERVAL + "ms" );

@Test
Expand Down
Expand Up @@ -19,7 +19,7 @@
*/
package org.neo4j.kernel.api;

import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
Expand Down Expand Up @@ -78,10 +78,6 @@
} )
public class ConstraintHaIT
{
@ClassRule
public static ClusterRule clusterRule = new ClusterRule( AbstractConstraintHaIT.class )
.withSharedSetting( HaSettings.read_timeout, "4000s" );

public static class NodePropertyExistenceConstraintHaIT extends AbstractConstraintHaIT
{
@Override
Expand Down Expand Up @@ -264,6 +260,10 @@ protected Class<? extends ConstraintDefinition> constraintDefinitionClass()

public abstract static class AbstractConstraintHaIT
{
@Rule
public ClusterRule clusterRule = new ClusterRule( getClass() )
.withSharedSetting( HaSettings.read_timeout, "4000s" );

private static final String TYPE = "Type";
private static final String PROPERTY_KEY = "name";

Expand Down
Expand Up @@ -20,7 +20,7 @@
package org.neo4j.kernel.ha;

import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

import java.util.concurrent.TimeUnit;
Expand All @@ -36,21 +36,20 @@
import org.neo4j.tooling.GlobalGraphOperations;

import static org.junit.Assert.assertEquals;

import static org.neo4j.helpers.collection.IteratorUtil.count;
import static org.neo4j.kernel.configuration.Config.parseLongWithUnit;

public class BiggerThanLogTxIT
{
private static final String ROTATION_THRESHOLD = "1M";

@ClassRule
public static ClusterRule clusterRule = new ClusterRule( BiggerThanLogTxIT.class )
@Rule
public ClusterRule clusterRule = new ClusterRule( getClass() )
.withSharedSetting( GraphDatabaseSettings.logical_log_rotation_threshold, ROTATION_THRESHOLD );

protected ClusterManager.ManagedCluster cluster;

protected TransactionTemplate template = new TransactionTemplate().retries( 10 ).backoff( 3, TimeUnit.SECONDS );
private TransactionTemplate template = new TransactionTemplate().retries( 10 ).backoff( 3, TimeUnit.SECONDS );

@Before
public void setup() throws Exception
Expand Down
Expand Up @@ -19,7 +19,7 @@
*/
package org.neo4j.kernel.ha;

import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

import org.neo4j.graphdb.Relationship;
Expand All @@ -28,7 +28,6 @@
import org.neo4j.test.ha.ClusterRule;

import static org.junit.Assert.assertNotNull;

import static org.neo4j.graphdb.DynamicRelationshipType.withName;
import static org.neo4j.kernel.impl.ha.ClusterManager.clusterOfSize;

Expand All @@ -54,9 +53,8 @@
*/
public class DeletionTest
{
@ClassRule
public static ClusterRule clusterRule = new ClusterRule( DeletionTest.class )
.withProvider( clusterOfSize( 2 ) );
@Rule
public ClusterRule clusterRule = new ClusterRule( getClass() ).withProvider( clusterOfSize( 2 ) );

/**
* The problem would manifest even if the transaction was performed on the Master, it would then occur when the
Expand Down
Expand Up @@ -21,6 +21,7 @@

import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

import org.neo4j.graphdb.DynamicLabel;
Expand Down Expand Up @@ -51,8 +52,8 @@ public class HaCountsIT
private static final String PROPERTY_NAME = "prop";
private static final String PROPERTY_VALUE = "value";

@ClassRule
public static ClusterRule clusterRule = new ClusterRule( DeletionTest.class );
@Rule
public ClusterRule clusterRule = new ClusterRule( getClass() );

private ManagedCluster cluster;
private HighlyAvailableGraphDatabase master;
Expand Down

0 comments on commit 3b87c22

Please sign in to comment.