Search in sources :

Example 91 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest in project logging-log4j2 by apache.

the class JsonTemplateLayoutConcurrentEncodeTest method test_concurrent_encode.

@ParameterizedTest
@ValueSource(strings = { "dummy", "threadLocal", "queue:supplier=java.util.concurrent.ArrayBlockingQueue.new", "queue:supplier=org.jctools.queues.MpmcArrayQueue.new" })
void test_concurrent_encode(final String recyclerFactory) throws IOException {
    final Path appenderFilepath = createAppenderFilepath(recyclerFactory);
    final int workerCount = 10;
    final int messageLength = 1_000;
    final int messageCount = 1_000;
    try {
        withContextFromTemplate(appenderFilepath, recyclerFactory, loggerContext -> {
            final Logger logger = loggerContext.getLogger(JsonTemplateLayoutConcurrentEncodeTest.class);
            runWorkers(workerCount, messageLength, messageCount, logger);
        });
        verifyLines(appenderFilepath, messageLength, workerCount * messageCount);
    } catch (final Throwable error) {
        final String message = String.format("test failure for appender pointing to file: `%s`", appenderFilepath);
        throw new AssertionError(message, error);
    }
    Files.delete(appenderFilepath);
}
Also used : Path(java.nio.file.Path) Logger(org.apache.logging.log4j.Logger) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 92 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest in project logging-log4j2 by apache.

the class AsyncAppenderExceptionHandlingTest method AsyncAppender_should_not_stop_on_appender_failures.

@ParameterizedTest
@ValueSource(strings = { FailOnceAppender.ThrowableClassName.RUNTIME_EXCEPTION, FailOnceAppender.ThrowableClassName.LOGGING_EXCEPTION, FailOnceAppender.ThrowableClassName.EXCEPTION, FailOnceAppender.ThrowableClassName.ERROR, FailOnceAppender.ThrowableClassName.THROWABLE, FailOnceAppender.ThrowableClassName.THREAD_DEATH })
void AsyncAppender_should_not_stop_on_appender_failures(String throwableClassName) {
    // Create the logger.
    final String throwableClassNamePropertyName = "throwableClassName";
    System.setProperty(throwableClassNamePropertyName, throwableClassName);
    try (final LoggerContext loggerContext = Configurator.initialize("Test", "AsyncAppenderExceptionHandlingTest.xml")) {
        final Logger logger = loggerContext.getRootLogger();
        // Log the 1st message, which should fail due to the FailOnceAppender.
        logger.info("message #1");
        // Log the 2nd message, which should succeed.
        final String lastLogMessage = "message #2";
        logger.info(lastLogMessage);
        // Stop the AsyncAppender to drain the queued events.
        Configuration configuration = loggerContext.getConfiguration();
        AsyncAppender asyncAppender = configuration.getAppender("Async");
        Assertions.assertNotNull(asyncAppender, "couldn't obtain the FailOnceAppender");
        asyncAppender.stop();
        // Verify the logged message.
        final FailOnceAppender failOnceAppender = configuration.getAppender("FailOnce");
        Assertions.assertNotNull(failOnceAppender, "couldn't obtain the FailOnceAppender");
        Assertions.assertTrue(failOnceAppender.isFailed(), "FailOnceAppender hasn't failed yet");
        final List<String> accumulatedMessages = failOnceAppender.drainEvents().stream().map(LogEvent::getMessage).map(Message::getFormattedMessage).collect(Collectors.toList());
        Assertions.assertEquals(Collections.singletonList(lastLogMessage), accumulatedMessages);
    } finally {
        System.setProperty(throwableClassNamePropertyName, Strings.EMPTY);
    }
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) AsyncAppender(org.apache.logging.log4j.core.appender.AsyncAppender) LogEvent(org.apache.logging.log4j.core.LogEvent) Logger(org.apache.logging.log4j.core.Logger) LoggerContext(org.apache.logging.log4j.core.LoggerContext) FailOnceAppender(org.apache.logging.log4j.core.test.appender.FailOnceAppender) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 93 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest in project okhttp by square.

the class HpackRoundTripTest method testRoundTrip.

