You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ra...@apache.org on 2015/11/20 14:41:31 UTC
ignite git commit: IGNITE-1270 OSGi: Refactor tests and add new test
for Ignite OSGi service.
Repository: ignite
Updated Branches:
refs/heads/ignite-1270 b6a80095d -> 29823cabe
IGNITE-1270 OSGi: Refactor tests and add new test for Ignite OSGi service.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/29823cab
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/29823cab
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/29823cab
Branch: refs/heads/ignite-1270
Commit: 29823cabe851e22581adfa3babaf58be19ce8d8f
Parents: b6a8009
Author: Raul Kripalani <ra...@apache.org>
Authored: Fri Nov 20 13:41:14 2015 +0000
Committer: Raul Kripalani <ra...@apache.org>
Committed: Fri Nov 20 13:41:14 2015 +0000
----------------------------------------------------------------------
.../osgi-karaf/src/main/resources/features.xml | 1 +
modules/osgi/pom.xml | 9 +-
.../ignite/osgi/AbstractIgniteKarafTest.java | 111 +++++++++++++++++++
.../IgniteKarafFeaturesInstallationTest.java | 83 ++------------
.../ignite/osgi/IgniteOsgiServiceTest.java | 91 +++++++++++++++
.../activators/BasicIgniteTestActivator.java | 46 ++++++++
6 files changed, 265 insertions(+), 76 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/29823cab/modules/osgi-karaf/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/modules/osgi-karaf/src/main/resources/features.xml b/modules/osgi-karaf/src/main/resources/features.xml
index d2eaa1d..2a9987d 100644
--- a/modules/osgi-karaf/src/main/resources/features.xml
+++ b/modules/osgi-karaf/src/main/resources/features.xml
@@ -51,6 +51,7 @@
<feature name="ignite-core" version="${project.version}" description="Apache Ignite :: Core">
<details><![CDATA[The Apache Ignite core module. This feature also installs the JCache 1.0 specification API.]]></details>
<bundle start="true" dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.javax-cache-api/${javax.cache.bundle.version}</bundle>
+ <bundle dependency="true">mvn:org.apache.ignite/ignite-osgi/${project.version}</bundle>
<bundle start="true">mvn:org.apache.ignite/ignite-core/${project.version}</bundle>
</feature>
http://git-wip-us.apache.org/repos/asf/ignite/blob/29823cab/modules/osgi/pom.xml
----------------------------------------------------------------------
diff --git a/modules/osgi/pom.xml b/modules/osgi/pom.xml
index c1418cc..336ba20 100644
--- a/modules/osgi/pom.xml
+++ b/modules/osgi/pom.xml
@@ -20,7 +20,8 @@
<!--
POM file.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -131,6 +132,7 @@
<plugin>
<groupId>org.apache.servicemix.tooling</groupId>
<artifactId>depends-maven-plugin</artifactId>
+ <version>1.3.1</version>
<executions>
<execution>
<id>generate-depends-file</id>
@@ -145,6 +147,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
+ <forkCount>1</forkCount>
<systemProperties>
<property>
<name>karafVersion</name>
@@ -154,10 +157,6 @@
<name>projectVersion</name>
<value>${project.version}</value>
</property>
- <property>
- <name>java.protocol.handler.pkgs</name>
- <value>org.ops4j.pax.url</value>
- </property>
</systemProperties>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/ignite/blob/29823cab/modules/osgi/src/test/java/org/apache/ignite/osgi/AbstractIgniteKarafTest.java
----------------------------------------------------------------------
diff --git a/modules/osgi/src/test/java/org/apache/ignite/osgi/AbstractIgniteKarafTest.java b/modules/osgi/src/test/java/org/apache/ignite/osgi/AbstractIgniteKarafTest.java
new file mode 100644
index 0000000..d2d2e43
--- /dev/null
+++ b/modules/osgi/src/test/java/org/apache/ignite/osgi/AbstractIgniteKarafTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.ignite.osgi;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import javax.inject.Inject;
+
+import org.apache.karaf.features.FeaturesService;
+
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.karaf.options.LogLevelOption;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerMethod;
+import org.osgi.framework.BundleContext;
+
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.maven;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFileExtend;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
+
+/**
+ * Abstract test class that sets up an Apache Karaf container with Ignite installed.
+ */
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerMethod.class)
+public abstract class AbstractIgniteKarafTest {
+
+ /** Features we do not expect to be installed. */
+ protected static final Set<String> IGNORED_FEATURES = new HashSet<>(
+ Arrays.asList("ignite-log4j", "ignite-scalar-2.10"));
+
+ /** Regex matching ignite features. */
+ protected static final String IGNITE_FEATURES_NAME_REGEX = "ignite.*";
+
+ /** Project version. */
+ protected static final String PROJECT_VERSION = System.getProperty("projectVersion");
+
+ /** Pax Exam will inject the Bundle Context here. */
+ @Inject
+ protected BundleContext bundleCtx;
+
+ /** Pax Exam will inject the Karaf Features Service. */
+ @Inject
+ protected FeaturesService featuresSvc;
+
+ /**
+ * Base configuration for a Karaf container running the specified Ignite features.
+ *
+ * @return The configuration.
+ */
+ public Option[] baseConfig() {
+ return options(
+
+ // Specify which version of Karaf to use.
+ karafDistributionConfiguration()
+ .frameworkUrl(maven().groupId("org.apache.karaf").artifactId("apache-karaf").type("tar.gz")
+ .versionAsInProject())
+ .karafVersion(System.getProperty("karafVersion"))
+ .useDeployFolder(false)
+ .unpackDirectory(new File("target/paxexam/unpack")),
+
+ // Add JUnit bundles.
+ junitBundles(),
+
+ // Add the additional JRE exports that Ignite requires.
+ editConfigurationFileExtend("etc/jre.properties", "jre-1.7", "sun.nio.ch"),
+ editConfigurationFileExtend("etc/jre.properties", "jre-1.8", "sun.nio.ch"),
+
+ // Make log level INFO.
+ logLevel(LogLevelOption.LogLevel.INFO),
+
+ // Add our features repository.
+ features(mavenBundle()
+ .groupId("org.apache.ignite").artifactId("ignite-osgi-karaf")
+ .version(System.getProperty("projectVersion")).type("xml/features"),
+ featuresToInstall().toArray(new String[0])),
+
+ // Propagate the projectVersion system property.
+ systemProperty("projectVersion").value(System.getProperty("projectVersion"))
+ );
+ }
+
+ protected abstract List<String> featuresToInstall();
+
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/29823cab/modules/osgi/src/test/java/org/apache/ignite/osgi/IgniteKarafFeaturesInstallationTest.java
----------------------------------------------------------------------
diff --git a/modules/osgi/src/test/java/org/apache/ignite/osgi/IgniteKarafFeaturesInstallationTest.java b/modules/osgi/src/test/java/org/apache/ignite/osgi/IgniteKarafFeaturesInstallationTest.java
index 4fcfd30..5365938 100644
--- a/modules/osgi/src/test/java/org/apache/ignite/osgi/IgniteKarafFeaturesInstallationTest.java
+++ b/modules/osgi/src/test/java/org/apache/ignite/osgi/IgniteKarafFeaturesInstallationTest.java
@@ -17,101 +17,34 @@
package org.apache.ignite.osgi;
-import java.io.File;
import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-import javax.inject.Inject;
+import java.util.List;
import org.apache.karaf.features.Feature;
-import org.apache.karaf.features.FeaturesService;
import org.junit.Test;
-import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.karaf.options.LogLevelOption;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerMethod;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.ops4j.pax.exam.CoreOptions.junitBundles;
-import static org.ops4j.pax.exam.CoreOptions.maven;
-import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
-import static org.ops4j.pax.exam.CoreOptions.options;
-import static org.ops4j.pax.exam.CoreOptions.systemProperty;
-import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFileExtend;
-import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
-import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
-import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
/**
* Pax Exam test class to check if all features could be resolved and installed.
*/
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerMethod.class)
-public class IgniteKarafFeaturesInstallationTest {
-
- /** Features we do not expect to be installed. */
- private static final Set<String> IGNORED_FEATURES = new HashSet<>(
- Arrays.asList("ignite-log4j", "ignite-scalar-2.10"));
-
- /** Regex matching ignite features. */
- private static final String IGNITE_FEATURES_NAME_REGEX = "ignite.*";
-
- /** Project version. */
- private static final String PROJECT_VERSION = System.getProperty("projectVersion");
-
- /** Pax Exam will inject the Bundle Context here. */
- @Inject
- private BundleContext bundleCtx;
-
- /** Pax Exam will inject the Karaf Features Service. */
- @Inject
- private FeaturesService featuresSvc;
+public class IgniteKarafFeaturesInstallationTest extends AbstractIgniteKarafTest {
/**
- * Returns configuration for Karaf container.
+ * Container configuration.
*
* @return The configuration.
*/
@Configuration
public Option[] config() {
- return options(
-
- // Specify which version of Karaf to use.
- karafDistributionConfiguration()
- .frameworkUrl(maven().groupId("org.apache.karaf").artifactId("apache-karaf").type("tar.gz")
- .versionAsInProject())
- .karafVersion(System.getProperty("karafVersion"))
- .useDeployFolder(false)
- .unpackDirectory(new File("target/paxexam/unpack")),
-
- // Add JUnit bundles.
- junitBundles(),
-
- // Add the additional JRE exports that Ignite requires.
- editConfigurationFileExtend("etc/jre.properties", "jre-1.7", "sun.nio.ch"),
- editConfigurationFileExtend("etc/jre.properties", "jre-1.8", "sun.nio.ch"),
-
- // Make log level INFO.
- logLevel(LogLevelOption.LogLevel.INFO),
-
- // Add our features repository.
- features(mavenBundle()
- .groupId("org.apache.ignite").artifactId("ignite-osgi-karaf")
- .version(System.getProperty("projectVersion")).type("xml/features"),
- "ignite-all"),
-
- // Propagate the projectVersion system property.
- systemProperty("projectVersion").value(System.getProperty("projectVersion"))
- );
+ return baseConfig();
}
/**
@@ -147,4 +80,12 @@ public class IgniteKarafFeaturesInstallationTest {
assertEquals(PROJECT_VERSION.replaceAll("-", "."), f.getVersion());
}
}
+
+ /**
+ * @return
+ */
+ @Override
+ protected List<String> featuresToInstall() {
+ return Arrays.asList("ignite-all");
+ }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/29823cab/modules/osgi/src/test/java/org/apache/ignite/osgi/IgniteOsgiServiceTest.java
----------------------------------------------------------------------
diff --git a/modules/osgi/src/test/java/org/apache/ignite/osgi/IgniteOsgiServiceTest.java b/modules/osgi/src/test/java/org/apache/ignite/osgi/IgniteOsgiServiceTest.java
new file mode 100644
index 0000000..1d348ab
--- /dev/null
+++ b/modules/osgi/src/test/java/org/apache/ignite/osgi/IgniteOsgiServiceTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.ignite.osgi;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import javax.inject.Inject;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.osgi.activators.BasicIgniteTestActivator;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.CoreOptions;
+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.PerMethod;
+import org.ops4j.pax.exam.util.Filter;
+import org.osgi.framework.Constants;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.ops4j.pax.exam.CoreOptions.streamBundle;
+import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle;
+import static org.ops4j.pax.tinybundles.core.TinyBundles.withBnd;
+
+/**
+ * Pax Exam test class to check whether the Ignite service is exposed properly.
+ */
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerMethod.class)
+public class IgniteOsgiServiceTest extends AbstractIgniteKarafTest {
+
+ /** Injects the Ignite OSGi service. */
+ @Inject @Filter("(ignite.name=testGrid)")
+ private Ignite ignite;
+
+ /**
+ * @return
+ */
+ @Configuration
+ public Option[] bundleDelegatingConfig() {
+ List<Option> options = new ArrayList<>(Arrays.asList(baseConfig()));
+
+ // Add bundles we require.
+ options.add(
+ streamBundle(bundle()
+ .add(BasicIgniteTestActivator.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, BasicIgniteTestActivator.class.getSimpleName())
+ .set(Constants.BUNDLE_ACTIVATOR, BasicIgniteTestActivator.class.getName())
+ .set(Constants.DYNAMICIMPORT_PACKAGE, "*")
+ .build(withBnd())));
+
+ return CoreOptions.options(options.toArray(new Option[0]));
+ }
+
+ /**
+ * @throws Exception
+ */
+ @Test
+ public void testServiceExposed() throws Exception {
+ assertNotNull(ignite);
+ assertEquals("testGrid", ignite.name());
+ }
+
+ /**
+ * @return
+ */
+ @Override protected List<String> featuresToInstall() {
+ return Arrays.asList("ignite-core");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/29823cab/modules/osgi/src/test/java/org/apache/ignite/osgi/activators/BasicIgniteTestActivator.java
----------------------------------------------------------------------
diff --git a/modules/osgi/src/test/java/org/apache/ignite/osgi/activators/BasicIgniteTestActivator.java b/modules/osgi/src/test/java/org/apache/ignite/osgi/activators/BasicIgniteTestActivator.java
new file mode 100644
index 0000000..328f875
--- /dev/null
+++ b/modules/osgi/src/test/java/org/apache/ignite/osgi/activators/BasicIgniteTestActivator.java
@@ -0,0 +1,46 @@
+/*
+ * 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.ignite.osgi.activators;
+
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.osgi.IgniteOsgiContextActivator;
+import org.apache.ignite.osgi.classloaders.OsgiClassLoadingStrategyType;
+
+/**
+ * Basic Ignite Activator for testing.
+ */
+public class BasicIgniteTestActivator extends IgniteOsgiContextActivator {
+
+ /**
+ * @return
+ */
+ @Override public IgniteConfiguration igniteConfiguration() {
+ IgniteConfiguration config = new IgniteConfiguration();
+
+ config.setGridName("testGrid");
+
+ return config;
+ }
+
+ /**
+ * @return
+ */
+ @Override public OsgiClassLoadingStrategyType classLoadingStrategy() {
+ return OsgiClassLoadingStrategyType.BUNDLE_DELEGATING;
+ }
+}