Search in sources :

Example 11 with ValueSource

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

the class TestDefaultResourceAwareStrategy method testDefaultResourceAwareStrategyWithoutSettingAckerExecutors.

/**
 * test if the scheduling logic for the DefaultResourceAwareStrategy is correct
 * when topology.acker.executors.per.worker is set to different values.
 *
 * If {@link Config#TOPOLOGY_ACKER_EXECUTORS} is not set,
 * it will be calculated by Nimbus as (num of estimated worker * topology.acker.executors.per.worker).
 * In this test, {@link Config#TOPOLOGY_ACKER_EXECUTORS} is set to 2 (num of estimated workers based on topo resources usage)
 *
 * For different value for {@link Config#TOPOLOGY_RAS_ACKER_EXECUTORS_PER_WORKER}:
 * -1: Note we don't really set it to be -1.
 *     It is just a special case in this test that topology.acker.executors.per.worker is unset, nimbus will set to 1 by default.
 * 0:  Since {@link Config#TOPOLOGY_ACKER_EXECUTORS} is not set either, acking is disabled.
 * 1:  2 ackers in total. Distribute 1 acker per worker. With ackers being added, this topology will now need 3 workers.
 *     Then first two worker will get 1 acker and last worker get 0.
 * 2:  4 ackers in total. First two workers will get 2 acker per worker respectively.
 */
@ParameterizedTest
@ValueSource(ints = { -1, 0, 1, 2 })
public void testDefaultResourceAwareStrategyWithoutSettingAckerExecutors(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");
    builder.setBolt("bolt-3", new TestBolt(), boltParallelism).shuffleGrouping("bolt-2");
    String topoName = "testTopology";
    StormTopology stormToplogy = builder.createTopology();
    INimbus iNimbus = new INimbusTest();
    Map<String, SupervisorDetails> supMap = genSupervisors(4, 4, 200, 2000);
    Config conf = createClusterConfig(50, 450, 0, null);
    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");
    // Parameterized test on different numOfAckersPerWorker
    if (numOfAckersPerWorker == -1) {
    // Both Config.TOPOLOGY_ACKER_EXECUTORS and Config.TOPOLOGY_RAS_ACKER_EXECUTORS_PER_WORKER are not set
    // Default will be 2 (estimate num of workers) and 1 respectively
    } 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)), CURRENT_TIME, "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);
    // Ordered execs: [[6, 6], [2, 2], [4, 4], [5, 5], [1, 1], [3, 3], [0, 0], [8, 8], [7, 7]]
    // Ackers: [[8, 8], [7, 7]] (+ [[9, 9], [10, 10]] when numOfAckersPerWorker=2)
    HashSet<HashSet<ExecutorDetails>> expectedScheduling = new HashSet<>();
    if (numOfAckersPerWorker == -1 || numOfAckersPerWorker == 1) {
        // Setting topology.acker.executors = null and topology.acker.executors.per.worker = null
        // are equivalent to topology.acker.executors = null and topology.acker.executors.per.worker = 1
        expectedScheduling.add(new HashSet<>(Arrays.asList(// bolt-3
        new ExecutorDetails(6, 6), // bolt-1
        new ExecutorDetails(2, 2), // bolt-2
        new ExecutorDetails(4, 4), // acker
        new ExecutorDetails(8, 8))));
        expectedScheduling.add(new HashSet<>(Arrays.asList(// bolt-3
        new ExecutorDetails(5, 5), // bolt-1
        new ExecutorDetails(1, 1), // bolt-2
        new ExecutorDetails(3, 3), // acker
        new ExecutorDetails(7, 7))));
        expectedScheduling.add(new HashSet<>(Arrays.asList(// spout
        new ExecutorDetails(0, 0))));
    } else if (numOfAckersPerWorker == 0) {
        expectedScheduling.add(new HashSet<>(Arrays.asList(// bolt-3
        new ExecutorDetails(6, 6), // bolt-1
        new ExecutorDetails(2, 2), // bolt-2
        new ExecutorDetails(4, 4), // bolt-3
        new ExecutorDetails(5, 5))));
        expectedScheduling.add(new HashSet<>(Arrays.asList(// spout
        new ExecutorDetails(0, 0), // bolt-2
        new ExecutorDetails(3, 3), // bolt-1
        new ExecutorDetails(1, 1))));
    } else if (numOfAckersPerWorker == 2) {
        expectedScheduling.add(new HashSet<>(Arrays.asList(// bolt-3
        new ExecutorDetails(6, 6), // bolt-1
        new ExecutorDetails(2, 2), // acker
        new ExecutorDetails(7, 7), // acker
        new ExecutorDetails(8, 8))));
        expectedScheduling.add(new HashSet<>(Arrays.asList(// bolt-2
        new ExecutorDetails(4, 4), // bolt-3
        new ExecutorDetails(5, 5), // acker
        new ExecutorDetails(9, 9), // acker
        new ExecutorDetails(10, 10))));
        expectedScheduling.add(new HashSet<>(Arrays.asList(// bolt-1
        new ExecutorDetails(1, 1), // bolt-2
        new ExecutorDetails(3, 3), // spout
        new ExecutorDetails(0, 0))));
    }
    HashSet<HashSet<ExecutorDetails>> foundScheduling = new HashSet<>();
    SchedulerAssignment assignment = cluster.getAssignmentById("testTopology-id");
    for (Collection<ExecutorDetails> execs : assignment.getSlotToExecutors().values()) {
        foundScheduling.add(new HashSet<>(execs));
    }
    Assert.assertEquals(expectedScheduling, foundScheduling);
}
Also used : ExecutorDetails(org.apache.storm.scheduler.ExecutorDetails) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) StormTopology(org.apache.storm.generated.StormTopology) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) Cluster(org.apache.storm.scheduler.Cluster) INimbus(org.apache.storm.scheduler.INimbus) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) TestUtilsForResourceAwareScheduler(org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler) ResourceAwareScheduler(org.apache.storm.scheduler.resource.ResourceAwareScheduler) ResourceMetrics(org.apache.storm.scheduler.resource.normalization.ResourceMetrics) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) Topologies(org.apache.storm.scheduler.Topologies) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) HashSet(java.util.HashSet) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with ValueSource

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

