You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by at...@apache.org on 2010/01/13 23:00:58 UTC
svn commit: r898958 - in /incubator/aries/trunk/jmx:
jmx-core/src/main/java/org/apache/aries/jmx/framework/
jmx-itests/src/test/java/org/apache/aries/jmx/framework/
Author: atk
Date: Wed Jan 13 22:00:58 2010
New Revision: 898958
URL: http://svn.apache.org/viewvc?rev=898958&view=rev
Log:
ARIES-35 Adding integration tests and updating handler close
Added:
incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java (with props)
Modified:
incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceState.java
incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceStateMBeanHandler.java
Modified: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceState.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceState.java?rev=898958&r1=898957&r2=898958&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceState.java (original)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceState.java Wed Jan 13 22:00:58 2010
@@ -23,6 +23,7 @@
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@ -150,8 +151,7 @@
*/
public void postDeregister() {
if (registrations.decrementAndGet() < 1) {
- bundleContext.removeServiceListener(serviceListener);
- eventDispatcher.shutdown();
+ shutDownDispatcher();
}
}
@@ -187,6 +187,9 @@
sendNotification(notification);
}
});
+ } catch (RejectedExecutionException re) {
+ logger.log(LogService.LOG_WARNING, "Task rejected for JMX Notification dispatch of event ["
+ + serviceevent + "] - Dispatcher may have been shutdown");
} catch (Exception e) {
logger.log(LogService.LOG_WARNING,
"Exception occured on JMX Notification dispatch for event [" + serviceevent + "]",
@@ -202,9 +205,21 @@
}
/*
+ * Shuts down the notification dispatcher
+ */
+ protected void shutDownDispatcher() {
+ if (serviceListener != null) {
+ bundleContext.removeServiceListener(serviceListener);
+ }
+ if (eventDispatcher != null) {
+ eventDispatcher.shutdown();
+ }
+ }
+
+ /*
* Returns the ExecutorService used to dispatch Notifications
*/
- public ExecutorService getEventDispatcher() {
+ protected ExecutorService getEventDispatcher() {
return eventDispatcher;
}
Modified: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceStateMBeanHandler.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceStateMBeanHandler.java?rev=898958&r1=898957&r2=898958&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceStateMBeanHandler.java (original)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/ServiceStateMBeanHandler.java Wed Jan 13 22:00:58 2010
@@ -40,6 +40,7 @@
private String name;
private StandardMBean mbean;
+ private ServiceState serviceStateMBean;
private BundleContext bundleContext;
private Logger logger;
@@ -54,7 +55,7 @@
* @see org.apache.aries.jmx.MBeanHandler#open()
*/
public void open() {
- ServiceStateMBean serviceStateMBean = new ServiceState(bundleContext, logger);
+ serviceStateMBean = new ServiceState(bundleContext, logger);
try {
mbean = new RegistrableStandardEmitterMBean(serviceStateMBean, ServiceStateMBean.class);
} catch (NotCompliantMBeanException e) {
@@ -80,7 +81,10 @@
* @see org.apache.aries.jmx.MBeanHandler#close()
*/
public void close() {
- // No action
+ // ensure dispatcher is shutdown even if postDeRegister is not honored
+ if (serviceStateMBean != null) {
+ serviceStateMBean.shutDownDispatcher();
+ }
}
Added: incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java?rev=898958&view=auto
==============================================================================
--- incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java (added)
+++ incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java Wed Jan 13 22:00:58 2010
@@ -0,0 +1,232 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.aries.jmx.framework;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.modifyBundle;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.newBundle;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.withBnd;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import javax.management.openmbean.TabularData;
+
+import org.apache.aries.jmx.AbstractIntegrationTest;
+import org.apache.aries.jmx.codec.PropertyData;
+import org.apache.aries.jmx.test.bundlea.api.InterfaceA;
+import org.apache.aries.jmx.test.bundleb.api.InterfaceB;
+import org.junit.Before;
+import org.junit.Test;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Customizer;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.jmx.JmxConstants;
+import org.osgi.jmx.framework.ServiceStateMBean;
+import org.osgi.service.cm.ManagedService;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServiceStateMBeanTest extends AbstractIntegrationTest {
+
+ @Configuration
+ public static Option[] configuration() {
+ Option[] options = CoreOptions
+ .options(
+ CoreOptions.equinox(),
+ mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
+ mavenBundle("org.osgi", "org.osgi.compendium"),
+ mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx"),
+ new Customizer() {
+ public InputStream customizeTestProbe(InputStream testProbe) throws Exception {
+ return modifyBundle(testProbe)
+ .removeHeader(Constants.DYNAMICIMPORT_PACKAGE)
+ .set(Constants.REQUIRE_BUNDLE, "org.apache.aries.jmx.test.bundlea,org.apache.aries.jmx.test.bundleb")
+ .build(withBnd());
+ }
+ },
+ provision(newBundle()
+ .add(org.apache.aries.jmx.test.bundlea.Activator.class)
+ .add(org.apache.aries.jmx.test.bundlea.api.InterfaceA.class)
+ .add(org.apache.aries.jmx.test.bundlea.impl.A.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME, "org.apache.aries.jmx.test.bundlea")
+ .set(Constants.BUNDLE_VERSION, "2.0.0")
+ .set(Constants.EXPORT_PACKAGE, "org.apache.aries.jmx.test.bundlea.api;version=2.0.0")
+ .set(Constants.IMPORT_PACKAGE,
+ "org.osgi.framework;version=1.5.0,org.osgi.util.tracker,org.apache.aries.jmx.test.bundleb.api;version=1.1.0;resolution:=optional" +
+ ",org.osgi.service.cm")
+ .set(Constants.BUNDLE_ACTIVATOR,
+ org.apache.aries.jmx.test.bundlea.Activator.class.getName())
+ .build(withBnd())),
+ provision(newBundle()
+ .add(org.apache.aries.jmx.test.bundleb.Activator.class)
+ .add(org.apache.aries.jmx.test.bundleb.api.InterfaceB.class)
+ .add(org.apache.aries.jmx.test.bundleb.api.MSF.class)
+ .add(org.apache.aries.jmx.test.bundleb.impl.B.class)
+ .set(Constants.BUNDLE_SYMBOLICNAME,"org.apache.aries.jmx.test.bundleb")
+ .set(Constants.BUNDLE_VERSION, "1.0.0")
+ .set(Constants.EXPORT_PACKAGE,"org.apache.aries.jmx.test.bundleb.api;version=1.1.0")
+ .set(Constants.IMPORT_PACKAGE,"org.osgi.framework;version=1.5.0,org.osgi.util.tracker" +
+ ",org.osgi.service.cm")
+ .set(Constants.BUNDLE_ACTIVATOR,
+ org.apache.aries.jmx.test.bundleb.Activator.class.getName())
+ .build(withBnd()))
+ );
+ options = updateOptions(options);
+ return options;
+ }
+
+ @Before
+ public void doSetUp() throws Exception {
+ super.setUp();
+ int i=0;
+ while (true) {
+ try {
+ mbeanServer.getObjectInstance(new ObjectName(ServiceStateMBean.OBJECTNAME));
+ break;
+ } catch (InstanceNotFoundException e) {
+ if (i == 5) {
+ throw new Exception("ServiceStateMBean not available after waiting 5 seconds");
+ }
+ }
+ i++;
+ Thread.sleep(1000);
+ }
+ }
+
+
+ @Test
+ public void testMBeanInterface() throws Exception {
+
+ ServiceStateMBean mbean = getMBean(ServiceStateMBean.OBJECTNAME, ServiceStateMBean.class);
+ assertNotNull(mbean);
+
+ //get bundles
+
+ Bundle a = getBundle("org.apache.aries.jmx.test.bundlea");
+ assertNotNull(a);
+
+ Bundle b = getBundle("org.apache.aries.jmx.test.bundleb");
+ assertNotNull(b);
+
+ // get services
+
+ ServiceReference refA = bundleContext.getServiceReference(InterfaceA.class.getName());
+ assertNotNull(refA);
+ long serviceAId = (Long) refA.getProperty(Constants.SERVICE_ID);
+ assertTrue(serviceAId > -1);
+
+ ServiceReference refB = bundleContext.getServiceReference(InterfaceB.class.getName());
+ assertNotNull(refB);
+ long serviceBId = (Long) refB.getProperty(Constants.SERVICE_ID);
+ assertTrue(serviceBId > -1);
+
+ ServiceReference[] refs = bundleContext.getServiceReferences(ManagedServiceFactory.class.getName(), "(" + Constants.SERVICE_PID + "=jmx.test.B.factory)");
+ assertNotNull(refs);
+ assertEquals(1, refs.length);
+ ServiceReference msf = refs[0];
+
+
+ // getBundleIdentifier
+
+ assertEquals(a.getBundleId(), mbean.getBundleIdentifier(serviceAId));
+
+ //getObjectClass
+
+ String[] objectClass = mbean.getObjectClass(serviceAId);
+ assertEquals(2, objectClass.length);
+ List<String> classNames = Arrays.asList(objectClass);
+ assertTrue(classNames.contains(InterfaceA.class.getName()));
+ assertTrue(classNames.contains(ManagedService.class.getName()));
+
+ // getProperties
+
+ TabularData serviceProperties = mbean.getProperties(serviceBId);
+ assertNotNull(serviceProperties);
+ assertEquals(JmxConstants.PROPERTIES_TYPE, serviceProperties.getTabularType());
+ assertTrue(serviceProperties.values().size() > 1);
+ assertEquals("org.apache.aries.jmx.test.ServiceB",
+ PropertyData.from(serviceProperties.get(new Object[] { Constants.SERVICE_PID })).getValue());
+
+ // getUsingBundles
+
+ long[] usingBundles = mbean.getUsingBundles(serviceBId);
+ assertEquals(1, usingBundles.length);
+ assertEquals(a.getBundleId(), usingBundles[0]);
+
+ // listServices
+
+ TabularData allServices = mbean.listServices();
+ assertNotNull(allServices);
+ assertEquals(bundleContext.getAllServiceReferences(null, null).length, allServices.values().size());
+
+ // notifications
+
+ final List<Notification> received = new ArrayList<Notification>();
+
+ mbeanServer.addNotificationListener(new ObjectName(ServiceStateMBean.OBJECTNAME), new NotificationListener() {
+ public void handleNotification(Notification notification, Object handback) {
+ received.add(notification);
+ }
+ }, null, null);
+
+
+ assertNotNull(refB);
+ assertNotNull(msf);
+ b.stop();
+ refB = bundleContext.getServiceReference(InterfaceB.class.getName());
+ refs = bundleContext.getServiceReferences(ManagedServiceFactory.class.getName(), "(" + Constants.SERVICE_PID + "=jmx.test.B.factory)");
+ assertNull(refs);
+ assertNull(refB);
+ b.start();
+ refB = bundleContext.getServiceReference(InterfaceB.class.getName());
+ refs = bundleContext.getServiceReferences(ManagedServiceFactory.class.getName(), "(" + Constants.SERVICE_PID + "=jmx.test.B.factory)");
+ assertNotNull(refB);
+ assertNotNull(refs);
+ assertEquals(1, refs.length);
+
+ int i = 0;
+ while (received.size() < 4 && i < 3) {
+ Thread.sleep(1000);
+ i++;
+ }
+
+ assertEquals(4, received.size());
+
+ }
+
+}
Propchange: incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java
------------------------------------------------------------------------------
svn:keywords = Revision Date