use of com.amazonaws.xray.strategy.sampling.rand.RandImpl in project aws-xray-sdk-java by aws.
the class CentralizedRuleTest method testRuleUpdateWithoutInvalidation.
@Test
public void testRuleUpdateWithoutInvalidation() {
SamplingRule input = createInput("r1", 300, 10, 0.0).withHTTPMethod("POST").withServiceName("s1").withURLPath("/foo/bar");
CentralizedRule r = new CentralizedRule(input, new RandImpl());
SamplingRule update = createInput("r1", 300, 10, 0.0).withHTTPMethod("GET").withServiceName("s2").withURLPath("/bar/foo");
boolean invalidate = r.update(update);
Matchers m = Whitebox.getInternalState(r, "matchers", CentralizedRule.class);
Assert.assertEquals("GET", Whitebox.getInternalState(m, "method", Matchers.class));
Assert.assertEquals("s2", Whitebox.getInternalState(m, "service", Matchers.class));
Assert.assertEquals("/bar/foo", Whitebox.getInternalState(m, "url", Matchers.class));
Assert.assertFalse(invalidate);
}
use of com.amazonaws.xray.strategy.sampling.rand.RandImpl in project aws-xray-sdk-java by aws.
the class CentralizedRuleTest method testPositiveSampleTake.
@Test
public void testPositiveSampleTake() {
Clock clock = Clock.fixed(Instant.ofEpochSecond(1500000000), ZoneId.systemDefault());
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());
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());
}
use of com.amazonaws.xray.strategy.sampling.rand.RandImpl in project aws-xray-sdk-java by aws.
the class CentralizedRuleTest method testSnapshot.
@Test
public void testSnapshot() {
Clock clock = Clock.fixed(Instant.ofEpochSecond(1500000000), ZoneId.systemDefault());
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());
Statistics s = Whitebox.getInternalState(rule, "statistics", CentralizedRule.class);
// Assert statistics were updated
Assert.assertEquals(1, s.getSampled());
Assert.assertEquals(1, s.getRequests());
Assert.assertEquals(0, s.getBorrowed());
SamplingStatisticsDocument snapshot = rule.snapshot(Date.from(clock.instant()));
// Assert snapshot contains expected statistics
Assert.assertEquals("r1", snapshot.getRuleName());
Assert.assertEquals(TimeUnit.SECONDS.toMillis(1500000000), snapshot.getTimestamp().toInstant().toEpochMilli());
Assert.assertEquals(1, snapshot.getRequestCount().intValue());
Assert.assertEquals(1, snapshot.getSampledCount().intValue());
Assert.assertEquals(0, snapshot.getBorrowCount().intValue());
// Assert current statistics are empty
Assert.assertEquals(0, rule.snapshot(Date.from(clock.instant())).getRequestCount().intValue());
Assert.assertEquals(0, rule.snapshot(Date.from(clock.instant())).getSampledCount().intValue());
Assert.assertEquals(0, rule.snapshot(Date.from(clock.instant())).getBorrowCount().intValue());
}
Aggregations