### Question:
WorkerRegistryV2 implements WorkerRegistry, WorkerEventSubscriber { @Override public boolean isWorkerValid(WorkerId workerId) { if(logger.isDebugEnabled()) { logger.debug("In isWorkerValid event {}", workerId); } Optional<JobId> jIdOp = JobId.fromId(workerId.getJobId()); if(!jIdOp.isPresent()) { logger.warn("Invalid job Id {}", workerId.getJobId()); return false; } List<IMantisWorkerMetadata> mantisWorkerMetadataList = jobToWorkerInfoMap.get(jIdOp.get()); boolean isValid = false; if(mantisWorkerMetadataList != null) { isValid = mantisWorkerMetadataList.stream().anyMatch((mData) -> mData.getWorkerId().equals(workerId)); } else { logger.warn("No such job {} found in job To worker map ", jIdOp.get()); } return isValid; } 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 testIsWorkerValid() { JobId jId = new JobId("testIsWorkerValid",1); WorkerRegistryV2 workerRegistryV2 = new WorkerRegistryV2(); initRegistryWithWorkers(workerRegistryV2,"testIsWorkerValid-1", 5); for(int i=0; i<5; i++) { assertTrue(workerRegistryV2.isWorkerValid(new WorkerId(jId.getId(),i,i+5))); } }