@Test(dataProvider = "environment") private void testAllHostsPicked( String environmentName, TestEnvironment cloudStoreEnvironment, CloudStoreConstraintChecker checker) throws Throwable { logger.info("Testing that all hosts are selected in {}", environmentName); List<DatastoreService.State> datastores = createDatastoreDescriptions(10); List<HostService.State> hosts = createHostDescriptions(10, false, datastores); logger.info("Making 10 datastores..."); createDatastores(cloudStoreEnvironment, datastores); logger.info("Making 10 cloud hosts..."); createHosts(cloudStoreEnvironment, hosts); List<ResourceConstraint> constraints = new LinkedList<>(); Boolean[] selectedHost = new Boolean[10]; boolean foundAll = false; int numAttempts = 0; Arrays.fill(selectedHost, false); for (int i = 0; i < 10000; i++) { Map<String, ServerAddress> candidate = checker.getCandidatesSync(constraints, 1); assertThat(candidate.size(), is(1)); for (String hostname : candidate.keySet()) { String[] hostnameSubstrings = hostname.split("-"); int hostIndex = Integer.parseInt(hostnameSubstrings[hostnameSubstrings.length - 1]); selectedHost[hostIndex] = true; } if (Arrays.stream(selectedHost).allMatch(selected -> selected == true)) { foundAll = true; numAttempts = i + 1; break; } } assertEquals(foundAll, true); if (foundAll) { logger.info("Took {} attempts to select all hosts", numAttempts); } deleteDatastores(cloudStoreEnvironment, datastores); deleteHosts(cloudStoreEnvironment, hosts); }
public Map<String, ServerAddress> getCandidatesSync( List<ResourceConstraint> resourceConstraints, int numCandidates) { List<Map<String, ServerAddress>> candidates = new ArrayList<Map<String, ServerAddress>>(); CountDownLatch latch = new CountDownLatch(1); getCandidates(resourceConstraints, numCandidates, (c, ex) -> { candidates.add(c); latch.countDown(); }); boolean done = false; while (!done) { try { latch.await(); done = true; } catch (InterruptedException ex) { } } return candidates.get(0); }
CloudStoreConstraintChecker implements ConstraintChecker { public Map<String, ServerAddress> getCandidatesSync( List<ResourceConstraint> resourceConstraints, int numCandidates) { List<Map<String, ServerAddress>> candidates = new ArrayList<Map<String, ServerAddress>>(); CountDownLatch latch = new CountDownLatch(1); getCandidates(resourceConstraints, numCandidates, (c, ex) -> { candidates.add(c); latch.countDown(); }); boolean done = false; while (!done) { try { latch.await(); done = true; } catch (InterruptedException ex) { } } return candidates.get(0); } }
CloudStoreConstraintChecker implements ConstraintChecker { public Map<String, ServerAddress> getCandidatesSync( List<ResourceConstraint> resourceConstraints, int numCandidates) { List<Map<String, ServerAddress>> candidates = new ArrayList<Map<String, ServerAddress>>(); CountDownLatch latch = new CountDownLatch(1); getCandidates(resourceConstraints, numCandidates, (c, ex) -> { candidates.add(c); latch.countDown(); }); boolean done = false; while (!done) { try { latch.await(); done = true; } catch (InterruptedException ex) { } } return candidates.get(0); } CloudStoreConstraintChecker(CloudStoreHelper cloudStoreHelper, ServiceHost xenonHost); }
CloudStoreConstraintChecker implements ConstraintChecker { public Map<String, ServerAddress> getCandidatesSync( List<ResourceConstraint> resourceConstraints, int numCandidates) { List<Map<String, ServerAddress>> candidates = new ArrayList<Map<String, ServerAddress>>(); CountDownLatch latch = new CountDownLatch(1); getCandidates(resourceConstraints, numCandidates, (c, ex) -> { candidates.add(c); latch.countDown(); }); boolean done = false; while (!done) { try { latch.await(); done = true; } catch (InterruptedException ex) { } } return candidates.get(0); } CloudStoreConstraintChecker(CloudStoreHelper cloudStoreHelper, ServiceHost xenonHost); Map<String, ServerAddress> getCandidatesSync(
      List<ResourceConstraint> resourceConstraints,
      int numCandidates); @Override void getCandidates(
      List<ResourceConstraint> resourceConstraints,
      int numCandidates,
      GetCandidatesCompletion completion); }
CloudStoreConstraintChecker implements ConstraintChecker { public Map<String, ServerAddress> getCandidatesSync( List<ResourceConstraint> resourceConstraints, int numCandidates) { List<Map<String, ServerAddress>> candidates = new ArrayList<Map<String, ServerAddress>>(); CountDownLatch latch = new CountDownLatch(1); getCandidates(resourceConstraints, numCandidates, (c, ex) -> { candidates.add(c); latch.countDown(); }); boolean done = false; while (!done) { try { latch.await(); done = true; } catch (InterruptedException ex) { } } return candidates.get(0); } CloudStoreConstraintChecker(CloudStoreHelper cloudStoreHelper, ServiceHost xenonHost); Map<String, ServerAddress> getCandidatesSync(
      List<ResourceConstraint> resourceConstraints,
      int numCandidates); @Override void getCandidates(
      List<ResourceConstraint> resourceConstraints,
      int numCandidates,
      GetCandidatesCompletion completion);  }