use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestManagedServiceFactoryTestForImmediate method testDelayedCreationAndReconfiguration.
@Test
public void testDelayedCreationAndReconfiguration() {
factory.stop();
Configuration configuration = null;
try {
configuration = admin.createFactoryConfiguration("CA-ImmConfigurableProvider", "?");
} catch (IOException e) {
fail(e.getMessage());
}
Dictionary props = configuration.getProperties();
if (props == null) {
props = new Properties();
}
props.put("message", "message");
try {
configuration.update(props);
} catch (IOException e) {
fail(e.getMessage());
}
String pid = configuration.getPid();
// Wait for the processing of the first configuration.
grace();
assertNull("check no instance", osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
factory.start();
// Wait for the processing of the first configuration.
grace();
// The instance should be created, wait for the architecture service
osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=" + pid + ")", 1000);
Architecture architecture = (Architecture) osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")");
assertEquals("Check object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
Properties p = fs.fooProps();
String mes = p.getProperty("message");
int count = (Integer) p.get("count");
// architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
assertEquals("Assert Message", "message", mes);
assertEquals("Assert count", 1, count);
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
props.put("message", "message2");
try {
configuration.update(props);
// Update the configuration ...
grace();
} catch (Exception e) {
fail(e.getMessage());
}
fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
p = fs.fooProps();
mes = p.getProperty("message");
count = (Integer) p.get("count");
// architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
assertEquals("Assert Message", "message2", mes);
// assertEquals("Assert count", 2, count);
// This test was removed as the result can be 3.
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
try {
configuration.delete();
grace();
} catch (Exception e) {
fail(e.getMessage());
}
ServiceReference ref = osgiHelper.getServiceReference(FooService.class.getName(), "(instance.name=" + pid + ")");
assertNull("Check unavailability", ref);
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestManagedServiceFactoryTestForImmediate method testCreationAndReconfiguration.
@Test
public void testCreationAndReconfiguration() {
Configuration configuration = null;
try {
configuration = admin.createFactoryConfiguration("CA-ImmConfigurableProvider", "?");
} catch (IOException e) {
fail(e.getMessage());
}
Dictionary props = configuration.getProperties();
if (props == null) {
props = new Properties();
}
props.put("message", "message");
try {
configuration.update(props);
} catch (IOException e) {
fail(e.getMessage());
}
String pid = configuration.getPid();
// Wait for the processing of the first configuration.
grace();
// The instance should be created, wait for the architecture service
osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=" + pid + ")", 1000);
Architecture architecture = (Architecture) osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")");
assertEquals("Check object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
Properties p = fs.fooProps();
String mes = p.getProperty("message");
int count = (Integer) p.get("count");
// architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
assertEquals("Assert Message", "message", mes);
assertEquals("Assert count", 1, count);
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
props.put("message", "message2");
try {
configuration.update(props);
// Update the configuration ...
grace();
} catch (Exception e) {
fail(e.getMessage());
}
fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
p = fs.fooProps();
mes = p.getProperty("message");
count = (Integer) p.get("count");
// architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
assertEquals("Assert Message", "message2", mes);
assertEquals("Assert count", 2, count);
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
try {
configuration.delete();
grace();
} catch (Exception e) {
fail(e.getMessage());
}
ServiceReference ref = osgiHelper.getServiceReference(FooService.class.getName(), "(instance.name=" + pid + ")");
assertNull("Check unavailability", ref);
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestManagedServiceFactoryTestForServices method testDelayedCreationAndReconfiguration2.
@Test
public void testDelayedCreationAndReconfiguration2() {
factory.stop();
// The reconfiguration happens before the service invocation
Configuration configuration = null;
try {
configuration = admin.createFactoryConfiguration("CA-ConfigurableProvider", "?");
} catch (IOException e) {
fail(e.getMessage());
}
Dictionary props = configuration.getProperties();
if (props == null) {
props = new Properties();
}
props.put("message", "message");
try {
configuration.update(props);
} catch (IOException e) {
fail(e.getMessage());
}
String pid = configuration.getPid();
System.out.println("PID : " + pid);
assertNull("check no instance", osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
factory.start();
// The instance should be created, wait for the architecture service
osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=" + pid + ")", 1000);
Architecture architecture = (Architecture) osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")");
assertEquals("Check no object", 0, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
// Wait for the processing of the first configuration.
grace();
props.put("message", "message2");
try {
configuration.update(props);
// Update the configuration ...
grace();
} catch (Exception e) {
fail(e.getMessage());
}
// architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
assertEquals("Check no object -2", 0, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
// Invoke
FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
Properties p = fs.fooProps();
String mes = p.getProperty("message");
int count = (Integer) p.get("count");
// architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
assertEquals("Assert Message", "message2", mes);
assertEquals("Assert count", 1, count);
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
try {
configuration.delete();
grace();
} catch (Exception e) {
fail(e.getMessage());
}
ServiceReference ref = osgiHelper.getServiceReference(FooService.class.getName(), "(instance.name=" + pid + ")");
assertNull("Check unavailability", ref);
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestManagedServiceTestForImmediate method testCreationAndReconfiguration3.
@Test
public void testCreationAndReconfiguration3() {
// The configuration exists before the instance creation.
// Update
Configuration configuration;
try {
configuration = admin.getConfiguration(msp, getTestBundle().getLocation());
Dictionary prc = configuration.getProperties();
if (prc == null) {
prc = new Properties();
}
prc.put("message", "message2");
configuration.update(prc);
grace();
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
Properties props = new Properties();
props.put("managed.service.pid", msp);
props.put("message", "message");
ComponentInstance instance = null;
try {
instance = factImm.createComponentInstance(props);
grace();
} catch (Exception e) {
fail(e.getMessage());
}
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
assertNotNull("FS availability", ref);
FooService fs = (FooService) bc.getService(ref);
Properties p = fs.fooProps();
String mes = p.getProperty("message");
// int count = ((Integer) p.get("count")).intValue();
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
// Already reconfigured.
assertEquals("Check message", "message2", mes);
// Reconfiguration
try {
configuration = admin.getConfiguration(msp);
Dictionary prc = configuration.getProperties();
if (prc == null) {
prc = new Properties();
}
prc.put("message", "message3");
configuration.update(prc);
grace();
} catch (Exception e) {
fail(e.getMessage());
}
instance.dispose();
// Recreation of the instance.
props = new Properties();
props.put("managed.service.pid", msp);
props.put("message", "message");
instance = null;
try {
instance = factImm.createComponentInstance(props);
} catch (Exception e) {
fail(e.getMessage());
}
// Wait until the configuration is delivered.
grace();
ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
assertNotNull("FS availability", ref);
fs = (FooService) bc.getService(ref);
p = fs.fooProps();
mes = p.getProperty("message");
// count = ((Integer) p.get("count")).intValue();
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
// Already reconfigured.
assertEquals("Check message", "message3", mes);
// assertEquals("Check count", 1, count);
instance.dispose();
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestManagedServiceTestForImmediate method testFactoryCreationAndReconfigurationUsingManagedService.
@Test
public void testFactoryCreationAndReconfigurationUsingManagedService() {
Properties props = new Properties();
// Exposes a ManagedService.
props.put("managed.service.pid", msp);
props.put("message", "message");
ComponentInstance instance = null;
try {
instance = factImm.createComponentInstance(props);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
assertNotNull("FS availability", ref);
FooService fs = (FooService) bc.getService(ref);
Properties p = fs.fooProps();
String mes = p.getProperty("message");
int count = (Integer) p.get("count");
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
assertEquals("Check message", "message", mes);
assertEquals("Check count", 1, count);
// Update
Configuration configuration;
try {
configuration = admin.getConfiguration(msp, getTestBundle().getLocation());
Dictionary prc = configuration.getProperties();
if (prc == null) {
prc = new Properties();
}
prc.put("message", "message2");
configuration.update(prc);
System.err.println("updated ? ");
grace();
} catch (Exception e) {
fail(e.getMessage());
}
ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
assertNotNull("FS availability", ref);
fs = (FooService) bc.getService(ref);
p = fs.fooProps();
mes = p.getProperty("message");
count = (Integer) p.get("count");
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
assertEquals("Check message", "message2", mes);
assertEquals("Check count", 2, count);
instance.dispose();
}
Aggregations