Search in sources :

Example 61 with MapConfig

use of org.apache.samza.config.MapConfig in project samza by apache.

the class TestHdfsSystemConsumer method generateDefaultConfig.

private Config generateDefaultConfig() throws IOException {
    Map<String, String> properties = new HashMap<>();
    properties.put(String.format(HdfsConfig.CONSUMER_PARTITIONER_WHITELIST(), SYSTEM_NAME), ".*TestHdfsSystemConsumer.*avro");
    Path stagingDirectory = Files.createTempDirectory("staging");
    stagingDirectory.toFile().deleteOnExit();
    properties.put(HdfsConfig.STAGING_DIRECTORY(), stagingDirectory.toString());
    return new MapConfig(properties);
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) MapConfig(org.apache.samza.config.MapConfig)

Example 62 with MapConfig

use of org.apache.samza.config.MapConfig in project samza by apache.

the class TestHdfsSystemConsumer method testEmptyStagingDirectory.

/*
   * Ensure that empty staging directory will not break system admin,
   * but should fail system consumer
   */
@Test
public void testEmptyStagingDirectory() throws Exception {
    Map<String, String> configMap = new HashMap<>();
    configMap.put(String.format(HdfsConfig.CONSUMER_PARTITIONER_WHITELIST(), SYSTEM_NAME), ".*avro");
    Config config = new MapConfig(configMap);
    HdfsSystemFactory systemFactory = new HdfsSystemFactory();
    // create admin and do partitioning
    HdfsSystemAdmin systemAdmin = systemFactory.getAdmin(SYSTEM_NAME, config);
    String stream = WORKING_DIRECTORY;
    Set<String> streamNames = new HashSet<>();
    streamNames.add(stream);
    generateAvroDataFiles();
    Map<String, SystemStreamMetadata> streamMetadataMap = systemAdmin.getSystemStreamMetadata(streamNames);
    SystemStreamMetadata systemStreamMetadata = streamMetadataMap.get(stream);
    Assert.assertEquals(NUM_FILES, systemStreamMetadata.getSystemStreamPartitionMetadata().size());
    // create consumer and read from files
    HdfsSystemConsumer systemConsumer = systemFactory.getConsumer(SYSTEM_NAME, config, new NoOpMetricsRegistry());
    Partition partition = new Partition(0);
    SystemStreamPartition ssp = new SystemStreamPartition(SYSTEM_NAME, stream, partition);
    try {
        systemConsumer.register(ssp, "0");
        Assert.fail("Empty staging directory should fail system consumer");
    } catch (UncheckedExecutionException e) {
        Assert.assertTrue(e.getCause() instanceof SamzaException);
    }
}
Also used : Partition(org.apache.samza.Partition) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) HashMap(java.util.HashMap) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) SystemStreamMetadata(org.apache.samza.system.SystemStreamMetadata) SamzaException(org.apache.samza.SamzaException) NoOpMetricsRegistry(org.apache.samza.util.NoOpMetricsRegistry) MapConfig(org.apache.samza.config.MapConfig) HashSet(java.util.HashSet) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Test(org.junit.Test)

Example 63 with MapConfig

use of org.apache.samza.config.MapConfig in project samza by apache.

the class TestTaskFactoryUtil method testCreateStreamApplication.

@Test
public void testCreateStreamApplication() throws Exception {
    Config config = new MapConfig(new HashMap<String, String>() {

        {
            this.put(ApplicationConfig.APP_CLASS, "org.apache.samza.testUtils.TestStreamApplication");
        }
    });
    StreamApplication streamApp = TaskFactoryUtil.createStreamApplication(config);
    assertNotNull(streamApp);
    Object retFactory = TaskFactoryUtil.createTaskFactory(config, streamApp, mockRunner);
    assertTrue(retFactory instanceof StreamTaskFactory);
    assertTrue(((StreamTaskFactory) retFactory).createInstance() instanceof StreamOperatorTask);
    config = new MapConfig(new HashMap<String, String>() {

        {
            this.put(ApplicationConfig.APP_CLASS, "org.apache.samza.testUtils.InvalidStreamApplication");
        }
    });
    try {
        TaskFactoryUtil.createStreamApplication(config);
        fail("Should have failed w/ no.such.class");
    } catch (ConfigException ce) {
    // expected
    }
    config = new MapConfig(new HashMap<String, String>() {

        {
            this.put(ApplicationConfig.APP_CLASS, "no.such.class");
        }
    });
    try {
        TaskFactoryUtil.createStreamApplication(config);
        fail("Should have failed w/ no.such.class");
    } catch (ConfigException ce) {
    // expected
    }
    config = new MapConfig(new HashMap<String, String>() {

        {
            this.put(ApplicationConfig.APP_CLASS, "");
        }
    });
    streamApp = TaskFactoryUtil.createStreamApplication(config);
    assertNull(streamApp);
    config = new MapConfig(new HashMap<>());
    streamApp = TaskFactoryUtil.createStreamApplication(config);
    assertNull(streamApp);
}
Also used : HashMap(java.util.HashMap) ApplicationConfig(org.apache.samza.config.ApplicationConfig) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) StreamApplication(org.apache.samza.application.StreamApplication) ConfigException(org.apache.samza.config.ConfigException) MapConfig(org.apache.samza.config.MapConfig) Test(org.junit.Test)

