Search in sources :

Example 86 with ValueSource

use of org.junit.jupiter.params.provider.ValueSource in project zookeeper by apache.

the class MultiOperationTest method testMultiRead.

@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testMultiRead(boolean useAsync) throws Exception {
    zk.create("/node1", "data1".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/node2", "data2".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
    zk.create("/node1/node1", "data11".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/node1/node2", "data12".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    List<OpResult> multiRead = multi(zk, Arrays.asList(Op.getChildren("/node1"), Op.getData("/node1"), Op.getChildren("/node2"), Op.getData("/node2")), useAsync);
    assertEquals(multiRead.size(), 4);
    assertTrue(multiRead.get(0) instanceof OpResult.GetChildrenResult);
    List<String> childrenList = ((OpResult.GetChildrenResult) multiRead.get(0)).getChildren();
    assertEquals(childrenList.size(), 2);
    assertEquals(new TreeSet<String>(childrenList), new TreeSet<String>(Arrays.asList("node1", "node2")));
    assertArrayEquals(((OpResult.GetDataResult) multiRead.get(1)).getData(), "data1".getBytes());
    Stat stat = ((OpResult.GetDataResult) multiRead.get(1)).getStat();
    assertEquals(stat.getMzxid(), stat.getCzxid());
    assertEquals(stat.getCtime(), stat.getMtime());
    assertEquals(2, stat.getCversion());
    assertEquals(0, stat.getVersion());
    assertEquals(0, stat.getAversion());
    assertEquals(0, stat.getEphemeralOwner());
    assertEquals(5, stat.getDataLength());
    assertEquals(2, stat.getNumChildren());
    assertTrue(multiRead.get(2) instanceof OpResult.GetChildrenResult);
    childrenList = ((OpResult.GetChildrenResult) multiRead.get(2)).getChildren();
    assertTrue(childrenList.isEmpty());
    assertArrayEquals(((OpResult.GetDataResult) multiRead.get(3)).getData(), "data2".getBytes());
    stat = ((OpResult.GetDataResult) multiRead.get(3)).getStat();
    assertEquals(stat.getMzxid(), stat.getCzxid());
    assertEquals(stat.getMzxid(), stat.getPzxid());
    assertEquals(stat.getCtime(), stat.getMtime());
    assertEquals(0, stat.getCversion());
    assertEquals(0, stat.getVersion());
    assertEquals(0, stat.getAversion());
    assertEquals(zk.getSessionId(), stat.getEphemeralOwner());
    assertEquals(5, stat.getDataLength());
    assertEquals(0, stat.getNumChildren());
}
Also used : Stat(org.apache.zookeeper.data.Stat) OpResult(org.apache.zookeeper.OpResult) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 87 with ValueSource

use of org.junit.jupiter.params.provider.ValueSource in project zookeeper by apache.

the class MultiOperationTest method testMultiGetChildrenAuthentication.

@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testMultiGetChildrenAuthentication(boolean useAsync) throws KeeperException, InterruptedException {
    List<ACL> writeOnly = Collections.singletonList(new ACL(ZooDefs.Perms.WRITE, new Id("world", "anyone")));
    zk.create("/foo_auth", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/foo_auth/bar", null, Ids.READ_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/foo_no_auth", null, writeOnly, CreateMode.PERSISTENT);
    // Check for normal behaviour.
    List<OpResult> multiChildrenList = multi(zk, Arrays.asList(Op.getChildren("/foo_auth")), useAsync);
    assertEquals(multiChildrenList.size(), 1);
    assertTrue(multiChildrenList.get(0) instanceof OpResult.GetChildrenResult);
    List<String> childrenList = ((OpResult.GetChildrenResult) multiChildrenList.get(0)).getChildren();
    assertEquals(childrenList.size(), 1);
    assertEquals(childrenList.get(0), "bar");
    // Check for authentication violation.
    multiChildrenList = multi(zk, Arrays.asList(Op.getChildren("/foo_no_auth")), useAsync);
    assertEquals(multiChildrenList.size(), 1);
    assertTrue(multiChildrenList.get(0) instanceof OpResult.ErrorResult);
    assertEquals(((OpResult.ErrorResult) multiChildrenList.get(0)).getErr(), KeeperException.Code.NOAUTH.intValue(), "Expected NoAuthException for getting the children of a write only node");
}
Also used : OpResult(org.apache.zookeeper.OpResult) ErrorResult(org.apache.zookeeper.OpResult.ErrorResult) ACL(org.apache.zookeeper.data.ACL) Id(org.apache.zookeeper.data.Id) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 88 with ValueSource

use of org.junit.jupiter.params.provider.ValueSource in project zookeeper by apache.

the class MultiOperationTest method testMultiGetChildrenMixedAuthenticationCorrectFirst.

@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testMultiGetChildrenMixedAuthenticationCorrectFirst(boolean useAsync) throws KeeperException, InterruptedException {
    List<ACL> writeOnly = Collections.singletonList(new ACL(ZooDefs.Perms.WRITE, new Id("world", "anyone")));
    zk.create("/foo_auth", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/foo_auth/bar", null, Ids.READ_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.create("/foo_no_auth", null, writeOnly, CreateMode.PERSISTENT);
    // Check for getting the children of the nodes with mixed authentication.
    // The getChildren operation returns GetChildrenResult if it happened before the error.
    List<OpResult> multiChildrenList;
    multiChildrenList = multi(zk, Arrays.asList(Op.getChildren("/foo_auth"), Op.getChildren("/foo_no_auth")), useAsync);
    assertSame(multiChildrenList.size(), 2);
    assertTrue(multiChildrenList.get(0) instanceof OpResult.GetChildrenResult);
    List<String> childrenList = ((OpResult.GetChildrenResult) multiChildrenList.get(0)).getChildren();
    assertEquals(childrenList.size(), 1);
    assertEquals(childrenList.get(0), "bar");
    assertTrue(multiChildrenList.get(1) instanceof OpResult.ErrorResult);
    assertEquals(((OpResult.ErrorResult) multiChildrenList.get(1)).getErr(), KeeperException.Code.NOAUTH.intValue(), "Expected NoAuthException for getting the children of a write only node");
}
Also used : OpResult(org.apache.zookeeper.OpResult) ErrorResult(org.apache.zookeeper.OpResult.ErrorResult) ACL(org.apache.zookeeper.data.ACL) Id(org.apache.zookeeper.data.Id) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 89 with ValueSource

use of org.junit.jupiter.params.provider.ValueSource in project zookeeper by apache.

the class MultiOperationTest method testOpResultEquals.

/**
 * Exercise the equals methods of OpResult classes.
 */
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testOpResultEquals(boolean useAsync) {
    opEquals(new CreateResult("/foo"), new CreateResult("/foo"), new CreateResult("nope"));
    opEquals(new CreateResult("/foo"), new CreateResult("/foo"), new CreateResult("/foo", new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)));
    opEquals(new CreateResult("/foo", new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)), new CreateResult("/foo", new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)), new CreateResult("nope", new Stat(11, 12, 13, 14, 15, 16, 17, 18, 19, 110, 111)));
    opEquals(new CreateResult("/foo", new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)), new CreateResult("/foo", new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)), new CreateResult("/foo"));
    opEquals(new CheckResult(), new CheckResult(), null);
    opEquals(new SetDataResult(new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)), new SetDataResult(new Stat(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)), new SetDataResult(new Stat(11, 12, 13, 14, 15, 16, 17, 18, 19, 110, 111)));
    opEquals(new ErrorResult(1), new ErrorResult(1), new ErrorResult(2));
    opEquals(new DeleteResult(), new DeleteResult(), null);
    opEquals(new ErrorResult(1), new ErrorResult(1), new ErrorResult(2));
}
Also used : SetDataResult(org.apache.zookeeper.OpResult.SetDataResult) Stat(org.apache.zookeeper.data.Stat) CreateResult(org.apache.zookeeper.OpResult.CreateResult) CheckResult(org.apache.zookeeper.OpResult.CheckResult) ErrorResult(org.apache.zookeeper.OpResult.ErrorResult) DeleteResult(org.apache.zookeeper.OpResult.DeleteResult) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 90 with ValueSource

