use of com.amazonaws.services.xray.model.SamplingTargetDocument 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());
}
use of com.amazonaws.services.xray.model.SamplingTargetDocument in project aws-xray-sdk-java by aws.
the class CentralizedRuleTest method testExpiredReservoirPositiveBernoulliSample.
@Test
public void testExpiredReservoirPositiveBernoulliSample() {
Clock clock = Clock.fixed(Instant.ofEpochSecond(1500000000), ZoneId.systemDefault());
SamplingRule input = createInput("r1", 300, 0, 0.5);
CentralizedRule rule = new CentralizedRule(input, rand);
SamplingTargetDocument target = createTarget(0, 0.5, 1499999999);
rule.update(target, clock.instant());
Mockito.when(rand.next()).thenReturn(0.2);
// BernoulliSample() from expired reservoir
SamplingResponse response = rule.sample(clock.instant());
Mockito.verify(rand).next();
Assert.assertTrue(response.isSampled());
Assert.assertEquals("r1", response.getRuleName().get());
Statistics s = Whitebox.getInternalState(rule, "statistics", CentralizedRule.class);
Assert.assertEquals(1, s.getSampled());
Assert.assertEquals(1, s.getRequests());
Assert.assertEquals(0, s.getBorrowed());
}
use of com.amazonaws.services.xray.model.SamplingTargetDocument in project aws-xray-sdk-java by aws.
the class CentralizedRuleTest method testNegativeSample.
@Test
public void testNegativeSample() {
Clock clock = Clock.fixed(Instant.ofEpochSecond(1500000000), ZoneId.systemDefault());
SamplingRule input = createInput("r1", 300, 10, 0.0);
CentralizedRule rule = new CentralizedRule(input, rand);
SamplingTargetDocument target = createTarget(0, 0.0, 1500000010);
rule.update(target, clock.instant());
SamplingResponse response = rule.sample(clock.instant());
Assert.assertFalse(response.isSampled());
Assert.assertEquals("r1", response.getRuleName().get());
Statistics s = Whitebox.getInternalState(rule, "statistics", CentralizedRule.class);
Assert.assertEquals(0, s.getSampled());
Assert.assertEquals(1, s.getRequests());
Assert.assertEquals(0, s.getBorrowed());
}
use of com.amazonaws.services.xray.model.SamplingTargetDocument in project aws-xray-sdk-java by aws.
the class CentralizedManifest method putTargets.
public void putTargets(List<SamplingTargetDocument> targets, Instant now) {
Map<String, CentralizedRule> rules = this.rules;
for (SamplingTargetDocument t : targets) {
CentralizedRule r = null;
if (rules.containsKey(t.getRuleName())) {
r = rules.get(t.getRuleName());
} else if (t.getRuleName().equals(CentralizedRule.DEFAULT_RULE_NAME)) {
r = defaultRule;
}
if (r == null) {
continue;
}
r.update(t, now);
}
}
use of com.amazonaws.services.xray.model.SamplingTargetDocument in project aws-xray-sdk-java by aws.
the class CentralizedRuleTest method testPositiveBernoulliSample.
@Test
public void testPositiveBernoulliSample() {
Clock clock = Clock.fixed(Instant.ofEpochSecond(1500000000), ZoneId.systemDefault());
SamplingRule input = createInput("r1", 300, 10, 0.0);
CentralizedRule rule = new CentralizedRule(input, rand);
Mockito.when(rand.next()).thenReturn(0.01);
SamplingTargetDocument target = createTarget(0, 0.05, 1500000010);
rule.update(target, clock.instant());
// Sample using bernoulli sampling
SamplingResponse response = rule.sample(clock.instant());
Assert.assertTrue(response.isSampled());
Assert.assertEquals("r1", response.getRuleName().get());
Statistics s = Whitebox.getInternalState(rule, "statistics", CentralizedRule.class);
Assert.assertEquals(1, s.getSampled());
Assert.assertEquals(1, s.getRequests());
Assert.assertEquals(0, s.getBorrowed());
}
Aggregations