use of java.util.concurrent.TimeUnit.MINUTES in project neo4j by neo4j.
the class BackupStoreCopyInteractionStressTesting method shouldBehaveCorrectlyUnderStress.
@Test
public void shouldBehaveCorrectlyUnderStress() throws Exception {
int numberOfCores = parseInt(fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_NUMBER_OF_CORES", DEFAULT_NUMBER_OF_CORES));
int numberOfEdges = parseInt(fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_NUMBER_OF_EDGES", DEFAULT_NUMBER_OF_EDGES));
long durationInMinutes = parseLong(fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_DURATION", DEFAULT_DURATION_IN_MINUTES));
String workingDirectory = fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_WORKING_DIRECTORY", DEFAULT_WORKING_DIR);
int baseCoreBackupPort = parseInt(fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_BASE_CORE_BACKUP_PORT", DEFAULT_BASE_CORE_BACKUP_PORT));
int baseEdgeBackupPort = parseInt(fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_BASE_EDGE_BACKUP_PORT", DEFAULT_BASE_EDGE_BACKUP_PORT));
boolean enableIndexes = parseBoolean(fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_ENABLE_INDEXES", DEFAULT_ENABLE_INDEXES));
String txPrune = fromEnv("BACKUP_STORE_COPY_INTERACTION_STRESS_TX_PRUNE", DEFAULT_TX_PRUNE);
File clusterDirectory = ensureExistsAndEmpty(new File(workingDirectory, "cluster"));
File backupDirectory = ensureExistsAndEmpty(new File(workingDirectory, "backups"));
BiFunction<Boolean, Integer, SocketAddress> backupAddress = (isCore, id) -> new AdvertisedSocketAddress("localhost", (isCore ? baseCoreBackupPort : baseEdgeBackupPort) + id);
Map<String, String> coreParams = enableRaftMessageLogging(configureRaftLogRotationAndPruning(configureTxLogRotationAndPruning(new HashMap<>(), txPrune)));
Map<String, String> readReplicaParams = configureTxLogRotationAndPruning(new HashMap<>(), txPrune);
Map<String, IntFunction<String>> instanceCoreParams = configureBackup(new HashMap<>(), id -> backupAddress.apply(true, id));
Map<String, IntFunction<String>> instanceReadReplicaParams = configureBackup(new HashMap<>(), id -> backupAddress.apply(false, id));
HazelcastDiscoveryServiceFactory discoveryServiceFactory = new HazelcastDiscoveryServiceFactory();
Cluster cluster = new Cluster(clusterDirectory, numberOfCores, numberOfEdges, discoveryServiceFactory, coreParams, instanceCoreParams, readReplicaParams, instanceReadReplicaParams, Standard.LATEST_NAME);
AtomicBoolean stopTheWorld = new AtomicBoolean();
BooleanSupplier notExpired = untilTimeExpired(durationInMinutes, MINUTES);
BooleanSupplier keepGoing = () -> !stopTheWorld.get() && notExpired.getAsBoolean();
Runnable onFailure = () -> stopTheWorld.set(true);
ExecutorService service = Executors.newFixedThreadPool(3);
try {
cluster.start();
if (enableIndexes) {
Workload.setupIndexes(cluster);
}
Future<Throwable> workload = service.submit(new Workload(keepGoing, onFailure, cluster));
Future<Throwable> startStopWorker = service.submit(new StartStopLoad(fs, pageCache, keepGoing, onFailure, cluster, numberOfCores, numberOfEdges));
Future<Throwable> backupWorker = service.submit(new BackupLoad(keepGoing, onFailure, cluster, numberOfCores, numberOfEdges, backupDirectory, backupAddress));
long timeout = durationInMinutes + 5;
assertNull(Exceptions.stringify(workload.get()), workload.get(timeout, MINUTES));
assertNull(Exceptions.stringify(startStopWorker.get()), startStopWorker.get(timeout, MINUTES));
assertNull(Exceptions.stringify(backupWorker.get()), backupWorker.get(timeout, MINUTES));
} finally {
cluster.shutdown();
service.shutdown();
}
// let's cleanup disk space when everything went well
FileUtils.deleteRecursively(clusterDirectory);
FileUtils.deleteRecursively(backupDirectory);
}
use of java.util.concurrent.TimeUnit.MINUTES in project neo4j by neo4j.
the class ReadReplicaReplicationIT method shouldEventuallyPullTransactionDownToAllReadReplicas.
@Test
public void shouldEventuallyPullTransactionDownToAllReadReplicas() throws Exception {
// given
Cluster cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
int nodesBeforeReadReplicaStarts = 1;
cluster.coreTx((db, tx) -> {
db.schema().constraintFor(Label.label("Foo")).assertPropertyIsUnique("foobar").create();
tx.success();
});
// when
for (int i = 0; i < 100; i++) {
cluster.coreTx((db, tx) -> {
createData(db, nodesBeforeReadReplicaStarts);
tx.success();
});
}
Set<Path> labelScanStoreFiles = new HashSet<>();
cluster.coreTx((db, tx) -> gatherLabelScanStoreFiles(db, labelScanStoreFiles));
AtomicBoolean labelScanStoreCorrectlyPlaced = new AtomicBoolean(false);
Monitors monitors = new Monitors();
ReadReplica rr = cluster.addReadReplicaWithIdAndMonitors(0, monitors);
Path readReplicateStoreDir = rr.storeDir().toPath().toAbsolutePath();
monitors.addMonitorListener((FileCopyMonitor) file -> {
Path relativPath = readReplicateStoreDir.relativize(file.toPath().toAbsolutePath());
relativPath = relativPath.subpath(1, relativPath.getNameCount());
if (labelScanStoreFiles.contains(relativPath)) {
labelScanStoreCorrectlyPlaced.set(true);
}
});
rr.start();
for (int i = 0; i < 100; i++) {
cluster.coreTx((db, tx) -> {
createData(db, nodesBeforeReadReplicaStarts);
tx.success();
});
}
// then
for (final ReadReplica server : cluster.readReplicas()) {
GraphDatabaseService readReplica = server.database();
try (Transaction tx = readReplica.beginTx()) {
ThrowingSupplier<Long, Exception> nodeCount = () -> count(readReplica.getAllNodes());
assertEventually("node to appear on read replica", nodeCount, is(400L), 1, MINUTES);
for (Node node : readReplica.getAllNodes()) {
assertThat(node.getProperty("foobar").toString(), startsWith("baz_bat"));
}
tx.success();
}
}
assertTrue(labelScanStoreCorrectlyPlaced.get());
}
Aggregations