Skip to content

Commit

Permalink
ARIES-339: JMX test improvements. Based on patch from Bartosz Kowalewski
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/incubator/aries/trunk/jmx@955108 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jgawor committed Jun 16, 2010
1 parent 65654ad commit 9c2ef25
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
import static org.junit.Assert.*;

import javax.management.InstanceNotFoundException;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.MBeanServerInvocationHandler;
Expand All @@ -49,6 +50,7 @@
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.framework.Version;
import org.osgi.jmx.framework.BundleStateMBean;
import org.osgi.util.tracker.ServiceTracker;

/**
Expand Down Expand Up @@ -83,6 +85,16 @@ public void setUp() throws Exception {
assertNotNull(reference);
MBeanServer mbeanService = (MBeanServer) bundleContext.getService(reference);
assertNotNull(mbeanService);

doSetUp();
}

/**
* A hook for subclasses.
*
* @throws Exception
*/
protected void doSetUp() throws Exception {
}

@After
Expand All @@ -91,6 +103,26 @@ public void tearDown() throws Exception {
//plainRegistration.unregister();
}

protected void waitForMBean(ObjectName name) throws Exception {
waitForMBean(name, 10);
}

protected void waitForMBean(ObjectName name, int timeoutInSeconds) throws Exception {
int i=0;
while (true) {
try {
mbeanServer.getObjectInstance(name);
break;
} catch (InstanceNotFoundException e) {
if (i == timeoutInSeconds) {
throw new Exception(name + " mbean is not available after waiting " + timeoutInSeconds + " seconds");
}
}
i++;
Thread.sleep(1000);
}
}

