Search in sources :

Example 6 with JobConfig

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

the class TestExecutionPlanner method testTriggerIntervalForStatelessOperators.

@Test
public void testTriggerIntervalForStatelessOperators() 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 = createSimpleGraph();
    ExecutionPlan plan = planner.plan(streamGraph);
    List<JobConfig> jobConfigs = plan.getJobConfigs();
    assertEquals(jobConfigs.size(), 1);
    assertFalse(jobConfigs.get(0).containsKey(TaskConfig.WINDOW_MS()));
}
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)

Example 7 with JobConfig

use of org.apache.samza.config.JobConfig 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 8 with JobConfig

use of org.apache.samza.config.JobConfig 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 9 with JobConfig

use of org.apache.samza.config.JobConfig 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)

Example 10 with JobConfig

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

the class TestExecutionPlanner method testTriggerIntervalWhenWindowMsIsConfigured.

@Test
public void testTriggerIntervalWhenWindowMsIsConfigured() throws Exception {
    Map<String, String> map = new HashMap<>(config);
    map.put(TaskConfig.WINDOW_MS(), "2000");
    map.put(JobConfig.JOB_INTERMEDIATE_STREAM_PARTITIONS(), String.valueOf(DEFAULT_PARTITIONS));
    Config cfg = new MapConfig(map);
    ExecutionPlanner planner = new ExecutionPlanner(cfg, streamManager);
    StreamGraphImpl streamGraph = createSimpleGraph();
    ExecutionPlan plan = planner.plan(streamGraph);
    List<JobConfig> jobConfigs = plan.getJobConfigs();
    assertEquals(jobConfigs.size(), 1);
    assertEquals(jobConfigs.get(0).get(TaskConfig.WINDOW_MS()), "2000");
}
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

JobConfig (org.apache.samza.config.JobConfig)13 HashMap (java.util.HashMap)10 MapConfig (org.apache.samza.config.MapConfig)10 Test (org.junit.Test)9 Config (org.apache.samza.config.Config)8 TaskConfig (org.apache.samza.config.TaskConfig)6 StreamGraphImpl (org.apache.samza.operators.StreamGraphImpl)6 StreamApplication (org.apache.samza.application.StreamApplication)5 ExecutionPlan (org.apache.samza.execution.ExecutionPlan)5 Field (java.lang.reflect.Field)4 ExecutionPlanner (org.apache.samza.execution.ExecutionPlanner)4 StreamSpec (org.apache.samza.system.StreamSpec)4 Matchers.anyString (org.mockito.Matchers.anyString)4 List (java.util.List)3 SamzaException (org.apache.samza.SamzaException)2 StreamManager (org.apache.samza.execution.StreamManager)2 StreamProcessor (org.apache.samza.processor.StreamProcessor)2 StreamProcessorLifecycleListener (org.apache.samza.processor.StreamProcessorLifecycleListener)2 Joiner (com.google.common.base.Joiner)1 ArrayList (java.util.ArrayList)1