Buuhuu commented on a change in pull request #16: SLING-8946 non deterministic
resource observation
URL:
https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/16#discussion_r363835997
##########
File path:
src/test/java/org/apache/sling/resourceresolver/impl/providers/ResourceProviderTrackerTest.java
##########
@@ -240,6 +248,62 @@ public void providerRemoved(String name, String pid,
boolean stateful, boolean u
assertThat(tracker.getResourceProviderStorage().getAllHandlers().size(),
equalTo(0));
}
+ /**
+ * This test verifies that shadowing of Resource observation is
deterministic when ResourceProviders get registered and unregistered,
+ * meaning it is independent of the order in which those events happen.
+ * <p>
+ * It does so by
+ * 1) registering a ResourceProvider A on a deeper path then root
(shadowing root)
+ * 2) registering a ResourceProvider B on root
+ * 3) unregistering the ResourceProvider A
+ * 4) and registering the ResoucreProvider A
+ * <p>
+ * This guarantees in both cases (A before B and B before A) the same
excludes are applied in the ObservationReporter.
+ *
+ * @throws InvalidSyntaxException
+ */
+ @Test
+ public void testDeterministicObservationShadowing() throws
InvalidSyntaxException {
+ final ResourceProviderTracker tracker = new ResourceProviderTracker();
+ final Map<String, List<String>> excludeSets = new HashMap<>();
+
+ tracker.activate(context.bundleContext(), eventAdmin, null);
+ tracker.setObservationReporterGenerator(new
SimpleObservationReporterGenerator(new DoNothingObservationReporter()) {
+ @Override
+ public ObservationReporter create(Path path, PathSet excludes) {
+ List<String> excludeSetsPerPath =
excludeSets.get(path.getPath());
+ if (excludeSetsPerPath == null) {
+ excludeSetsPerPath = new ArrayList<>(1);
+ excludeSets.put(path.getPath(), excludeSetsPerPath);
+ }
+
+ excludeSetsPerPath.clear();
+ for (Iterator<Path> excludesIt = excludes.iterator();
excludesIt.hasNext(); ) {
+ excludeSetsPerPath.add(excludesIt.next().getPath());
+ }
+
+ return super.create(path, excludes);
+ }
+ });
+
+ ResourceProvider rp = mock(ResourceProvider.class);
+ ResourceProviderInfo info;
+ // register on RP on /content/B2C, empty exclude set expected
Review comment:
I will remove those project specifics
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services