the class TestBlacklistScheduler method TestBadSlot.

@ParameterizedTest
@ValueSource(booleans = { true, false })
public void TestBadSlot(boolean blacklistOnBadSlot) {
    INimbus iNimbus = new TestUtilsForBlacklistScheduler.INimbusTest();
    Map<String, SupervisorDetails> supMap = TestUtilsForBlacklistScheduler.genSupervisors(3, 4);
    Config config = new Config();
    config.putAll(Utils.readDefaultConfig());
    config.put(DaemonConfig.BLACKLIST_SCHEDULER_TOLERANCE_TIME, 200);
    config.put(DaemonConfig.BLACKLIST_SCHEDULER_TOLERANCE_COUNT, 2);
    config.put(DaemonConfig.BLACKLIST_SCHEDULER_RESUME_TIME, 300);
    config.put(DaemonConfig.BLACKLIST_SCHEDULER_ASSUME_SUPERVISOR_BAD_BASED_ON_BAD_SLOT, blacklistOnBadSlot);
    Map<String, TopologyDetails> topoMap = new HashMap<String, TopologyDetails>();
    TopologyDetails topo1 = TestUtilsForBlacklistScheduler.getTopology("topo-1", config, 5, 15, 1, 1, currentTime - 2, true);
    topoMap.put(topo1.getId(), topo1);
    Topologies topologies = new Topologies(topoMap);
    StormMetricsRegistry metricsRegistry = new StormMetricsRegistry();
    ResourceMetrics resourceMetrics = new ResourceMetrics(metricsRegistry);
    Cluster cluster = new Cluster(iNimbus, resourceMetrics, supMap, new HashMap<String, SchedulerAssignmentImpl>(), topologies, config);
    scheduler = new BlacklistScheduler(new DefaultScheduler());
    scheduler.prepare(config, metricsRegistry);
    scheduler.schedule(topologies, cluster);
    cluster = new Cluster(iNimbus, resourceMetrics, TestUtilsForBlacklistScheduler.removePortFromSupervisors(supMap, "sup-0", 0), TestUtilsForBlacklistScheduler.assignmentMapToImpl(cluster.getAssignments()), topologies, config);
    scheduler.schedule(topologies, cluster);
    cluster = new Cluster(iNimbus, resourceMetrics, TestUtilsForBlacklistScheduler.removePortFromSupervisors(supMap, "sup-0", 0), TestUtilsForBlacklistScheduler.assignmentMapToImpl(cluster.getAssignments()), topologies, config);
    scheduler.schedule(topologies, cluster);
    cluster = new Cluster(iNimbus, resourceMetrics, supMap, new HashMap<String, SchedulerAssignmentImpl>(), topologies, config);
    scheduler.schedule(topologies, cluster);
    if (blacklistOnBadSlot) {
        Assert.assertEquals("blacklist", Collections.singleton("host-0"), cluster.getBlacklistedHosts());
    } else {
        Assert.assertEquals("blacklist", Collections.emptySet(), cluster.getBlacklistedHosts());
    }
}
Also used : HashMap(java.util.HashMap) DaemonConfig(org.apache.storm.DaemonConfig) Config(org.apache.storm.Config) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) Cluster(org.apache.storm.scheduler.Cluster) INimbus(org.apache.storm.scheduler.INimbus) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) ResourceMetrics(org.apache.storm.scheduler.resource.normalization.ResourceMetrics) SchedulerAssignmentImpl(org.apache.storm.scheduler.SchedulerAssignmentImpl) Topologies(org.apache.storm.scheduler.Topologies) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) DefaultScheduler(org.apache.storm.scheduler.DefaultScheduler) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with ValueSource

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