Example 64 with MapConfig

use of org.apache.samza.config.MapConfig in project samza by apache.

the class TestStreamProcessor method testStreamProcessorWithStreamTaskFactory.

/**
   * Should be able to create task instances from the provided task factory.
   */
@Test
public void testStreamProcessorWithStreamTaskFactory() {
    final String testSystem = "test-system";
    final String inputTopic = "numbers2";
    final String outputTopic = "output2";
    final int messageCount = 20;
    final Config configs = new MapConfig(createConfigs("1", testSystem, inputTopic, outputTopic, messageCount));
    createTopics(inputTopic, outputTopic);
    final StreamTaskFactory stf = IdentityStreamTask::new;
    final StreamProcessor processor = new StreamProcessor(configs, new HashMap<>(), stf, listener);
    produceMessages(inputTopic, messageCount);
    run(processor, endLatch);
    verifyNumMessages(outputTopic, messageCount);
}
Also used : StreamProcessor(org.apache.samza.processor.StreamProcessor) MapConfig(org.apache.samza.config.MapConfig) ZkConfig(org.apache.samza.config.ZkConfig) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) StreamTaskFactory(org.apache.samza.task.StreamTaskFactory) AsyncStreamTaskFactory(org.apache.samza.task.AsyncStreamTaskFactory) Test(org.junit.Test)

Example 65 with MapConfig

use of org.apache.samza.config.MapConfig in project samza by apache.

the class MockTaskProxy method getJobModel.

@Override
protected JobModel getJobModel(JobInstance jobInstance) {
    if (jobInstance.getJobId().contains("Bad") || jobInstance.getJobName().contains("Bad")) {
        throw new IllegalArgumentException("No tasks found.");
    }
    TaskModel task1Model = new TaskModel(new TaskName(TASK_1_NAME), SYSTEM_STREAM_PARTITIONS, CHANGE_LOG_PARTITION);
    TaskModel task2Model = new TaskModel(new TaskName(TASK_2_NAME), SYSTEM_STREAM_PARTITIONS, CHANGE_LOG_PARTITION);
    ContainerModel task1ContainerModel = new ContainerModel(TASK_1_CONTAINER_ID, 1, ImmutableMap.of(new TaskName(TASK_1_NAME), task1Model));
    ContainerModel task2ContainerModel = new ContainerModel(TASK_2_CONTAINER_ID, 2, ImmutableMap.of(new TaskName(TASK_2_NAME), task2Model));
    return new JobModel(new MapConfig(), ImmutableMap.of(TASK_1_CONTAINER_ID, task1ContainerModel, TASK_2_CONTAINER_ID, task2ContainerModel));
}
Also used : TaskName(org.apache.samza.container.TaskName) JobModel(org.apache.samza.job.model.JobModel) MapConfig(org.apache.samza.config.MapConfig) TaskModel(org.apache.samza.job.model.TaskModel) ContainerModel(org.apache.samza.job.model.ContainerModel)

Aggregations

MapConfig (org.apache.samza.config.MapConfig)80 Test (org.junit.Test)60 HashMap (java.util.HashMap)51 Config (org.apache.samza.config.Config)51 JobConfig (org.apache.samza.config.JobConfig)21 StreamApplication (org.apache.samza.application.StreamApplication)8 TaskConfig (org.apache.samza.config.TaskConfig)8 StreamGraphImpl (org.apache.samza.operators.StreamGraphImpl)8 SamzaException (org.apache.samza.SamzaException)7 ApplicationConfig (org.apache.samza.config.ApplicationConfig)7 HashSet (java.util.HashSet)6 ConfigException (org.apache.samza.config.ConfigException)6 TaskName (org.apache.samza.container.TaskName)6 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)6 StreamProcessor (org.apache.samza.processor.StreamProcessor)6 StreamSpec (org.apache.samza.system.StreamSpec)6 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)6 HttpFileSystem (org.apache.samza.util.hadoop.HttpFileSystem)6 Field (java.lang.reflect.Field)5 Map (java.util.Map)5