Search in sources :

Example 1 with ConfigException

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

the class MockCoordinatorStreamSystemFactory method getConsumer.

/**
   * Returns a consumer that sends all configs to the coordinator stream.
   *
   * @param config Along with the configs, you can pass checkpoints and changelog stream messages into the stream.
   *               The expected pattern is cp:source:taskname -> ssp,offset for checkpoint (Use sspToString util)
   *               ch:source:taskname -> changelogPartition for changelog
   *               Everything else is processed as normal config
   */
public SystemConsumer getConsumer(String systemName, Config config, MetricsRegistry registry) {
    if (useCachedConsumer && mockConsumer != null) {
        return mockConsumer;
    }
    String jobName = config.get("job.name");
    String jobId = config.get("job.id");
    if (jobName == null) {
        throw new ConfigException("Must define job.name.");
    }
    if (jobId == null) {
        jobId = "1";
    }
    String streamName = Util.getCoordinatorStreamName(jobName, jobId);
    SystemStreamPartition systemStreamPartition = new SystemStreamPartition(systemName, streamName, new Partition(0));
    mockConsumer = new MockCoordinatorStreamWrappedConsumer(systemStreamPartition, config);
    return mockConsumer;
}
Also used : Partition(org.apache.samza.Partition) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) ConfigException(org.apache.samza.config.ConfigException) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition)

Example 2 with ConfigException

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

the class TestTaskFactoryUtil method testStreamTaskClassWithInvalidStreamApplication.

@Test
public void testStreamTaskClassWithInvalidStreamApplication() throws Exception {
    Config 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("task.class", "org.apache.samza.testUtils.TestStreamTask");
            this.put(ApplicationConfig.APP_CLASS, "");
        }
    });
    StreamApplication streamApp = TaskFactoryUtil.createStreamApplication(config);
    Object retFactory = TaskFactoryUtil.createTaskFactory(config, streamApp, mockRunner);
    assertTrue(retFactory instanceof StreamTaskFactory);
    assertTrue(((StreamTaskFactory) retFactory).createInstance() instanceof TestStreamTask);
    config = new MapConfig(new HashMap<String, String>() {

        {
            this.put("task.class", "");
            this.put(ApplicationConfig.APP_CLASS, "org.apache.samza.testUtils.InvalidStreamApplication");
        }
    });
    try {
        TaskFactoryUtil.createStreamApplication(config);
        fail("Should have failed w/ no class not found");
    } catch (ConfigException cne) {
    // expected
    }
}
Also used : HashMap(java.util.HashMap) ApplicationConfig(org.apache.samza.config.ApplicationConfig) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) TestStreamTask(org.apache.samza.testUtils.TestStreamTask) StreamApplication(org.apache.samza.application.StreamApplication) ConfigException(org.apache.samza.config.ConfigException) MapConfig(org.apache.samza.config.MapConfig) Test(org.junit.Test)

Example 3 with ConfigException

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

the class TestTaskFactoryUtil method testStreamTaskClass.

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

        {
            this.put("task.class", "org.apache.samza.testUtils.TestStreamTask");
        }
    });
    Object retFactory = TaskFactoryUtil.createTaskFactory(config, null, null);
    assertTrue(retFactory instanceof StreamTaskFactory);
    assertTrue(((StreamTaskFactory) retFactory).createInstance() instanceof TestStreamTask);
    config = new MapConfig(new HashMap<String, String>() {

        {
            this.put("task.class", "no.such.class");
        }
    });
    try {
        TaskFactoryUtil.createTaskFactory(config, null, null);
        fail("Should have failed w/ no.such.class");
    } catch (ConfigException cfe) {
    // expected
    }
}
Also used : HashMap(java.util.HashMap) ApplicationConfig(org.apache.samza.config.ApplicationConfig) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) TestStreamTask(org.apache.samza.testUtils.TestStreamTask) ConfigException(org.apache.samza.config.ConfigException) MapConfig(org.apache.samza.config.MapConfig) Test(org.junit.Test)

Example 4 with ConfigException

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

the class TestTaskFactoryUtil method testAsyncStreamTask.

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

        {
            this.put("task.class", "org.apache.samza.testUtils.TestAsyncStreamTask");
        }
    });
    Object retFactory = TaskFactoryUtil.createTaskFactory(config, null, null);
    assertTrue(retFactory instanceof AsyncStreamTaskFactory);
    assertTrue(((AsyncStreamTaskFactory) retFactory).createInstance() instanceof TestAsyncStreamTask);
    config = new MapConfig(new HashMap<String, String>() {

        {
            this.put("task.class", "no.such.class");
        }
    });
    try {
        TaskFactoryUtil.createTaskFactory(config, null, null);
        fail("Should have failed w/ no.such.class");
    } catch (ConfigException cfe) {
    // expected
    }
}
Also used : HashMap(java.util.HashMap) ApplicationConfig(org.apache.samza.config.ApplicationConfig) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) ConfigException(org.apache.samza.config.ConfigException) MapConfig(org.apache.samza.config.MapConfig) TestAsyncStreamTask(org.apache.samza.testUtils.TestAsyncStreamTask) Test(org.junit.Test)

Example 5 with ConfigException

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

the class TestTaskFactoryUtil method testAsyncStreamTaskWithInvalidStreamGraphBuilder.

@Test
public void testAsyncStreamTaskWithInvalidStreamGraphBuilder() throws Exception {
    Config 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 cfe) {
    // expected
    }
    config = new MapConfig(new HashMap<String, String>() {

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

        {
            this.put("task.class", "org.apache.samza.testUtils.TestAsyncStreamTask");
            this.put(ApplicationConfig.APP_CLASS, null);
        }
    });
    streamApp = TaskFactoryUtil.createStreamApplication(config);
    retFactory = TaskFactoryUtil.createTaskFactory(config, streamApp, mockRunner);
    assertTrue(retFactory instanceof AsyncStreamTaskFactory);
    assertTrue(((AsyncStreamTaskFactory) retFactory).createInstance() instanceof TestAsyncStreamTask);
}
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) TestAsyncStreamTask(org.apache.samza.testUtils.TestAsyncStreamTask) Test(org.junit.Test)

Aggregations

ConfigException (org.apache.samza.config.ConfigException)10 ApplicationConfig (org.apache.samza.config.ApplicationConfig)7 HashMap (java.util.HashMap)6 Config (org.apache.samza.config.Config)6 MapConfig (org.apache.samza.config.MapConfig)6 Test (org.junit.Test)6 StreamApplication (org.apache.samza.application.StreamApplication)5 TaskConfig (org.apache.samza.config.TaskConfig)2 TestAsyncStreamTask (org.apache.samza.testUtils.TestAsyncStreamTask)2 TestStreamTask (org.apache.samza.testUtils.TestStreamTask)2 Partition (org.apache.samza.Partition)1 SamzaException (org.apache.samza.SamzaException)1 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)1