use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestManagedServiceFactoryTestForImmediate method testDelayedCreationAndReconfiguration2.
@Test
public void testDelayedCreationAndReconfiguration2() {
factory.stop();
// The reconfiguration happens before the service invocation
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);
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 object -1", 1, ((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", 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 testMSFCreationAndReconfiguration.
@Test
public void testMSFCreationAndReconfiguration() {
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);
// 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);
osgiHelper.waitForService(FooService.class.getName(), "(instance.name=" + pid + ")", 1000);
ServiceReference refx = osgiHelper.getServiceReference(FooService.class.getName(), "(instance.name=" + pid + ")");
assertNotNull("Check refx", refx);
FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
assertNotNull("Check fs", fs);
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);
// Wait for the processing of the first configuration.
grace();
Dictionary p2 = configuration.getProperties();
p2.put("message", "message2");
try {
System.err.println("The configuration will be updated with message2");
configuration.update(p2);
// Update the configuration ...
grace();
} catch (Exception e) {
fail(e.getMessage());
}
System.err.println("The configuration should be updated with message2");
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 testMSFCreationAndReconfiguration2.
@Test
public void testMSFCreationAndReconfiguration2() {
// 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();
// 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 TestManagedServiceFactoryTestForServices method testDelayedCreationAndReconfiguration.
@Test
public void testDelayedCreationAndReconfiguration() {
factory.stop();
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();
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);
osgiHelper.waitForService(FooService.class.getName(), "(instance.name=" + pid + ")", 1000);
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);
// Wait for the processing of the first configuration.
grace();
System.out.println("===");
props.put("message", "message2");
try {
configuration.update(props);
// Update the configuration ...
grace();
} catch (Exception e) {
fail(e.getMessage());
}
System.out.println("===");
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 TestManagedServiceTestForImmediate method testCreationUsingFactoryConfigurationSettingTheManagedServicePid.
/**
* Creates an instance using a factory configuration.
* The configuration specifies the managed.service.pid property
* Reconfiguration is applied using the exposed managed service.
*/
@Test
public void testCreationUsingFactoryConfigurationSettingTheManagedServicePid() {
Configuration conf = null;
try {
conf = admin.createFactoryConfiguration(factNameImm, getTestBundle().getLocation());
Dictionary props = conf.getProperties();
if (props == null) {
props = new Properties();
}
props.put("managed.service.pid", msp);
props.put("message", "message");
conf.update(props);
grace();
} catch (Exception e) {
fail(e.getMessage());
}
Architecture arch = (Architecture) osgiHelper.getServiceObject(org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), conf.getPid());
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) arch.getInstanceDescription()).getCreatedObjects().length);
assertNotNull("FS availability", ref);
// arch = (Architecture) osgiHelper.getServiceObject( org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
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) arch.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);
grace();
} catch (Exception e) {
fail(e.getMessage());
}
// arch = (Architecture) osgiHelper.getServiceObject( org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), conf.getPid());
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) arch.getInstanceDescription()).getCreatedObjects().length);
assertNotNull("FS availability", ref);
// arch = (Architecture) osgiHelper.getServiceObject( org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
fs = (FooService) bc.getService(ref);
p = fs.fooProps();
mes = p.getProperty("message");
count = ((Integer) p.get("count")).intValue();
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) arch.getInstanceDescription()).getCreatedObjects().length);
if (mes.equals("message")) {
System.out.println("Warning, configuration not yet applied");
assertEquals("Check count - W", 1, count);
} else {
assertEquals("Check message", "message2", mes);
assertEquals("Check count", 2, count);
}
try {
conf.delete();
grace();
} catch (IOException e) {
fail(e.getMessage());
}
}
Aggregations