Search in sources :

Example 1 with Parameters

use of io.mantisrx.runtime.parameter.Parameters in project mantis by Netflix.

the class MantisKafkaConsumerConfigTest method testJobParamOverrides.

@Test
public void testJobParamOverrides() {
    Context context = mock(Context.class);
    String testTopic = "topic123";
    String testConsumerGroupId = "testKafkaConsumer-1";
    Parameters params = ParameterTestUtils.createParameters(KafkaSourceParameters.TOPIC, testTopic, KafkaSourceParameters.PREFIX + ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest", KafkaSourceParameters.PREFIX + ConsumerConfig.GROUP_ID_CONFIG, testConsumerGroupId, KafkaSourceParameters.PREFIX + ConsumerConfig.DEFAULT_API_TIMEOUT_MS_CONFIG, 500);
    when(context.getParameters()).then((Answer<Parameters>) invocation -> params);
    MantisKafkaConsumerConfig mantisKafkaConsumerConfig = new MantisKafkaConsumerConfig(context);
    Map<String, Object> consumerProperties = mantisKafkaConsumerConfig.getConsumerProperties();
    // MantisKafkaConsumerConfig only affects Kafka's ConsumerConfig defined properties
    assertFalse(ConsumerConfig.configNames().contains(KafkaSourceParameters.TOPIC));
    assertFalse(consumerProperties.containsKey(KafkaSourceParameters.TOPIC));
    assertEquals("earliest", consumerProperties.get(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG));
    assertEquals(testConsumerGroupId, consumerProperties.get(ConsumerConfig.GROUP_ID_CONFIG));
    assertEquals(500, consumerProperties.get(ConsumerConfig.DEFAULT_API_TIMEOUT_MS_CONFIG));
}
Also used : Context(io.mantisrx.runtime.Context) KafkaSourceParameters(io.mantisrx.connector.kafka.KafkaSourceParameters) Arrays(java.util.Arrays) ParameterTestUtils(io.mantisrx.connector.kafka.ParameterTestUtils) Parameters(io.mantisrx.runtime.parameter.Parameters) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Context(io.mantisrx.runtime.Context) Answer(org.mockito.stubbing.Answer) RangeAssignor(org.apache.kafka.clients.consumer.RangeAssignor) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) JmxReporter(org.apache.kafka.common.metrics.JmxReporter) KafkaSourceParameters(io.mantisrx.connector.kafka.KafkaSourceParameters) Parameters(io.mantisrx.runtime.parameter.Parameters) Test(org.junit.Test)

Example 2 with Parameters

use of io.mantisrx.runtime.parameter.Parameters in project mantis by Netflix.

the class MantisKafkaConsumerConfig method applyJobParamOverrides.

private static Map<String, Object> applyJobParamOverrides(Context context, Map<String, Object> parsedValues) {
    final Parameters parameters = context.getParameters();
    if (!parsedValues.containsKey(ConsumerConfig.GROUP_ID_CONFIG)) {
        // set consumerGroupId if not already set
        final String consumerGroupId = (String) parameters.get(KafkaSourceParameters.PREFIX + ConsumerConfig.GROUP_ID_CONFIG, getGroupId());
        parsedValues.put(ConsumerConfig.GROUP_ID_CONFIG, consumerGroupId);
    }
    for (String key : configNames()) {
        Object value = parameters.get(KafkaSourceParameters.PREFIX + key, null);
        if (value != null) {
            LOGGER.info("job param override for key {} -> {}", key, value);
            parsedValues.put(key, value);
        }
    }
    return parsedValues;
}
Also used : KafkaSourceParameters(io.mantisrx.connector.kafka.KafkaSourceParameters) Parameters(io.mantisrx.runtime.parameter.Parameters)

Example 3 with Parameters

use of io.mantisrx.runtime.parameter.Parameters in project mantis by Netflix.

the class MantisKafkaSourceConfigTest method testJobParamOverrides.

