use of com.amazonaws.services.xray.model.SamplingStatisticsDocument in project aws-xray-sdk-java by aws.
the class CentralizedManifestTest method testSnapshotsWithoutDefaultRule.
@Test
void testSnapshotsWithoutDefaultRule() {
Instant now = Instant.ofEpochSecond(1500000000);
CentralizedManifest m = new CentralizedManifest();
m.putRules(Arrays.asList(rule("r1"), rule("r2")), now);
Map<String, CentralizedRule> rules = Whitebox.getInternalState(m, "rules", CentralizedManifest.class);
rules.forEach((key, r) -> r.sample(now));
List<SamplingStatisticsDocument> snapshots = m.snapshots(now);
Assertions.assertEquals(2, snapshots.size());
}
use of com.amazonaws.services.xray.model.SamplingStatisticsDocument in project aws-xray-sdk-java by aws.
the class UnsignedXrayClientTest method getSamplingTargets.
@Test
public void getSamplingTargets() throws Exception {
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withBody(SAMPLING_TARGETS)));
GetSamplingTargetsRequest request = new GetSamplingTargetsRequest().withSamplingStatisticsDocuments(new SamplingStatisticsDocument().withClientID("client-id"));
GetSamplingTargetsResult result = client.getSamplingTargets(request);
GetSamplingTargetsResult expected = OBJECT_MAPPER.readValue(SAMPLING_TARGETS, GetSamplingTargetsResult.class);
assertThat(expected).isEqualTo(result);
verify(postRequestedFor(urlEqualTo("/SamplingTargets")).withHeader("Content-Type", equalTo("application/json")).withRequestBody(equalToJson("{" + " \"SamplingStatisticsDocuments\": [" + " {" + " \"ClientID\": \"client-id\"" + " }" + " ] " + "}")));
}
use of com.amazonaws.services.xray.model.SamplingStatisticsDocument in project aws-xray-sdk-java by aws.
the class CentralizedRuleTest method testSnapshot.
@Test
public void testSnapshot() {
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());
rule.sample(clock.instant());
Statistics s = Whitebox.getInternalState(rule, "statistics", CentralizedRule.class);
// Assert statistics were updated
Assert.assertEquals(1, s.getSampled());
Assert.assertEquals(1, s.getRequests());
Assert.assertEquals(0, s.getBorrowed());
SamplingStatisticsDocument snapshot = rule.snapshot(Date.from(clock.instant()));
// Assert snapshot contains expected statistics
Assert.assertEquals("r1", snapshot.getRuleName());
Assert.assertEquals(TimeUnit.SECONDS.toMillis(1500000000), snapshot.getTimestamp().toInstant().toEpochMilli());
Assert.assertEquals(1, snapshot.getRequestCount().intValue());
Assert.assertEquals(1, snapshot.getSampledCount().intValue());
Assert.assertEquals(0, snapshot.getBorrowCount().intValue());
// Assert current statistics are empty
Assert.assertEquals(0, rule.snapshot(Date.from(clock.instant())).getRequestCount().intValue());
Assert.assertEquals(0, rule.snapshot(Date.from(clock.instant())).getSampledCount().intValue());
Assert.assertEquals(0, rule.snapshot(Date.from(clock.instant())).getBorrowCount().intValue());
}
use of com.amazonaws.services.xray.model.SamplingStatisticsDocument in project aws-xray-sdk-java by aws.
the class CentralizedManifestTest method testSnapshotsWithDefaultRule.
@Test
void testSnapshotsWithDefaultRule() {
Instant now = Instant.ofEpochSecond(1500000000);
CentralizedManifest m = new CentralizedManifest();
m.putRules(Arrays.asList(rule("r1"), rule("r2"), rule(CentralizedRule.DEFAULT_RULE_NAME)), now);
Map<String, CentralizedRule> rules = Whitebox.getInternalState(m, "rules", CentralizedManifest.class);
CentralizedRule defaultRule = Whitebox.getInternalState(m, "defaultRule", CentralizedManifest.class);
rules.forEach((key, r) -> r.sample(now));
defaultRule.sample(now);
List<SamplingStatisticsDocument> snapshots = m.snapshots(now);
Assertions.assertEquals(3, snapshots.size());
}
use of com.amazonaws.services.xray.model.SamplingStatisticsDocument in project aws-xray-sdk-java by aws.
the class CentralizedRule method snapshot.
public SamplingStatisticsDocument snapshot(Date now) {
SamplingStatisticsDocument s = new SamplingStatisticsDocument().withRuleName(name).withTimestamp(now);
lock.writeLock().lock();
try {
s.setRequestCount(statistics.getRequests());
s.setSampledCount(statistics.getSampled());
s.setBorrowCount(statistics.getBorrowed());
statistics.reset();
} finally {
lock.writeLock().unlock();
}
return s;
}
Aggregations