use of org.neo4j.test.Race in project neo4j by neo4j.
the class TerminationOfSlavesDuringPullUpdatesTest method slavesDontTerminateAndReadConsistentDataWhenApplyingBatchSmallerThanSafeZone.
@Test
public void slavesDontTerminateAndReadConsistentDataWhenApplyingBatchSmallerThanSafeZone() throws Throwable {
long safeZone = TimeUnit.MINUTES.toMillis(1);
clusterRule.withSharedSetting(HaSettings.id_reuse_safe_zone_time, String.valueOf(safeZone));
// given
final ClusterManager.ManagedCluster cluster = clusterRule.startCluster();
HighlyAvailableGraphDatabase master = cluster.getMaster();
// when
// ... slaves and master has node with long string property
long entityId = action.createInitialEntity(master);
cluster.sync();
// ... and property is removed on master
action.removeProperties(master, entityId);
// ... and maintenance is called to make sure "safe" ids are freed to be reused
forceMaintenance(master);
// ... and a new property is created on master that
action.setNewProperties(master, entityId);
final HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
Race race = new Race();
final AtomicBoolean end = new AtomicBoolean(false);
for (int i = 0; i < READER_CONTESTANTS; i++) {
race.addContestant(readContestant(action, entityId, slave, end));
}
race.addContestant(pullUpdatesContestant(slave, end));
race.go();
}
use of org.neo4j.test.Race in project neo4j by neo4j.
the class TransactionLogAppendAndRotateIT method shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending.
@Test
public void shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending() throws Throwable {
// GIVEN
PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory().getAbsoluteFile(), fileSystemRule.get());
long rotationThreshold = mebiBytes(1);
LogVersionRepository logVersionRepository = new DeadSimpleLogVersionRepository(0);
final AtomicBoolean end = new AtomicBoolean();
AllTheMonitoring monitoring = new AllTheMonitoring(end, 100);
TransactionIdStore txIdStore = new DeadSimpleTransactionIdStore();
TransactionMetadataCache metadataCache = new TransactionMetadataCache(100);
LogHeaderCache logHeaderCache = new LogHeaderCache(10);
LogFile logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, rotationThreshold, () -> txIdStore.getLastCommittedTransactionId(), logVersionRepository, monitoring, logHeaderCache));
monitoring.setLogFile(logFile);
DatabaseHealth health = new DatabaseHealth(mock(DatabasePanicEventGenerator.class), NullLog.getInstance());
LogRotation rotation = new LogRotationImpl(monitoring, logFile, health);
final TransactionAppender appender = life.add(new BatchingTransactionAppender(logFile, rotation, metadataCache, txIdStore, BYPASS, health));
// WHEN
Race race = new Race();
for (int i = 0; i < 10; i++) {
race.addContestant(new Runnable() {
@Override
public void run() {
while (!end.get()) {
try {
appender.append(new TransactionToApply(sillyTransaction(1_000)), NULL);
} catch (Exception e) {
e.printStackTrace(System.out);
end.set(true);
fail(e.getMessage());
}
}
}
});
}
race.addContestant(endAfterMax(10, SECONDS, end));
race.go();
// THEN
assertTrue(monitoring.numberOfRotations() > 0);
}
use of org.neo4j.test.Race in project neo4j by neo4j.
the class StoreCopyCheckPointMutexTest method shouldHandleMultipleConcurrentStoreCopyRequests.
@Test
public void shouldHandleMultipleConcurrentStoreCopyRequests() throws Throwable {
// GIVEN
Race race = new Race();
CountingAction action = new CountingAction();
int threads = Runtime.getRuntime().availableProcessors() * 10;
race.addContestants(threads, throwing(() -> {
parkARandomWhile();
try (Resource lock = mutex.storeCopy(action)) {
parkARandomWhile();
}
}));
race.go();
// THEN
// It's hard to make predictions about what should have been seen. Most importantly is that
// The lock doesn't hang any requests and that number of calls to the action less than number of threads
assertThat(action.count(), lessThan(threads));
}
use of org.neo4j.test.Race in project neo4j by neo4j.
the class GroupsTest method shouldHandleConcurrentGetOrCreate.
@Test
public void shouldHandleConcurrentGetOrCreate() throws Throwable {
// GIVEN
Groups groups = new Groups();
Race race = new Race();
String name = "MyGroup";
for (int i = 0; i < Runtime.getRuntime().availableProcessors(); i++) {
race.addContestant(() -> {
Group group = groups.getOrCreate(name);
assertEquals(0, group.id());
});
}
// WHEN
race.go();
// THEN
Group otherGroup = groups.getOrCreate("MyOtherGroup");
assertEquals(1, otherGroup.id());
}
use of org.neo4j.test.Race in project neo4j by neo4j.
the class DynamicTaskExecutorTest method shouldCopeWithConcurrentIncrementOfProcessorsAndShutdown.
@Repeat(times = 10)
@Test
public void shouldCopeWithConcurrentIncrementOfProcessorsAndShutdown() throws Throwable {
// GIVEN
TaskExecutor<Void> executor = new DynamicTaskExecutor<>(1, 2, 2, PARK, "test");
Race race = new Race().withRandomStartDelays();
race.addContestant(() -> executor.close());
race.addContestant(() -> executor.processors(1));
// WHEN
race.go(10, SECONDS);
// THEN we should be able to do so, there was a recent fix here and before that fix
// shutdown() would hang, that's why we wait for 10 seconds here to cap it if there's an issue.
}
Aggregations