Source:
public void testBadControlRequestRejected() throws Exception { SamzaApplicationState state = new SamzaApplicationState(JobModelManagerTestUtil.getJobModelManager(getConfig(), 2, this.server)); ClusterResourceManager.Callback callback = mock(ClusterResourceManager.Callback.class); MockClusterResourceManager clusterResourceManager = new MockClusterResourceManager(callback, state); LocalityManager mockLocalityManager = mock(LocalityManager.class); when(mockLocalityManager.readLocality()) .thenReturn(new LocalityModel(ImmutableMap.of( "0", new ProcessorLocality("0", "host-1"), "1", new ProcessorLocality("1", "host-2")))); ContainerManager containerManager = spy(new ContainerManager(containerPlacementMetadataStore, state, clusterResourceManager, true, false, mockLocalityManager)); MockContainerAllocatorWithHostAffinity allocatorWithHostAffinity = new MockContainerAllocatorWithHostAffinity(clusterResourceManager, config, state, containerManager); ContainerProcessManager cpm = new ContainerProcessManager( new ClusterManagerConfig(new MapConfig(getConfig(), getConfigWithHostAffinityAndRetries(true, 1, true))), state, new MetricsRegistryMap(), clusterResourceManager, Optional.of(allocatorWithHostAffinity), containerManager, mockLocalityManager); doAnswer(new Answer<Void>() { public Void answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); cpm.onResourcesAvailable((List<SamzaResource>) args[0]); return null; } }).when(callback).onResourcesAvailable(anyList()); doAnswer(new Answer<Void>() { public Void answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); cpm.onStreamProcessorLaunchSuccess((SamzaResource) args[0]); return null; } }).when(callback).onStreamProcessorLaunchSuccess(any()); cpm.start(); if (!allocatorWithHostAffinity.awaitContainersStart(2, 3, TimeUnit.SECONDS)) { fail("timed out waiting for the containers to start"); } assertBadRequests(null, "host2", containerManager, allocatorWithHostAffinity); assertBadRequests("0", null, containerManager, allocatorWithHostAffinity); assertBadRequests("2", "host8", containerManager, allocatorWithHostAffinity); }

Target:
public void testBadControlRequestRejected() throws Exception { SamzaApplicationState state = new SamzaApplicationState(JobModelManagerTestUtil.getJobModelManager(getConfig(), 2, this.server)); ClusterResourceManager.Callback callback = mock(ClusterResourceManager.Callback.class); MockClusterResourceManager clusterResourceManager = new MockClusterResourceManager(callback, state); ContainerManager containerManager = spy(new ContainerManager(containerPlacementMetadataStore, state, clusterResourceManager, true, false, localityManager)); MockContainerAllocatorWithHostAffinity allocatorWithHostAffinity = new MockContainerAllocatorWithHostAffinity(clusterResourceManager, config, state, containerManager); ContainerProcessManager cpm = new ContainerProcessManager( new ClusterManagerConfig(new MapConfig(getConfig(), getConfigWithHostAffinityAndRetries(true, 1, true))), state, new MetricsRegistryMap(), clusterResourceManager, Optional.of(allocatorWithHostAffinity), containerManager, localityManager); doAnswer(new Answer<Void>() { public Void answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); cpm.onResourcesAvailable((List<SamzaResource>) args[0]); return null; } }).when(callback).onResourcesAvailable(anyList()); doAnswer(new Answer<Void>() { public Void answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); cpm.onStreamProcessorLaunchSuccess((SamzaResource) args[0]); return null; } }).when(callback).onStreamProcessorLaunchSuccess(any()); cpm.start(); if (!allocatorWithHostAffinity.awaitContainersStart(2, 3, TimeUnit.SECONDS)) { fail("timed out waiting for the containers to start"); } assertBadRequests(null, "host2", containerManager, allocatorWithHostAffinity); assertBadRequests("0", null, containerManager, allocatorWithHostAffinity); assertBadRequests("2", "host8", containerManager, allocatorWithHostAffinity); }