@Test
public void testJobParamOverrides() {
    Context context = mock(Context.class);
    String testTopic = "topic123";
    int checkpointIntervalOverride = 100;
    boolean staticPartitionAssignEnableOverride = true;
    Parameters params = ParameterTestUtils.createParameters(KafkaSourceParameters.TOPIC, testTopic, KafkaSourceParameters.CHECKPOINT_INTERVAL_MS, checkpointIntervalOverride, KafkaSourceParameters.ENABLE_STATIC_PARTITION_ASSIGN, staticPartitionAssignEnableOverride, KafkaSourceParameters.TOPIC_PARTITION_COUNTS, testTopic + ":1024");
    when(context.getParameters()).then((Answer<Parameters>) invocation -> params);
    MantisKafkaSourceConfig mantisKafkaSourceConfig = new MantisKafkaSourceConfig(context);
    assertEquals(checkpointIntervalOverride, mantisKafkaSourceConfig.getCheckpointIntervalMs());
    assertEquals(staticPartitionAssignEnableOverride, mantisKafkaSourceConfig.getStaticPartitionAssignmentEnabled());
    Map<String, Integer> topicPartitionCounts = new HashMap<>();
    topicPartitionCounts.put(testTopic, 1024);
    assertEquals(Optional.ofNullable(topicPartitionCounts), mantisKafkaSourceConfig.getTopicPartitionCounts());
}
Also used : Context(io.mantisrx.runtime.Context) KafkaSourceParameters(io.mantisrx.connector.kafka.KafkaSourceParameters) Arrays(java.util.Arrays) ParserType(io.mantisrx.connector.kafka.source.serde.ParserType) ParameterTestUtils(io.mantisrx.connector.kafka.ParameterTestUtils) Parameters(io.mantisrx.runtime.parameter.Parameters) HashMap(java.util.HashMap) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Context(io.mantisrx.runtime.Context) CheckpointStrategyOptions(io.mantisrx.connector.kafka.source.checkpoint.strategy.CheckpointStrategyOptions) Answer(org.mockito.stubbing.Answer) Map(java.util.Map) Optional(java.util.Optional) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) KafkaSourceParameters(io.mantisrx.connector.kafka.KafkaSourceParameters) Parameters(io.mantisrx.runtime.parameter.Parameters) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 4 with Parameters

use of io.mantisrx.runtime.parameter.Parameters in project mantis by Netflix.

the class IcebergCommitterStageTest method setUp.

@BeforeEach
void setUp() {
    this.scheduler = new TestScheduler();
    this.subscriber = new TestSubscriber<>();
    Parameters parameters = StageOverrideParameters.newParameters();
    CommitterConfig config = new CommitterConfig(parameters);
    CommitterMetrics metrics = new CommitterMetrics();
    this.committer = mock(IcebergCommitter.class);
    transformer = new IcebergCommitterStage.Transformer(config, metrics, committer, scheduler);
    ServiceLocator serviceLocator = mock(ServiceLocator.class);
    when(serviceLocator.service(Configuration.class)).thenReturn(mock(Configuration.class));
    this.catalog = mock(Catalog.class);
    Table table = mock(Table.class);
    when(table.spec()).thenReturn(PartitionSpec.unpartitioned());
    when(this.catalog.loadTable(any())).thenReturn(table);
    when(serviceLocator.service(Catalog.class)).thenReturn(this.catalog);
    this.context = mock(Context.class);
    when(this.context.getParameters()).thenReturn(parameters);
    when(this.context.getServiceLocator()).thenReturn(serviceLocator);
}
Also used : Context(io.mantisrx.runtime.Context) Parameters(io.mantisrx.runtime.parameter.Parameters) StageOverrideParameters(io.mantisrx.connector.iceberg.sink.StageOverrideParameters) Table(org.apache.iceberg.Table) Configuration(org.apache.hadoop.conf.Configuration) Catalog(org.apache.iceberg.catalog.Catalog) CommitterConfig(io.mantisrx.connector.iceberg.sink.committer.config.CommitterConfig) ServiceLocator(io.mantisrx.runtime.lifecycle.ServiceLocator) TestScheduler(rx.schedulers.TestScheduler) CommitterMetrics(io.mantisrx.connector.iceberg.sink.committer.metrics.CommitterMetrics) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with Parameters

