You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/10/12 12:50:00 UTC

[jira] [Commented] (SLING-8010) Flaw when executionplans are configured as empty in packageinit

    [ https://issues.apache.org/jira/browse/SLING-8010?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16647876#comment-16647876 ] 

ASF GitHub Bot commented on SLING-8010:
---------------------------------------

DominikSuess closed pull request #1: SLING-8010 - replacing nullcheck by check for empty list as it is alw…
URL: https://github.com/apache/sling-org-apache-sling-jcr-packageinit/pull/1
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7aba5f8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+.settings
+.classpath
+.project
diff --git a/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java b/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
index 8631cf7..9d5346f 100644
--- a/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
+++ b/src/main/java/org/apache/sling/jcr/packageinit/impl/ExecutionPlanRepoInitializer.java
@@ -143,7 +143,7 @@ private boolean isCandidateProcessed(String candidate, Integer executedHash) {
 
     @Override
     public void processRepository(SlingRepository slingRepository) throws Exception {
-        if (executionPlans != null) {
+        if (!executionPlans.isEmpty()) {
             ServiceTracker<PackageRegistry, ?> st = new ServiceTracker<>(context, PackageRegistry.class, null);
             try {
                 st.open();
diff --git a/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java b/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
index 40f4157..822ae8b 100644
--- a/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
+++ b/src/test/java/org/apache/sling/jcr/packageinit/ExecutionPlanRepoInitializerTest.java
@@ -16,7 +16,9 @@
  */
 package org.apache.sling.jcr.packageinit;
 
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.never;
@@ -45,15 +47,23 @@
 import org.apache.sling.jcr.packageinit.impl.ExecutionPlanRepoInitializer;
 import org.apache.sling.testing.mock.osgi.MockOsgi;
 import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
 import org.mockito.Mock;
 import org.mockito.Spy;
 import org.mockito.junit.MockitoJUnitRunner;
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.Appender;
 
 @RunWith(MockitoJUnitRunner.class)
 public class ExecutionPlanRepoInitializerTest {
@@ -93,10 +103,15 @@
     @Mock
     ExecutionPlanBuilder builder2;
 
-
     @Mock
     ExecutionPlan xplan;
 
+    @Mock
+    private Appender<ILoggingEvent> mockAppender;
+    
+    @Captor
+    private ArgumentCaptor<LoggingEvent> captorLoggingEvent;
+
     private File statusFile;
     
 
@@ -105,11 +120,31 @@ public void setup() throws IOException, PackageException {
         when(registry.createExecutionPlan()).thenReturn(builder);
         when(builder.execute()).thenReturn(xplan);
         this.statusFile = temporaryFolder.newFile(STATUSFILE_NAME + UUID.randomUUID());
+        final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+        logger.addAppender(mockAppender);
     }
 
+    @After
+    public void teardown() {
+        final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+        logger.detachAppender(mockAppender);
+    }
+
+    @Test
+    public void skipWithoutExecution() throws Exception {
+        ExecutionPlanRepoInitializer initializer = registerRepoInitializer(new String[]{});
+
+        initializer.processRepository(slingRepo);
+        verify(mockAppender).doAppend(captorLoggingEvent.capture());
+        final LoggingEvent loggingEvent = captorLoggingEvent.getValue();
+        assertThat(loggingEvent.getFormattedMessage(),
+                is("No executionplans configured skipping init."));
+    }
+
+
     @Test
     public void waitForRegistryAndInstall() throws Exception {
-        ExecutionPlanRepoInitializer initializer = registerRepoInitializer();
+        ExecutionPlanRepoInitializer initializer = registerRepoInitializer(EXECUTIONSPLANS);
 
         CountDownLatch cdl = new CountDownLatch(1);
         processRepository(initializer, cdl);
@@ -131,7 +166,7 @@ public void waitForRegistryAndInstall() throws Exception {
 
     @Test
     public void doubleExecute() throws Exception {
-        ExecutionPlanRepoInitializer initializer = registerRepoInitializer();
+        ExecutionPlanRepoInitializer initializer = registerRepoInitializer(EXECUTIONSPLANS);
 
         CountDownLatch cdl = new CountDownLatch(1);
         processRepository(initializer, cdl);
@@ -147,7 +182,7 @@ public void doubleExecute() throws Exception {
         when(registry.createExecutionPlan()).thenReturn(builder2);
         
         MockOsgi.deactivate(initializer, context.bundleContext());
-        initializer = registerRepoInitializer();
+        initializer = registerRepoInitializer(EXECUTIONSPLANS);
         processRepository(initializer, cdl);;
         
         cdl.await(500, TimeUnit.MILLISECONDS);
@@ -155,10 +190,10 @@ public void doubleExecute() throws Exception {
 
     }
 
-    private ExecutionPlanRepoInitializer registerRepoInitializer() {
+    private ExecutionPlanRepoInitializer registerRepoInitializer(String[] executionPlans) {
         ExecutionPlanRepoInitializer initializer = new ExecutionPlanRepoInitializer();
         Dictionary<String, Object> props = new Hashtable<String, Object>();
-        props.put("executionplans", EXECUTIONSPLANS);
+        props.put("executionplans", executionPlans);
         props.put("statusfilepath", statusFile.getAbsolutePath());
         context.registerInjectActivateService(initializer, props);
         return initializer;


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Flaw when executionplans are configured as empty in packageinit
> ---------------------------------------------------------------
>
>                 Key: SLING-8010
>                 URL: https://issues.apache.org/jira/browse/SLING-8010
>             Project: Sling
>          Issue Type: Bug
>          Components: Installer
>            Reporter: Dominik Süß
>            Priority: Major
>
> While adding a bit more test coverage I noticed that there is a refactoring flaw in the code not handling the case well where packageinit should skip when no executionplan is configured.
> The background is that an early draft was based on ConfigurationPolicy where this SlingRepositoryInitializer Service is supposed to always be active but skip in case there is nothing to install.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)