private void assertConsistent(
      double[] pcts, Percentiles percentiles, long minValue, long maxValue) {
    final List<Percentile> percentileList = CollectionUtils.iterableAsArrayList(percentiles);
    assertEquals(pcts.length, percentileList.size());
    for (int i = 0; i < pcts.length; ++i) {
      final Percentile percentile = percentileList.get(i);
      assertThat(percentile.getPercent(), equalTo(pcts[i]));
      double value = percentile.getValue();
      assertThat(value, greaterThanOrEqualTo((double) minValue));
      assertThat(value, lessThanOrEqualTo((double) maxValue));

      if (percentile.getPercent() == 0) {
        assertThat(value, equalTo((double) minValue));
      }
      if (percentile.getPercent() == 100) {
        assertThat(value, equalTo((double) maxValue));
      }
    }

    for (int i = 1; i < percentileList.size(); ++i) {
      assertThat(
          percentileList.get(i).getValue(),
          greaterThanOrEqualTo(percentileList.get(i - 1).getValue()));
    }
  }
Exemplo n.º 2
0
    @Override
    public BytesRef binaryValue() {
      CollectionUtils.sortAndDedup(values);

      final byte[] bytes = new byte[values.size() * 8];
      for (int i = 0; i < values.size(); ++i) {
        ByteUtils.writeDoubleLE(values.get(i), bytes, i * 8);
      }
      return new BytesRef(bytes);
    }
 private List<DiscoveryNode> sortedMasterNodes(Iterable<DiscoveryNode> nodes) {
   List<DiscoveryNode> possibleNodes = CollectionUtils.iterableAsArrayList(nodes);
   if (possibleNodes.isEmpty()) {
     return null;
   }
   // clean non master nodes
   for (Iterator<DiscoveryNode> it = possibleNodes.iterator(); it.hasNext(); ) {
     DiscoveryNode node = it.next();
     if (!node.masterNode()) {
       it.remove();
     }
   }
   CollectionUtil.introSort(possibleNodes, nodeComparator);
   return possibleNodes;
 }
 public UnicastZen(int numOfNodes, int numOfUnicastHosts, Settings extraSettings) {
   super(numOfNodes, extraSettings);
   if (numOfUnicastHosts == numOfNodes) {
     unicastHostOrdinals = new int[numOfNodes];
     for (int i = 0; i < numOfNodes; i++) {
       unicastHostOrdinals[i] = i;
     }
   } else {
     Set<Integer> ordinals = new HashSet<>(numOfUnicastHosts);
     while (ordinals.size() != numOfUnicastHosts) {
       ordinals.add(RandomizedTest.randomInt(numOfNodes - 1));
     }
     unicastHostOrdinals = CollectionUtils.toArray(ordinals);
   }
   this.unicastHostPorts = unicastHostPorts(numOfNodes);
   assert unicastHostOrdinals.length <= unicastHostPorts.length;
 }
Exemplo n.º 5
0
 /**
  * If an array only consists of zero or one element, which is "*" or "_all" return an empty array
  * which is usually used as everything
  */
 public static boolean isAllOrWildcard(String[] data) {
   return CollectionUtils.isEmpty(data)
       || data.length == 1 && ("_all".equals(data[0]) || "*".equals(data[0]));
 }
 /**
  * Returns the given nodes sorted by likelyhood of being elected as master, most likely first.
  * Non-master nodes are not removed but are rather put in the end
  */
 public List<DiscoveryNode> sortByMasterLikelihood(Iterable<DiscoveryNode> nodes) {
   ArrayList<DiscoveryNode> sortedNodes = CollectionUtils.iterableAsArrayList(nodes);
   CollectionUtil.introSort(sortedNodes, nodeComparator);
   return sortedNodes;
 }