PercentileFunction extends Metrics implements AcceptableValue<PercentileFunction.PercentileArgument>, MultiIntValuesHolder { @Override public void accept(final MeterEntity entity, final PercentileArgument value) { if (dataset.size() > 0) { if (!value.getBucketedValues().isCompatible(dataset)) { throw new IllegalArgumentException( "Incompatible BucketedValues [" + value + "] for current PercentileFunction[" + dataset + "]"); } } for (final int rank : value.getRanks()) { if (rank <= 0) { throw new IllegalArgumentException("Illegal rank value " + rank + ", must be positive"); } } if (ranks.size() > 0) { if (ranks.size() != value.getRanks().length) { throw new IllegalArgumentException( "Incompatible ranks size = [" + value.getRanks().length + "] for current PercentileFunction[" + ranks .size() + "]"); } else { for (final int rank : value.getRanks()) { if (!ranks.include(rank)) { throw new IllegalArgumentException( "Rank " + rank + " doesn't exist in the previous ranks " + ranks); } } } } else { for (final int rank : value.getRanks()) { ranks.add(rank); } } this.entityId = entity.id(); final long[] values = value.getBucketedValues().getValues(); for (int i = 0; i < values.length; i++) { final long bucket = value.getBucketedValues().getBuckets()[i]; String bucketName = bucket == Long.MIN_VALUE ? Bucket.INFINITE_NEGATIVE : String.valueOf(bucket); final long bucketValue = values[i]; dataset.valueAccumulation(bucketName, bucketValue); } this.isCalculated = false; }  @Override void accept(final MeterEntity entity, final PercentileArgument value); @Override void combine(final Metrics metrics); @Override void calculate(); @Override Metrics toHour(); @Override Metrics toDay(); @Override int[] getValues(); @Override int remoteHashCode(); @Override void deserialize(final RemoteData remoteData); @Override RemoteData.Builder serialize(); @Override String id(); @Override Class<? extends StorageBuilder> builder(); @Override boolean equals(Object o); @Override int hashCode(); static final String DATASET; static final String RANKS; static final String VALUE; }
@Test(expected = IllegalArgumentException.class) public void testIncompatible() { PercentileFunctionInst inst = new PercentileFunctionInst(); inst.accept( MeterEntity.newService("service-test"), new PercentileFunction.PercentileArgument( new BucketedValues( BUCKETS, new long[] { 10, 20, 30, 40 } ), RANKS ) ); inst.accept( MeterEntity.newService("service-test"), new PercentileFunction.PercentileArgument( new BucketedValues( BUCKETS_2ND, new long[] { 10, 20, 30, 40 } ), RANKS ) ); }