Search in sources :

Example 6 with ValueSource

use of org.junit.jupiter.params.provider.ValueSource 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 7 with ValueSource

use of org.junit.jupiter.params.provider.ValueSource 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 8 with ValueSource

use of org.junit.jupiter.params.provider.ValueSource 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)

Example 9 with ValueSource

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

the class BlobStoreTest method testWithAuthenticationDummy.

@ParameterizedTest
@ValueSource(booleans = { true, false })
void testWithAuthenticationDummy(boolean securityEnabled) throws Exception {
    try (AutoCloseableBlobStoreContainer container = initHdfs("/storm/blobstore-auth-dummy-sec-" + securityEnabled)) {
        BlobStore store = container.blobStore;
        Subject who = getSubject("test_subject");
        assertStoreHasExactly(store);
        // Tests for case when subject != null (security turned on) and
        // acls for the blob are set to WORLD_EVERYTHING
        SettableBlobMeta metadata = new SettableBlobMeta(securityEnabled ? BlobStoreAclHandler.DEFAULT : BlobStoreAclHandler.WORLD_EVERYTHING);
        try (AtomicOutputStream out = store.createBlob("test", metadata, who)) {
            out.write(1);
        }
        assertStoreHasExactly(store, "test");
        if (securityEnabled) {
            // Testing whether acls are set to WORLD_EVERYTHING. Here the acl should not contain WORLD_EVERYTHING because
            // the subject is neither null nor empty. The ACL should however contain USER_EVERYTHING as user needs to have
            // complete access to the blob
            assertTrue("ACL contains WORLD_EVERYTHING", !metadata.toString().contains("AccessControl(type:OTHER, access:7)"));
        } else {
            // Testing whether acls are set to WORLD_EVERYTHING
            assertTrue("ACL does not contain WORLD_EVERYTHING", metadata.toString().contains("AccessControl(type:OTHER, access:7)"));
        }
        readAssertEqualsWithAuth(store, who, "test", 1);
        LOG.info("Deleting test");
        store.deleteBlob("test", who);
        assertStoreHasExactly(store);
    }
}
Also used : AtomicOutputStream(org.apache.storm.blobstore.AtomicOutputStream) SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta) BlobStore(org.apache.storm.blobstore.BlobStore) Subject(javax.security.auth.Subject) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with ValueSource

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

the class TestGenericResourceAwareStrategy method testGenericResourceAwareStrategyWithSettingAckerExecutors.

/**
 * Test if the scheduling logic for the GenericResourceAwareStrategy is correct
 * with setting {@link Config#TOPOLOGY_ACKER_EXECUTORS}.
 *
 * Test details refer to {@link TestDefaultResourceAwareStrategy#testDefaultResourceAwareStrategyWithSettingAckerExecutors(int)}
 */
