Search in sources :

Example 36 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class TemporalTest method testDelay.

@Test
public void testDelay() {
    String prov = "provider";
    ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
    String un = "under-1";
    ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-CheckServiceProviderUsingTemporal", 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();
    assertNull("No FooService", osgiHelper.getServiceReference(FooService.class.getName(), null));
    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) + ")", (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();
}
Also used : FooService(org.apache.felix.ipojo.handler.temporal.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.handler.temporal.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 37 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class TemporalTest method testDelayWithProxy.

@Test
public void testDelayWithProxy() {
    String prov = "provider";
    ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
    String un = "under-1";
    ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-ProxiedCheckServiceProviderUsingTemporal", 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();
}
Also used : FooService(org.apache.felix.ipojo.handler.temporal.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.handler.temporal.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 38 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class TemporalTest method testTimeout.

@Test
public void testTimeout() {
    String prov = "provider";
    ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
    String un = "under-1";
    ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-CheckServiceProviderUsingTemporal", 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);
    DelayedProvider dp = new DelayedProvider(provider, 4000);
    dp.start();
    cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    try {
        cs.check();
    } catch (RuntimeException e) {
        // OK
        dp.stop();
        provider.stop();
        provider.dispose();
        under.stop();
        under.dispose();
        return;
    }
    fail("Timeout expected");
}
Also used : FooService(org.apache.felix.ipojo.handler.temporal.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.handler.temporal.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 39 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class TemporalTest method testSetTimeoutWithProxy.

@Test
public void testSetTimeoutWithProxy() {
    String prov = "provider";
    ComponentInstance provider = ipojoHelper.createComponentInstance("TEMPORAL-FooProvider", prov);
    String un = "under-1";
    ComponentInstance under = ipojoHelper.createComponentInstance("TEMPORAL-ProxiedCheckServiceProviderTimeoutUsingTemporal", 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);
    DelayedProvider dp = new DelayedProvider(provider, 400);
    dp.start();
    cs = (CheckService) osgiHelper.getServiceObject(ref_cs);
    try {
        cs.check();
    } catch (RuntimeException e) {
        // OK
        dp.stop();
        provider.stop();
        provider.dispose();
        under.stop();
        under.dispose();
        return;
    }
    fail("Timeout expected");
}
Also used : FooService(org.apache.felix.ipojo.handler.temporal.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.handler.temporal.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 40 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance in project felix by apache.

the class TestInstallation method install.

@Test
public void install() throws NotSupportedException, SystemException, IllegalStateException, SecurityException, HeuristicMixedException, HeuristicRollbackException, RollbackException, InvalidSyntaxException {
    Bundle[] bundles = context.getBundles();
    for (Bundle b : bundles) {
        System.out.println("Bundle : " + b.getSymbolicName() + " - " + b.getState());
        Assert.assertTrue(b.getSymbolicName(), b.getState() == Bundle.ACTIVE);
    }
    osgiHelper.waitForService(TransactionManager.class.getName(), null, 5000);
    // Transaction Service available
    osgiHelper.isServiceAvailable(TransactionManager.class.getName());
    TransactionManager tm = (TransactionManager) osgiHelper.getServiceObject(TransactionManager.class.getName(), null);
    tm.begin();
    Assert.assertNotNull(tm.getTransaction());
    tm.commit();
    tm.begin();
    Assert.assertNotNull(tm.getTransaction());
    tm.rollback();
    // Handler exposed
    ServiceReference ref = osgiHelper.getServiceReference(HandlerFactory.class.getName(), "(&(handler.name=transaction)(handler.namespace=org.apache.felix.ipojo.transaction))");
    Assert.assertNotNull(ref);
    // Create an install of the components
    ComponentInstance prov = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.handler.transaction.components.FooImpl");
    ComponentInstance under = ipojoHelper.createComponentInstance("requires-ok");
    Assert.assertEquals(ComponentInstance.VALID, prov.getState());
    Assert.assertEquals(ComponentInstance.VALID, under.getState());
    ServiceReference[] refs = context.getAllServiceReferences(CheckService.class.getName(), "(instance.name=" + under.getInstanceName() + ")");
    // ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), under.getInstanceName());
    Assert.assertNotNull(refs);
    ((CheckService) osgiHelper.getServiceObject(refs[0])).doSomethingGood();
}
Also used : Bundle(org.osgi.framework.Bundle) CoreOptions.mavenBundle(org.ops4j.pax.exam.CoreOptions.mavenBundle) HandlerFactory(org.apache.felix.ipojo.HandlerFactory) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.handler.transaction.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

ComponentInstance (org.apache.felix.ipojo.ComponentInstance)373 Test (org.junit.Test)360 ServiceReference (org.osgi.framework.ServiceReference)215 Properties (java.util.Properties)142 CheckService (org.apache.felix.ipojo.handler.temporal.services.CheckService)70 FooService (org.apache.felix.ipojo.handler.temporal.services.FooService)70 CheckService (org.apache.felix.ipojo.handler.transaction.services.CheckService)65 Factory (org.apache.felix.ipojo.Factory)53 CheckService (org.apache.felix.ipojo.runtime.core.services.CheckService)50 ServiceContext (org.apache.felix.ipojo.ServiceContext)47 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)39 IOException (java.io.IOException)29 CheckService (org.apache.felix.ipojo.runtime.core.test.services.CheckService)22 BundleContext (org.osgi.framework.BundleContext)19 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)17 ComponentFactory (org.apache.felix.ipojo.ComponentFactory)14 Dictionary (java.util.Dictionary)12 Hashtable (java.util.Hashtable)12 BarService (org.apache.felix.ipojo.runtime.core.services.BarService)10 DependencyDescription (org.apache.felix.ipojo.handlers.dependency.DependencyDescription)9