Search in sources :

Example 71 with ValueSource

use of org.junit.jupiter.params.provider.ValueSource in project dhis2-core by dhis2.

the class TeiUpdateTests method shouldReturnErrorWhenTeiDoesntExist.

@ParameterizedTest
@ValueSource(strings = { "UPDATE", "DELETE" })
public void shouldReturnErrorWhenTeiDoesntExist(String importStrategy) throws Exception {
    JsonObject teiBody = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/importer/teis/tei.json"));
    ApiResponse response = trackerActions.postAndGetJobReport(teiBody, new QueryParamsBuilder().add(String.format("importStrategy=%s", importStrategy)));
    response.validate().statusCode(200).body("status", equalTo("ERROR")).body("stats.ignored", equalTo(1)).body("validationReport.errorReports", notNullValue()).rootPath("validationReport.errorReports[0]").body("errorCode", equalTo("E1063")).body("message", containsStringIgnoringCase("does not exist"));
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 72 with ValueSource

use of org.junit.jupiter.params.provider.ValueSource in project spring-framework by spring-projects.

the class DataSourceTransactionManagerTests method transactionWithTimeout.

@ParameterizedTest(name = "transaction with {0} second timeout")
@ValueSource(ints = { 1, 10 })
@EnabledForTestGroups(LONG_RUNNING)
public void transactionWithTimeout(int timeout) throws Exception {
    PreparedStatement ps = mock(PreparedStatement.class);
    given(con.getAutoCommit()).willReturn(true);
    given(con.prepareStatement("some SQL statement")).willReturn(ps);
    TransactionTemplate tt = new TransactionTemplate(tm);
    tt.setTimeout(timeout);
    boolean condition1 = !TransactionSynchronizationManager.hasResource(ds);
    assertThat(condition1).as("Hasn't thread connection").isTrue();
    try {
        tt.execute(new TransactionCallbackWithoutResult() {

            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                try {
                    Thread.sleep(1500);
                } catch (InterruptedException ex) {
                }
                try {
                    Connection con = DataSourceUtils.getConnection(ds);
                    PreparedStatement ps = con.prepareStatement("some SQL statement");
                    DataSourceUtils.applyTransactionTimeout(ps, ds);
                } catch (SQLException ex) {
                    throw new DataAccessResourceFailureException("", ex);
                }
            }
        });
        if (timeout <= 1) {
            fail("Should have thrown TransactionTimedOutException");
        }
    } catch (TransactionTimedOutException ex) {
        if (timeout <= 1) {
        // expected
        } else {
            throw ex;
        }
    }
    boolean condition = !TransactionSynchronizationManager.hasResource(ds);
    assertThat(condition).as("Hasn't thread connection").isTrue();
    if (timeout > 1) {
        verify(ps).setQueryTimeout(timeout - 1);
        verify(con).commit();
    } else {
        verify(con).rollback();
    }
    InOrder ordered = inOrder(con);
    ordered.verify(con).setAutoCommit(false);
    ordered.verify(con).setAutoCommit(true);
    verify(con).close();
}
Also used : TransactionTimedOutException(org.springframework.transaction.TransactionTimedOutException) InOrder(org.mockito.InOrder) UncategorizedSQLException(org.springframework.jdbc.UncategorizedSQLException) SQLException(java.sql.SQLException) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Connection(java.sql.Connection) TransactionStatus(org.springframework.transaction.TransactionStatus) PreparedStatement(java.sql.PreparedStatement) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) EnabledForTestGroups(org.springframework.core.testfixture.EnabledForTestGroups)

Example 73 with ValueSource

use of org.junit.jupiter.params.provider.ValueSource in project spring-framework by spring-projects.

the class JdbcTransactionManagerTests method transactionWithTimeout.

