Search in sources :

Example 16 with Race

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();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) Race(org.neo4j.test.Race) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Test(org.junit.Test)

Example 17 with Race

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);
}
Also used : DatabaseHealth(org.neo4j.kernel.internal.DatabaseHealth) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) DatabasePanicEventGenerator(org.neo4j.kernel.impl.core.DatabasePanicEventGenerator) DeadSimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.DeadSimpleLogVersionRepository) DeadSimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.DeadSimpleLogVersionRepository) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Race(org.neo4j.test.Race) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) LogRotationImpl(org.neo4j.kernel.impl.transaction.log.rotation.LogRotationImpl) Test(org.junit.Test)

Example 18 with Race

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));
}
Also used : Race(org.neo4j.test.Race) Resource(org.neo4j.graphdb.Resource) Test(org.junit.Test)

Example 19 with Race

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());
}
Also used : Race(org.neo4j.test.Race) Test(org.junit.Test)

Example 20 with Race

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.
}
Also used : Race(org.neo4j.test.Race) Test(org.junit.Test) Repeat(org.neo4j.test.rule.RepeatRule.Repeat)

Aggregations

Race (org.neo4j.test.Race)26 Test (org.junit.Test)24 AtomicLong (java.util.concurrent.atomic.AtomicLong)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 Transaction (org.neo4j.graphdb.Transaction)5 Node (org.neo4j.graphdb.Node)4 NotFoundException (org.neo4j.graphdb.NotFoundException)4 DelegatingPagedFile (org.neo4j.io.pagecache.DelegatingPagedFile)3 IOException (java.io.IOException)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Relationship (org.neo4j.graphdb.Relationship)2 PageCursor (org.neo4j.io.pagecache.PageCursor)2 PagedFile (org.neo4j.io.pagecache.PagedFile)2 DelegatingPageCursor (org.neo4j.io.pagecache.impl.DelegatingPageCursor)2 File (java.io.File)1 Clock (java.time.Clock)1 ArrayList (java.util.ArrayList)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 CountDownLatch (java.util.concurrent.CountDownLatch)1