jeudi 27 août 2015

Produce a unit test to assert that Coda Hale's Metrics are biased toward more recent results

I have a component that configures some of it's own metrics. I would like to produce a stable unit test to assert that the metric has the expected bias toward more recent results. I am not interested in asserting any other property, having successfully tested that the metric is supplied with data.

The bias is produced by an "Exponentially Decaying Reservoir" of samples that is apparently somewhat random, therefore the result is not predictable and even an ostensibly vague assertion occasionally produces an unexpected result.

This approach fails some of the time (I have not measured how often exactly).

@Test
public void assumingTheHistogramIsBiasedTowardsMoreRecentValues() {

    for(int i=1; i <= 10000; i++) {
        messageParser.getSizeHistogram().update(i);
    }

    assertThat(messageParser.getSizeHistogram().getSnapshot().getMedian(), greaterThan(5000d));

}

I have tried increasing the number of values updated and also controlling the timing of updates, neither helped. I also tried the mean and 75th percentile.

Aucun commentaire:

Enregistrer un commentaire