use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.
the class TestMBean method testMBeanWithoutAnnotations.
/**
* Test the MBean exposed by the simple component, defined without
* annotations and with the brand new JMX handler syntax.
*/
@Test
public void testMBeanWithoutAnnotations() throws MalformedObjectNameException, IntrospectionException, InstanceNotFoundException, ListenerNotFoundException, ReflectionException, MBeanException {
// Create an instance of the component
ComponentInstance componentInstance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.jmx.components.SimpleManagedComponent");
String instanceName = componentInstance.getInstanceName();
ObjectName objectName = new ObjectName("org.apache.felix.ipojo.handler.jmx.components:type=org.apache.felix.ipojo.handler.jmx.components.SimpleManagedComponent,instance=" + instanceName);
doTest(objectName);
}
use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.
the class TestMBean method testMBeanWithAnnotations.
/**
* Test the MBean exposed by the simple component, defined with
* annotations.
*/
@Test
public void testMBeanWithAnnotations() throws MalformedObjectNameException, IntrospectionException, InstanceNotFoundException, ListenerNotFoundException, ReflectionException, MBeanException {
// Create an instance of the component
ComponentInstance componentInstance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.jmx.components.SimpleManagedComponentAnnotated");
String instanceName = componentInstance.getInstanceName();
ObjectName objectName = new ObjectName("org.apache.felix.ipojo.handler.jmx.components:type=org.apache.felix.ipojo.handler.jmx.components.SimpleManagedComponentAnnotated,instance=" + instanceName);
doTest(objectName);
}
use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.
the class DefaultImplementationTest method testDefaultImplementationTimeoutWithProxy.
@Test
public void testDefaultImplementationTimeoutWithProxy() {
String prov = "provider";
ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
String un = "under-1";
ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-DIProxiedCheckServiceProvider", un);
ServiceReference ref_fs = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov);
assertNotNull("Check foo availability", ref_fs);
ServiceReference ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
assertNotNull("Check cs availability", ref_cs);
CheckService cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
assertTrue("Check invocation", cs.check());
// Stop the provider.
provider.stop();
ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
assertNotNull("Check cs availability - 2", ref_cs);
cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
boolean res = false;
try {
res = cs.check();
} catch (RuntimeException e) {
fail("A nullable was expected ...");
}
assertFalse("Check nullable", res);
provider.stop();
provider.dispose();
under.stop();
under.dispose();
return;
}
use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.
the class DefaultImplementationTest method testDelayTimeout.
@Test
public void testDelayTimeout() {
String prov = "provider";
ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
String un = "under-1";
ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-DICheckServiceProviderTimeout", un);
ServiceReference ref_fs = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov);
assertNotNull("Check foo availability", ref_fs);
ServiceReference ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
assertNotNull("Check cs availability", ref_cs);
CheckService cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
assertTrue("Check invocation", cs.check());
// Stop the provider.
provider.stop();
ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
assertNotNull("Check cs availability - 2", ref_cs);
long begin = System.currentTimeMillis();
DelayedProvider dp = new DelayedProvider(provider, 200);
dp.start();
cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
assertTrue("Check invocation - 2", cs.check());
long end = System.currentTimeMillis();
assertTrue("Assert delay", (end - begin) >= 200);
ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
assertNotNull("Check cs availability - 3", ref_cs);
cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
assertTrue("Check invocation - 3", cs.check());
provider.stop();
provider.dispose();
under.stop();
under.dispose();
}
use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.
the class DefaultImplementationTest method testDelayOnMultipleDependency.
@Test
public void testDelayOnMultipleDependency() {
String prov = "provider";
ComponentInstance provider1 = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
String prov2 = "provider2";
ComponentInstance provider2 = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov2);
String un = "under-1";
ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-NullableMultipleCheckServiceProviderTimeout", un);
ServiceReference ref_fs = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov);
assertNotNull("Check foo availability", ref_fs);
ServiceReference ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
assertNotNull("Check cs availability", ref_cs);
CheckService cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
assertTrue("Check invocation", cs.check());
// Stop the providers.
provider1.stop();
provider2.stop();
ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
assertNotNull("Check cs availability - 2", ref_cs);
long begin = System.currentTimeMillis();
DelayedProvider dp = new DelayedProvider(provider1, 1500);
DelayedProvider dp2 = new DelayedProvider(provider2, 100);
dp.start();
dp2.start();
cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
assertTrue("Check invocation - 2", cs.check());
long end = System.currentTimeMillis();
System.out.println("delay = " + (end - begin));
assertTrue("Assert min delay", (end - begin) >= 100);
assertTrue("Assert max delay", (end - begin) <= 1000);
dp.stop();
dp2.stop();
provider1.stop();
provider2.stop();
ref_cs = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), un);
assertNotNull("Check cs availability - 3", ref_cs);
cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
// Will return false as the contained DI will return false to the foo method.
assertFalse("Check invocation - 3", cs.check());
provider1.dispose();
provider2.dispose();
under.stop();
under.dispose();
}
Aggregations