use of io.mantisrx.runtime.parameter.Parameters in project mantis by Netflix.

the class KafkaSinkTest method testKafkaSink.

@Test
public void testKafkaSink() throws InterruptedException {
    String testTopic = "testTopic" + topicNum.incrementAndGet();
    int numPartitions = 1;
    kafkaServer.createTopic(testTopic, numPartitions);
    int numMessages = 10;
    KafkaSink<String> kafkaSink = new KafkaSink<>(new NoopRegistry(), s -> s.getBytes());
    Context context = mock(Context.class);
    Parameters params = ParameterTestUtils.createParameters(KafkaSinkJobParameters.TOPIC, testTopic);
    when(context.getParameters()).then((Answer<Parameters>) invocation -> params);
    when(context.getWorkerInfo()).then((Answer<WorkerInfo>) invocation -> new WorkerInfo("testJobName", "testJobName-1", 1, 0, 1, MantisJobDurationType.Perpetual, "1.1.1.1"));
    when(context.getJobId()).then((Answer<String>) invocation -> "testJobName-1");
    kafkaSink.call(context, mock(PortRequest.class), Observable.range(0, numMessages).map(x -> String.valueOf(x)));
    List<String> messages = kafkaServer.readAllMessages(testTopic);
    LOGGER.info("got {}", messages);
    assertEquals(numMessages, messages.size());
    for (int i = 0; i < numMessages; i++) {
        assertEquals(i, Integer.parseInt(messages.get(i)));
    }
    kafkaServer.deleteTopic(testTopic);
}
Also used : Context(io.mantisrx.runtime.Context) NoopRegistry(com.netflix.spectator.api.NoopRegistry) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) BeforeClass(org.junit.BeforeClass) KafkaSourceTest(io.mantisrx.connector.kafka.source.KafkaSourceTest) MantisJobDurationType(io.mantisrx.runtime.MantisJobDurationType) LoggerFactory(org.slf4j.LoggerFactory) PortRequest(io.mantisrx.runtime.PortRequest) ParameterTestUtils(io.mantisrx.connector.kafka.ParameterTestUtils) Parameters(io.mantisrx.runtime.parameter.Parameters) Random(java.util.Random) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Context(io.mantisrx.runtime.Context) Observable(rx.Observable) Answer(org.mockito.stubbing.Answer) List(java.util.List) Ignore(org.junit.Ignore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KafkaUnit(info.batey.kafka.unit.KafkaUnit) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) WorkerInfo(io.mantisrx.runtime.WorkerInfo) Parameters(io.mantisrx.runtime.parameter.Parameters) NoopRegistry(com.netflix.spectator.api.NoopRegistry) PortRequest(io.mantisrx.runtime.PortRequest) WorkerInfo(io.mantisrx.runtime.WorkerInfo) KafkaSourceTest(io.mantisrx.connector.kafka.source.KafkaSourceTest) Test(org.junit.Test)

Aggregations

Parameters (io.mantisrx.runtime.parameter.Parameters)18 Context (io.mantisrx.runtime.Context)15 Map (java.util.Map)12 ParameterTestUtils (io.mantisrx.connector.kafka.ParameterTestUtils)11 Assert.assertEquals (org.junit.Assert.assertEquals)11 Test (org.junit.Test)11 Mockito.mock (org.mockito.Mockito.mock)11 Mockito.when (org.mockito.Mockito.when)11 Answer (org.mockito.stubbing.Answer)11 KafkaSourceParameters (io.mantisrx.connector.kafka.KafkaSourceParameters)9 ConsumerConfig (org.apache.kafka.clients.consumer.ConsumerConfig)8 WorkerInfo (io.mantisrx.runtime.WorkerInfo)7 Arrays (java.util.Arrays)7 Optional (java.util.Optional)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 Observable (rx.Observable)7 MantisJobDurationType (io.mantisrx.runtime.MantisJobDurationType)6 NoopRegistry (com.netflix.spectator.api.NoopRegistry)5 KafkaUnit (info.batey.kafka.unit.KafkaUnit)5