Skip to content

Commit

Permalink
[resolves #990] Compatibility for LogService & ConfigurationAdmin
Browse files Browse the repository at this point in the history
[resolves #989] NCDFE starting gravia subsystem
  • Loading branch information
Thomas Diesler committed Nov 20, 2015
1 parent e5cef1a commit 7d588df
Show file tree
Hide file tree
Showing 7 changed files with 372 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* #%L
* Gravia :: Integration Tests :: Common
* %%
* Copyright (C) 2010 - 2014 JBoss by Red Hat
* %%
* 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.
* #L%
*/
package org.wildfly.camel.test.compatibility;

import java.io.InputStream;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.concurrent.TimeUnit;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.osgi.StartLevelAware;
import org.jboss.gravia.resource.Resource;
import org.jboss.gravia.runtime.Module;
import org.jboss.gravia.runtime.ModuleContext;
import org.jboss.gravia.runtime.Runtime;
import org.jboss.gravia.runtime.RuntimeLocator;
import org.jboss.gravia.runtime.ServiceReference;
import org.jboss.osgi.metadata.OSGiManifestBuilder;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.Asset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.component.ComponentContext;
import org.wildfly.camel.test.compatibility.subA.ServiceD;
import org.wildfly.camel.test.compatibility.subA.ServiceD1;

/**
* Test basic SCR Component test with ConfigurationAdmin
*
* @author thomas.diesler@jboss.com
* @since 04-Oct-2013
*/
@RunWith(Arquillian.class)
public class ConfigurationAdminTest {

@Deployment
@StartLevelAware(autostart = true)
public static JavaArchive deployment() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "configadmin-test.jar");
archive.addClasses(ServiceD.class, ServiceD1.class);
archive.addAsResource("OSGI-INF/org.wildfly.camel.test.compatibility.subA.ServiceD.xml");
archive.addAsResource("OSGI-INF/org.wildfly.camel.test.compatibility.subA.ServiceD1.xml");
archive.setManifest(new Asset() {
@Override
public InputStream openStream() {
OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
builder.addBundleManifestVersion(2);
builder.addBundleSymbolicName(archive.getName());
builder.addBundleVersion("1.0.0");
builder.addImportPackages(RuntimeLocator.class, ComponentContext.class, ConfigurationAdmin.class, Resource.class);
builder.addManifestHeader("Service-Component", "OSGI-INF/org.wildfly.camel.test.compatibility.subA.ServiceD.xml,OSGI-INF/org.wildfly.camel.test.compatibility.subA.ServiceD1.xml");
return builder.openStream();
}
});
return archive;
}

@Test
public void testBasicModule() throws Exception {

Runtime runtime = RuntimeLocator.getRequiredRuntime();
Module module = runtime.getModule(getClass().getClassLoader());

ModuleContext ctxA = module.getModuleContext();
ServiceReference<ServiceD> srefD = ctxA.getServiceReference(ServiceD.class);
Assert.assertNotNull("ServiceReference not null", srefD);

ServiceD srvD = ctxA.getService(srefD);
Assert.assertEquals("ServiceD#1:ServiceD1#1:null:Hello", srvD.doStuff("Hello"));

ConfigurationAdmin configAdmin = getConfigurationAdmin(module);
Configuration config = configAdmin.getConfiguration(ServiceD1.class.getName());
Assert.assertNotNull("Config not null", config);
Assert.assertNull("Config is empty, but was: " + config.getProperties(), config.getProperties());

Dictionary<String, String> configProps = new Hashtable<String, String>();
configProps.put("foo", "bar");
config.update(configProps);

ServiceD1 srvD1 = srvD.getServiceD1();
Assert.assertTrue(srvD1.awaitModified(4000, TimeUnit.MILLISECONDS));

Assert.assertEquals("ServiceD#1:ServiceD1#1:bar:Hello", srvD.doStuff("Hello"));
}

protected ConfigurationAdmin getConfigurationAdmin(Module module) {
ModuleContext context = module.getModuleContext();
return context.getService(context.getServiceReference(ConfigurationAdmin.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* #%L
* Gravia :: Integration Tests :: Common
* %%
* Copyright (C) 2010 - 2014 JBoss by Red Hat
* %%
* 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.
* #L%
*/
package org.wildfly.camel.test.compatibility;

import java.io.InputStream;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.osgi.StartLevelAware;
import org.jboss.gravia.resource.Resource;
import org.jboss.gravia.runtime.Module;
import org.jboss.gravia.runtime.ModuleContext;
import org.jboss.gravia.runtime.Runtime;
import org.jboss.gravia.runtime.RuntimeLocator;
import org.jboss.gravia.runtime.ServiceReference;
import org.jboss.osgi.metadata.OSGiManifestBuilder;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.Asset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.osgi.service.log.LogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Test LogService access
*
* @author thomas.diesler@jboss.com
* @since 04-Oct-2013
*/
@RunWith(Arquillian.class)
public class LogServiceTest {

@Deployment
@StartLevelAware(autostart = true)
public static JavaArchive deployment() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "logging-test.jar");
archive.addClasses(LogServiceTest.class);
archive.setManifest(new Asset() {
@Override
public InputStream openStream() {
OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
builder.addBundleManifestVersion(2);
builder.addBundleSymbolicName(archive.getName());
builder.addBundleVersion("1.0.0");
builder.addImportPackages(RuntimeLocator.class, LogService.class, LoggerFactory.class, Resource.class);
return builder.openStream();
}
});
return archive;
}

@Test
public void testLogService() throws Exception {
Runtime runtime = RuntimeLocator.getRequiredRuntime();
Module module = runtime.getModule(getClass().getClassLoader());

LogService log = getLogService(module.getModuleContext());
String msg = "LogServiceTest LogService ";
log.log(LogService.LOG_ERROR, msg + " ERROR");
log.log(LogService.LOG_WARNING, msg + " WARNING");
log.log(LogService.LOG_INFO, msg + " INFO");
log.log(LogService.LOG_DEBUG, msg + " DEBUG");
}

@Test
public void testSLF4J() throws Exception {
Logger logsrv = LoggerFactory.getLogger(LogServiceTest.class);
String msg = "LogServiceTest SLF4J ";
logsrv.error(msg + " ERROR");
logsrv.warn(msg + " WARN");
logsrv.info(msg + " INFO");
logsrv.debug(msg + " DEBUG");
}

private LogService getLogService(ModuleContext context) {
ServiceReference<LogService> sref = context.getServiceReference(LogService.class);
Assert.assertNotNull("LogService not null", sref);
return context.getService(sref);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* #%L
* Gravia :: Integration Tests :: Common
* %%
* Copyright (C) 2010 - 2014 JBoss by Red Hat
* %%
* 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.
* #L%
*/
package org.wildfly.camel.test.compatibility.subA;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;

@Component(service = { ServiceD.class }, immediate = true)
public class ServiceD {

static AtomicInteger INSTANCE_COUNT = new AtomicInteger();
final String name = getClass().getSimpleName() + "#" + INSTANCE_COUNT.incrementAndGet();

final AtomicReference<ServiceD1> ref = new AtomicReference<ServiceD1>();
final CountDownLatch activateLatch = new CountDownLatch(1);
final CountDownLatch deactivateLatch = new CountDownLatch(1);

@Activate
void activate(ComponentContext context) {
activateLatch.countDown();
}

@Deactivate
void deactivate() {
deactivateLatch.countDown();
}

public boolean awaitActivate(long timeout, TimeUnit unit) throws InterruptedException {
return activateLatch.await(timeout, unit);
}

public boolean awaitDeactivate(long timeout, TimeUnit unit) throws InterruptedException {
return deactivateLatch.await(timeout, unit);
}

@Reference
void bindServiceD1(ServiceD1 service) {
ref.set(service);
}

void unbindServiceD1(ServiceD1 service) {
ref.compareAndSet(service, null);
}

public ServiceD1 getServiceD1() {
return ref.get();
}

public String doStuff(String msg) {
ServiceD1 srv = ref.get();
return name + ":" + srv.doStuff(msg);
}

@Override
public String toString() {
return name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* #%L
* Gravia :: Integration Tests :: Common
* %%
* Copyright (C) 2010 - 2014 JBoss by Red Hat
* %%
* 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.
* #L%
*/
package org.wildfly.camel.test.compatibility.subA;

import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Modified;

@Component(service = { ServiceD1.class })
public class ServiceD1 {

static AtomicInteger INSTANCE_COUNT = new AtomicInteger();
final String name = getClass().getSimpleName() + "#" + INSTANCE_COUNT.incrementAndGet();

final CountDownLatch modifiedLatch = new CountDownLatch(1);
private volatile Map<String, ?> config;

@Activate
void activate(ComponentContext context, Map<String, ?> config) {
this.config = config;
}

@Modified
void modified(Map<String, ?> config) {
this.config = config;
modifiedLatch.countDown();
}

@Deactivate
void deactivate() {
}

public boolean awaitModified(long timeout, TimeUnit unit) throws InterruptedException {
return modifiedLatch.await(timeout, unit);
}

public String doStuff(String msg) {
Object fooval = config.get("foo");
return name + ":" + fooval + ":" + msg;
}

@Override
public String toString() {
return name;
}
}
6 changes: 3 additions & 3 deletions modules/etc/baseline/module-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@
/org/fusesource/hawtdispatch/main/hawtdispatch-1.21.jar
/org/fusesource/hawtdispatch/main/hawtdispatch-transport-1.21.jar
/org/fusesource/mqtt/main/mqtt-client-1.12.jar
/org/jboss/gravia/main/gravia-resource-1.2.1.jar
/org/jboss/gravia/main/gravia-runtime-api-1.2.1.jar
/org/jboss/gravia/main/gravia-runtime-embedded-1.2.1.jar
/org/jboss/gravia/main/gravia-resource-1.3.0.jar
/org/jboss/gravia/main/gravia-runtime-api-1.3.0.jar
/org/jboss/gravia/main/gravia-runtime-embedded-1.3.0.jar
/org/mvel/mvel2/main/mvel2-2.2.6.Final.jar
/org/osgi/core/main/org.osgi.core-4.3.1.jar
/org/osgi/enterprise/main/org.osgi.enterprise-5.0.0.jar
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.jboss.gravia">
<resources>
<resource-root path="gravia-resource-1.2.1.jar" />
<resource-root path="gravia-runtime-api-1.2.1.jar" />
<resource-root path="gravia-runtime-embedded-1.2.1.jar" />
<resource-root path="gravia-resource-1.3.0.jar" />
<resource-root path="gravia-runtime-api-1.3.0.jar" />
<resource-root path="gravia-runtime-embedded-1.3.0.jar" />
</resources>
<dependencies>
<module name="javax.api" />
Expand Down
Loading

0 comments on commit 7d588df

Please sign in to comment.