Search in sources :

Example 56 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 57 with MapConfig

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

the class TestLocalApplicationRunner method testRunComplete.

@Test
public void testRunComplete() throws Exception {
    final Map<String, String> config = new HashMap<>();
    config.put(ApplicationConfig.APP_PROCESSOR_ID_GENERATOR_CLASS, UUIDGenerator.class.getName());
    LocalApplicationRunner runner = new LocalApplicationRunner(new MapConfig(config));
    StreamApplication app = mock(StreamApplication.class);
    doNothing().when(app).init(anyObject(), anyObject());
    ExecutionPlanner planner = mock(ExecutionPlanner.class);
    Field plannerField = runner.getClass().getSuperclass().getDeclaredField("planner");
    plannerField.setAccessible(true);
    plannerField.set(runner, planner);
    ExecutionPlan plan = new ExecutionPlan() {

        @Override
        public List<JobConfig> getJobConfigs() {
            return Collections.singletonList(new JobConfig(new MapConfig(config)));
        }

        @Override
        public List<StreamSpec> getIntermediateStreams() {
            return Collections.emptyList();
        }

        @Override
        public String getPlanAsJson() throws Exception {
            return "";
        }
    };
    when(planner.plan(anyObject())).thenReturn(plan);
    StreamProcessor sp = mock(StreamProcessor.class);
    ArgumentCaptor<StreamProcessorLifecycleListener> captor = ArgumentCaptor.forClass(StreamProcessorLifecycleListener.class);
    doAnswer(i -> {
        StreamProcessorLifecycleListener listener = captor.getValue();
        listener.onStart();
        listener.onShutdown();
        return null;
    }).when(sp).start();
    LocalApplicationRunner spy = spy(runner);
    doReturn(sp).when(spy).createStreamProcessor(anyObject(), anyObject(), captor.capture());
    spy.run(app);
    assertEquals(spy.status(app), ApplicationStatus.SuccessfulFinish);
}
Also used : StreamSpec(org.apache.samza.system.StreamSpec) StreamProcessor(org.apache.samza.processor.StreamProcessor) HashMap(java.util.HashMap) StreamApplication(org.apache.samza.application.StreamApplication) ExecutionPlanner(org.apache.samza.execution.ExecutionPlanner) Matchers.anyString(org.mockito.Matchers.anyString) StreamProcessorLifecycleListener(org.apache.samza.processor.StreamProcessorLifecycleListener) JobConfig(org.apache.samza.config.JobConfig) Field(java.lang.reflect.Field) ExecutionPlan(org.apache.samza.execution.ExecutionPlan) MapConfig(org.apache.samza.config.MapConfig) Test(org.junit.Test)

Example 58 with MapConfig

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

the class TestStorageRecovery method putConfig.

private void putConfig() {
    Map<String, String> map = new HashMap<String, String>();
    map.put("job.name", "changelogTest");
    map.put("systems.mockSystem.samza.factory", MockSystemFactory.class.getCanonicalName());
    map.put(String.format("stores.%s.factory", STORE_NAME), MockStorageEngineFactory.class.getCanonicalName());
    map.put(String.format("stores.%s.changelog", STORE_NAME), "mockSystem." + SYSTEM_STREAM_NAME);
    map.put("task.inputs", "mockSystem.input");
    map.put("job.coordinator.system", "coordinator");
    map.put("systems.coordinator.samza.factory", MockCoordinatorStreamSystemFactory.class.getCanonicalName());
    map.put("task.name.grouper.factory", "org.apache.samza.container.grouper.task.GroupByContainerCountFactory");
    config = new MapConfig(map);
}
Also used : HashMap(java.util.HashMap) MapConfig(org.apache.samza.config.MapConfig) MockCoordinatorStreamSystemFactory(org.apache.samza.coordinator.stream.MockCoordinatorStreamSystemFactory)

Example 59 with MapConfig

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

the class TestLocalApplicationRunner method testStreamCreationWithCoordination.

