use of org.apache.samza.job.model.ProcessorLocality in project samza by apache.
the class TestJobModelHelper method testAllProcessorLocalityExists.
@Test
public void testAllProcessorLocalityExists() {
Map<String, ContainerModel> containerModels = ImmutableMap.of("0", new ContainerModel("0", ImmutableMap.of(taskName(0), taskModel(0, 0, 0), taskName(2), taskModel(2, 2, 2))), "1", new ContainerModel("1", ImmutableMap.of(taskName(1), taskModel(1, 1, 1), taskName(3), taskModel(3, 3))));
Map<String, ProcessorLocality> processorLocalities = ImmutableMap.of("0", processorLocality("0", HOST0), "1", processorLocality("1", HOST1));
when(this.localityModel.getProcessorLocalities()).thenReturn(processorLocalities);
setupOldTaskAssignments(containerModels);
runAndCheckNewJobModel(config(), containerModels);
verifyGrouperMetadata(processorIdToLocationId(ImmutableMap.of("0", HOST0, "1", HOST1)), ImmutableMap.of(taskName(0), new LocationId(HOST0), taskName(1), new LocationId(HOST1), taskName(2), new LocationId(HOST0), taskName(3), new LocationId(HOST1)), activeTaskToSSPs(containerModels), activeTaskToContainer(containerModels));
verifyNewTaskAssignments(null, null, containerToTaskToMode(containerModels), sspToTasks(containerModels));
}
use of org.apache.samza.job.model.ProcessorLocality in project samza by apache.
the class TestJobModelHelper method processorLocality.
private static ProcessorLocality processorLocality(String id, String host) {
ProcessorLocality processorLocality = mock(ProcessorLocality.class);
when(processorLocality.id()).thenReturn(id);
when(processorLocality.host()).thenReturn(host);
return processorLocality;
}
use of org.apache.samza.job.model.ProcessorLocality in project samza by apache.
the class TestJobModelHelper method testNewContainerWithProcessorLocality.
@Test
public void testNewContainerWithProcessorLocality() {
Map<String, ContainerModel> oldContainerModels = ImmutableMap.of("0", new ContainerModel("0", ImmutableMap.of(taskName(0), taskModel(0, 0, 0))));
Map<String, ProcessorLocality> processorLocalities = ImmutableMap.of("0", processorLocality("0", HOST0));
when(this.localityModel.getProcessorLocalities()).thenReturn(processorLocalities);
setupOldTaskAssignments(oldContainerModels);
Map<String, ContainerModel> containerModels = ImmutableMap.of("0", new ContainerModel("0", ImmutableMap.of(taskName(0), taskModel(0, 0, 0), taskName(2), taskModel(2, 2, 2))), "1", new ContainerModel("1", ImmutableMap.of(taskName(1), taskModel(1, 1, 1), taskName(3), taskModel(3, 3))));
runAndCheckNewJobModel(config(), containerModels);
verifyGrouperMetadata(processorIdToLocationId(ImmutableMap.of("0", HOST0)), ImmutableMap.of(taskName(0), new LocationId(HOST0)), activeTaskToSSPs(oldContainerModels), activeTaskToContainer(oldContainerModels));
verifyNewTaskAssignments(taskNameStrings(oldContainerModels, TaskMode.Active), allSSPs(containerModels), containerToTaskToMode(containerModels), sspToTasks(containerModels));
}
use of org.apache.samza.job.model.ProcessorLocality 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.ProcessorLocality 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