### Question:
SummedSampledCounter extends DerivedSampledCounterImpl { @Override public long getValue() { long l = 0; for (SampledCounter sc : delegates) { l = l + sc.getValue(); } return l; } SummedSampledCounter(SampledCounterConfig config, SampledCounter... delegates); @Override long getValue();  }### Answer:
@Test public void testSummed() { SampledCounterConfig configSec = new SampledCounterConfig(1, 10, true, 0); SampledCounterImpl counter1 = new SampledCounterImpl(configSec); SampledCounterImpl counter2 = new SampledCounterImpl(configSec); SampledCounterImpl counter3 = new SampledCounterImpl(configSec); SummedSampledCounter summedCounter = new SummedSampledCounter(configSec, counter1, counter2, counter3); counter1.setValue(0); counter2.setValue(0); counter3.setValue(0); Assert.assertEquals(0, summedCounter.getValue()); counter1.setValue(10); Assert.assertEquals(10, summedCounter.getValue()); summedCounter.setValue(-10); Assert.assertEquals(10, summedCounter.getValue()); Assert.assertEquals(10, summedCounter.getAndReset()); Assert.assertEquals(10, summedCounter.getValue()); counter2.setValue(20); counter3.setValue(30); summedCounter.recordSample(); counter1.getAndReset(); counter2.getAndReset(); counter3.getAndReset(); summedCounter.recordSample(); System.out.println("summed"); for (TimeStampedCounterValue tscv : summedCounter.getAllSampleValues()) { System.out.println("\t" + tscv); } Assert.assertEquals(0, summedCounter.getMostRecentSample().getCounterValue()); Assert.assertEquals(0, summedCounter.getAllSampleValues()[0].getCounterValue()); Assert.assertEquals(60, summedCounter.getAllSampleValues()[1].getCounterValue()); Assert.assertEquals(0, summedCounter.getAllSampleValues()[2].getCounterValue()); }
@Test public void testNoops() { SampledCounterConfig configSec = new SampledCounterConfig(1, 10, true, 0); SampledCounterImpl counter1 = new SampledCounterImpl(configSec); SampledCounterImpl counter2 = new SampledCounterImpl(configSec); SampledCounterImpl counter3 = new SampledCounterImpl(configSec); SummedSampledCounter summedCounter = new SummedSampledCounter(configSec, counter1, counter2, counter3); counter1.setValue(10); counter2.setValue(10); counter3.setValue(10); summedCounter.decrement(); summedCounter.decrement(10); summedCounter.increment(); summedCounter.increment(10); summedCounter.setValue(100); summedCounter.getAndReset(); Assert.assertEquals(30, summedCounter.getValue()); }