@Test
public void testStreamCreationWithCoordination() throws Exception {
    Map<String, String> config = new HashMap<>();
    LocalApplicationRunner runner = new LocalApplicationRunner(new MapConfig(config));
    StreamApplication app = mock(StreamApplication.class);
    doNothing().when(app).init(anyObject(), anyObject());
    ExecutionPlanner planner = mock(ExecutionPlanner.class);
    Field plannerField = runner.getClass().getSuperclass().getDeclaredField("planner");
    plannerField.setAccessible(true);
    plannerField.set(runner, planner);
    StreamManager streamManager = mock(StreamManager.class);
    Field streamManagerField = runner.getClass().getSuperclass().getDeclaredField("streamManager");
    streamManagerField.setAccessible(true);
    streamManagerField.set(runner, streamManager);
    ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
    ExecutionPlan plan = new ExecutionPlan() {

        @Override
        public List<JobConfig> getJobConfigs() {
            return Collections.emptyList();
        }

        @Override
        public List<StreamSpec> getIntermediateStreams() {
            return Collections.singletonList(new StreamSpec("test-stream", "test-stream", "test-system"));
        }

        @Override
        public String getPlanAsJson() throws Exception {
            return "";
        }
    };
    when(planner.plan(anyObject())).thenReturn(plan);
    LocalApplicationRunner spy = spy(runner);
    CoordinationUtils coordinationUtils = mock(CoordinationUtils.class);
    LeaderElector leaderElector = new LeaderElector() {

        private LeaderElectorListener leaderElectorListener;

        @Override
        public void setLeaderElectorListener(LeaderElectorListener listener) {
            this.leaderElectorListener = listener;
        }

        @Override
        public void tryBecomeLeader() {
            leaderElectorListener.onBecomingLeader();
        }

        @Override
        public void resignLeadership() {
        }

        @Override
        public boolean amILeader() {
            return false;
        }
    };
    Latch latch = new Latch() {

        boolean done = false;

        @Override
        public void await(long timeout, TimeUnit tu) throws TimeoutException {
            // in this test, latch is released before wait
            assertTrue(done);
        }

        @Override
        public void countDown() {
            done = true;
        }
    };
    when(coordinationUtils.getLeaderElector()).thenReturn(leaderElector);
    when(coordinationUtils.getLatch(anyInt(), anyString())).thenReturn(latch);
    doReturn(coordinationUtils).when(spy).createCoordinationUtils();
    try {
        spy.run(app);
    } catch (Throwable t) {
        //no jobs exception
        assertNotNull(t);
    }
    verify(streamManager).createStreams(captor.capture());
    List<StreamSpec> streamSpecs = captor.getValue();
    assertEquals(streamSpecs.size(), 1);
    assertEquals(streamSpecs.get(0).getId(), "test-stream");
}
Also used : StreamSpec(org.apache.samza.system.StreamSpec) HashMap(java.util.HashMap) StreamApplication(org.apache.samza.application.StreamApplication) ExecutionPlanner(org.apache.samza.execution.ExecutionPlanner) Matchers.anyString(org.mockito.Matchers.anyString) JobConfig(org.apache.samza.config.JobConfig) Field(java.lang.reflect.Field) ExecutionPlan(org.apache.samza.execution.ExecutionPlan) StreamManager(org.apache.samza.execution.StreamManager) LeaderElectorListener(org.apache.samza.coordinator.LeaderElectorListener) LeaderElector(org.apache.samza.coordinator.LeaderElector) Latch(org.apache.samza.coordinator.Latch) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) MapConfig(org.apache.samza.config.MapConfig) CoordinationUtils(org.apache.samza.coordinator.CoordinationUtils) Test(org.junit.Test)

Example 60 with MapConfig

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

the class TestExecutionPlanner method testTriggerIntervalForWindowsAndJoins.

@Test
public void testTriggerIntervalForWindowsAndJoins() throws Exception {
    Map<String, String> map = new HashMap<>(config);
    map.put(JobConfig.JOB_INTERMEDIATE_STREAM_PARTITIONS(), String.valueOf(DEFAULT_PARTITIONS));
    Config cfg = new MapConfig(map);
    ExecutionPlanner planner = new ExecutionPlanner(cfg, streamManager);
    StreamGraphImpl streamGraph = createStreamGraphWithJoinAndWindow();
    ExecutionPlan plan = planner.plan(streamGraph);
    List<JobConfig> jobConfigs = plan.getJobConfigs();
    assertEquals(jobConfigs.size(), 1);
    // GCD of 8, 16, 1600 and 252 is 4
    assertEquals(jobConfigs.get(0).get(TaskConfig.WINDOW_MS()), "4");
}
Also used : HashMap(java.util.HashMap) JobConfig(org.apache.samza.config.JobConfig) MapConfig(org.apache.samza.config.MapConfig) TaskConfig(org.apache.samza.config.TaskConfig) Config(org.apache.samza.config.Config) StreamGraphImpl(org.apache.samza.operators.StreamGraphImpl) MapConfig(org.apache.samza.config.MapConfig) JobConfig(org.apache.samza.config.JobConfig) Test(org.junit.Test)

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