Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix jetcd-all which was broken under OSGi (#382) #385

Merged
merged 1 commit into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jetcd-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
</Export-Package>
<Import-Package>
org.slf4j;version="[1.7,2)",
javax.security.cert,
javax.net.ssl;resolution:=optional
</Import-Package>
</instructions>
Expand Down
12 changes: 0 additions & 12 deletions jetcd-launcher/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
</parent>

<artifactId>jetcd-launcher</artifactId>
<packaging>bundle</packaging>

<properties>
<checkstyle.config.location>${basedir}/../etc/checkstyle.xml</checkstyle.config.location>
Expand Down Expand Up @@ -64,17 +63,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>etcd :: ${project.artifactId}</Bundle-Name>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
5 changes: 5 additions & 0 deletions jetcd-osgi/jetcd-karaf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jetcd-launcher</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;

import io.etcd.jetcd.Client;
import io.etcd.jetcd.data.ByteSequence;
import io.etcd.jetcd.resolver.URIResolver;
import java.io.File;
import java.nio.charset.Charset;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -51,7 +54,8 @@

@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class ClientServiceTest extends TestSupport {
public class ClientServiceChecks extends TestSupport {

@Inject
protected BundleContext bundleContext;

Expand Down Expand Up @@ -109,7 +113,7 @@ public Option[] config() {
.artifactId("assertj-core")
.versionAsInProject()
.start(),
editConfigurationFilePut("etc/io.etcd.jetcd.cfg", "endpoints", "localhost:2379"),
editConfigurationFilePut("etc/io.etcd.jetcd.cfg", "endpoints", PaxExamWrapperTest.getClientEndpoints()),
editConfigurationFilePut("etc/io.etcd.jetcd.resolver.dnssrv.cfg", "foo", "bar"),
keepRuntimeFolder(),
cleanCaches(),
Expand All @@ -118,10 +122,23 @@ public Option[] config() {
}

@Test
public void testServiceAvailability() {
public void testServiceAvailability() throws Exception {
assertThat(bundleContext).isNotNull();
assertThat(client).isNotNull();
assertThat(uriResolver).isNotNull();
}

try {
client.getKVClient().get(ByteSequence.from("non-existing", Charset.forName("UTF-8"))).get(13, TimeUnit.SECONDS);
} catch (Throwable t) {
// Pax Exam's WrappedTestContainerException unfortunately only includes the message, not the cause,
// so the real reason for failures needs to be searched for in target/exam/*/data/log/karaf.log ...
// Just for convenience in local debugging, and to eastily understand failures on CI, we dump
// the failure's stack trace to STDOUT; like that it's easy to see in maven-surefire-plugin,
// or when running in the IDE, like for any other non-OSGi test failure.
t.printStackTrace();
throw t;
}
// NB: Any NoClassDefFoundError/ClassNotFoundException in the log "because the bundle wiring for io.etcd.jetcd-all is no longer valid"
// can be safely ignored - that's just jetcd/gRPC/Netty not being cleany shut down and still running.. doesn't really matter much.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Copyright 2017 The jetcd authors
*
* Licensed 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 io.etcd.jetcd.osgi;

import io.etcd.jetcd.launcher.junit.EtcdClusterResource;
import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.JUnitCore;
import org.junit.runner.notification.Failure;

/**
* Pax Exam test wrapper which starts (and stops) an etcd test server via
* launcher. We need to do this because jetcd-launcher uses Testcontainers,
* which cannot run inside OSGi (due to the use of TCL loadClass(String) in
* DockerClientProviderStrategy). And even if we were to use the launcher only
* in the config() method (which "is executed before the OSGi container is
* launched, so it does run in plain Java"), the Pax Exam probe still needs to
* load the entire test class and all of its references (launcher with
* Testcontainers) into OSGi, which is a PITA. There is also no easy way to stop
* the testcontainer after. It is therefore simplest to just launch the etcd
* server before getting Pax Exam's world, like this does.
*
* @author Michael Vorburger.ch
*/
public class PaxExamWrapperTest {

private static final String ETCD_ENDPOINT_SYSTEM_PROPERTY_NAME = "etcd.endpoint";

@Rule
public final EtcdClusterResource etcd = new EtcdClusterResource("karaf");

@Test
public void testClientServiceChecks() throws Throwable {
String endpoint = etcd.cluster().getClientEndpoints().get(0);
System.setProperty(ETCD_ENDPOINT_SYSTEM_PROPERTY_NAME, endpoint);

Optional<Failure> failure = JUnitCore.runClasses(ClientServiceChecks.class).getFailures().stream().findFirst();
if (failure.isPresent()) {
throw failure.get().getException();
}
}

static String getClientEndpoints() {
return System.getProperty(ETCD_ENDPOINT_SYSTEM_PROPERTY_NAME);
}
}
2 changes: 0 additions & 2 deletions jetcd-osgi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,5 @@
<module>jetcd-osgi</module>
<module>jetcd-karaf</module>
</modules>


</project>