use of com.amazonaws.services.xray.model.SamplingRule 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.SamplingRule 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.SamplingRule in project aws-xray-sdk-java by aws.
the class MatchersTest method testSimpleMismatch.
@Test
void testSimpleMismatch() {
SamplingRule rule = new SamplingRule().withAttributes(null).withHost("192.168.1.1").withServiceName("www.foo.com").withHTTPMethod("POST").withResourceARN("arn:aws:service:us-east-1:111111111111:resource").withURLPath("/bar/123").withServiceType("AWS::EC2::Instance");
SamplingRequest req = new SamplingRequest("role-arn", "arn:aws:service:us-east-1:111111111111:resource", "www.bar.com", "192.168.1.1", "POST", "/bar/123", "AWS::EC2::Instance", null);
Matchers m = new Matchers(rule);
Assertions.assertFalse(m.match(req));
}
use of com.amazonaws.services.xray.model.SamplingRule in project aws-xray-sdk-java by aws.
the class MatchersTest method testPartialRequestMismatch.
@Test
void testPartialRequestMismatch() {
SamplingRule rule = new SamplingRule().withAttributes(null).withHost("192.168.1.1").withServiceName("www.foo.com").withHTTPMethod("POST").withResourceARN("arn:aws:service:us-east-1:111111111111:resource").withURLPath("/bar/123").withServiceType("AWS::EC2::Instance");
SamplingRequest req = new SamplingRequest("role-arn", "arn:aws:service:us-east-1:111111111111:resource", "www.bar.com", null, "POST", "/bar/123", "AWS::EC2::Instance", null);
Matchers m = new Matchers(rule);
Assertions.assertFalse(m.match(req));
}
use of com.amazonaws.services.xray.model.SamplingRule in project aws-xray-sdk-java by aws.
the class MatchersTest method testPartialGlobMismatch.
@Test
void testPartialGlobMismatch() {
SamplingRule rule = new SamplingRule().withAttributes(null).withHost("*").withServiceName("*.foo.*").withHTTPMethod("*").withResourceARN("*").withURLPath("/bar/*").withServiceType("AWS::EC2::Instance");
SamplingRequest req = new SamplingRequest("role-arn", "arn:aws:service:us-east-1:111111111111:resource", "www.bar.com", "192.168.1.1", "GET", "/foo/baz", "AWS::EC2::Instance", null);
Matchers m = new Matchers(rule);
Assertions.assertFalse(m.match(req));
}
Aggregations