Skip to content

Commit

Permalink
Fix HA tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Aug 21, 2018
1 parent 7e2512f commit b4314e6
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 40 deletions.
7 changes: 4 additions & 3 deletions enterprise/ha/src/test/java/org/neo4j/ha/BackupHaIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.helpers.HostnamePort;
import org.neo4j.io.layout.DatabaseLayout;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.configuration.Settings;
import org.neo4j.kernel.ha.HighlyAvailableGraphDatabase;
Expand Down Expand Up @@ -61,7 +62,7 @@ public class BackupHaIT
@Before
public void setup() throws Exception
{
backupPath = clusterRule.cleanDirectory( "backup-db" );
backupPath = clusterRule.getTestDirectory().storeDir( "backup-db" );
createSomeData( clusterRule.startCluster().getMaster() );
}

Expand All @@ -85,7 +86,7 @@ public void makeSureBackupCanBePerformed() throws Throwable
Config config = Config.builder()
.withSetting( OnlineBackupSettings.online_backup_enabled, Settings.FALSE )
.withSetting( GraphDatabaseSettings.active_database, databaseName ).build();
DbRepresentation backupRepresentation = DbRepresentation.of( backupPath, config );
DbRepresentation backupRepresentation = DbRepresentation.of( DatabaseLayout.of( backupPath, databaseName ).databaseDirectory(), config );
assertEquals( beforeChange, backupRepresentation );
assertNotEquals( backupRepresentation, afterChange );
}
Expand Down Expand Up @@ -113,7 +114,7 @@ public void makeSureBackupCanBePerformedFromAnyInstance() throws Throwable
Config config = Config.builder()
.withSetting( OnlineBackupSettings.online_backup_enabled, Settings.FALSE )
.withSetting( GraphDatabaseSettings.active_database, databaseName ).build();
DbRepresentation backupRepresentation = DbRepresentation.of( backupPath, config );
DbRepresentation backupRepresentation = DbRepresentation.of( DatabaseLayout.of( backupPath, databaseName ).databaseDirectory(), config );
assertEquals( beforeChange, backupRepresentation );
assertNotEquals( backupRepresentation, afterChange );
}
Expand Down
3 changes: 1 addition & 2 deletions enterprise/ha/src/test/java/org/neo4j/ha/BranchedDataIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,10 @@ public void migrationOfBranchedDataDirectories() throws Exception
Thread.sleep( 1 ); // To make sure we get different timestamps
}

File storeDirectory = directory.directory();
File databaseDirectory = directory.databaseDir();
int clusterPort = PortAuthority.allocatePort();
new TestHighlyAvailableGraphDatabaseFactory().
newEmbeddedDatabaseBuilder( storeDirectory )
newEmbeddedDatabaseBuilder( databaseDirectory )
.setConfig( ClusterSettings.server_id, "1" )
.setConfig( ClusterSettings.cluster_server, "127.0.0.1:" + clusterPort )
.setConfig( ClusterSettings.initial_hosts, "localhost:" + clusterPort )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import org.neo4j.graphdb.factory.EnterpriseGraphDatabaseFactory;
import org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory;
import org.neo4j.kernel.configuration.Settings;
import org.neo4j.ports.allocation.PortAuthority;
import org.neo4j.kernel.impl.enterprise.configuration.OnlineBackupSettings;
import org.neo4j.ports.allocation.PortAuthority;
import org.neo4j.test.rule.TestDirectory;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -81,7 +81,7 @@ public void emptyForeignDbShouldJoinAfterHavingItsEmptyDbDeleted()
.setConfig( OnlineBackupSettings.online_backup_enabled, Settings.FALSE )
.newGraphDatabase();
// -- another instance preparing to join with a store with a different store ID
File foreignDbStoreDir = createAnotherStore( testDirectory.directory( "2" ), 0 );
File foreignDbStoreDir = createAnotherStore( testDirectory.databaseDir( "2" ), 0 );

// WHEN
// -- the other joins
Expand Down Expand Up @@ -117,7 +117,7 @@ public void nonEmptyForeignDbShouldNotBeAbleToJoin()
.newGraphDatabase();
createNodes( firstInstance, 3, "first" );
// -- another instance preparing to join with a store with a different store ID
File foreignDbStoreDir = createAnotherStore( testDirectory.directory( "2" ), 1 );
File foreignDbStoreDir = createAnotherStore( testDirectory.databaseDir( "2" ), 1 );