@ParameterizedTest
@ArgumentsSource(StoriesTestProvider.class)
public void testRoundTrip(Story story) throws Exception {
    Assumptions.assumeFalse(story == Story.MISSING, "Test stories missing, checkout git submodule");
    Story story2 = story.clone();
    // Mutate cases in base class.
    for (Case caze : story2.getCases()) {
        hpackWriter.writeHeaders(caze.getHeaders());
        caze.setWire(bytesOut.readByteString());
    }
    testDecoder(story2);
}
Also used : Story(okhttp3.internal.http2.hpackjson.Story) Case(okhttp3.internal.http2.hpackjson.Case) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 94 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest in project spring-security by spring-projects.

the class NimbusReactiveOpaqueTokenIntrospectorTests method handleNonJsonContentType.

@ParameterizedTest(name = "{displayName} when Content-Type={0}")
@ValueSource(strings = { MediaType.APPLICATION_CBOR_VALUE, MediaType.TEXT_MARKDOWN_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_OCTET_STREAM_VALUE })
public void handleNonJsonContentType(String type) {
    WebClient client = mockResponse(ACTIVE_RESPONSE, type);
    ReactiveOpaqueTokenIntrospector introspectionClient = new NimbusReactiveOpaqueTokenIntrospector(INTROSPECTION_URL, client);
    assertThatExceptionOfType(OAuth2IntrospectionException.class).isThrownBy(() -> introspectionClient.introspect("sometokenhere").block());
}
Also used : WebClient(org.springframework.web.reactive.function.client.WebClient) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 95 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest in project storm by apache.

the class TopologyIntegrationTest method testBasicTopology.

