Skip to content

Commit

Permalink
{WIP} fix jetcd-all which was broken under OSGi (etcd-io#382)
Browse files Browse the repository at this point in the history
TODO With the ClientServiceTest actually "doing something" now (before
it dit not really), it only works if you have an etcd locally running
("sudo systemctl start etcd") ... we would need to actually start a
server, like the tests in jetcd-core do, for the ClientServiceTest to
pass on CI.
  • Loading branch information
vorburger committed Sep 6, 2018
1 parent 89a03c7 commit cb79697
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
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
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 @@ -52,6 +55,7 @@
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
public class ClientServiceTest 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", "http://localhost:2379"),
editConfigurationFilePut("etc/io.etcd.jetcd.resolver.dnssrv.cfg", "foo", "bar"),
keepRuntimeFolder(),
cleanCaches(),
Expand All @@ -118,10 +122,25 @@ 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.
}

}

0 comments on commit cb79697

Please sign in to comment.