### Question:
WorkerRegistryV2 implements WorkerRegistry, WorkerEventSubscriber { @Override public Map<WorkerId, String> getAllRunningWorkerSlaveIdMappings() { return jobToWorkerInfoMap.values().stream() .flatMap(workerList -> workerList.stream() .filter(wm -> WorkerState.isRunningState(wm.getState()))) .collect(toMap( IMantisWorkerMetadata::getWorkerId, IMantisWorkerMetadata::getSlaveID, (s1, s2) -> (s1 != null) ? s1 : s2)); } WorkerRegistryV2(); static Props props(); void clearState(); @Override int getNumRunningWorkers(); @Override Set<WorkerId> getAllRunningWorkers(); @Override Map<WorkerId, String> getAllRunningWorkerSlaveIdMappings(); @Override boolean isWorkerValid(WorkerId workerId); @Override Optional<Long> getAcceptedAt(WorkerId workerId); @Override void process(LifecycleEventsProto.WorkerListChangedEvent event); @Override void process(LifecycleEventsProto.JobStatusEvent statusEvent); static final WorkerRegistryV2 INSTANCE; }### Answer:
@Test public void testGetSlaveIdMappings() { WorkerRegistryV2 workerRegistryV2 = new WorkerRegistryV2(); initRegistryWithWorkers(workerRegistryV2,"testGetSlaveIdMappings-1", 5); Map<WorkerId, String> workerIdToSlaveIdMap = workerRegistryV2.getAllRunningWorkerSlaveIdMappings(); assertEquals(5, workerIdToSlaveIdMap.size()); for(int i=0; i<5; i++) { assertEquals("slaveId-"+i, workerIdToSlaveIdMap.get(new WorkerId("testGetSlaveIdMappings-1",i,i+5))); } }