Search in sources :

Example 1 with Timeout

use of org.junit.jupiter.api.Timeout in project neo4j by neo4j.

the class DijkstraIncreasingWeightTest method testForLoops.

@Test
@Timeout(5)
void testForLoops() {
    /*
         *
         *            (b)
         *           /  \         0
         *          0    0       / \            - 0 - (c1) - 0 -
         *           \  /        \/           /                 \
         * (s) - 1 - (a1) - 1 - (a2) - 1 - (a3)                (a4) - 1 - (t)
         *                                    \                 /
         *                                     - 0 - (c2) - 0 -
         *
         */
    try (Transaction transaction = graphDb.beginTx()) {
        Node s = graph.makeNode(transaction, "s");
        Node t = graph.makeNode(transaction, "t");
        // Blob loop
        graph.makeEdge(transaction, "s", "a1", "length", 1);
        graph.makeEdge(transaction, "a1", "b", "length", 0);
        graph.makeEdge(transaction, "b", "a1", "length", 0);
        // Self loop
        graph.makeEdge(transaction, "a1", "a2", "length", 1);
        graph.makeEdge(transaction, "a2", "a2", "length", 0);
        // Diamond loop
        graph.makeEdge(transaction, "a2", "a3", "length", 1);
        graph.makeEdge(transaction, "a3", "c1", "length", 0);
        graph.makeEdge(transaction, "a3", "c2", "length", 0);
        graph.makeEdge(transaction, "c1", "a4", "length", 0);
        graph.makeEdge(transaction, "c1", "a4", "length", 0);
        graph.makeEdge(transaction, "a4", "t", "length", 1);
        PathExpander<Double> expander = PathExpanders.allTypesAndDirections();
        Dijkstra algo = new Dijkstra(expander, CommonEvaluators.doubleCostEvaluator("length"), DEFAULT_EPSILON, PathInterestFactory.all(DEFAULT_EPSILON));
        Iterator<WeightedPath> paths = algo.findAllPaths(s, t).iterator();
        assertTrue(paths.hasNext(), "Expected at least one path");
        assertEquals(6, paths.next().length(), "Expected first path of length 6");
        assertTrue(paths.hasNext(), "Expected at least two paths");
        assertEquals(6, paths.next().length(), "Expected second path of length 6");
        assertFalse(paths.hasNext(), "Expected exactly two paths");
        transaction.commit();
    }
}
Also used : WeightedPath(org.neo4j.graphalgo.WeightedPath) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Dijkstra(org.neo4j.graphalgo.impl.path.Dijkstra) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 2 with Timeout

use of org.junit.jupiter.api.Timeout in project neo4j by neo4j.

the class CentralJobSchedulerTest method scheduledTasksThatThrowsPropagateDoNotPropagateExceptionAfterSubsequentExecution.

