Search in sources :

Example 1 with CentralizedReservoir

use of com.amazonaws.xray.strategy.sampling.reservoir.CentralizedReservoir in project aws-xray-sdk-java by aws.

the class CentralizedRuleTest method testReservoirReset.

@Test
public void testReservoirReset() {
    Mockito.when(clock.instant()).thenReturn(Instant.ofEpochSecond(1500000000));
    SamplingRule input = createInput("r1", 300, 10, 0.0);
    CentralizedRule rule = new CentralizedRule(input, new RandImpl());
    SamplingTargetDocument target = createTarget(2, 0.0, 1500000010);
    rule.update(target, clock.instant());
    rule.sample(clock.instant());
    CentralizedReservoir reservoir = Whitebox.getInternalState(rule, "centralizedReservoir", CentralizedRule.class);
    Assert.assertEquals(1, reservoir.getUsed());
    Mockito.when(clock.instant()).thenReturn(Instant.ofEpochSecond(1500000001));
    rule.sample(clock.instant());
    // Assert to ensure reservoir was reset before being updated
    Assert.assertEquals(1, reservoir.getUsed());
}
Also used : RandImpl(com.amazonaws.xray.strategy.sampling.rand.RandImpl) CentralizedReservoir(com.amazonaws.xray.strategy.sampling.reservoir.CentralizedReservoir) SamplingRule(com.amazonaws.services.xray.model.SamplingRule) SamplingTargetDocument(com.amazonaws.services.xray.model.SamplingTargetDocument) Test(org.junit.Test)

Aggregations

SamplingRule (com.amazonaws.services.xray.model.SamplingRule)1 SamplingTargetDocument (com.amazonaws.services.xray.model.SamplingTargetDocument)1 RandImpl (com.amazonaws.xray.strategy.sampling.rand.RandImpl)1 CentralizedReservoir (com.amazonaws.xray.strategy.sampling.reservoir.CentralizedReservoir)1 Test (org.junit.Test)1