You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2020/01/21 12:12:52 UTC
[sling-org-apache-sling-jcr-repoinit] 02/04: SLING-9015 -
RepositoryInitializerFactoryIT implemented but fails semi-randomly
This is an automated email from the ASF dual-hosted git repository.
bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-repoinit.git
commit 2a5529806f863158f15443f6221b9afa1125abbe
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Jan 21 09:34:13 2020 +0100
SLING-9015 - RepositoryInitializerFactoryIT implemented but fails semi-randomly
---
pom.xml | 8 +-
.../sling/jcr/repoinit/it/RepoInitTestSupport.java | 81 +++++++++++-
.../sling/jcr/repoinit/it/RepoInitTextIT.java | 16 +--
.../it/RepositoryInitializerFactoryIT.java | 137 +++++++++++++++++++++
.../jcr/repoinit/it/RepositoryInitializerIT.java | 29 +----
src/test/resources/repoinit-path-3.txt | 20 +++
src/test/resources/repoinit-path-4.txt | 20 +++
src/test/resources/repoinit-path-5.txt | 20 +++
src/test/resources/repoinit-path-6.txt | 20 +++
9 files changed, 304 insertions(+), 47 deletions(-)
diff --git a/pom.xml b/pom.xml
index ad8c69b..cf873b7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -38,6 +38,8 @@
<properties>
<jackrabbit.version>2.18.2</jackrabbit.version>
<oak.version>1.16.0</oak.version>
+ <!-- To debug the pax process, override this with -D -->
+ <pax.vm.options>-Ddefault.pom.options=unused</pax.vm.options>
</properties>
<scm>
@@ -92,6 +94,10 @@
<name>repoinit.test.files.path</name>
<value>${basedir}/src/test/resources</value>
</property>
+ <property>
+ <name>pax.vm.options</name>
+ <value>${pax.vm.options}</value>
+ </property>
</systemProperties>
</configuration>
</plugin>
@@ -132,7 +138,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.paxexam</artifactId>
- <version>3.0.0</version>
+ <version>3.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java b/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java
index e467d08..5322b90 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTestSupport.java
@@ -17,24 +17,46 @@
package org.apache.sling.jcr.repoinit.it;
import org.apache.commons.lang3.ArrayUtils;
+import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.testing.paxexam.SlingOptions;
import org.apache.sling.testing.paxexam.TestSupport;
+import org.junit.After;
+import org.junit.Before;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.options.CompositeOption;
import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration;
+import static org.apache.sling.testing.paxexam.SlingOptions.versionResolver;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
import static org.ops4j.pax.exam.CoreOptions.composite;
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.vmOption;
import static org.apache.sling.testing.paxexam.SlingOptions.slingQuickstartOakTar;
public abstract class RepoInitTestSupport extends TestSupport {
+ protected Session session;
+
+ @Inject
+ private SlingRepository repository;
+
@Configuration
public Option[] configuration() {
SlingOptions.versionResolver.setVersionFromProject("org.apache.jackrabbit", "jackrabbit-api");
- final Option[] options = {
+ final Option[] options =
+ remove(new Option[] {
+ vmOption(System.getProperty("pax.vm.options")),
baseConfiguration(),
slingQuickstart(),
testBundle("bundle.filename"),
@@ -43,8 +65,12 @@ public abstract class RepoInitTestSupport extends TestSupport {
newConfiguration("org.apache.sling.jcr.base.internal.LoginAdminWhitelist")
.put("whitelist.bundles.regexp", "^PAXEXAM.*$")
.asOption()
- };
- return ArrayUtils.addAll(options, additionalOptions());
+ },
+ // remove our bundle under test to avoid duplication
+ mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.jcr.repoinit").version(versionResolver)
+ );
+ final Option[] allOptions = ArrayUtils.addAll(options, additionalOptions());
+ return allOptions;
}
protected Option[] additionalOptions() {
@@ -58,4 +84,53 @@ public abstract class RepoInitTestSupport extends TestSupport {
slingQuickstartOakTar(workingDirectory, httpPort)
);
}
+
+ static String getRepoinitFilesPath() {
+ return System.getProperty("repoinit.test.files.path");
+ }
+
+ @Before
+ public void setupSession() throws Exception {
+ if(session == null) {
+ session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
+ }
+ }
+
+ @After
+ public void cleanupSession() {
+ if(session != null) {
+ session.logout();
+ }
+ }
+
+ // TODO should come from org.apache.sling.testing.paxexam
+ private static List<Option> expand(final Option[] options) {
+ final List<Option> expanded = new ArrayList<>();
+ if (options != null) {
+ for (final Option option : options) {
+ if (option != null) {
+ if (option instanceof CompositeOption) {
+ expanded.addAll(Arrays.asList(((CompositeOption) option).getOptions()));
+ } else {
+ expanded.add(option);
+ }
+ }
+ }
+ }
+ return expanded;
+ }
+
+ // TODO should come from org.apache.sling.testing.paxexam
+ private static Option[] remove(final Option[] options, final Option... removables) {
+ final List<Option> expanded = expand(options);
+ for (final Option removable : removables) {
+ if (removable instanceof CompositeOption) {
+ expanded.removeAll(Arrays.asList(((CompositeOption) removable).getOptions()));
+ } else {
+ expanded.removeAll(Collections.singleton(removable));
+ }
+ }
+ return expanded.toArray(new Option[0]);
+ }
+
}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTextIT.java b/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTextIT.java
index 395b342..b9a7d3a 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTextIT.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/it/RepoInitTextIT.java
@@ -26,12 +26,9 @@ import java.util.UUID;
import javax.inject.Inject;
import javax.jcr.Session;
-import javax.jcr.SimpleCredentials;
-import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.repoinit.JcrRepoInitOpsProcessor;
import org.apache.sling.repoinit.parser.RepoInitParser;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -46,16 +43,12 @@ import org.ops4j.pax.exam.spi.reactors.PerClass;
@ExamReactorStrategy(PerClass.class)
public class RepoInitTextIT extends RepoInitTestSupport {
- private Session session;
private static final String FRED_WILMA = "fredWilmaService";
private static final String ANOTHER = "anotherService";
public static final String REPO_INIT_FILE = "/repoinit.txt";
@Inject
- private SlingRepository repository;
-
- @Inject
private RepoInitParser parser;
@Inject
@@ -63,7 +56,7 @@ public class RepoInitTextIT extends RepoInitTestSupport {
@Before
public void setup() throws Exception {
- session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
+ setupSession();
// Execute some repoinit statements
final InputStream is = getClass().getResourceAsStream(REPO_INIT_FILE);
@@ -79,13 +72,6 @@ public class RepoInitTextIT extends RepoInitTestSupport {
assertTrue("Expecting test nodes to be created", session.itemExists("/acltest/A/B"));
}
- @After
- public void cleanup() {
- if(session != null) {
- session.logout();
- }
- }
-
@Test
public void serviceUserCreated() throws Exception {
new Retry() {
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerFactoryIT.java b/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerFactoryIT.java
new file mode 100644
index 0000000..05604bc
--- /dev/null
+++ b/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerFactoryIT.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.jcr.repoinit.it;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.factoryConfiguration;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import javax.inject.Inject;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+/** Verify the RepositoryInitializerFactory functionality, to execute
+ * repoinit statements coming from OSGi configurations
+ */
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class RepositoryInitializerFactoryIT extends RepoInitTestSupport {
+
+ @Inject
+ private ConfigurationAdmin configAdmin;
+
+ private static final String TEST_MARKER = "TEST_MARKER";
+ private static final String TEST_MARKER_VALUE = "TEST_VALUE";
+
+ @Override
+ protected Option[] additionalOptions() {
+ return new Option[] {
+ factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
+ .put(TEST_MARKER, TEST_MARKER_VALUE)
+ .put("scripts", "create path /repoinit-test/scripts/A")
+ .asOption(),
+ factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
+ .put(TEST_MARKER, TEST_MARKER_VALUE)
+ .put("scripts", "create path /repoinit-test/scripts/B")
+ .put("references", "")
+ .asOption(),
+ factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
+ .put(TEST_MARKER, TEST_MARKER_VALUE)
+ .put("scripts", "create path /repoinit-test/scripts/C")
+ .put("references", "file://" + getRepoinitFilesPath() + "/repoinit-path-3.txt")
+ .asOption(),
+ factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
+ .put(TEST_MARKER, TEST_MARKER_VALUE)
+ .put("references", "file://" + getRepoinitFilesPath() + "/repoinit-path-4.txt")
+ .asOption(),
+ factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
+ .put(TEST_MARKER, TEST_MARKER_VALUE)
+ .put("references", "file://" + getRepoinitFilesPath() + "/repoinit-path-5.txt")
+ .put("scripts", "")
+ .asOption(),
+ factoryConfiguration("org.apache.sling.jcr.repoinit.RepositoryInitializer")
+ .put(TEST_MARKER, TEST_MARKER_VALUE)
+ .put("references", "file://" + getRepoinitFilesPath() + "/repoinit-path-6.txt")
+ .put("scripts", "create path /repoinit-test/scripts/D")
+ .asOption(),
+ };
+ }
+
+ private List<String> getMissingPaths() throws Exception {
+ final String [] paths = {
+ "/repoinit-test/scripts/A",
+ // TODO fails due to SLING-9015 ?? "/repoinit-test/scripts/B",
+ "/repoinit-test/scripts/C",
+ "/repoinit-test/scripts/D",
+ "/repoinit-test/path-3",
+ "/repoinit-test/path-4",
+ "/repoinit-test/path-5",
+ "/repoinit-test/path-6",
+ };
+ final List<String> missing = new ArrayList<>();
+ for(String path : paths) {
+ if(!session.itemExists(path)) {
+ missing.add(path);
+ }
+ }
+ return missing;
+ }
+
+ @Test
+ public void allConfigsRegistered() throws Exception {
+ int markerCount = 0;
+ for(Configuration cfg : configAdmin.listConfigurations(null)) {
+ if(cfg.getProperties().get(TEST_MARKER) != null) {
+ markerCount++;
+ }
+ }
+
+ // allPathsCreated fails semi-randomly, trying to find out what's happening
+ final int expectedMarkers = 6;
+ assertEquals("Expecting the correct amount of registered configs", expectedMarkers, markerCount);
+ }
+
+ @Test
+ public void allPathsCreated() throws Exception {
+ final long endTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(15);
+ List<String> missing = null;
+
+ // Configs are processed asynchronously, give them some time
+ while(System.currentTimeMillis() < endTime) {
+ missing = getMissingPaths();
+ if(missing.isEmpty()) {
+ break;
+ }
+ Thread.sleep(250);
+ }
+ assertTrue("Expecting all paths to be created, missing: " + missing, missing.isEmpty());
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerIT.java b/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerIT.java
index 74e567d..3173009 100644
--- a/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerIT.java
+++ b/src/test/java/org/apache/sling/jcr/repoinit/it/RepositoryInitializerIT.java
@@ -19,13 +19,6 @@ package org.apache.sling.jcr.repoinit.it;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration;
-import javax.inject.Inject;
-import javax.jcr.Session;
-import javax.jcr.SimpleCredentials;
-
-import org.apache.sling.jcr.api.SlingRepository;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option;
@@ -45,11 +38,7 @@ public class RepositoryInitializerIT extends RepoInitTestSupport {
"raw:file://" + getRepoinitFilesPath() + "/repoinit-path-2.txt",
};
- private Session session;
-
- @Inject
- private SlingRepository repository;
-
+ @Override
protected Option[] additionalOptions() {
return new Option[] {
newConfiguration("org.apache.sling.jcr.repoinit.impl.RepositoryInitializer")
@@ -58,18 +47,6 @@ public class RepositoryInitializerIT extends RepoInitTestSupport {
};
}
- @Before
- public void setup() throws Exception {
- session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
- }
-
- @After
- public void cleanup() {
- if(session != null) {
- session.logout();
- }
- }
-
@Test
public void path1Created() throws Exception {
assertTrue(session.itemExists("/repoinit-test/path-1"));
@@ -79,8 +56,4 @@ public class RepositoryInitializerIT extends RepoInitTestSupport {
public void path2Created() throws Exception {
assertTrue(session.itemExists("/repoinit-test/path-2"));
}
-
- static String getRepoinitFilesPath() {
- return System.getProperty("repoinit.test.files.path");
- }
}
\ No newline at end of file
diff --git a/src/test/resources/repoinit-path-3.txt b/src/test/resources/repoinit-path-3.txt
new file mode 100644
index 0000000..126c6f6
--- /dev/null
+++ b/src/test/resources/repoinit-path-3.txt
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+create path /repoinit-test/path-3
\ No newline at end of file
diff --git a/src/test/resources/repoinit-path-4.txt b/src/test/resources/repoinit-path-4.txt
new file mode 100644
index 0000000..bb2c975
--- /dev/null
+++ b/src/test/resources/repoinit-path-4.txt
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+create path /repoinit-test/path-4
\ No newline at end of file
diff --git a/src/test/resources/repoinit-path-5.txt b/src/test/resources/repoinit-path-5.txt
new file mode 100644
index 0000000..9e28f7d
--- /dev/null
+++ b/src/test/resources/repoinit-path-5.txt
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+create path /repoinit-test/path-5
\ No newline at end of file
diff --git a/src/test/resources/repoinit-path-6.txt b/src/test/resources/repoinit-path-6.txt
new file mode 100644
index 0000000..5fd1ba9
--- /dev/null
+++ b/src/test/resources/repoinit-path-6.txt
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+create path /repoinit-test/path-6
\ No newline at end of file