the class BoltStateMachineFactoryImplTest method shouldThrowExceptionIfVersionIsUnknown.

@ParameterizedTest(name = "V{0}")
@ValueSource(ints = { 999, -1, 1, 2 })
void shouldThrowExceptionIfVersionIsUnknown(int protocolVersion) {
    BoltStateMachineFactoryImpl factory = newBoltFactory();
    BoltProtocolVersion boltProtocolVersion = new BoltProtocolVersion(protocolVersion, 0);
    var memoryTracker = mock(MemoryTracker.class);
    IllegalArgumentException error = assertThrows(IllegalArgumentException.class, () -> factory.newStateMachine(boltProtocolVersion, CHANNEL, MapValue.EMPTY, memoryTracker));
    assertThat(error.getMessage()).startsWith("Failed to create a state machine for protocol version");
    verifyNoMoreInteractions(memoryTracker);
}
Also used : BoltProtocolVersion(org.neo4j.bolt.BoltProtocolVersion) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with ValueSource

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

the class IndexTransactionStateTestBase method shouldPerformStringRangeSearchWithRemovedRemovedPropertyInTxState.

@ParameterizedTest
@ValueSource(strings = { "true", "false" })
void shouldPerformStringRangeSearchWithRemovedRemovedPropertyInTxState(boolean needsValues) throws Exception {
    // given
    Set<Pair<Long, Value>> expected = new HashSet<>();
    long entityToChange;
    try (KernelTransaction tx = beginTransaction()) {
        entityToChange = entityWithPropId(tx, "banana");
        entityWithPropId(tx, "apple");
        tx.commit();
    }
    createIndex();
    // when
    try (KernelTransaction tx = beginTransaction()) {
        expected.add(entityWithProp(tx, "cherry"));
        entityWithProp(tx, "dragonfruit");
        IndexDescriptor index = tx.schemaRead().indexGetForName(INDEX_NAME);
        removeProperty(tx, entityToChange);
        int prop = tx.tokenRead().propertyKey(DEFAULT_PROPERTY_NAME);
        assertEntityAndValueForSeek(expected, tx, index, needsValues, "berry", PropertyIndexQuery.range(prop, "b", true, "d", false));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Pair(org.neo4j.internal.helpers.collection.Pair) HashSet(java.util.HashSet) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with ValueSource

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

the class IndexTransactionStateTestBase method shouldPerformStringRangeSearchWithAddedEntityInTxState.

@ParameterizedTest
@ValueSource(strings = { "true", "false" })
void shouldPerformStringRangeSearchWithAddedEntityInTxState(boolean needsValues) throws Exception {
    // given
    Set<Pair<Long, Value>> expected = new HashSet<>();
    long entityToChange;
    try (KernelTransaction tx = beginTransaction()) {
        expected.add(entityWithProp(tx, "banana"));
        entityToChange = entityWithPropId(tx, "apple");
        tx.commit();
    }
    createIndex();
    // when
    try (KernelTransaction tx = beginTransaction()) {
        expected.add(entityWithProp(tx, "cherry"));
        entityWithProp(tx, "dragonfruit");
        IndexDescriptor index = tx.schemaRead().indexGetForName(INDEX_NAME);
        TextValue newProperty = stringValue("blueberry");
        setProperty(tx, entityToChange, newProperty);
        expected.add(Pair.of(entityToChange, newProperty));
        int prop = tx.tokenRead().propertyKey(DEFAULT_PROPERTY_NAME);
        assertEntityAndValueForSeek(expected, tx, index, needsValues, "berry", PropertyIndexQuery.range(prop, "b", true, "d", false));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TextValue(org.neo4j.values.storable.TextValue) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Pair(org.neo4j.internal.helpers.collection.Pair) HashSet(java.util.HashSet) 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