use of org.apache.samza.coordinator.CoordinationUtils in project samza by apache.
the class TestLocalApplicationRunner method prepareTest.
private void prepareTest() throws Exception {
CoordinationUtils coordinationUtils = mock(CoordinationUtils.class);
DistributedLock distributedLock = mock(DistributedLock.class);
when(distributedLock.lock(anyObject())).thenReturn(true);
when(coordinationUtils.getLock(anyString())).thenReturn(distributedLock);
ZkMetadataStore zkMetadataStore = mock(ZkMetadataStore.class);
when(zkMetadataStore.get(any())).thenReturn(null);
PowerMockito.whenNew(ZkMetadataStore.class).withAnyArguments().thenReturn(zkMetadataStore);
ApplicationDescriptorImpl<? extends ApplicationDescriptor> appDesc = ApplicationDescriptorUtil.getAppDescriptor(mockApp, config);
localPlanner = spy(new LocalJobPlanner(appDesc, coordinationUtils, "FAKE_UID", "FAKE_RUNID"));
runner = spy(new LocalApplicationRunner(mockApp, config, coordinationUtils));
doReturn(localPlanner).when(runner).getPlanner();
}
use of org.apache.samza.coordinator.CoordinationUtils in project samza by apache.
the class TestLocalJobPlanner method testStreamCreationWithCoordination.
@Test
public void testStreamCreationWithCoordination() throws Exception {
StreamApplicationDescriptorImpl appDesc = mock(StreamApplicationDescriptorImpl.class);
doReturn(mock(Config.class)).when(appDesc).getConfig();
localPlanner = createLocalJobPlanner(appDesc);
StreamManager streamManager = mock(StreamManager.class);
doReturn(streamManager).when(localPlanner).buildAndStartStreamManager(any(Config.class));
ExecutionPlan plan = mock(ExecutionPlan.class);
when(plan.getIntermediateStreams()).thenReturn(Collections.singletonList(new StreamSpec("test-stream", "test-stream", "test-system")));
when(plan.getPlanAsJson()).thenReturn("");
when(plan.getJobConfigs()).thenReturn(Collections.singletonList(mock(JobConfig.class)));
doReturn(plan).when(localPlanner).getExecutionPlan(any());
CoordinationUtils coordinationUtils = mock(CoordinationUtils.class);
CoordinationUtilsFactory coordinationUtilsFactory = mock(CoordinationUtilsFactory.class);
JobCoordinatorConfig mockJcConfig = mock(JobCoordinatorConfig.class);
when(mockJcConfig.getCoordinationUtilsFactory()).thenReturn(coordinationUtilsFactory);
PowerMockito.whenNew(JobCoordinatorConfig.class).withAnyArguments().thenReturn(mockJcConfig);
DistributedLock lock = mock(DistributedLock.class);
when(lock.lock(anyObject())).thenReturn(true);
when(coordinationUtils.getLock(anyString())).thenReturn(lock);
when(coordinationUtilsFactory.getCoordinationUtils(anyString(), anyString(), anyObject())).thenReturn(coordinationUtils);
localPlanner.prepareJobs();
ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class);
verify(streamManager).createStreams(captor.capture());
List<StreamSpec> streamSpecs = captor.getValue();
assertEquals(streamSpecs.size(), 1);
assertEquals(streamSpecs.get(0).getId(), "test-stream");
verify(streamManager).stop();
}
Aggregations