}
private void run(ORB orb, POA root)
{
org.omg.CORBA.Object obj;
POA system;
POA nonretain;
POA multiple;
POA ether;
byte[] id1;
byte[] id2;
byte[] id3;
Policy[] policies;
Test_impl servant1;
Test_impl servant2;
Servant tmpserv;
POAManager manager = root.the_POAManager();
try
{
manager.activate();
}
catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
//
// Create POAs
//
policies = new Policy[ 3 ];
policies [ 0 ] =
root.create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.SYSTEM_ID);
policies [ 1 ] =
root.create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.UNIQUE_ID);
policies [ 2 ] =
root.create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN);
try
{
system = root.create_POA("system_id", manager, policies);
}
catch (AdapterAlreadyExists ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (InvalidPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
policies = new Policy[ 5 ];
policies [ 0 ] =
root.create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID);
policies [ 1 ] =
root.create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID);
policies [ 2 ] =
root.create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.NON_RETAIN);
policies [ 3 ] =
root.create_request_processing_policy(org.omg.PortableServer.RequestProcessingPolicyValue.USE_DEFAULT_SERVANT);
policies [ 4 ] =
root.create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION);
try
{
nonretain = root.create_POA("nonretain", manager, policies);
}
catch (AdapterAlreadyExists ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (InvalidPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
policies = new Policy[ 3 ];
policies [ 0 ] =
root.create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.SYSTEM_ID);
policies [ 1 ] =
root.create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID);
policies [ 2 ] =
root.create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN);
try
{
multiple = root.create_POA("multiple_id", manager, policies);
}
catch (AdapterAlreadyExists ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (InvalidPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
policies = new Policy[ 3 ];
policies [ 0 ] =
root.create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.SYSTEM_ID);
policies [ 1 ] =
root.create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID);
policies [ 2 ] =
root.create_request_processing_policy(org.omg.PortableServer.RequestProcessingPolicyValue.USE_SERVANT_MANAGER);
try
{
ether = root.create_POA("ether", manager, policies);
}
catch (AdapterAlreadyExists ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (InvalidPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
TestActivator_impl activatorImpl = new TestActivator_impl();
ServantActivator activator = activatorImpl._this(orb);
//
// Start tests
//
try
{
ether.set_servant_manager(activator);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
servant1 = new Test_impl(orb, "obj1", false);
servant2 = new Test_impl(orb, "obj2", false);
//
// Test: activate_object w/ SYSTEM_ID POA
//
try
{
id1 = system.activate_object(servant1);
id2 = system.activate_object(servant2);
}
catch (ServantAlreadyActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
TEST(!TestUtil.Compare(id1, id2));
try
{
tmpserv = system.id_to_servant(id1);
}
catch (ObjectNotActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
TEST(tmpserv == servant1);
try
{
tmpserv = system.id_to_servant(id2);
}
catch (ObjectNotActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
TEST(tmpserv == servant2);
//
// Test: ServantAlreadyActive exception
//
try
{
system.activate_object(servant1);
TEST(false); // activate_object should not have succeeded
}
catch (ServantAlreadyActive ex)
{
// expected
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
try
{
system.activate_object(servant2);
TEST(false); // activate_object should not have succeeded
}
catch (ServantAlreadyActive ex)
{
// expected
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
//
// Test: deactivate_object
//
try
{
system.deactivate_object(id2);
system.deactivate_object(id1);
}
catch (ObjectNotActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
//
// Test: ObjectNotActive exception
//
try
{
system.deactivate_object(id1);
TEST(false); // deactivate_object should not have succeeded
}
catch (ObjectNotActive ex)
{
// expected
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
try
{
system.deactivate_object(id2);
TEST(false); // deactivate_object should not have succeeded
}
catch (ObjectNotActive ex)
{
// expected
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
//
// Test: WrongPolicy exception
//
try
{
nonretain.activate_object(servant1);
TEST(false); // activate_object should not have succeeded
}
catch (WrongPolicy ex)
{
// expected
}
catch (ServantAlreadyActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
try
{
byte[] id = ("XXX").getBytes();
nonretain.activate_object_with_id(id, servant1);
TEST(false); // activate_object_with_id should not have succeeded
}
catch (WrongPolicy ex)
{
// expected
}
catch (ServantAlreadyActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (ObjectAlreadyActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
try
{
byte[] id = ("XXX").getBytes();
nonretain.deactivate_object(id);
TEST(false); // deactivate_object should not have succeeded
}
catch (ObjectNotActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (WrongPolicy ex)
{
// expected
}
//
// Test: activate_object w/ MULTIPLE_ID POA
//
try
{
id1 = multiple.activate_object(servant1);
id2 = multiple.activate_object(servant1);
}
catch (ServantAlreadyActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
TEST(!TestUtil.Compare(id1, id2));
try
{
tmpserv = multiple.id_to_servant(id1);
}
catch (ObjectNotActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
TEST(tmpserv == servant1);
try
{
tmpserv = multiple.id_to_servant(id2);
}
catch (ObjectNotActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
TEST(tmpserv == servant1);
//
// Test: confirm servant1 is no longer active
//
try
{
multiple.deactivate_object(id1);
multiple.deactivate_object(id2);
}
catch (ObjectNotActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
try
{
multiple.id_to_servant(id1);
}
catch (ObjectNotActive ex)
{
// expected
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
try
{
multiple.id_to_servant(id2);
}
catch (ObjectNotActive ex)
{
// expected
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
//
// Test: confirm ServantActivator::etherealize is invoked on
// deactivate
//
try
{
id1 = ether.activate_object(servant1);
id2 = ether.activate_object(servant1);
id3 = ether.activate_object(servant2);
}
catch (ServantAlreadyActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
activatorImpl.expect(id1, ether, servant1, true);
try
{
ether.deactivate_object(id1);
}
catch (ObjectNotActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
TEST(activatorImpl.isValid(), regression_note);
activatorImpl.expect(id2, ether, servant1, false);
try
{
ether.deactivate_object(id2);
}
catch (ObjectNotActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
TEST(activatorImpl.isValid(), regression_note);
activatorImpl.expect(id3, ether, servant2, false);
try
{
ether.deactivate_object(id3);
}
catch (ObjectNotActive ex)
{
fail(ex);
throw new RuntimeException(ex);
}
catch (WrongPolicy ex)
{
fail(ex);
throw new RuntimeException(ex);
}
TEST(activatorImpl.isValid(), "Regression in 1.5");
system.destroy(true, true);
nonretain.destroy(true, true);
multiple.destroy(true, true);
ether.destroy(true, true);
//
// Since activatorImpl is a stack-based servant, we need to deactivate
// it before it goes out of scope
//