@ParameterizedTest
@ValueSource(strings = { "true", "false" })
public void testBasicTopology(boolean useLocalMessaging) throws Exception {
    try (LocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().withSupervisors(4).withDaemonConf(Collections.singletonMap(Config.STORM_LOCAL_MODE_ZMQ, !useLocalMessaging)).build()) {
        TopologyBuilder builder = new TopologyBuilder();
        builder.setSpout("1", new TestWordSpout(true), 3);
        builder.setBolt("2", new TestWordCounter(), 4).fieldsGrouping("1", new Fields("word"));
        builder.setBolt("3", new TestGlobalCount()).globalGrouping("1");
        builder.setBolt("4", new TestAggregatesCounter()).globalGrouping("2");
        StormTopology topology = builder.createTopology();
        Map<String, Object> stormConf = new HashMap<>();
        stormConf.put(Config.TOPOLOGY_WORKERS, 2);
        stormConf.put(Config.TOPOLOGY_TESTING_ALWAYS_TRY_SERIALIZE, true);
        List<FixedTuple> testTuples = Arrays.asList("nathan", "bob", "joey", "nathan").stream().map(value -> new FixedTuple(new Values(value))).collect(Collectors.toList());
        MockedSources mockedSources = new MockedSources(Collections.singletonMap("1", testTuples));
        CompleteTopologyParam completeTopologyParams = new CompleteTopologyParam();
        completeTopologyParams.setMockedSources(mockedSources);
        completeTopologyParams.setStormConf(stormConf);
        Map<String, List<FixedTuple>> results = Testing.completeTopology(cluster, topology, completeTopologyParams);
        assertThat(Testing.readTuples(results, "1"), containsInAnyOrder(new Values("nathan"), new Values("nathan"), new Values("bob"), new Values("joey")));
        assertThat(Testing.readTuples(results, "2"), containsInAnyOrder(new Values("nathan", 1), new Values("nathan", 2), new Values("bob", 1), new Values("joey", 1)));
        assertThat(Testing.readTuples(results, "3"), contains(new Values(1), new Values(2), new Values(3), new Values(4)));
        assertThat(Testing.readTuples(results, "4"), contains(new Values(1), new Values(2), new Values(3), new Values(4)));
    }
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) OutputFieldsDeclarer(org.apache.storm.topology.OutputFieldsDeclarer) BaseRichSpout(org.apache.storm.topology.base.BaseRichSpout) Arrays(java.util.Arrays) TopologyContext(org.apache.storm.task.TopologyContext) SubmitOptions(org.apache.storm.generated.SubmitOptions) AssertLoop.assertFailed(org.apache.storm.AssertLoop.assertFailed) Assert.assertThat(org.junit.Assert.assertThat) Map(java.util.Map) TestAggregatesCounter(org.apache.storm.testing.TestAggregatesCounter) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) TestWordSpout(org.apache.storm.testing.TestWordSpout) MockedSources(org.apache.storm.testing.MockedSources) BaseRichBolt(org.apache.storm.topology.base.BaseRichBolt) EmitInfo(org.apache.storm.hooks.info.EmitInfo) FixedTuple(org.apache.storm.testing.FixedTuple) BoltAckInfo(org.apache.storm.hooks.info.BoltAckInfo) Fields(org.apache.storm.tuple.Fields) Collectors(java.util.stream.Collectors) TestWordCounter(org.apache.storm.testing.TestWordCounter) Test(org.junit.jupiter.api.Test) List(java.util.List) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) TrackedTopology(org.apache.storm.testing.TrackedTopology) Config(org.apache.storm.Config) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) TestGlobalCount(org.apache.storm.testing.TestGlobalCount) IntStream(java.util.stream.IntStream) TestConfBolt(org.apache.storm.testing.TestConfBolt) Testing(org.apache.storm.Testing) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FeederSpout(org.apache.storm.testing.FeederSpout) Values(org.apache.storm.tuple.Values) Tuple(org.apache.storm.tuple.Tuple) OutputCollector(org.apache.storm.task.OutputCollector) StormTopology(org.apache.storm.generated.StormTopology) BoltFailInfo(org.apache.storm.hooks.info.BoltFailInfo) CompleteTopologyParam(org.apache.storm.testing.CompleteTopologyParam) BoltExecuteInfo(org.apache.storm.hooks.info.BoltExecuteInfo) TestPlannerSpout(org.apache.storm.testing.TestPlannerSpout) ValueSource(org.junit.jupiter.params.provider.ValueSource) AssertLoop.assertAcked(org.apache.storm.AssertLoop.assertAcked) AckFailMapTracker(org.apache.storm.testing.AckFailMapTracker) TopologyInitialStatus(org.apache.storm.generated.TopologyInitialStatus) BaseTaskHook(org.apache.storm.hooks.BaseTaskHook) Consumer(java.util.function.Consumer) LocalCluster(org.apache.storm.LocalCluster) IntegrationTest(org.apache.storm.testing.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) Collections(java.util.Collections) LocalCluster(org.apache.storm.LocalCluster) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) HashMap(java.util.HashMap) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) StormTopology(org.apache.storm.generated.StormTopology) Values(org.apache.storm.tuple.Values) TestWordCounter(org.apache.storm.testing.TestWordCounter) TestAggregatesCounter(org.apache.storm.testing.TestAggregatesCounter) FixedTuple(org.apache.storm.testing.FixedTuple) MockedSources(org.apache.storm.testing.MockedSources) Fields(org.apache.storm.tuple.Fields) TestGlobalCount(org.apache.storm.testing.TestGlobalCount) CompleteTopologyParam(org.apache.storm.testing.CompleteTopologyParam) TestWordSpout(org.apache.storm.testing.TestWordSpout) List(java.util.List) ArrayList(java.util.ArrayList) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2045 MethodSource (org.junit.jupiter.params.provider.MethodSource)1116 EnumSource (org.junit.jupiter.params.provider.EnumSource)325 ValueSource (org.junit.jupiter.params.provider.ValueSource)302 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)181 Transaction (org.neo4j.graphdb.Transaction)117 CsvSource (org.junit.jupiter.params.provider.CsvSource)113 ArrayList (java.util.ArrayList)112 ByteBuffer (java.nio.ByteBuffer)81 List (java.util.List)81 Path (java.nio.file.Path)75 Test (org.junit.jupiter.api.Test)74 InterruptAfter (io.aeron.test.InterruptAfter)72 IOException (java.io.IOException)72 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)67 TimeUnit (java.util.concurrent.TimeUnit)65 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)62 CountDownLatch (java.util.concurrent.CountDownLatch)61 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)60 Stream (java.util.stream.Stream)59