Search in sources :

Example 51 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource in project redisson by redisson.

the class RedissonSpringCacheTest method testPutGet.

@ParameterizedTest
@MethodSource("data")
public void testPutGet(Class<?> contextClass) {
    AnnotationConfigApplicationContext context = contexts.get(contextClass);
    SampleBean bean = context.getBean(SampleBean.class);
    bean.store("object1", new SampleObject("name1", "value1"));
    SampleObject s = bean.read("object1");
    assertThat(s.getName()).isEqualTo("name1");
    assertThat(s.getValue()).isEqualTo("value1");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 52 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource in project neo4j by neo4j.

the class TestAStar method testSimplest.

/**
 * <pre>
 *   01234567
 *  +-------->x  A - C: 10
 * 0|A      C    A - B:  2 (x2)
 * 1|  B         B - C:  3
 *  V
 *  y
 * </pre>
 */
@ParameterizedTest
@MethodSource("params")
void testSimplest(Function<EvaluationContext, PathFinder<WeightedPath>> finderFactory) {
    try (Transaction transaction = graphDb.beginTx()) {
        Node nodeA = graph.makeNode(transaction, "A", "x", 0d, "y", 0d);
        Node nodeB = graph.makeNode(transaction, "B", "x", 2d, "y", 1d);
        Node nodeC = graph.makeNode(transaction, "C", "x", 7d, "y", 0d);
        Relationship relAB = graph.makeEdge(transaction, "A", "B", "length", 2d);
        Relationship relAB2 = graph.makeEdge(transaction, "A", "B", "length", 2);
        Relationship relBC = graph.makeEdge(transaction, "B", "C", "length", 3f);
        Relationship relAC = graph.makeEdge(transaction, "A", "C", "length", (short) 10);
        int counter = 0;
        var context = new BasicEvaluationContext(transaction, graphDb);
        Iterable<WeightedPath> allPaths = finderFactory.apply(context).findAllPaths(nodeA, nodeC);
        for (WeightedPath path : allPaths) {
            assertEquals((Double) 5d, (Double) path.weight());
            assertPath(path, nodeA, nodeB, nodeC);
            counter++;
        }
        assertEquals(1, counter);
        transaction.commit();
    }
}
Also used : BasicEvaluationContext(org.neo4j.graphalgo.BasicEvaluationContext) WeightedPath(org.neo4j.graphalgo.WeightedPath) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 53 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource in project neo4j by neo4j.

the class TestAStar method pathToSelfReturnsZero.

@ParameterizedTest
@MethodSource("params")
void pathToSelfReturnsZero(Function<EvaluationContext, PathFinder<WeightedPath>> finderFactory) {
    // GIVEN
    try (Transaction transaction = graphDb.beginTx()) {
        Node start = graph.makeNode(transaction, "start", "x", 0d, "y", 0d);
        // WHEN
        var context = new BasicEvaluationContext(transaction, graphDb);
        WeightedPath path = finderFactory.apply(context).findSinglePath(start, start);
        // THEN
        assertNotNull(path);
        assertEquals(start, path.startNode());
        assertEquals(start, path.endNode());
        assertEquals(0, path.length());
        transaction.commit();
    }
}
Also used : BasicEvaluationContext(org.neo4j.graphalgo.BasicEvaluationContext) WeightedPath(org.neo4j.graphalgo.WeightedPath) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 54 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource in project neo4j by neo4j.

the class TestAStar method wikipediaExample.

@ParameterizedTest
@MethodSource("params")
void wikipediaExample(Function<EvaluationContext, PathFinder<WeightedPath>> finderFactory) {
    /* GIVEN
         *
         * (start)---2--->(d)
         *    \             \
         *    1.5            .\
         *     v               3
         *    (a)-\             v
         *         -2-\         (e)
         *             ->(b)     \
         *               /        \
         *           /--           2
         *      /-3-                v
         *     v        --4------->(end)
         *    (c)------/
         */
    try (Transaction transaction = graphDb.beginTx()) {
        Node start = graph.makeNode(transaction, "start", "x", 0d, "y", 0d);
        graph.makeNode(transaction, "a", "x", 0.3d, "y", 1d);
        graph.makeNode(transaction, "b", "x", 2d, "y", 2d);
        graph.makeNode(transaction, "c", "x", 0d, "y", 3d);
        graph.makeNode(transaction, "d", "x", 2d, "y", 0d);
        graph.makeNode(transaction, "e", "x", 3d, "y", 1.5d);
        Node end = graph.makeNode(transaction, "end", "x", 3.3d, "y", 2.8d);
        graph.makeEdge(transaction, "start", "a", "length", 1.5d);
        graph.makeEdge(transaction, "a", "b", "length", 2f);
        graph.makeEdge(transaction, "b", "c", "length", 3);
        graph.makeEdge(transaction, "c", "end", "length", 4L);
        graph.makeEdge(transaction, "start", "d", "length", (short) 2);
        graph.makeEdge(transaction, "d", "e", "length", (byte) 3);
        graph.makeEdge(transaction, "e", "end", "length", 2);
        // WHEN
        var context = new BasicEvaluationContext(transaction, graphDb);
        WeightedPath path = finderFactory.apply(context).findSinglePath(start, end);
        // THEN
        assertPathDef(path, "start", "d", "e", "end");
        transaction.commit();
    }
}
Also used : BasicEvaluationContext(org.neo4j.graphalgo.BasicEvaluationContext) WeightedPath(org.neo4j.graphalgo.WeightedPath) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 55 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource in project neo4j by neo4j.

the class TestBestFirstSelectorFactory method shouldDoWholeTraversalInCorrectOrder.

@ParameterizedTest
@MethodSource("params")
void shouldDoWholeTraversalInCorrectOrder(PathExpander expander, PathInterest<Integer> interest, Uniqueness uniqueness, String[] expectedResult) {
    try (Transaction transaction = graphDb.beginTx()) {
        var factory = new BestFirstSelectorFactory<Integer, Integer>(interest) {

            private final CostEvaluator<Integer> evaluator = CommonEvaluators.intCostEvaluator(LENGTH);

            @Override
            protected Integer getStartData() {
                return 0;
            }

            @Override
            protected Integer addPriority(TraversalBranch source, Integer currentAggregatedValue, Integer value) {
                return value + currentAggregatedValue;
            }

            @Override
            protected Integer calculateValue(TraversalBranch next) {
                return next.length() == 0 ? 0 : evaluator.getCost(next.lastRelationship(), Direction.BOTH);
            }
        };
        Node a = transaction.getNodeById(graph.getNode(transaction, "a").getId());
        Traverser traverser = new MonoDirectionalTraversalDescription().expand(expander).order(factory).uniqueness(uniqueness).traverse(a);
        var iterator = traverser.iterator();
        int i = 0;
        while (iterator.hasNext()) {
            assertPath(transaction, iterator.next(), expectedResult[i]);
            i++;
        }
        assertEquals(expectedResult.length, i, String.format("Not all expected paths where traversed. Missing paths are %s\n", Arrays.toString(Arrays.copyOfRange(expectedResult, i, expectedResult.length))));
        transaction.commit();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) CostEvaluator(org.neo4j.graphalgo.CostEvaluator) Node(org.neo4j.graphdb.Node) Traverser(org.neo4j.graphdb.traversal.Traverser) MonoDirectionalTraversalDescription(org.neo4j.kernel.impl.traversal.MonoDirectionalTraversalDescription) TraversalBranch(org.neo4j.graphdb.traversal.TraversalBranch) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

MethodSource (org.junit.jupiter.params.provider.MethodSource)1199 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1184 Transaction (org.neo4j.graphdb.Transaction)103 Stream (java.util.stream.Stream)70 Test (org.junit.jupiter.api.Test)67 ArrayList (java.util.ArrayList)63 InterruptAfter (io.aeron.test.InterruptAfter)60 List (java.util.List)60 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)58 TimeUnit (java.util.concurrent.TimeUnit)54 IOException (java.io.IOException)52 CountDownLatch (java.util.concurrent.CountDownLatch)52 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)52 lombok.val (lombok.val)52 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)51 Arguments (org.junit.jupiter.params.provider.Arguments)47 AfterEach (org.junit.jupiter.api.AfterEach)46 SSLEngine (javax.net.ssl.SSLEngine)44 AtomicReference (java.util.concurrent.atomic.AtomicReference)43 Path (java.nio.file.Path)42