-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[resolves #990] Compatibility for LogService & ConfigurationAdmin
[resolves #989] NCDFE starting gravia subsystem
- Loading branch information
Thomas Diesler
committed
Nov 20, 2015
1 parent
e5cef1a
commit 7d588df
Showing
7 changed files
with
372 additions
and
7 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
...sts/common/src/main/java/org/wildfly/camel/test/compatibility/ConfigurationAdminTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
...lity/itests/common/src/main/java/org/wildfly/camel/test/compatibility/LogServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
...ility/itests/common/src/main/java/org/wildfly/camel/test/compatibility/subA/ServiceD.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...lity/itests/common/src/main/java/org/wildfly/camel/test/compatibility/subA/ServiceD1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
modules/etc/generated/wildfly/modules/system/layers/fuse/org/jboss/gravia/main/module.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.