SchedulerUtils { public static boolean isUniqueHostname(Protos.OfferOrBuilder offer, NodeTask taskToLaunch, Collection<NodeTask> tasks) { Preconditions.checkArgument(offer != null); String offerHostname = offer.getHostname(); if (!CollectionUtils.isEmpty(tasks)) { for (NodeTask task : tasks) { if (offerHostname.equalsIgnoreCase(task.getHostname())) { LOGGER.debug("Offer's hostname {} is not unique", offerHostname); return false; } } } LOGGER.debug("Offer's hostname {} is unique", offerHostname); return true; }  static boolean isUniqueHostname(Protos.OfferOrBuilder offer, NodeTask taskToLaunch, Collection<NodeTask> tasks); static boolean isEligibleForFineGrainedScaling(String hostName, SchedulerState state);  }
@Test public void testIsUniqueFilenameTrue() throws Exception { List<NodeTask> tasks = Lists.newArrayList(taskOne, taskTwo, taskThree); NodeTask newTask = TestObjectFactory.getNodeTask("medium", "server1", 0.4, 2048.0, Long.valueOf(1), Long.valueOf(2)); Offer offer = TestObjectFactory.getOffer("server2", "slave1", "mock-framework", "offer1", 0.0, 0.0); assertTrue(SchedulerUtils.isUniqueHostname(offer, newTask, tasks)); }
@Test public void testIsUniqueFilenameFalse() throws Exception { List<NodeTask> tasks = Lists.newArrayList(taskOne, taskTwo, taskThree); NodeTask newTask = TestObjectFactory.getNodeTask("medium", "localhost", 0.4, 2048.0, Long.valueOf(1), Long.valueOf(2)); Offer offer = TestObjectFactory.getOffer("localhost", "slave1", "mock-framework", "offer1", 0.2, 512.0); assertFalse(SchedulerUtils.isUniqueHostname(offer, newTask, tasks)); }