@ParameterizedTest
@ValueSource(ints = { -1, 0, 2, 200 })
public void testGenericResourceAwareStrategyWithSettingAckerExecutors(int numOfAckersPerWorker) throws InvalidTopologyException {
    int spoutParallelism = 1;
    int boltParallelism = 2;
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("spout", new TestSpout(), spoutParallelism);
    builder.setBolt("bolt-1", new TestBolt(), boltParallelism).shuffleGrouping("spout");
    builder.setBolt("bolt-2", new TestBolt(), boltParallelism).shuffleGrouping("bolt-1").addResource("gpu.count", 1.0);
    builder.setBolt("bolt-3", new TestBolt(), boltParallelism).shuffleGrouping("bolt-2").addResource("gpu.count", 2.0);
    String topoName = "testTopology";
    StormTopology stormToplogy = builder.createTopology();
    INimbus iNimbus = new INimbusTest();
    Config conf = createGrasClusterConfig(50, 500, 0, null, Collections.emptyMap());
    Map<String, Double> genericResourcesMap = new HashMap<>();
    genericResourcesMap.put("gpu.count", 2.0);
    Map<String, SupervisorDetails> supMap = genSupervisors(4, 4, 200, 2000, genericResourcesMap);
    conf.put(Config.TOPOLOGY_PRIORITY, 0);
    conf.put(Config.TOPOLOGY_NAME, topoName);
    conf.put(Config.TOPOLOGY_WORKER_MAX_HEAP_SIZE_MB, 2000);
    conf.put(Config.TOPOLOGY_SUBMITTER_USER, "user");
    conf.put(Config.TOPOLOGY_ACKER_EXECUTORS, 4);
    if (numOfAckersPerWorker == -1) {
    // Leave topology.acker.executors.per.worker unset
    } else {
        conf.put(Config.TOPOLOGY_RAS_ACKER_EXECUTORS_PER_WORKER, numOfAckersPerWorker);
    }
    int estimatedNumWorker = ServerUtils.getEstimatedWorkerCountForRasTopo(conf, stormToplogy);
    Nimbus.setUpAckerExecutorConfigs(topoName, conf, conf, estimatedNumWorker);
    conf.put(Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB, 250);
    conf.put(Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT, 50);
    TopologyDetails topo = new TopologyDetails("testTopology-id", conf, stormToplogy, 0, genExecsAndComps(StormCommon.systemTopology(conf, stormToplogy)), currentTime, "user");
    Topologies topologies = new Topologies(topo);
    Cluster cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supMap, new HashMap<>(), topologies, conf);
    scheduler = new ResourceAwareScheduler();
    scheduler.prepare(conf, new StormMetricsRegistry());
    scheduler.schedule(topologies, cluster);
    // We need to have 3 slots on 3 separate hosts. The topology needs 6 GPUs 3500 MB memory and 350% CPU
    // The bolt-3 instances must be on separate nodes because they each need 2 GPUs.
    // The bolt-2 instances must be on the same node as they each need 1 GPU
    // (this assumes that we are packing the components to avoid fragmentation).
    // The bolt-1 and spout instances fill in the rest.
    // Ordered execs: [[6, 6], [2, 2], [4, 4], [5, 5], [1, 1], [3, 3], [0, 0]]
    // Ackers: [[8, 8], [7, 7]] (+ [[9, 9], [10, 10]] when numOfAckersPerWorker=2)
    HashSet<HashSet<ExecutorDetails>> expectedScheduling = new HashSet<>();
    expectedScheduling.add(new HashSet<>(Arrays.asList(// bolt-3 - 500 MB, 50% CPU, 2 GPU
    new ExecutorDetails(3, 3))));
    // Total 500 MB, 50% CPU, 2 - GPU -> this node has 1500 MB, 150% cpu, 0 GPU left
    expectedScheduling.add(new HashSet<>(Arrays.asList(// acker - 250 MB, 50% CPU, 0 GPU
    new ExecutorDetails(7, 7), // acker - 250 MB, 50% CPU, 0 GPU
    new ExecutorDetails(8, 8), // bolt-2 - 500 MB, 50% CPU, 1 GPU
    new ExecutorDetails(6, 6), // bolt-1 - 500 MB, 50% CPU, 0 GPU
    new ExecutorDetails(2, 2))));
    // Total 1500 MB, 200% CPU, 2 GPU -> this node has 500 MB, 0% CPU, 0 GPU left
    expectedScheduling.add(new HashSet<>(Arrays.asList(// acker- 250 MB, 50% CPU, 0 GPU
    new ExecutorDetails(9, 9), // acker- 250 MB, 50% CPU, 0 GPU
    new ExecutorDetails(10, 10), // bolt-1 - 500 MB, 50% CPU, 0 GPU
    new ExecutorDetails(1, 1), // bolt-3 500 MB, 50% cpu, 2 GPU
    new ExecutorDetails(4, 4))));
    // Total 1500 MB, 200% CPU, 2 GPU -> this node has 500 MB, 0% CPU, 0 GPU left
    expectedScheduling.add(new HashSet<>(Arrays.asList(// Spout - 500 MB, 50% CPU, 0 GPU
    new ExecutorDetails(0, 0), // bolt-2 - 500 MB, 50% CPU, 1 GPU
    new ExecutorDetails(5, 5))));
    // Total 1000 MB, 100% CPU, 2 GPU -> this node has 1000 MB, 100% CPU, 0 GPU left
    HashSet<HashSet<ExecutorDetails>> foundScheduling = new HashSet<>();
    SchedulerAssignment assignment = cluster.getAssignmentById("testTopology-id");
    for (Collection<ExecutorDetails> execs : assignment.getSlotToExecutors().values()) {
        foundScheduling.add(new HashSet<>(execs));
    }
    assertEquals(expectedScheduling, foundScheduling);
}
Also used : ExecutorDetails(org.apache.storm.scheduler.ExecutorDetails) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) HashMap(java.util.HashMap) DaemonConfig(org.apache.storm.DaemonConfig) Config(org.apache.storm.Config) StormTopology(org.apache.storm.generated.StormTopology) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) ResourceAwareScheduler(org.apache.storm.scheduler.resource.ResourceAwareScheduler) TestUtilsForResourceAwareScheduler(org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler) ResourceMetrics(org.apache.storm.scheduler.resource.normalization.ResourceMetrics) Topologies(org.apache.storm.scheduler.Topologies) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) HashSet(java.util.HashSet) Cluster(org.apache.storm.scheduler.Cluster) INimbus(org.apache.storm.scheduler.INimbus) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) 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