@Test
@Timeout(60)
void scheduledTasksThatThrowsPropagateDoNotPropagateExceptionAfterSubsequentExecution() throws InterruptedException {
    life.start();
    RuntimeException boom = new RuntimeException("boom");
    AtomicBoolean throwException = new AtomicBoolean();
    CountDownLatch startCounter = new CountDownLatch(10);
    AtomicBoolean canceled = new AtomicBoolean();
    Runnable job = () -> {
        try {
            if (throwException.compareAndSet(false, true)) {
                throw boom;
            }
        } finally {
            startCounter.countDown();
        }
    };
    JobHandle<?> handle = scheduler.scheduleRecurring(Group.INDEX_POPULATION, NOT_MONITORED, job, 1, TimeUnit.MILLISECONDS);
    handle.registerCancelListener(() -> canceled.set(true));
    startCounter.await();
    handle.cancel();
    assertTrue(canceled.get());
    assertThrows(CancellationException.class, handle::waitTermination);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 3 with Timeout

use of org.junit.jupiter.api.Timeout in project neo4j by neo4j.

the class InternalTransactionCommitProcessIT method commitDuringContinuousCheckpointing.

@Test
@Timeout(value = 5, unit = TimeUnit.MINUTES)
void commitDuringContinuousCheckpointing() throws Exception {
    final AtomicBoolean done = new AtomicBoolean();
    Workers<Runnable> workers = new Workers<>(getClass().getSimpleName());
    try {
        for (int i = 0; i < TOTAL_ACTIVE_THREADS; i++) {
            workers.start(new Runnable() {

                private final ThreadLocalRandom random = ThreadLocalRandom.current();

                @Override
                public void run() {
                    while (!done.get()) {
                        try (Transaction tx = db.beginTx()) {
                            tx.createNode();
                            tx.commit();
                        }
                        randomSleep();
                    }
                }

                private void randomSleep() {
                    try {
                        Thread.sleep(random.nextInt(50));
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            });
        }
        Thread.sleep(SECONDS.toMillis(2));
    } finally {
        done.set(true);
    }
    workers.awaitAndThrowOnError();
    assertThat(countsStore.txId()).as("Count store should be rotated once at least").isGreaterThan(0L);
    long lastRotationTx = checkPointer.forceCheckPoint(new SimpleTriggerInfo("test"));
    assertEquals(transactionIdStore.getLastClosedTransactionId(), lastRotationTx, "NeoStore last closed transaction id should be equal last count store rotation transaction id.");
    assertEquals(transactionIdStore.getLastClosedTransactionId(), countsStore.txId(), "Last closed transaction should be last rotated tx in count store");
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) Transaction(org.neo4j.graphdb.Transaction) Workers(org.neo4j.internal.batchimport.cache.idmapping.string.Workers) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 4 with Timeout

use of org.junit.jupiter.api.Timeout in project neo4j by neo4j.

the class KernelTransactionTimeoutMonitorIT method terminatingTransactionMustEagerlyReleaseTheirLocks.

@Test
@Timeout(30)
void terminatingTransactionMustEagerlyReleaseTheirLocks() throws Exception {
    AtomicBoolean nodeLockAcquired = new AtomicBoolean();
    AtomicBoolean lockerDone = new AtomicBoolean();
    BinaryLatch lockerPause = new BinaryLatch();
    long nodeId;
    try (Transaction tx = database.beginTx()) {
        nodeId = tx.createNode().getId();
        tx.commit();
    }
    Future<?> locker = executor.submit(() -> {
        try (Transaction tx = database.beginTx()) {
            Node node = tx.getNodeById(nodeId);
            tx.acquireReadLock(node);
            nodeLockAcquired.set(true);
            lockerPause.await();
        }
        lockerDone.set(true);
    });
    boolean proceed;
    do {
        proceed = nodeLockAcquired.get();
    } while (!proceed);
    terminateOngoingTransaction();
    // but the thread should still be blocked on the latch
    assertFalse(lockerDone.get());
    // Yet we should be able to proceed and grab the locks they once held
    try (Transaction tx = database.beginTx()) {
        // Write-locking is only possible if their shared lock was released
        tx.acquireWriteLock(tx.getNodeById(nodeId));
        tx.commit();
    }
    // No exception from our lock client being stopped (e.g. we ended up blocked for too long) or from timeout
    lockerPause.release();
    locker.get();
    assertTrue(lockerDone.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Node(org.neo4j.graphdb.Node) BinaryLatch(org.neo4j.util.concurrent.BinaryLatch) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 5 with Timeout

use of org.junit.jupiter.api.Timeout in project neo4j by neo4j.

the class RecordStorageEngineTest method shutdownRecordStorageEngineAfterFailedTransaction.

@Test
@Timeout(30)
void shutdownRecordStorageEngineAfterFailedTransaction() throws Exception {
    RecordStorageEngine engine = buildRecordStorageEngine();
    Exception applicationError = executeFailingTransaction(engine);
    assertNotNull(applicationError);
}
Also used : UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) IOException(java.io.IOException) KernelException(org.neo4j.exceptions.KernelException) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Aggregations

Timeout (org.junit.jupiter.api.Timeout)228 Test (org.junit.jupiter.api.Test)198 CountDownLatch (java.util.concurrent.CountDownLatch)45 ZooKeeper (org.apache.zookeeper.ZooKeeper)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)29 LocalChannel (io.netty.channel.local.LocalChannel)27 CountdownWatcher (org.apache.zookeeper.test.ClientBase.CountdownWatcher)26 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)25 Bootstrap (io.netty.bootstrap.Bootstrap)24 ArrayList (java.util.ArrayList)24 Channel (io.netty.channel.Channel)23 MethodSource (org.junit.jupiter.params.provider.MethodSource)23 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)21 IOException (java.io.IOException)20 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)20 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)19 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)19 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)19 EventLoopGroup (io.netty.channel.EventLoopGroup)18 InetSocketAddress (java.net.InetSocketAddress)18