### Question:
CentralizedManifest implements Manifest { public void putRules(List<SamplingRule> inputs, Instant now) { boolean invalidate = false; Map<String, CentralizedRule> rules = this.rules; for (SamplingRule i : inputs) { if (i.getRuleName().equals(CentralizedRule.DEFAULT_RULE_NAME)) { putDefaultRule(i); } else { invalidate = putCustomRule(rules, i); } } if (invalidate) { this.rules = rebuild(rules, inputs); } this.refreshedAt = now; } CentralizedManifest(); LinkedHashMap<String, CentralizedRule> getRules(); @Nullable CentralizedRule getDefaultRule(); boolean isExpired(Instant now); int size(); @Override // TODO(anuraaga): It seems like this should never return null, check where defaultRule is guaranteed to be present and remove @Nullable Rule match(SamplingRequest req, Instant now); void putRules(List<SamplingRule> inputs, Instant now); List<SamplingStatisticsDocument> snapshots(Instant now); void putTargets(List<SamplingTargetDocument> targets, Instant now);  }### Answer:
@Test void testPutRules() { Instant now = Instant.ofEpochSecond(1500000000); CentralizedManifest manifest = new CentralizedManifest(); SamplingRule r1 = new SamplingRule() .withRuleName("r1") .withPriority(10) .withReservoirSize(20) .withFixedRate(0.05) .withHost("*") .withServiceName("*") .withHTTPMethod("*") .withURLPath("*") .withResourceARN("*") .withServiceType("*"); manifest.putRules(Arrays.asList(r1), now); SamplingRequest req = new SamplingRequest( "privileged", "resourceARN", "service", "host", "method", "url", "serviceType", null ); Assertions.assertEquals("r1", manifest.match(req, now).sample(now).getRuleName().get()); }
@Test void testPutRulesWithoutRebuild() { CentralizedManifest manifest = new CentralizedManifest(); manifest.putRules(Arrays.asList(rule("r1")), Instant.now()); Map<String, CentralizedRule> rules1 = Whitebox.getInternalState(manifest, "rules", CentralizedManifest.class); SamplingRule r = rule("r1").withResourceARN("arn3"); manifest.putRules(Arrays.asList(r), Instant.now()); Map<String, CentralizedRule> rules2 = Whitebox.getInternalState(manifest, "rules", CentralizedManifest.class); Assertions.assertTrue(rules1 == rules2); }