Search in sources :

Example 1 with SamplingRule

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

the class CentralizedManifestTest method testPositiveDefaultRuleMatch.

@Test
void testPositiveDefaultRuleMatch() {
    Instant now = Instant.ofEpochSecond(1500000000);
    CentralizedManifest manifest = new CentralizedManifest();
    SamplingRule r2 = new SamplingRule().withRuleName(CentralizedRule.DEFAULT_RULE_NAME).withReservoirSize(20).withFixedRate(0.05);
    manifest.putRules(Arrays.asList(rule("r1"), r2), now);
    // Request that matches against the default rule
    SamplingRequest req = new SamplingRequest("privileged", "resourceARN", "service", "host", "method", "url", "serviceType", null);
    Assertions.assertEquals(CentralizedRule.DEFAULT_RULE_NAME, manifest.match(req, now).sample(now).getRuleName().get());
}
Also used : Instant(java.time.Instant) SamplingRule(com.amazonaws.services.xray.model.SamplingRule) SamplingRequest(com.amazonaws.xray.strategy.sampling.SamplingRequest) Test(org.junit.jupiter.api.Test)

Example 2 with SamplingRule

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

the class CentralizedManifestTest method testRebuild.

@Test
void testRebuild() {
    Map<String, CentralizedRule> rules = new HashMap<>();
    rules.put("r1", new CentralizedRule(rule("r1").withPriority(11), new RandImpl()));
    rules.put("r2", new CentralizedRule(rule("r2"), new RandImpl()));
    List<SamplingRule> inputs = new ArrayList<>();
    inputs.add(rule("r2"));
    inputs.add(rule("r1"));
    inputs.add(rule("r3"));
    CentralizedManifest m = new CentralizedManifest();
    Map<String, CentralizedRule> rebuiltRules = m.rebuild(rules, inputs);
    Assertions.assertEquals(3, rebuiltRules.size());
    String[] orderedList = new String[3];
    rebuiltRules.keySet().toArray(orderedList);
    Assertions.assertEquals("r2", orderedList[0]);
    Assertions.assertEquals("r3", orderedList[1]);
    Assertions.assertEquals("r1", orderedList[2]);
}
Also used : RandImpl(com.amazonaws.xray.strategy.sampling.rand.RandImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CentralizedRule(com.amazonaws.xray.strategy.sampling.rule.CentralizedRule) SamplingRule(com.amazonaws.services.xray.model.SamplingRule) Test(org.junit.jupiter.api.Test)

Example 3 with SamplingRule

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

the class CentralizedManifestTest method testExpirationForOldManifest.

@Test
void testExpirationForOldManifest() {
    Instant now = Instant.ofEpochSecond(1500000000);
    CentralizedManifest manifest = new CentralizedManifest();
    SamplingRule r1 = rule("r1");
    manifest.putRules(Arrays.asList(r1), now);
    // Increment time to be one second past expiration
    now = Instant.ofEpochSecond(1500003601);
    Assertions.assertTrue(manifest.isExpired(now));
}
Also used : Instant(java.time.Instant) SamplingRule(com.amazonaws.services.xray.model.SamplingRule) Test(org.junit.jupiter.api.Test)

Example 4 with SamplingRule

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

the class CentralizedManifestTest method testExpirationForNewlyRefreshedManifest.

@Test
void testExpirationForNewlyRefreshedManifest() {
    Instant now = Instant.ofEpochSecond(1500000000);
    CentralizedManifest manifest = new CentralizedManifest();
    SamplingRule r1 = rule("r1");
    manifest.putRules(Arrays.asList(r1), now);
    Assertions.assertFalse(manifest.isExpired(now));
}
Also used : Instant(java.time.Instant) SamplingRule(com.amazonaws.services.xray.model.SamplingRule) Test(org.junit.jupiter.api.Test)

Example 5 with SamplingRule

use of com.amazonaws.services.xray.model.SamplingRule 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)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