Skip to content

Commit e82071e

Browse files
committed
AFFINITY-16 Add OSGi unit tests
1 parent 6c343a4 commit e82071e

File tree

6 files changed

+438
-13
lines changed

6 files changed

+438
-13
lines changed

affinity-test/pom.xml

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2013 Peter Lawrey
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xmlns="http://maven.apache.org/POM/4.0.0"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
22+
<parent>
23+
<groupId>net.openhft</groupId>
24+
<artifactId>java-parent-pom</artifactId>
25+
<version>1.1.1</version>
26+
<relativePath/>
27+
</parent>
28+
29+
<modelVersion>4.0.0</modelVersion>
30+
31+
<artifactId>lang-test</artifactId>
32+
<version>2.1.2-SNAPSHOT</version>
33+
<packaging>bundle</packaging>
34+
35+
<name>OpenHFT/Java-Thread-Affinity/affinity-test</name>
36+
<description>Java Thread Affinity library</description>
37+
38+
<dependencyManagement>
39+
<dependencies>
40+
<dependency>
41+
<groupId>net.openhft</groupId>
42+
<artifactId>third-party-bom</artifactId>
43+
<type>pom</type>
44+
<version>3.4.6</version>
45+
<scope>import</scope>
46+
</dependency>
47+
<dependency>
48+
<groupId>net.openhft</groupId>
49+
<artifactId>affinity</artifactId>
50+
<version>${project.version}</version>
51+
</dependency>
52+
</dependencies>
53+
</dependencyManagement>
54+
55+
<dependencies>
56+
<dependency>
57+
<groupId>com.sun.java</groupId>
58+
<artifactId>tools</artifactId>
59+
</dependency>
60+
<dependency>
61+
<groupId>net.openhft</groupId>
62+
<artifactId>affinity</artifactId>
63+
</dependency>
64+
<dependency>
65+
<groupId>javax.inject</groupId>
66+
<artifactId>javax.inject</artifactId>
67+
<scope>test</scope>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.osgi</groupId>
71+
<artifactId>org.osgi.core</artifactId>
72+
<scope>test</scope>
73+
</dependency>
74+
<dependency>
75+
<groupId>org.osgi</groupId>
76+
<artifactId>org.osgi.compendium</artifactId>
77+
<scope>test</scope>
78+
</dependency>
79+
<dependency>
80+
<groupId>org.ops4j.pax.exam</groupId>
81+
<artifactId>pax-exam-container-native</artifactId>
82+
<scope>test</scope>
83+
</dependency>
84+
85+
<dependency>
86+
<groupId>org.ops4j.pax.exam</groupId>
87+
<artifactId>pax-exam-junit4</artifactId>
88+
<scope>test</scope>
89+
</dependency>
90+
<dependency>
91+
<groupId>org.ops4j.pax.exam</groupId>
92+
<artifactId>pax-exam-link-mvn</artifactId>
93+
<scope>test</scope>
94+
</dependency>
95+
<dependency>
96+
<groupId>org.ops4j.pax.url</groupId>
97+
<artifactId>pax-url-aether</artifactId>
98+
<scope>test</scope>
99+
</dependency>
100+
<dependency>
101+
<groupId>org.ops4j.pax.url</groupId>
102+
<artifactId>pax-url-reference</artifactId>
103+
<scope>test</scope>
104+
</dependency>
105+
<dependency>
106+
<groupId>org.apache.felix</groupId>
107+
<artifactId>org.apache.felix.framework</artifactId>
108+
<version>4.4.1</version>
109+
<scope>test</scope>
110+
</dependency>
111+
<dependency>
112+
<groupId>org.slf4j</groupId>
113+
<artifactId>slf4j-api</artifactId>
114+
<scope>test</scope>
115+
</dependency>
116+
<dependency>
117+
<groupId>org.slf4j</groupId>
118+
<artifactId>slf4j-simple</artifactId>
119+
<scope>test</scope>
120+
</dependency>
121+
</dependencies>
122+
123+
<build>
124+
<plugins>
125+
<plugin>
126+
<groupId>org.apache.maven.plugins</groupId>
127+
<artifactId>maven-compiler-plugin</artifactId>
128+
<configuration>
129+
<source>${openhft.java.version}</source>
130+
<target>${openhft.java.version}</target>
131+
<encoding>UTF-8</encoding>
132+
<verbose>true</verbose>
133+
<fork>true</fork>
134+
<executable>${openhft.java.home}/bin/javac</executable>
135+
<compilerVersion>${openhft.java.version}</compilerVersion>
136+
</configuration>
137+
</plugin>
138+
<plugin>
139+
<groupId>org.apache.maven.plugins</groupId>
140+
<artifactId>maven-surefire-plugin</artifactId>
141+
<configuration>
142+
<jvm>${openhft.java.home}/bin/java</jvm>
143+
<systemPropertyVariables>
144+
<main.basedir>${project.basedir}</main.basedir>
145+
</systemPropertyVariables>
146+
</configuration>
147+
</plugin>
148+
<!--
149+
generate maven dependencies versions file that can be used later
150+
to install the right bundle in test phase.
151+
152+
The file is:
153+
154+
target/classes/META-INF/maven/dependencies.properties
155+
-->
156+
<plugin>
157+
<groupId>org.apache.servicemix.tooling</groupId>
158+
<artifactId>depends-maven-plugin</artifactId>
159+
<executions>
160+
<execution>
161+
<id>generate-depends-file</id>
162+
<goals>
163+
<goal>generate-depends-file</goal>
164+
</goals>
165+
</execution>
166+
</executions>
167+
</plugin>
168+
169+
<plugin>
170+
<groupId>org.apache.felix</groupId>
171+
<artifactId>maven-bundle-plugin</artifactId>
172+
<extensions>true</extensions>
173+
<configuration>
174+
<instructions>
175+
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}
176+
</Bundle-SymbolicName>
177+
<Bundle-Name>${project.artifactId}</Bundle-Name>
178+
<Export-Package>
179+
net.openhft.affinity
180+
</Export-Package>
181+
<Import-Package>
182+
*
183+
</Import-Package>
184+
</instructions>
185+
</configuration>
186+
<executions>
187+
<!--
188+
This execution makes sure that the manifest is available
189+
when the tests are executed
190+
-->
191+
<execution>
192+
<goals>
193+
<goal>manifest</goal>
194+
</goals>
195+
</execution>
196+
</executions>
197+
</plugin>
198+
</plugins>
199+
</build>
200+
201+
<scm>
202+
<url>scm:git:https://github.com/OpenHFT/Java-Lang.git</url>
203+
</scm>
204+
205+
<!-- ******************************************************************* -->
206+
<!-- PROFILES -->
207+
<!-- ******************************************************************* -->
208+
209+
<profiles>
210+
211+
<profile>
212+
<id>jdk_default</id>
213+
<activation>
214+
<activeByDefault>true</activeByDefault>
215+
</activation>
216+
<properties>
217+
<openhft.java.home>${env.JAVA_HOME}</openhft.java.home>
218+
<openhft.java.version>1.6</openhft.java.version>
219+
</properties>
220+
</profile>
221+
222+
<profile>
223+
<id>jdk_6</id>
224+
<activation>
225+
<activeByDefault>false</activeByDefault>
226+
</activation>
227+
<properties>
228+
<openhft.java.home>${env.JAVA_HOME_6}</openhft.java.home>
229+
<openhft.java.version>1.6</openhft.java.version>
230+
</properties>
231+
</profile>
232+
233+
<profile>
234+
<id>jdk_7</id>
235+
<activation>
236+
<activeByDefault>false</activeByDefault>
237+
</activation>
238+
<properties>
239+
<openhft.java.home>${env.JAVA_HOME_7}</openhft.java.home>
240+
<openhft.java.version>1.7</openhft.java.version>
241+
</properties>
242+
</profile>
243+
244+
<profile>
245+
<id>jdk_8</id>
246+
<activation>
247+
<activeByDefault>false</activeByDefault>
248+
</activation>
249+
<properties>
250+
<openhft.java.home>${env.JAVA_HOME_8}</openhft.java.home>
251+
<openhft.java.version>1.7</openhft.java.version>
252+
</properties>
253+
</profile>
254+
255+
</profiles>
256+
257+
</project>
258+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2014 Higher Frequency Trading
3+
* <p/>
4+
* http://www.higherfrequencytrading.com
5+
* <p/>
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
* <p/>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p/>
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package net.openhft.affinity.osgi;
19+
20+
/**
21+
* A placeholder to have some plugin works
22+
*/
23+
public class OSGiPlaceholder {
24+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright 2014 Higher Frequency Trading
3+
* <p/>
4+
* http://www.higherfrequencytrading.com
5+
* <p/>
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
* <p/>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p/>
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package net.openhft.affinity.osgi;
19+
20+
import org.junit.Ignore;
21+
import org.junit.Test;
22+
import org.junit.runner.RunWith;
23+
import org.ops4j.pax.exam.Configuration;
24+
import org.ops4j.pax.exam.Option;
25+
import org.ops4j.pax.exam.junit.PaxExam;
26+
import org.osgi.framework.Bundle;
27+
import org.osgi.framework.BundleContext;
28+
29+
import java.util.Dictionary;
30+
import javax.inject.Inject;
31+
32+
import static org.junit.Assert.*;
33+
import static org.ops4j.pax.exam.CoreOptions.*;
34+
35+
36+
//@Ignore
37+
@RunWith(PaxExam.class)
38+
public class OSGiBundleTest extends OSGiTestBase {
39+
@Inject
40+
BundleContext context;
41+
42+
@Configuration
43+
public Option[] config() {
44+
return options(
45+
systemProperty("org.osgi.framework.storage.clean").value("true"),
46+
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN"),
47+
mavenBundleAsInProject("org.slf4j","slf4j-api"),
48+
mavenBundleAsInProject("org.slf4j","slf4j-simple").noStart(),
49+
mavenBundleAsInProject("net.openhft","affinity"),
50+
workspaceBundle("affinity-test"),
51+
junitBundles(),
52+
systemPackage("sun.misc"),
53+
systemPackage("sun.nio.ch"),
54+
systemPackage("com.sun.jna"),
55+
systemPackage("com.sun.jna.ptr"),
56+
cleanCaches()
57+
);
58+
}
59+
60+
@Test
61+
public void checkInject() {
62+
assertNotNull(context);
63+
}
64+
65+
@Test
66+
public void checkBundleState() {
67+
final Bundle bundle = findBundle(context, "net.openhft.affinity");
68+
assertNotNull(bundle);
69+
assertEquals(bundle.getState(),Bundle.ACTIVE);
70+
}
71+
72+
@Test
73+
public void checkBundleExports() {
74+
final Bundle bundle = findBundle(context, "net.openhft.affinity");
75+
assertNotNull(bundle);
76+
77+
final String exports = bundle.getHeaders().get("Export-Package");
78+
final String[] packages = exports.split(",");
79+
80+
assertEquals(2, packages.length);
81+
assertTrue(packages[0].startsWith("net.openhft.affinity;")
82+
|| packages[0].startsWith("net.openhft.affinity.impl;"));
83+
assertTrue(packages[1].startsWith("net.openhft.affinity;")
84+
|| packages[1].startsWith("net.openhft.affinity.impl;"));
85+
}
86+
}

0 commit comments

Comments
 (0)