예제 #1
0
 public void testBitSize() {
   double fpp = 0.03;
   for (int i = 1; i < 10000; i++) {
     long numBits = BloomFilter.optimalNumOfBits(i, fpp);
     int arraySize = Ints.checkedCast(LongMath.divide(numBits, 64, RoundingMode.CEILING));
     assertEquals(
         arraySize * Long.SIZE,
         BloomFilter.create(Funnels.unencodedCharsFunnel(), i, fpp).bitSize());
   }
 }
예제 #2
0
  /**
   * Given a low watermark (starting point) and a high watermark (target), returns the percentage of
   * events pulled.
   *
   * @return a percentage value between 0 and 100.
   */
  @Override
  public short calculatePercentCompletion(Watermark lowWatermark, Watermark highWatermark) {
    Preconditions.checkArgument(
        lowWatermark instanceof MultiLongWatermark && highWatermark instanceof MultiLongWatermark,
        String.format(
            "Arguments of %s.%s must be of type %s",
            MultiLongWatermark.class.getSimpleName(),
            Thread.currentThread().getStackTrace()[1].getMethodName(),
            MultiLongWatermark.class.getSimpleName()));

    long pulled = ((MultiLongWatermark) lowWatermark).getGap(this);
    long all = ((MultiLongWatermark) lowWatermark).getGap((MultiLongWatermark) highWatermark);
    Preconditions.checkState(all > 0);
    long percent = Math.min(100, LongMath.divide(pulled * 100, all, RoundingMode.HALF_UP));
    return (short) percent;
  }