Skip to content

Commit

Permalink
Add merge to Distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
tdcmeehan committed Aug 17, 2022
1 parent 29e7325 commit 3675616
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ public synchronized void add(long value, long count)
digest.add(value, count);
total.add(value * count);
}

public synchronized void merge(Distribution distribution)
{
total.merge(distribution.total);
digest.merge(distribution.digest);
}
@Managed
public synchronized double getMaxError()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.facebook.airlift.stats;

import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;

public class TestDistribution
{
@Test
public void testMerge()
{
Distribution distribution1 = new Distribution();
Distribution distribution2 = new Distribution();

for (int i = 0; i < 10; i++) {
distribution1.add(i);
}

for (int i = 10; i < 20; i++) {
distribution2.add(i);
}

distribution1.merge(distribution2);

assertEquals(distribution1.getP50(), 10);
assertEquals(distribution1.getMin(), 0);
assertEquals(distribution1.getMax(), 19);
assertEquals(distribution1.getCount(), 20.0);
}

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Expected decayCounter to have alpha.*")
public void testMergeWithIncompatibleAlphaFails()
{
Distribution distribution1 = new Distribution(0.5);
Distribution distribution2 = new Distribution(0.7);

distribution1.merge(distribution2);
}
}

0 comments on commit 3675616

Please sign in to comment.