String sharedVmLog = "/tmp/sharedvm.log";
String[] sharedvm_props = new String[] {// server properties
"com.sun.jini.start.activatewrapper.debug", "init",
};
SharedActivationGroupDescriptor sharedvm =
new SharedActivationGroupDescriptor(
"/view/resendes/vob/jive/policy/policy.sharedvm",
"/view/resendes/vob/jive/lib/bogus_sharedvm.jar",
sharedVmLog,
"/bin/java", //server command
new String[] {// server options
"-ea",
},
sharedvm_props);
SharedActivatableServiceDescriptor sasd =
new SharedActivatableServiceDescriptor(
"http://resendes:8080/mercury-dl.jar",
"http://resendes:8086/policy.mercury",
"http://resendes:8080/mercury.jar",
"com.sun.jini.mercury.MailboxBogusImpl",
sharedVmLog,
new String[] {
"http://resendes:8089/mercury_service_act.config"
},
true);
SharedActivatableServiceDescriptor sasdWithExtras =
new SharedActivatableServiceDescriptor(
"http://resendes:8080/mercury-dl.jar",
"http://resendes:8086/policy.mercury",
"http://resendes:8080/mercury.jar",
"com.sun.jini.mercury.MailboxBogusImpl",
sharedVmLog,
new String[] {
"http://resendes:8089/mercury_service_act.config"
},
pp,
pp,
true,
"localhost",
1234);
ServiceDescriptor[] serviceDescriptors =
new ServiceDescriptor[] {
// sasdWithExtras & nasdWithExtras not written because
// default/recovered preparer and lifecycle objects won't match.
nasdWithoutExtras,
sharedvm,
sasd
};
// Serialize service descriptors to a file
FileOutputStream f = new FileOutputStream("tmp");
ObjectOutput oos = new ObjectOutputStream(f);
oos.writeObject(nasdWithExtras);
oos.writeObject(nasdWithoutExtras);
oos.writeObject(sharedvm);
oos.writeObject(sasd);
oos.writeObject(sasdWithExtras);
oos.writeObject(serviceDescriptors);
oos.flush();
oos.close();
logger.log(Level.INFO, "Wrote: " + nasdWithExtras);
logger.log(Level.INFO, "Wrote: " + nasdWithoutExtras);
logger.log(Level.INFO, "Wrote: " + sharedvm);
logger.log(Level.INFO, "Wrote: " + sasd);
logger.log(Level.INFO, "Wrote: " + sasdWithExtras);
logger.log(Level.INFO, "Wrote: " + Arrays.asList(serviceDescriptors));
// Deserialize objects from a file.
FileInputStream in = new FileInputStream("tmp");
ObjectInputStream ois = new ObjectInputStream(in);
NonActivatableServiceDescriptor nasdWithExtras_r =
(NonActivatableServiceDescriptor)ois.readObject();
nasdWithExtras_r.setLifeCycle(lc);
nasdWithExtras_r.setServicePreparer(pp);
NonActivatableServiceDescriptor nasdWithoutExtras_r =
(NonActivatableServiceDescriptor)ois.readObject();
SharedActivationGroupDescriptor sharedvm_r =
(SharedActivationGroupDescriptor)ois.readObject();
SharedActivatableServiceDescriptor sasd_r =
(SharedActivatableServiceDescriptor)ois.readObject();
SharedActivatableServiceDescriptor sasdWithExtras_r =
(SharedActivatableServiceDescriptor)ois.readObject();
//sasdWithExtras_r.setLifeCycle(lc);
sasdWithExtras_r.setServicePreparer(pp);
sasdWithExtras_r.setInnerProxyPreparer(pp);
ServiceDescriptor[] recovered =
(ServiceDescriptor[])ois.readObject();
ois.close();
logger.log(Level.INFO, "Read: " + nasdWithExtras_r);
logger.log(Level.INFO, "Read: " + nasdWithoutExtras_r);
logger.log(Level.INFO, "Read: " + sharedvm_r);
logger.log(Level.INFO, "Read: " + sasd_r);
logger.log(Level.INFO, "Read: " + sasdWithExtras_r);
logger.log(Level.INFO, "Read: " + Arrays.asList(recovered));
if (!verifyNonActivatableServiceDescriptors(nasdWithExtras, nasdWithExtras_r)) {
throw new TestException(
"Written and recovered NonActivatableServiceDescriptors don't match");
}
if (!verifyNonActivatableServiceDescriptors(nasdWithoutExtras, nasdWithoutExtras_r)) {
throw new TestException(
"Written and recovered NonActivatableServiceDescriptors don't match");
}
if (!verifySharedActivationGroupDescriptors(sharedvm, sharedvm_r)) {
throw new TestException(
"Written and recovered SharedActivationGroupDescriptors don't match");
}
if (!verifySharedActivatableServiceDescriptors(sasd, sasd_r)) {
throw new TestException(
"Written and recovered SharedActivatableServiceDescriptors don't match");
}
if (!verifySharedActivatableServiceDescriptors(sasdWithExtras, sasdWithExtras_r)) {
throw new TestException(
"Written and recovered SharedActivatableServiceDescriptors don't match");
}
if (!verifyServiceDescriptors(serviceDescriptors, recovered)) {
throw new TestException(
"Written and recovered ServiceDescriptor[] don't match");
}
//Do some negative tests - Ensure bad descriptor doesn't match
NonActivatableServiceDescriptor bogus_nasd =
new NonActivatableServiceDescriptor(
nasdWithoutExtras.getExportCodebase(),
nasdWithoutExtras.getPolicy(),
nasdWithoutExtras.getImportCodebase(),
nasdWithoutExtras.getImplClassName() + "_bogus",
nasdWithoutExtras.getServerConfigArgs(),
nasdWithoutExtras.getLifeCycle());
if (verifyNonActivatableServiceDescriptors(bogus_nasd, nasdWithoutExtras)) {
throw new TestException("Bogus NASD passed verification");
}
//Do some negative tests - Ensure setLifeCycle can't be called after creation
try {
nasdWithoutExtras.create(EmptyConfiguration.INSTANCE); //Original descriptor
} catch (Exception e) {
logger.log(Level.INFO, "exception creating NASD ... ignoring", e);
}
try {
nasdWithoutExtras.setLifeCycle(lc);
} catch (IllegalStateException ie) {
logger.log(Level.INFO, "Expected exception setting NASD LifeCycle ... ignoring", ie);
} catch (Exception e) {
e.printStackTrace();
throw new TestException("Unexpected exception: " + e);
}
try {
nasdWithoutExtras_r.create(EmptyConfiguration.INSTANCE); //Recovered descriptor
} catch (Exception e) {
logger.log(Level.INFO, "exception creating recovered NASD ... ignoring", e);
}
try {
nasdWithoutExtras_r.setLifeCycle(lc);
} catch (IllegalStateException ie) {
logger.log(Level.INFO, "Expected exception setting recovered NASD LifeCycle ... ignoring", ie);
} catch (Exception e) {
e.printStackTrace();
throw new TestException("Unexpected exception: " + e);
}
//Do some negative tests - Ensure bad descriptor doesn't match
SharedActivatableServiceDescriptor bogus_sasd =
new SharedActivatableServiceDescriptor(
sasd.getExportCodebase(),
sasd.getPolicy(),
sasd.getImportCodebase(),
sasd.getImplClassName(),
sasd.getSharedGroupLog() + "_bogus",
sasd.getServerConfigArgs(),
sasd.getRestart());
if (verifySharedActivatableServiceDescriptors(bogus_sasd, sasd)) {
throw new TestException("Bogus SASD passed verification");
}
//Do some negative tests - Ensure setLifeCycle can't be called after creation
try {
sasd.create(EmptyConfiguration.INSTANCE); //Original descriptor
} catch (Exception e) {
logger.log(Level.INFO, "exception creating SASD ... ignoring", e);
}
try {
sasd.setLifeCycle(lc);
} catch (IllegalStateException ie) {
logger.log(Level.INFO, "Expected exception setting SASD LifeCycle ... ignoring", ie);
} catch (Exception e) {
e.printStackTrace();
throw new TestException("Unexpected exception: " + e);
}
try {
sasd_r.create(EmptyConfiguration.INSTANCE); //Recovered descriptor
} catch (Exception e) {
logger.log(Level.INFO, "exception creating recovered SASD ... ignoring", e);
}
try {
sasd_r.setLifeCycle(lc);
} catch (IllegalStateException ie) {
logger.log(Level.INFO, "Expected exception setting recovered SASD LifeCycle ... ignoring", ie);
} catch (Exception e) {
e.printStackTrace();
throw new TestException("Unexpected exception: " + e);
}
SharedActivationGroupDescriptor bogus_sharedvm =
new SharedActivationGroupDescriptor(
sharedvm.getPolicy(),
sharedvm.getClasspath(),
sharedvm.getLog() + "_bogus",
sharedvm.getServerCommand(),
sharedvm.getServerOptions(),