Search in sources :

Example 1 with TestAsyncStreamTask

use of org.apache.samza.testUtils.TestAsyncStreamTask 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 2 with TestAsyncStreamTask

use of org.apache.samza.testUtils.TestAsyncStreamTask 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

HashMap (java.util.HashMap)2 ApplicationConfig (org.apache.samza.config.ApplicationConfig)2 Config (org.apache.samza.config.Config)2 ConfigException (org.apache.samza.config.ConfigException)2 MapConfig (org.apache.samza.config.MapConfig)2 TestAsyncStreamTask (org.apache.samza.testUtils.TestAsyncStreamTask)2 Test (org.junit.Test)2 StreamApplication (org.apache.samza.application.StreamApplication)1