use of com.amazonaws.xray.strategy.sampling.rand.RandImpl 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.xray.strategy.sampling.rand.RandImpl 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());
}
use of com.amazonaws.xray.strategy.sampling.rand.RandImpl in project aws-xray-sdk-java by aws.
the class CentralizedManifest method rebuild.
LinkedHashMap<String, CentralizedRule> rebuild(Map<String, CentralizedRule> old, List<SamplingRule> inputs) {
List<CentralizedRule> rules = new ArrayList<>(inputs.size() - 1);
for (SamplingRule i : inputs) {
if (i.getRuleName().equals(CentralizedRule.DEFAULT_RULE_NAME)) {
continue;
}
CentralizedRule r = old.get(i.getRuleName());
if (r == null) {
r = new CentralizedRule(i, new RandImpl());
}
rules.add(r);
}
Collections.sort(rules);
LinkedHashMap<String, CentralizedRule> current = new LinkedHashMap<>(rules.size());
for (CentralizedRule r : rules) {
current.put(r.getName(), r);
}
return current;
}
use of com.amazonaws.xray.strategy.sampling.rand.RandImpl 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);
}
use of com.amazonaws.xray.strategy.sampling.rand.RandImpl 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);
}
Aggregations