Search in sources :

Example 16 with SamplingRule

use of com.amazonaws.services.xray.model.SamplingRule in project aws-xray-sdk-java by aws.

the class CentralizedRuleTest method testTargetUpdate.

@Test
public void testTargetUpdate() {
    SamplingRule input = createInput("r1", 300, 10, 0.0);
    CentralizedRule r = new CentralizedRule(input, new RandImpl());
    SamplingTargetDocument update = new SamplingTargetDocument().withRuleName("r1").withFixedRate(0.5).withInterval(20);
    r.update(update, Instant.now());
    double fixedRate = Whitebox.getInternalState(r, "fixedRate", CentralizedRule.class);
    Assert.assertEquals(0.5, fixedRate, 0);
}
Also used : RandImpl(com.amazonaws.xray.strategy.sampling.rand.RandImpl) SamplingRule(com.amazonaws.services.xray.model.SamplingRule) SamplingTargetDocument(com.amazonaws.services.xray.model.SamplingTargetDocument) Test(org.junit.Test)

Example 17 with SamplingRule

use of com.amazonaws.services.xray.model.SamplingRule in project aws-xray-sdk-java by aws.

the class CentralizedRuleTest method testRuleUpdateWithInvalidation.

@Test
public void testRuleUpdateWithInvalidation() {
    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", 301, 5, 0.5).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.assertTrue(invalidate);
}
Also used : RandImpl(com.amazonaws.xray.strategy.sampling.rand.RandImpl) SamplingRule(com.amazonaws.services.xray.model.SamplingRule) Test(org.junit.Test)

Example 18 with SamplingRule

use of com.amazonaws.services.xray.model.SamplingRule in project aws-xray-sdk-java by aws.

the class CentralizedRuleTest method testExpiredReservoirNegativeBernoulliSample.

@Test
public void testExpiredReservoirNegativeBernoulliSample() {
    Clock clock = Clock.fixed(Instant.ofEpochSecond(1500000000), ZoneId.systemDefault());
    SamplingRule input = createInput("r1", 300, 0, 0.2);
    CentralizedRule rule = new CentralizedRule(input, rand);
    SamplingTargetDocument target = createTarget(0, 0.2, 1499999999);
    rule.update(target, clock.instant());
    Mockito.when(rand.next()).thenReturn(0.4);
    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());
}
Also used : SamplingRule(com.amazonaws.services.xray.model.SamplingRule) Clock(java.time.Clock) SamplingTargetDocument(com.amazonaws.services.xray.model.SamplingTargetDocument) SamplingResponse(com.amazonaws.xray.strategy.sampling.SamplingResponse) Test(org.junit.Test)

Example 19 with SamplingRule

use of com.amazonaws.services.xray.model.SamplingRule 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);
}
Also used : RandImpl(com.amazonaws.xray.strategy.sampling.rand.RandImpl) SamplingRule(com.amazonaws.services.xray.model.SamplingRule) Test(org.junit.Test)

Example 20 with SamplingRule

use of com.amazonaws.services.xray.model.SamplingRule 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());
}
Also used : RandImpl(com.amazonaws.xray.strategy.sampling.rand.RandImpl) SamplingRule(com.amazonaws.services.xray.model.SamplingRule) Clock(java.time.Clock) SamplingTargetDocument(com.amazonaws.services.xray.model.SamplingTargetDocument) SamplingResponse(com.amazonaws.xray.strategy.sampling.SamplingResponse) Test(org.junit.Test)

Aggregations

SamplingRule (com.amazonaws.services.xray.model.SamplingRule)30 Test (org.junit.jupiter.api.Test)17 SamplingRequest (com.amazonaws.xray.strategy.sampling.SamplingRequest)10 Test (org.junit.Test)10 SamplingTargetDocument (com.amazonaws.services.xray.model.SamplingTargetDocument)8 RandImpl (com.amazonaws.xray.strategy.sampling.rand.RandImpl)8 Clock (java.time.Clock)6 Instant (java.time.Instant)6 SamplingResponse (com.amazonaws.xray.strategy.sampling.SamplingResponse)5 CentralizedRule (com.amazonaws.xray.strategy.sampling.rule.CentralizedRule)5 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 GetSamplingRulesRequest (com.amazonaws.services.xray.model.GetSamplingRulesRequest)1 GetSamplingRulesResult (com.amazonaws.services.xray.model.GetSamplingRulesResult)1 SamplingRuleRecord (com.amazonaws.services.xray.model.SamplingRuleRecord)1 SamplingStatisticsDocument (com.amazonaws.services.xray.model.SamplingStatisticsDocument)1 CentralizedReservoir (com.amazonaws.xray.strategy.sampling.reservoir.CentralizedReservoir)1 LinkedHashMap (java.util.LinkedHashMap)1