Skip to content

Commit

Permalink
Add core-edge stress test for backup/store copy interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed Sep 13, 2016
1 parent 8405bfd commit 822061d
Show file tree
Hide file tree
Showing 11 changed files with 319 additions and 20 deletions.
10 changes: 10 additions & 0 deletions community/common/src/main/java/org/neo4j/function/Suppliers.java
Expand Up @@ -19,10 +19,14 @@
*/
package org.neo4j.function;

import java.util.concurrent.TimeUnit;
import java.util.function.BooleanSupplier;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

import static java.lang.System.currentTimeMillis;

/**
* Constructors for basic {@link Supplier} types
*/
Expand Down Expand Up @@ -118,4 +122,10 @@ public static <T> Supplier<Boolean> compose( final Supplier<T> input, final Pred
{
return () -> predicate.test( input.get() );
}

public static BooleanSupplier untilTimeExpired( long duration, TimeUnit unit )
{
final long endTimeInMilliseconds = currentTimeMillis() + unit.toMillis( duration );
return () -> currentTimeMillis() <= endTimeInMilliseconds;
}
}
Expand Up @@ -47,6 +47,7 @@
import static java.lang.System.currentTimeMillis;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.Assert.assertEquals;
import static org.neo4j.function.Suppliers.untilTimeExpired;

public class TransactionAppenderStressTest
{
Expand All @@ -59,7 +60,7 @@ public void concurrentTransactionAppendingTest() throws Exception
int threads = 10;
File workingDirectory = directory.directory( "work" );
Callable<Long> runner = new Builder()
.with( Builder.untilTimeExpired( 10, SECONDS ) )
.with( untilTimeExpired( 10, SECONDS ) )
.withWorkingDirectory( workingDirectory )
.withNumThreads( threads )
.build();
Expand All @@ -75,12 +76,6 @@ public static class Builder
private File workingDirectory;
private int threads;

public static BooleanSupplier untilTimeExpired( long duration, TimeUnit unit )
{
final long endTimeInMilliseconds = currentTimeMillis() + unit.toMillis( duration );
return () -> currentTimeMillis() <= endTimeInMilliseconds;
}

public Builder with( BooleanSupplier condition )
{
this.condition = condition;
Expand Down
Expand Up @@ -105,7 +105,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.neo4j.backup.BackupServiceStressTestingBuilder.untilTimeExpired;
import static org.neo4j.function.Suppliers.untilTimeExpired;
import static org.neo4j.kernel.impl.storemigration.StoreFile.COUNTS_STORE_LEFT;
import static org.neo4j.kernel.impl.storemigration.StoreFile.COUNTS_STORE_RIGHT;

Expand Down
Expand Up @@ -68,12 +68,6 @@ public class BackupServiceStressTestingBuilder
private String backupHostname = "localhost";
private int backupPort = 8200;

public static BooleanSupplier untilTimeExpired( long duration, TimeUnit unit )
{
final long endTimeInMilliseconds = currentTimeMillis() + unit.toMillis( duration );
return () -> currentTimeMillis() <= endTimeInMilliseconds;
}

public BackupServiceStressTestingBuilder until( BooleanSupplier untilCondition )
{
Objects.requireNonNull( untilCondition );
Expand Down
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2002-2016 "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 Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.coreedge.discovery;

public interface ClusterMember
{
void start();

void shutdown();
}
Expand Up @@ -43,7 +43,7 @@
import static org.neo4j.coreedge.core.consensus.log.RaftLog.PHYSICAL_LOG_DIRECTORY_NAME;
import static org.neo4j.helpers.collection.MapUtil.stringMap;

public class CoreClusterMember
public class CoreClusterMember implements ClusterMember
{
private final File neo4jHome;
private final DiscoveryServiceFactory discoveryServiceFactory;
Expand Down Expand Up @@ -98,12 +98,14 @@ public CoreClusterMember( int serverId, int clusterSize,
storeDir.mkdirs();
}

@Override
public void start()
{
database = new CoreGraphDatabase( storeDir, config,
GraphDatabaseDependencies.newDependencies(), discoveryServiceFactory );
}

@Override
public void shutdown()
{
if ( database != null )
Expand Down
Expand Up @@ -34,7 +34,7 @@
import static java.util.stream.Collectors.joining;
import static org.neo4j.helpers.collection.MapUtil.stringMap;

public class EdgeClusterMember
public class EdgeClusterMember implements ClusterMember
{
private final Map<String, String> config = stringMap();
private final DiscoveryServiceFactory discoveryServiceFactory;
Expand Down Expand Up @@ -76,12 +76,14 @@ public class EdgeClusterMember
storeDir.mkdirs();
}

@Override
public void start()
{
database = new EdgeGraphDatabase( storeDir, config,
GraphDatabaseDependencies.newDependencies(), discoveryServiceFactory );
}

@Override
public void shutdown()
{
if ( database != null )
Expand Down
13 changes: 13 additions & 0 deletions stresstests/pom.xml
Expand Up @@ -103,5 +103,18 @@
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-core-edge</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-core-edge</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
</dependencies>
</project>
Expand Up @@ -22,7 +22,6 @@
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.Callable;

import org.neo4j.backup.BackupServiceStressTestingBuilder;
Expand All @@ -31,12 +30,11 @@
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.getProperty;
import static java.lang.System.getenv;
import static java.util.concurrent.TimeUnit.MINUTES;
import static org.junit.Assert.assertEquals;
import static org.neo4j.StressTestingHelper.ensureExistsAndEmpty;
import static org.neo4j.StressTestingHelper.fromEnv;
import static org.neo4j.backup.BackupServiceStressTestingBuilder.untilTimeExpired;
import static org.neo4j.function.Suppliers.untilTimeExpired;

/**
* Notice the class name: this is _not_ going to be run as part of the main build.
Expand Down

0 comments on commit 822061d

Please sign in to comment.