@ParameterizedTest(name = "transaction with {0} second timeout")
@ValueSource(ints = { 1, 10 })
@EnabledForTestGroups(LONG_RUNNING)
public void transactionWithTimeout(int timeout) throws Exception {
    PreparedStatement ps = mock(PreparedStatement.class);
    given(con.getAutoCommit()).willReturn(true);
    given(con.prepareStatement("some SQL statement")).willReturn(ps);
    TransactionTemplate tt = new TransactionTemplate(tm);
    tt.setTimeout(timeout);
    boolean condition1 = !TransactionSynchronizationManager.hasResource(ds);
    assertThat(condition1).as("Hasn't thread connection").isTrue();
    try {
        tt.execute(new TransactionCallbackWithoutResult() {

            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                try {
                    Thread.sleep(1500);
                } catch (InterruptedException ex) {
                }
                try {
                    Connection con = DataSourceUtils.getConnection(ds);
                    PreparedStatement ps = con.prepareStatement("some SQL statement");
                    DataSourceUtils.applyTransactionTimeout(ps, ds);
                } catch (SQLException ex) {
                    throw new DataAccessResourceFailureException("", ex);
                }
            }
        });
        if (timeout <= 1) {
            fail("Should have thrown TransactionTimedOutException");
        }
    } catch (TransactionTimedOutException ex) {
        if (timeout <= 1) {
        // expected
        } else {
            throw ex;
        }
    }
    boolean condition = !TransactionSynchronizationManager.hasResource(ds);
    assertThat(condition).as("Hasn't thread connection").isTrue();
    if (timeout > 1) {
        verify(ps).setQueryTimeout(timeout - 1);
        verify(con).commit();
    } else {
        verify(con).rollback();
    }
    InOrder ordered = inOrder(con);
    ordered.verify(con).setAutoCommit(false);
    ordered.verify(con).setAutoCommit(true);
    verify(con).close();
}
Also used : TransactionTimedOutException(org.springframework.transaction.TransactionTimedOutException) InOrder(org.mockito.InOrder) UncategorizedSQLException(org.springframework.jdbc.UncategorizedSQLException) SQLException(java.sql.SQLException) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Connection(java.sql.Connection) TransactionStatus(org.springframework.transaction.TransactionStatus) PreparedStatement(java.sql.PreparedStatement) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) EnabledForTestGroups(org.springframework.core.testfixture.EnabledForTestGroups)

Example 74 with ValueSource

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

the class GraphHopperWebTest method testGetClientForRequest.

@ParameterizedTest(name = "POST={0}")
@ValueSource(booleans = { true, false })
public void testGetClientForRequest(boolean usePost) {
    GraphHopperWeb gh = new GraphHopperWeb(null).setPostRequest(usePost);
    GHRequest req = new GHRequest().addPoint(new GHPoint(42.509225, 1.534728)).addPoint(new GHPoint(42.512602, 1.551558)).putHint("vehicle", "car");
    req.putHint(GraphHopperWeb.TIMEOUT, 5);
    assertEquals(5, gh.getClientForRequest(req).connectTimeoutMillis());
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 75 with ValueSource

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

the class CHTurnCostTest method test_issue_1593_simple.

@ParameterizedTest
@ValueSource(strings = { DIJKSTRA_BI, ASTAR_BI })
public void test_issue_1593_simple(String algo) {
    // 1
    // |
    // 3-0-x-5-4
    // |
    // 2
    NodeAccess na = graph.getNodeAccess();
    na.setNode(1, 0.2, 0.0);
    na.setNode(3, 0.1, 0.0);
    na.setNode(2, 0.0, 0.0);
    na.setNode(0, 0.1, 0.1);
    na.setNode(5, 0.1, 0.2);
    na.setNode(4, 0.1, 0.3);
    EdgeIteratorState edge0 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 1).setDistance(10));
    EdgeIteratorState edge1 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 3).setDistance(10));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 0).setDistance(10));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 5).setDistance(10));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(5, 4).setDistance(10));
    // cannot go, 2-3-1
    setRestriction(edge1, edge0, 3);
    graph.freeze();
    prepareCH(0, 1, 2, 3, 4, 5);
    assertEquals(5, chGraph.getBaseGraph().getEdges());
    assertEquals(7, chGraph.getEdges(), "expected two shortcuts: 3->5 and 5->3");
    // there should be no path from 2 to 1, because of the turn restriction and because u-turns are not allowed
    assertFalse(findPathUsingDijkstra(2, 1).isFound());
    compareCHQueryWithDijkstra(2, 1);
    // we have to pay attention when there are virtual nodes: turning from the shortcut 3-5 onto the
    // virtual edge 5-x should be forbidden.
    LocationIndexTree index = new LocationIndexTree(graph, new RAMDirectory());
    index.prepareIndex();
    Snap snap = index.findClosest(0.1, 0.15, EdgeFilter.ALL_EDGES);
    QueryGraph queryGraph = QueryGraph.create(graph, snap);
    assertEquals(1, queryGraph.getNodes() - chGraph.getNodes(), "expected one virtual node");
    QueryRoutingCHGraph routingCHGraph = new QueryRoutingCHGraph(chGraph, queryGraph);
    RoutingAlgorithm chAlgo = new CHRoutingAlgorithmFactory(routingCHGraph).createAlgo(new PMap().putObject(ALGORITHM, algo));
    Path path = chAlgo.calcPath(2, 1);
    assertFalse(path.isFound(), "no path should be found, but found " + path.calcNodes());
}
Also used : RoutingAlgorithm(com.graphhopper.routing.RoutingAlgorithm) Path(com.graphhopper.routing.Path) QueryRoutingCHGraph(com.graphhopper.routing.querygraph.QueryRoutingCHGraph) Snap(com.graphhopper.storage.index.Snap) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) 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