use of org.apache.samza.job.model.LocalityModel in project samza by apache.
the class TestContainerPlacementActions method setupStandby.
public void setupStandby() throws Exception {
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"), "0-0", new ProcessorLocality("0", "host-2"), "1-0", new ProcessorLocality("0", "host-1"))));
state = new SamzaApplicationState(getJobModelManagerWithStandby());
callback = mock(ClusterResourceManager.Callback.class);
MockClusterResourceManager clusterResourceManager = new MockClusterResourceManager(callback, state);
FaultDomainManager faultDomainManager = mock(FaultDomainManager.class);
ClusterManagerConfig clusterManagerConfig = new ClusterManagerConfig(config);
// Enable standby
containerManager = spy(new ContainerManager(containerPlacementMetadataStore, state, clusterResourceManager, true, true, mockLocalityManager, faultDomainManager, config));
allocatorWithHostAffinity = new MockContainerAllocatorWithHostAffinity(clusterResourceManager, config, state, containerManager);
cpm = new ContainerProcessManager(clusterManagerConfig, state, new MetricsRegistryMap(), clusterResourceManager, Optional.of(allocatorWithHostAffinity), containerManager, mockLocalityManager, false);
}
use of org.apache.samza.job.model.LocalityModel in project samza by apache.
the class TestLocalityServlet method testReadContainerLocality.
@Test
public void testReadContainerLocality() throws Exception {
URL url = new URL(webApp.getUrl().toString() + "locality");
String response = HttpUtil.read(url, 1000, new ExponentialSleepStrategy());
LocalityModel locality = mapper.readValue(response, LocalityModel.class);
assertEquals("Expected locality for two containers", 2, locality.getProcessorLocalities().size());
assertEquals("Mismatch in locality for processor " + PROCESSOR_ID1, locality.getProcessorLocality(PROCESSOR_ID1), PROCESSOR_1_LOCALITY);
assertEquals("Mismatch in locality for processor " + PROCESSOR_ID2, locality.getProcessorLocality(PROCESSOR_ID2), PROCESSOR_2_LOCALITY);
}
use of org.apache.samza.job.model.LocalityModel in project samza by apache.
the class TestLocalityServlet method testReadProcessorLocalityWithNoLocality.
@Test
public void testReadProcessorLocalityWithNoLocality() throws Exception {
final ProcessorLocality expectedProcessorLocality = new ProcessorLocality(PROCESSOR_ID2, "");
URL url = new URL(webApp.getUrl().toString() + "locality?processorId=" + PROCESSOR_ID2);
when(localityManager.readLocality()).thenReturn(new LocalityModel(ImmutableMap.of()));
String response = HttpUtil.read(url, 1000, new ExponentialSleepStrategy());
ProcessorLocality processorLocality = mapper.readValue(response, ProcessorLocality.class);
assertEquals("Expected empty response for processor locality " + PROCESSOR_ID2 + " but got " + processorLocality, processorLocality, expectedProcessorLocality);
}
use of org.apache.samza.job.model.LocalityModel in project samza by apache.
the class TestLocalityServlet method setup.
@Before
public void setup() throws Exception {
localityManager = mock(LocalityManager.class);
when(localityManager.readLocality()).thenReturn(new LocalityModel(ImmutableMap.of(PROCESSOR_ID1, PROCESSOR_1_LOCALITY, PROCESSOR_ID2, PROCESSOR_2_LOCALITY)));
webApp = new HttpServer("/", 0, "", new ServletHolder(new DefaultServlet()));
webApp.addServlet("/locality", new LocalityServlet(localityManager));
webApp.start();
}
use of org.apache.samza.job.model.LocalityModel in project samza by apache.
the class TestContainerAllocatorWithHostAffinity method setup.
@Before
public void setup() throws Exception {
LocalityManager mockLocalityManager = mock(LocalityManager.class);
when(mockLocalityManager.readLocality()).thenReturn(new LocalityModel(ImmutableMap.of("0", new ProcessorLocality("0", "abc"))));
CoordinatorStreamStoreTestUtil coordinatorStreamStoreTestUtil = new CoordinatorStreamStoreTestUtil(config);
CoordinatorStreamStore coordinatorStreamStore = coordinatorStreamStoreTestUtil.getCoordinatorStreamStore();
coordinatorStreamStore.init();
containerPlacementMetadataStore = new ContainerPlacementMetadataStore(coordinatorStreamStore);
containerPlacementMetadataStore.start();
containerManager = new ContainerManager(containerPlacementMetadataStore, state, clusterResourceManager, true, false, mockLocalityManager, faultDomainManager, config);
containerAllocator = new ContainerAllocator(clusterResourceManager, config, state, true, containerManager);
requestState = new MockContainerRequestState(clusterResourceManager, true);
Field requestStateField = containerAllocator.getClass().getDeclaredField("resourceRequestState");
requestStateField.setAccessible(true);
requestStateField.set(containerAllocator, requestState);
allocatorThread = new Thread(containerAllocator);
}
Aggregations