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());
}
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]);
}
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));
}
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));
}
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());
}
Aggregations