// WHEN
// -- the other joins
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private SortedMap<Integer, Configuration> createConfigurations()
{
int clusterPort = PortAuthority.allocatePort();
int haPort = PortAuthority.allocatePort();
File directory = testDirectory.directory( Integer.toString( serverId ) ).getAbsoluteFile();
File directory = testDirectory.databaseDir( Integer.toString( serverId ) ).getAbsoluteFile();

configurations.put( serverId, new Configuration( serverId, clusterPort, haPort, directory ) );
} );
Expand Down Expand Up @@ -220,8 +220,7 @@ public void failed( InstanceId server )
Thread.sleep( 15000 );

restart( serverIdOfDatabaseToKill ); // recovery and branching.
File databaseDirectory = testDirectory.databaseDir( storeDirectory );
boolean hasBranchedData = new File( databaseDirectory, "branched" ).listFiles().length > 0;
boolean hasBranchedData = new File( storeDirectory, "branched" ).listFiles().length > 0;
assertFalse( hasBranchedData );
}

Expand Down
4 changes: 2 additions & 2 deletions enterprise/ha/src/test/java/org/neo4j/ha/PullUpdatesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void shouldPullUpdatesOnStartupNoMatterWhat() throws Exception
try
{
File testRootDir = clusterRule.cleanDirectory( "shouldPullUpdatesOnStartupNoMatterWhat" );
File masterDir = new File( testRootDir, "master" );
File masterDir = clusterRule.getTestDirectory().databaseDir( "master" );
int masterClusterPort = PortAuthority.allocatePort();
master = (HighlyAvailableGraphDatabase) new TestHighlyAvailableGraphDatabaseFactory().
newEmbeddedDatabaseBuilder( masterDir )
Expand All @@ -217,7 +217,7 @@ public void shouldPullUpdatesOnStartupNoMatterWhat() throws Exception
.newGraphDatabase();

// Copy the store, then shutdown, so update pulling later makes sense
File slaveDir = new File( testRootDir, "slave" );
File slaveDir = clusterRule.getTestDirectory().databaseDir( "slave" );
slave = (HighlyAvailableGraphDatabase) new TestHighlyAvailableGraphDatabaseFactory().
newEmbeddedDatabaseBuilder( slaveDir )
.setConfig( ClusterSettings.server_id, "2" )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
*/
package org.neo4j.kernel.ha;

import static org.junit.Assert.assertTrue;
import org.junit.Rule;
import org.junit.Test;

import java.io.File;
import java.util.ArrayList;
Expand All @@ -32,18 +33,17 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

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

import org.neo4j.cluster.ClusterSettings;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseBuilder;
import org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory;
import org.neo4j.kernel.configuration.Settings;
import org.neo4j.ports.allocation.PortAuthority;
import org.neo4j.kernel.impl.enterprise.configuration.OnlineBackupSettings;
import org.neo4j.ports.allocation.PortAuthority;
import org.neo4j.test.rule.TestDirectory;

import static org.junit.Assert.assertTrue;

public class ConcurrentInstanceStartupIT
{
@Rule
Expand Down Expand Up @@ -138,6 +138,6 @@ private HighlyAvailableGraphDatabase startDbAtBase( int i, String initialHosts,

private File path( int i )
{
return testDirectory.directory( i + "" );
return testDirectory.databaseDir( i + "" );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ public void testConflictingIdDoesNotSilentlyFail()

private File path( int i )
{
return new File( testDirectory.databaseDir(), "" + i );
return testDirectory.databaseDir( "" + i );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void testMasterSwitchHappensOnKillMinus9() throws Exception
}
}

private long getNamedNode( HighlyAvailableGraphDatabase db, String name )
private static long getNamedNode( HighlyAvailableGraphDatabase db, String name )
{
try ( Transaction transaction = db.beginTx() )
{
Expand All @@ -168,7 +168,7 @@ private long getNamedNode( HighlyAvailableGraphDatabase db, String name )
}
}

private long createNamedNode( HighlyAvailableGraphDatabase db, String name )
private static long createNamedNode( HighlyAvailableGraphDatabase db, String name )
{
try ( Transaction tx = db.beginTx() )
{
Expand Down Expand Up @@ -272,6 +272,6 @@ private static HighlyAvailableGraphDatabase startDb( int serverId, File path, in

private File path( int i )
{
return new File( testDirectory.databaseDir(), "" + i );
return testDirectory.databaseDir( "" + i );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
package org.neo4j.kernel.ha.cluster;

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

import java.io.File;
Expand All @@ -44,7 +45,6 @@
import org.neo4j.function.Suppliers;
import org.neo4j.helpers.CancellationRequest;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.layout.DatabaseLayout;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.io.pagecache.PagedFile;
import org.neo4j.kernel.DatabaseAvailability;
Expand Down Expand Up @@ -84,6 +84,7 @@
import org.neo4j.scheduler.Group;
import org.neo4j.scheduler.JobScheduler;
import org.neo4j.storageengine.api.StoreId;
import org.neo4j.test.rule.TestDirectory;

import static java.util.Collections.singletonList;
import static org.junit.Assert.assertNull;
Expand Down Expand Up @@ -113,6 +114,9 @@ public class SwitchToSlaveBranchThenCopyTest
private final RequestContextFactory requestContextFactory = mock( RequestContextFactory.class );
private final StoreId storeId = newStoreIdForCurrentVersion( 42, 42, 42, 42 );

@Rule
public final TestDirectory testDirectory = TestDirectory.testDirectory();

@Test
public void shouldRestartServicesIfCopyStoreFails() throws Throwable
{
Expand Down Expand Up @@ -149,7 +153,7 @@ public void shouldRestartServicesIfCopyStoreFails() throws Throwable
}
}

private PageCache mockPageCache() throws IOException
private static PageCache mockPageCache() throws IOException
{
PageCache pageCacheMock = mock( PageCache.class );
PagedFile pagedFileMock = mock( PagedFile.class );
Expand Down Expand Up @@ -271,7 +275,7 @@ public void updatesPulledAndPullingScheduledOnSwitchToSlave() throws Throwable
eq( 10L ), eq( 10L ), eq( TimeUnit.MILLISECONDS ) );
}

private URI getLocalhostUri() throws URISyntaxException
private static URI getLocalhostUri() throws URISyntaxException
{
return new URI( "cluster://127.0.0.1?serverId=1" );
}
Expand Down Expand Up @@ -336,7 +340,7 @@ private SwitchToSlaveBranchThenCopy newSwitchToSlaveSpy( PageCache pageCacheMock
when( masterClientResolver.instantiate( anyString(), anyInt(), anyString(), any( Monitors.class ),
argThat( storeId -> true ), any( LifeSupport.class ) ) ).thenReturn( masterClient );

return spy( new SwitchToSlaveBranchThenCopy( DatabaseLayout.of( new File( "" ) ), NullLogService.getInstance(),
return spy( new SwitchToSlaveBranchThenCopy( testDirectory.databaseLayout(), NullLogService.getInstance(),
configMock(),
mock( HaIdGeneratorFactory.class ),
mock( DelegateInvocationHandler.class ),
Expand All @@ -357,12 +361,12 @@ private SwitchToSlaveBranchThenCopy newSwitchToSlaveSpy( PageCache pageCacheMock
}, updatePuller, pageCacheMock, mock( Monitors.class ), () -> transactionCounters ) );
}

private Config configMock()
private static Config configMock()
{
return Config.defaults( ClusterSettings.server_id, "1" );
}

private <T> T mockWithLifecycle( Class<T> clazz )
private static <T> T mockWithLifecycle( Class<T> clazz )
{
return mock( clazz, withSettings().extraInterfaces( Lifecycle.class ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
package org.neo4j.kernel.ha.cluster;

import org.junit.Rule;
import org.junit.Test;
import org.mockito.InOrder;
import org.mockito.Mockito;
Expand All @@ -48,7 +49,6 @@
import org.neo4j.function.Suppliers;
import org.neo4j.helpers.CancellationRequest;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.layout.DatabaseLayout;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.io.pagecache.PagedFile;
import org.neo4j.kernel.DatabaseAvailability;
Expand Down Expand Up @@ -87,6 +87,7 @@
import org.neo4j.scheduler.Group;
import org.neo4j.scheduler.JobScheduler;
import org.neo4j.storageengine.api.StoreId;
import org.neo4j.test.rule.TestDirectory;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertNull;
Expand Down Expand Up @@ -116,6 +117,9 @@ public class SwitchToSlaveCopyThenBranchTest
private final RequestContextFactory requestContextFactory = mock( RequestContextFactory.class );
private final StoreId storeId = newStoreIdForCurrentVersion( 42, 42, 42, 42 );

@Rule
public final TestDirectory testDirectory = TestDirectory.testDirectory();

@Test
public void shouldRestartServicesIfCopyStoreFails() throws Throwable
{
Expand Down Expand Up @@ -272,7 +276,7 @@ public void shouldNotBranchStoreUnlessWeHaveCopiedDownAReplacement() throws Thro

inOrder.verify( storeCopyClient ).copyStore( any( StoreCopyClient.StoreCopyRequester.class ),
any( CancellationRequest.class ), any( MoveAfterCopy.class ) ) ;
inOrder.verify( branchPolicy ).handle( new File( "" ), pageCacheMock, NullLogService.getInstance() );
inOrder.verify( branchPolicy ).handle( testDirectory.databaseDir(), pageCacheMock, NullLogService.getInstance() );
}

@Test
Expand Down Expand Up @@ -387,7 +391,7 @@ private SwitchToSlaveCopyThenBranch newSwitchToSlaveSpy( PageCache pageCacheMock
when( masterClientResolver.instantiate( anyString(), anyInt(), anyString(), any( Monitors.class ),
argThat( storeId -> true ), any( LifeSupport.class ) ) ).thenReturn( masterClient );

return spy( new SwitchToSlaveCopyThenBranch( DatabaseLayout.of( new File( "" ) ), NullLogService.getInstance(),
return spy( new SwitchToSlaveCopyThenBranch( testDirectory.databaseLayout(), NullLogService.getInstance(),
configMock(),
mock( HaIdGeneratorFactory.class ),
mock( DelegateInvocationHandler.class ),
Expand All @@ -408,12 +412,12 @@ private SwitchToSlaveCopyThenBranch newSwitchToSlaveSpy( PageCache pageCacheMock
}, updatePuller, pageCacheMock, mock( Monitors.class ), () -> transactionCounters ) );
}

private Config configMock()
private static Config configMock()
{
return Config.defaults( ClusterSettings.server_id, "1" );
}

private <T> T mockWithLifecycle( Class<T> clazz )
private static <T> T mockWithLifecycle( Class<T> clazz )
{
return mock( clazz, withSettings().extraInterfaces( Lifecycle.class ) );
}
Expand Down
12 changes: 6 additions & 6 deletions enterprise/ha/src/test/java/slavetest/InstanceJoinIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public void makeSureSlaveCanJoinEvenIfTooFarBackComparedToMaster() throws Except

HighlyAvailableGraphDatabase master = null;
HighlyAvailableGraphDatabase slave = null;
File masterDir = testDirectory.directory( "master" );
File slaveDir = testDirectory.directory( "slave" );
File masterDir = testDirectory.databaseDir( "master" );
File slaveDir = testDirectory.databaseDir( "slave" );
try
{
int masterClusterPort = PortAuthority.allocatePort();
Expand Down Expand Up @@ -136,19 +136,19 @@ public void makeSureSlaveCanJoinEvenIfTooFarBackComparedToMaster() throws Except
}
}

private void rotateLog( HighlyAvailableGraphDatabase db ) throws IOException
private static void rotateLog( HighlyAvailableGraphDatabase db ) throws IOException
{
db.getDependencyResolver().resolveDependency( LogRotation.class ).rotateLogFile();
}

private void checkPoint( HighlyAvailableGraphDatabase db ) throws IOException
private static void checkPoint( HighlyAvailableGraphDatabase db ) throws IOException
{
db.getDependencyResolver().resolveDependency( CheckPointer.class ).forceCheckPoint(
new SimpleTriggerInfo( "test" )
);
}

private int nodesHavingProperty( HighlyAvailableGraphDatabase slave, String key, String value )
private static int nodesHavingProperty( HighlyAvailableGraphDatabase slave, String key, String value )
{
try ( Transaction tx = slave.beginTx() )
{
Expand All @@ -165,7 +165,7 @@ private int nodesHavingProperty( HighlyAvailableGraphDatabase slave, String key,
}
}

private void createNode( HighlyAvailableGraphDatabase db, String key, String value )
private static void createNode( HighlyAvailableGraphDatabase db, String key, String value )
{
try ( Transaction tx = db.beginTx() )
{
Expand Down

0 comments on commit b4314e6

Please sign in to comment.