use of org.junit.jupiter.params.provider.ValueSource in project graphhopper by graphhopper.

the class GraphHopperTest method testCompareAlgos.

@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testCompareAlgos(boolean turnCosts) {
    final String profile = "car";
    final String vehicle = "car";
    final String weighting = "fastest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MOSCOW).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting).setTurnCosts(turnCosts));
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile(profile));
    hopper.importOrLoad();
    long seed = System.nanoTime();
    Random rnd = new Random(seed);
    for (int i = 0; i < 100; i++) {
        BBox bounds = hopper.getGraphHopperStorage().getBounds();
        double lat1 = bounds.minLat + rnd.nextDouble() * (bounds.maxLat - bounds.minLat);
        double lat2 = bounds.minLat + rnd.nextDouble() * (bounds.maxLat - bounds.minLat);
        double lon1 = bounds.minLon + rnd.nextDouble() * (bounds.maxLon - bounds.minLon);
        double lon2 = bounds.minLon + rnd.nextDouble() * (bounds.maxLon - bounds.minLon);
        GHRequest req = new GHRequest(lat1, lon1, lat2, lon2);
        req.setProfile(profile);
        req.getHints().putObject(CH.DISABLE, false).putObject(Landmark.DISABLE, true);
        ResponsePath pathCH = hopper.route(req).getBest();
        req.getHints().putObject(CH.DISABLE, true).putObject(Landmark.DISABLE, false);
        ResponsePath pathLM = hopper.route(req).getBest();
        req.getHints().putObject(CH.DISABLE, true).putObject(Landmark.DISABLE, true);
        ResponsePath path = hopper.route(req).getBest();
        String failMessage = "seed: " + seed + ", i=" + i;
        assertEquals(path.hasErrors(), pathCH.hasErrors(), failMessage);
        assertEquals(path.hasErrors(), pathLM.hasErrors(), failMessage);
        if (!path.hasErrors()) {
            assertEquals(path.getDistance(), pathCH.getDistance(), 0.1, failMessage);
            assertEquals(path.getDistance(), pathLM.getDistance(), 0.1, failMessage);
            assertEquals(path.getTime(), pathCH.getTime(), failMessage);
            assertEquals(path.getTime(), pathLM.getTime(), failMessage);
        }
    }
}
Also used : CHProfile(com.graphhopper.config.CHProfile) BBox(com.graphhopper.util.shapes.BBox) LMProfile(com.graphhopper.config.LMProfile) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) GHPoint(com.graphhopper.util.shapes.GHPoint) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)266 ValueSource (org.junit.jupiter.params.provider.ValueSource)266 HashSet (java.util.HashSet)23 HistogramTestUtils.constructDoubleHistogram (org.HdrHistogram.HistogramTestUtils.constructDoubleHistogram)23 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)20 ApiResponse (org.hisp.dhis.dto.ApiResponse)15 UpdateModel (com.synopsys.integration.alert.update.model.UpdateModel)13 File (java.io.File)13 List (java.util.List)13 OffsetDateTime (java.time.OffsetDateTime)10 Map (java.util.Map)10 TimeUnit (java.util.concurrent.TimeUnit)10 TopicPartition (org.apache.kafka.common.TopicPartition)9 ListenerSubscribeMessage (io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage)8 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)8 ZooKeeper (org.apache.zookeeper.ZooKeeper)8 JsonObject (com.google.gson.JsonObject)7 IOException (java.io.IOException)7 CountDownLatch (java.util.concurrent.CountDownLatch)7