Search in sources :

Example 1 with HandlerManagerFactory

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

the class HandlerTest method testAvailability.

@Test
public void testAvailability() {
    String name = "HandlerTest-1";
    ServiceReference sr = null;
    ServiceReference[] refs = null;
    String filter = "(" + "instance.name" + "=" + name + ")";
    refs = osgiHelper.getServiceReferences(CheckService.class.getName(), filter);
    if (refs != null) {
        sr = refs[0];
    }
    assertNotNull("Check the check service availability", sr);
    ServiceReference sr_arch = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "HandlerTest-1");
    Architecture arch = (Architecture) osgiHelper.getRawServiceObject(sr_arch);
    assertEquals("Check validity", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
    // Kill the handler factory
    HandlerManagerFactory f = (HandlerManagerFactory) ipojoHelper.getHandlerFactory("check");
    f.stop();
    boolean av = ipojoHelper.isServiceAvailableByName(CheckService.class.getName(), "HandlerTest-1");
    assertFalse("Check the check service unavailability", av);
    boolean av2 = ipojoHelper.isServiceAvailableByName(Architecture.class.getName(), "HandlerTest-1");
    assertFalse("Check the architecture unavailability", av2);
    // The instance is disposed, restart the handler
    f.start();
    Properties props = new Properties();
    props.put("instance.name", "HandlerTest-1");
    props.put("csh.simple", "simple");
    Properties p = new Properties();
    p.put("a", "a");
    p.put("b", "b");
    p.put("c", "c");
    props.put("csh.map", p);
    instance = ipojoHelper.createComponentInstance("HANDLER-HandlerTester", props);
    sr = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), "HandlerTest-1");
    assertNotNull("Check the check service availability - 2", sr);
    sr_arch = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "HandlerTest-1");
    arch = (Architecture) osgiHelper.getRawServiceObject(sr_arch);
    assertEquals("Check validity - 2", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
}
Also used : Architecture(org.apache.felix.ipojo.architecture.Architecture) HandlerManagerFactory(org.apache.felix.ipojo.HandlerManagerFactory) CheckService(org.apache.felix.ipojo.runtime.externalhandlers.services.CheckService) Properties(java.util.Properties) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 2 with HandlerManagerFactory

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

the class TestObedience method testDisposeAfterFactoryInvalidation.

@Test
public void testDisposeAfterFactoryInvalidation() {
    ComponentFactory cf = (ComponentFactory) ipojoHelper.getFactory("org.apache.felix.ipojo.runtime.core.components.SimpleType");
    assertNotNull("Check factory availability -1", cf);
    assertEquals("Check factory state -1", Factory.VALID, cf.getState());
    ServiceReference ref_arch = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "SimpleInstance");
    assertNotNull("Check Architecture availability -1", ref_arch);
    HandlerManagerFactory hf = (HandlerManagerFactory) ipojoHelper.getHandlerFactory("controller");
    assertNotNull("Check handler availability -1", hf);
    assertEquals("Check handler state -1", Factory.VALID, hf.getState());
    // Stop the handler
    hf.stop();
    HandlerManagerFactory hf2 = (HandlerManagerFactory) ipojoHelper.getFactoryHelper().getHandlerFactory("controller", 1, false);
    assertNull("Check handler availability -2", hf2);
    // Check the factory invalidity
    cf = (ComponentFactory) ipojoHelper.getFactory("org.apache.felix.ipojo.runtime.core.components.SimpleType");
    assertNotNull("Check factory availability -2", cf);
    assertEquals("Check factory state -2", Factory.INVALID, cf.getState());
    // Check the instance disappearance, the instance was disposed.
    assertFalse("Check Architecture availability -1", ipojoHelper.isServiceAvailableByName(Architecture.class.getName(), "SimpleInstance"));
    // Restart the handler
    hf.start();
    hf2 = (HandlerManagerFactory) ipojoHelper.getHandlerFactory("controller");
    assertNotNull("Check handler availability -3", hf2);
    // Check the factory state
    cf = (ComponentFactory) ipojoHelper.getFactory("org.apache.felix.ipojo.runtime.core.components.SimpleType");
    assertNotNull("Check factory availability -3", cf);
    assertEquals("Check factory state -3", Factory.VALID, cf.getState());
    // Check the instance re-creation
    ref_arch = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "SimpleInstance");
    assertNotNull("Check Architecture availability -3", ref_arch);
}
Also used : Architecture(org.apache.felix.ipojo.architecture.Architecture) HandlerManagerFactory(org.apache.felix.ipojo.HandlerManagerFactory) ComponentFactory(org.apache.felix.ipojo.ComponentFactory) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

HandlerManagerFactory (org.apache.felix.ipojo.HandlerManagerFactory)2 Architecture (org.apache.felix.ipojo.architecture.Architecture)2 Test (org.junit.Test)2 ServiceReference (org.osgi.framework.ServiceReference)2 Properties (java.util.Properties)1 ComponentFactory (org.apache.felix.ipojo.ComponentFactory)1 CheckService (org.apache.felix.ipojo.runtime.externalhandlers.services.CheckService)1