@SuppressWarnings("unchecked")
protected <T> T getMBean(String name, Class<T> type) {
ObjectName objectName = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.io.InputStream;
import java.util.Dictionary;

import javax.management.InstanceNotFoundException;
import javax.management.ObjectName;
import javax.management.openmbean.TabularData;

Expand All @@ -37,7 +36,6 @@
import org.apache.aries.jmx.test.bundlea.api.InterfaceA;
import org.apache.aries.jmx.test.bundleb.api.InterfaceB;
import org.apache.aries.jmx.test.bundleb.api.MSF;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.ops4j.pax.exam.CoreOptions;
Expand Down Expand Up @@ -107,22 +105,9 @@ public InputStream customizeTestProbe(InputStream testProbe) throws Exception {
return options;
}

@Before
@Override
public void doSetUp() throws Exception {
super.setUp();
int i=0;
while (true) {
try {
mbeanServer.getObjectInstance(new ObjectName(ConfigurationAdminMBean.OBJECTNAME));
break;
} catch (InstanceNotFoundException e) {
if (i == 5) {
throw new Exception("ConfigurationAdminMBean not available after waiting 5 seconds");
}
}
i++;
Thread.sleep(1000);
}
waitForMBean(new ObjectName(ConfigurationAdminMBean.OBJECTNAME));
}

@Ignore("ManagedServiceFactory tests failing.. " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@
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.BundleData.Header;
import org.junit.Before;
import org.junit.Test;
import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.Option;
Expand Down Expand Up @@ -106,22 +104,9 @@ public static Option[] configuration() {
return options;
}

@Before
@Override
public void doSetUp() throws Exception {
super.setUp();
int i=0;
while (true) {
try {
mbeanServer.getObjectInstance(new ObjectName(BundleStateMBean.OBJECTNAME));
break;
} catch (InstanceNotFoundException e) {
if (i == 5) {
throw new Exception("BundleStateMBean not available after waiting 5 seconds");
}
}
i++;
Thread.sleep(1000);
}
waitForMBean(new ObjectName(BundleStateMBean.OBJECTNAME));
}

@Test
Expand Down Expand Up @@ -204,7 +189,7 @@ public void testMBeanInterface() throws Exception {

long[] requiring = mbean.getRequiringBundles(a.getBundleId());
assertEquals(3, requiring.length);
assertTrue(b.getSymbolicName(), arrayContains(frag.getBundleId(), requiring));
assertTrue(b.getSymbolicName(), arrayContains(b.getBundleId(), requiring));
assertTrue(frag.getSymbolicName(), arrayContains(frag.getBundleId(), requiring));
assertTrue(d.getSymbolicName(), arrayContains(d.getBundleId(), requiring));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;

import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;

import org.apache.aries.jmx.AbstractIntegrationTest;
Expand Down Expand Up @@ -58,6 +59,11 @@ public static Option[] configuration() {
return options;
}

@Override
public void doSetUp() throws Exception {
waitForMBean(new ObjectName(FrameworkMBean.OBJECTNAME));
}

@Test
public void testMBeanInterface() throws IOException {
FrameworkMBean framework = getMBean(FrameworkMBean.OBJECTNAME, FrameworkMBean.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@
import java.io.IOException;
import java.util.Collection;

import javax.management.InstanceNotFoundException;
import javax.management.ObjectName;
import javax.management.openmbean.TabularData;

import org.apache.aries.jmx.AbstractIntegrationTest;
import org.junit.Before;
import org.junit.Test;
import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.Option;
Expand All @@ -53,22 +51,9 @@ public static Option[] configuration() {
return options;
}

@Before
@Override
public void doSetUp() throws Exception {
super.setUp();
int i = 0;
while (true) {
try {
mbeanServer.getObjectInstance(new ObjectName(PackageStateMBean.OBJECTNAME));
break;
} catch (InstanceNotFoundException e) {
if (i == 5) {
throw new Exception("PackageStateMBean not available after waiting 5 seconds");
}
}
i++;
Thread.sleep(1000);
}
waitForMBean(new ObjectName(PackageStateMBean.OBJECTNAME));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.Arrays;
import java.util.List;

import javax.management.InstanceNotFoundException;
import javax.management.Notification;
import javax.management.NotificationListener;
import javax.management.ObjectName;
Expand All @@ -40,7 +39,6 @@
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;
Expand Down Expand Up @@ -110,24 +108,10 @@ public InputStream customizeTestProbe(InputStream testProbe) throws Exception {
return options;
}

@Before
@Override
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);
}
}

waitForMBean(new ObjectName(ServiceStateMBean.OBJECTNAME));
}

@Test
public void testMBeanInterface() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@

import java.io.IOException;

import javax.management.InstanceNotFoundException;
import javax.management.ObjectName;

import org.apache.aries.jmx.AbstractIntegrationTest;
import org.junit.Before;
import org.junit.Test;
import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.Option;
Expand Down Expand Up @@ -70,22 +68,9 @@ public static Option[] configuration() {
return options;
}

@Before
@Override
public void doSetUp() throws Exception {
super.setUp();
int i = 0;
while (true) {
try {
mbeanServer.getObjectInstance(new ObjectName(PermissionAdminMBean.OBJECTNAME));
break;
} catch (InstanceNotFoundException e) {
if (i == 5) {
throw new Exception("PermissionAdminMBean not available after waiting 5 seconds");
}
}
i++;
Thread.sleep(1000);
}
waitForMBean(new ObjectName(PermissionAdminMBean.OBJECTNAME));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;

import javax.management.InstanceNotFoundException;
import javax.management.ObjectName;
import javax.management.openmbean.TabularData;

import org.apache.aries.jmx.AbstractIntegrationTest;
import org.apache.aries.jmx.codec.PropertyData;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.ops4j.pax.exam.CoreOptions;
Expand Down Expand Up @@ -70,27 +68,10 @@ public static Option[] configuration() {
return options;
}

@Before
@Override
public void doSetUp() throws Exception {
super.setUp();
int i=0;
while (true) {
try {
mbeanServer.getObjectInstance(new ObjectName(ProvisioningServiceMBean.OBJECTNAME));
break;
} catch (InstanceNotFoundException e) {
if (i == 5) {
throw new Exception("ProvisioningServiceMBean not available after waiting 5 seconds");
}
}
i++;
Thread.sleep(1000);
}


waitForMBean(new ObjectName(ProvisioningServiceMBean.OBJECTNAME));
}



@Ignore("For now.. Cannot find public repo for org.eclipse.equinox.ip")
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import javax.management.InstanceNotFoundException;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
import javax.management.openmbean.TabularData;
Expand All @@ -43,21 +40,14 @@
import org.apache.aries.jmx.test.blueprint.framework.RegistrationListenerValidator;
import org.apache.aries.jmx.test.blueprint.framework.ServiceValidator;
import org.apache.aries.jmx.test.blueprint.framework.ValueValidator;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.Inject;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.Configuration;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.blueprint.container.BlueprintContainer;

public class BlueprintMBeanTest extends AbstractIntegrationTest {
Expand All @@ -79,27 +69,10 @@ public static Option[] configuration() {
return options;
}

@Before
public void setUp() throws Exception {
super.setUp();
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Before Test");

// Wait MBeans register in server
int i=0;
while (true) {
try {
mbeanServer.getObjectInstance(new ObjectName(BlueprintStateMBean.OBJECTNAME));
mbeanServer.getObjectInstance(new ObjectName(BlueprintMetadataMBean.OBJECTNAME));
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Found MBeans");
break;
} catch (InstanceNotFoundException e) {
if (i == 5) {
throw new Exception(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> BlueprintStateMBean & BlueprintMetadataMBean are not found in server");
}
}
i++;
Thread.sleep(100);
}
@Override
public void doSetUp() throws Exception {
waitForMBean(new ObjectName(BlueprintStateMBean.OBJECTNAME));
waitForMBean(new ObjectName(BlueprintMetadataMBean.OBJECTNAME));

// Wait enough time for osgi framework and blueprint bundles to be set up
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Waiting for bundles to be set up");
Expand Down

0 comments on commit 9c2ef25

Please sign in to comment.