Search in sources :

Example 1 with Repeat

use of org.neo4j.test.rule.RepeatRule.Repeat 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)

Example 2 with Repeat

use of org.neo4j.test.rule.RepeatRule.Repeat in project neo4j by neo4j.

the class TestPropertyReadOnNewEntityBeforeLockRelease method shouldBeAbleToReadPropertiesFromNewNodeReturnedFromIndex.

@Test
@Repeat(times = 100)
public void shouldBeAbleToReadPropertiesFromNewNodeReturnedFromIndex() throws Exception {
    String propertyKey = UUID.randomUUID().toString();
    String propertyValue = UUID.randomUUID().toString();
    AtomicBoolean start = new AtomicBoolean(false);
    int readerDelay = ThreadLocalRandom.current().nextInt(MAX_READER_DELAY_MS);
    Writer writer = new Writer(db, propertyKey, propertyValue, start);
    Reader reader = new Reader(db, propertyKey, propertyValue, start, readerDelay);
    ExecutorService executor = Executors.newFixedThreadPool(2);
    Future<?> readResult;
    Future<?> writeResult;
    try {
        writeResult = executor.submit(writer);
        readResult = executor.submit(reader);
        start.set(true);
    } finally {
        executor.shutdown();
        executor.awaitTermination(20, TimeUnit.SECONDS);
    }
    assertNull(writeResult.get());
    assertNull(readResult.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test) Repeat(org.neo4j.test.rule.RepeatRule.Repeat)

Aggregations

Test (org.junit.Test)2 Repeat (org.neo4j.test.rule.RepeatRule.Repeat)2 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Race (org.neo4j.test.Race)1