Search in sources :

Example 16 with Parameters

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

the class MantisKafkaConsumerConfigTest method testDefaultConsumerConfig.

@Test
public void testDefaultConsumerConfig() {
    Context context = mock(Context.class);
    Parameters params = ParameterTestUtils.createParameters();
    when(context.getParameters()).then((Answer<Parameters>) invocation -> params);
    MantisKafkaConsumerConfig mantisKafkaConsumerConfig = new MantisKafkaConsumerConfig(context);
    Map<String, Object> consumerProperties = mantisKafkaConsumerConfig.getConsumerProperties();
    assertEquals(Boolean.valueOf(MantisKafkaConsumerConfig.DEFAULT_AUTO_COMMIT_ENABLED), consumerProperties.get(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG));
    assertEquals(MantisKafkaConsumerConfig.DEFAULT_AUTO_COMMIT_INTERVAL_MS, consumerProperties.get(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG));
    assertEquals(MantisKafkaConsumerConfig.DEFAULT_AUTO_OFFSET_RESET, consumerProperties.get(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG));
    assertEquals(MantisKafkaConsumerConfig.DEFAULT_FETCH_MAX_WAIT_MS, consumerProperties.get(ConsumerConfig.FETCH_MAX_WAIT_MS_CONFIG));
    assertEquals(MantisKafkaConsumerConfig.DEFAULT_FETCH_MIN_BYTES, consumerProperties.get(ConsumerConfig.FETCH_MIN_BYTES_CONFIG));
    assertEquals(MantisKafkaConsumerConfig.DEFAULT_HEARTBEAT_INTERVAL_MS, consumerProperties.get(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG));
    assertEquals(MantisKafkaConsumerConfig.DEFAULT_SESSION_TIMEOUT_MS, consumerProperties.get(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG));
    assertEquals(MantisKafkaConsumerConfig.DEFAULT_KEY_DESERIALIZER, consumerProperties.get(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG));
    assertEquals(MantisKafkaConsumerConfig.DEFAULT_VALUE_DESERIALIZER, consumerProperties.get(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG));
    assertEquals(MantisKafkaConsumerConfig.DEFAULT_MAX_PARTITION_FETCH_BYTES, consumerProperties.get(ConsumerConfig.MAX_PARTITION_FETCH_BYTES_CONFIG));
    assertEquals(MantisKafkaConsumerConfig.DEFAULT_RECEIVE_BUFFER_BYTES, consumerProperties.get(ConsumerConfig.RECEIVE_BUFFER_CONFIG));
    assertEquals(MantisKafkaConsumerConfig.DEFAULT_SEND_BUFFER_BYTES, consumerProperties.get(ConsumerConfig.SEND_BUFFER_CONFIG));
    assertEquals(Arrays.asList(MantisKafkaConsumerConfig.DEFAULT_BOOTSTRAP_SERVERS_CONFIG), consumerProperties.get(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG));
    assertEquals(Arrays.asList(JmxReporter.class.getName()), consumerProperties.get(ConsumerConfig.METRIC_REPORTER_CLASSES_CONFIG));
    assertEquals(Arrays.asList(RangeAssignor.class.getName()), consumerProperties.get(ConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG));
    assertEquals(MantisKafkaConsumerConfig.getGroupId(), consumerProperties.get(ConsumerConfig.GROUP_ID_CONFIG));
    assertEquals(MantisKafkaConsumerConfig.DEFAULT_MAX_POLL_INTERVAL_MS, consumerProperties.get(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG));
    assertEquals(MantisKafkaConsumerConfig.DEFAULT_MAX_POLL_RECORDS, consumerProperties.get(ConsumerConfig.MAX_POLL_RECORDS_CONFIG));
    assertEquals(MantisKafkaConsumerConfig.DEFAULT_REQUEST_TIMEOUT_MS, consumerProperties.get(ConsumerConfig.REQUEST_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 17 with Parameters

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

the class FixedIcebergWriterPoolTest method setUp.

@BeforeEach
void setUp() {
    Parameters parameters = StageOverrideParameters.newParameters();
    WriterConfig config = new WriterConfig(parameters, mock(Configuration.class));
    IcebergWriterFactory factory = mock(IcebergWriterFactory.class);
    this.writer = mock(IcebergWriter.class);
    when(this.writer.length()).thenReturn(Long.MAX_VALUE);
    when(factory.newIcebergWriter()).thenReturn(this.writer);
    this.writerPool = spy(new FixedIcebergWriterPool(factory, config.getWriterFlushFrequencyBytes(), config.getWriterMaximumPoolSize()));
    this.record = GenericRecord.create(SCHEMA);
    this.record.setField("id", 1);
    // Identity partitioning (without explicitly using a Partitioner).
    this.partition = this.record.copy();
}
Also used : StageOverrideParameters(io.mantisrx.connector.iceberg.sink.StageOverrideParameters) Parameters(io.mantisrx.runtime.parameter.Parameters) Configuration(org.apache.hadoop.conf.Configuration) IcebergWriterFactory(io.mantisrx.connector.iceberg.sink.writer.factory.IcebergWriterFactory) FixedIcebergWriterPool(io.mantisrx.connector.iceberg.sink.writer.pool.FixedIcebergWriterPool) WriterConfig(io.mantisrx.connector.iceberg.sink.writer.config.WriterConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 18 with Parameters

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

the class IcebergWriterStageTest method setUp.

@BeforeEach
void setUp() {
    record = GenericRecord.create(SCHEMA);
    record.setField("id", 1);
    this.scheduler = new TestScheduler();
    this.subscriber = new TestSubscriber<>();
    // Writer
    Parameters parameters = StageOverrideParameters.newParameters();
    WriterConfig config = new WriterConfig(parameters, mock(Configuration.class));
    WriterMetrics metrics = new WriterMetrics();
    IcebergWriterFactory factory = FakeIcebergWriter::new;
    this.writerPool = spy(new FixedIcebergWriterPool(factory, config.getWriterFlushFrequencyBytes(), config.getWriterMaximumPoolSize()));
    doReturn(Collections.singleton(record)).when(writerPool).getFlushableWriters();
    this.partitioner = mock(Partitioner.class);
    when(partitioner.partition(record)).thenReturn(record);
    this.transformer = new IcebergWriterStage.Transformer(config, metrics, this.writerPool, this.partitioner, this.scheduler, this.scheduler);
    // Catalog
    ServiceLocator serviceLocator = mock(ServiceLocator.class);
    when(serviceLocator.service(Configuration.class)).thenReturn(mock(Configuration.class));
    this.catalog = mock(Catalog.class);
    Table table = mock(Table.class);
    PartitionSpec spec = PartitionSpec.builderFor(SCHEMA).identity("id").build();
    when(table.spec()).thenReturn(spec);
    when(this.catalog.loadTable(any())).thenReturn(table);
    when(serviceLocator.service(Catalog.class)).thenReturn(this.catalog);
    when(serviceLocator.service(PartitionerFactory.class)).thenReturn(mock(PartitionerFactory.class));
    // Mantis Context
    this.context = mock(Context.class);
    when(this.context.getParameters()).thenReturn(parameters);
    when(this.context.getServiceLocator()).thenReturn(serviceLocator);
    when(this.context.getWorkerInfo()).thenReturn(new WorkerInfo("testJobName", "jobId", 1, 1, 1, MantisJobDurationType.Perpetual, "host"));
    // Flow
    Observable<Record> source = Observable.interval(1, TimeUnit.MILLISECONDS, this.scheduler).map(i -> record);
    this.flow = source.compose(this.transformer);
}
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) WorkerInfo(io.mantisrx.runtime.WorkerInfo) IcebergWriterFactory(io.mantisrx.connector.iceberg.sink.writer.factory.IcebergWriterFactory) PartitionSpec(org.apache.iceberg.PartitionSpec) Catalog(org.apache.iceberg.catalog.Catalog) WriterConfig(io.mantisrx.connector.iceberg.sink.writer.config.WriterConfig) ServiceLocator(io.mantisrx.runtime.lifecycle.ServiceLocator) FixedIcebergWriterPool(io.mantisrx.connector.iceberg.sink.writer.pool.FixedIcebergWriterPool) PartitionerFactory(io.mantisrx.connector.iceberg.sink.writer.partitioner.PartitionerFactory) GenericRecord(org.apache.iceberg.data.GenericRecord) Record(org.apache.iceberg.data.Record) TestScheduler(rx.schedulers.TestScheduler) WriterMetrics(io.mantisrx.connector.iceberg.sink.writer.metrics.WriterMetrics) Partitioner(io.mantisrx.connector.iceberg.sink.writer.partitioner.Partitioner) BeforeEach(org.junit.jupiter.api.BeforeEach)

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