This is an automated email from the ASF dual-hosted git repository.
cschneider pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-journal.git
The following commit(s) were added to refs/heads/master by this push:
new 32d97f1 SLING-9649 - Fix for TEST request issue
32d97f1 is described below
commit 32d97f1bf133b603bcd4e77ec81435d94a10c991
Author: Christian Schneider <[email protected]>
AuthorDate: Mon Aug 10 12:13:07 2020 +0200
SLING-9649 - Fix for TEST request issue
---
.../impl/publisher/DistributionPublisher.java | 6 +-
.../impl/publisher/DistributionPublisherTest.java | 71 +++++++++++++---------
2 files changed, 48 insertions(+), 29 deletions(-)
diff --git
a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DistributionPublisher.java
b/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DistributionPublisher.java
index 15d11aa..ae0c964 100644
---
a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DistributionPublisher.java
+++
b/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DistributionPublisher.java
@@ -151,7 +151,7 @@ public class DistributionPublisher implements
DistributionAgent {
log = new DefaultDistributionLog(pubAgentName, this.getClass(),
DefaultDistributionLog.LogLevel.INFO);
REQ_TYPES.put(ADD, this::sendAndWait);
REQ_TYPES.put(DELETE, this::sendAndWait);
- REQ_TYPES.put(TEST, this.sender);
+ REQ_TYPES.put(TEST, this::send);
}
@Activate
@@ -291,6 +291,10 @@ public class DistributionPublisher implements
DistributionAgent {
}
}
}
+
+ private void send(PackageMessage pkg) {
+ sender.accept(pkg);
+ }
private void sendAndWait(PackageMessage pkg) {
try {
diff --git
a/src/test/java/org/apache/sling/distribution/journal/impl/publisher/DistributionPublisherTest.java
b/src/test/java/org/apache/sling/distribution/journal/impl/publisher/DistributionPublisherTest.java
index de4f552..180b8d8 100644
---
a/src/test/java/org/apache/sling/distribution/journal/impl/publisher/DistributionPublisherTest.java
+++
b/src/test/java/org/apache/sling/distribution/journal/impl/publisher/DistributionPublisherTest.java
@@ -171,38 +171,27 @@ public class DistributionPublisherTest {
verify(serviceReg).unregister();
}
- @SuppressWarnings("unchecked")
@Test
- public void testSend() throws DistributionException, IOException {
+ public void executeRequestADDAccepted() throws DistributionException,
IOException {
DistributionRequest request = new
SimpleDistributionRequest(DistributionRequestType.ADD, "/test");
-
- PackageMessage pkg = mockPackage(request);
-
when(factory.create(Matchers.any(DistributionPackageBuilder.class),Mockito.eq(resourceResolver),
anyString(), Mockito.eq(request))).thenReturn(pkg);
- CompletableFuture<Void> callback =
CompletableFuture.completedFuture(null);
-
when(queuedNotifier.registerWait(Mockito.eq(pkg.getPkgId()))).thenReturn(callback);
-
when(distributionMetricsService.getExportedPackageSize()).thenReturn(histogram);
-
when(distributionMetricsService.getAcceptedRequests()).thenReturn(meter);
-
when(distributionMetricsService.getDroppedRequests()).thenReturn(meter);
-
when(distributionMetricsService.getBuildPackageDuration()).thenReturn(timer);
-
when(distributionMetricsService.getEnqueuePackageDuration()).thenReturn(timer);
-
- DistributionResponse response = publisher.execute(resourceResolver,
request);
-
- assertThat(response.getState(),
equalTo(DistributionRequestState.ACCEPTED));
- verify(sender).accept(pkgCaptor.capture());
- PackageMessage sent = pkgCaptor.getValue();
- // Individual fields are checks in factory
- assertThat(sent, notNullValue());
-
- List<String> log = publisher.getLog().getLines();
- assertThat(log, contains(
- containsString("Started Publisher agent pub1agent1"),
- containsString("Distribution request accepted")));
+ executeAndCheck(request);
}
+ @Test
+ public void executeRequestDELETEAccepted() throws DistributionException,
IOException {
+ DistributionRequest request = new
SimpleDistributionRequest(DistributionRequestType.DELETE, "/test");
+ executeAndCheck(request);
+ }
+
+ @Test
+ public void executeRequestTESTAccepted() throws DistributionException,
IOException {
+ DistributionRequest request = new
SimpleDistributionRequest(DistributionRequestType.TEST, "/test");
+ executeAndCheck(request);
+ }
+
@SuppressWarnings("unchecked")
- @Test
- public void testSendUnsupported() throws DistributionException,
IOException {
+ @Test
+ public void testExecutePullUnsupported() throws DistributionException,
IOException {
DistributionRequest request = new
SimpleDistributionRequest(DistributionRequestType.PULL, "/test");
DistributionResponse response = publisher.execute(resourceResolver,
request);
@@ -210,7 +199,7 @@ public class DistributionPublisherTest {
List<String> log = publisher.getLog().getLines();
assertThat(log, contains(
- containsString("Started Publisher agent pub1agent1"),
+ containsString("Started Publisher agent pub1agent1"),
containsString("Request type PULL is not supported by this
agent, expected one of")));
}
@@ -270,6 +259,32 @@ public class DistributionPublisherTest {
assertEquals("Wrong getQueue error counter",1, counter.getCount());
}
+ @SuppressWarnings("unchecked")
+ private void executeAndCheck(DistributionRequest request) throws
IOException, DistributionException {
+ PackageMessage pkg = mockPackage(request);
+
when(factory.create(Matchers.any(DistributionPackageBuilder.class),Mockito.eq(resourceResolver),
anyString(), Mockito.eq(request))).thenReturn(pkg);
+ CompletableFuture<Void> callback =
CompletableFuture.completedFuture(null);
+
when(queuedNotifier.registerWait(Mockito.eq(pkg.getPkgId()))).thenReturn(callback);
+
when(distributionMetricsService.getExportedPackageSize()).thenReturn(histogram);
+
when(distributionMetricsService.getAcceptedRequests()).thenReturn(meter);
+
when(distributionMetricsService.getDroppedRequests()).thenReturn(meter);
+
when(distributionMetricsService.getBuildPackageDuration()).thenReturn(timer);
+
when(distributionMetricsService.getEnqueuePackageDuration()).thenReturn(timer);
+
+ DistributionResponse response = publisher.execute(resourceResolver,
request);
+
+ assertThat(response.getState(),
equalTo(DistributionRequestState.ACCEPTED));
+ verify(sender).accept(pkgCaptor.capture());
+ PackageMessage sent = pkgCaptor.getValue();
+ // Individual fields are checks in factory
+ assertThat(sent, notNullValue());
+
+ List<String> log = publisher.getLog().getLines();
+ assertThat(log, contains(
+ containsString("Started Publisher agent pub1agent1"),
+ containsString("Distribution request accepted")));
+ }
+
private PackageMessage mockPackage(DistributionRequest request) throws
IOException {
return PackageMessage.builder()
.pkgId("myid")