diff --git a/RMI_Demo/finish/build.gradle b/RMI_Demo/finish/build.gradle index e18d74dc1..222fa4df1 100644 --- a/RMI_Demo/finish/build.gradle +++ b/RMI_Demo/finish/build.gradle @@ -16,9 +16,9 @@ repositories { dependencies { testImplementation 'org.apache.yoko:yoko-testify:1.5.0.9cce293956' - testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2' + testImplementation 'org.junit.jupiter:junit-jupiter:5.9.0' testRuntimeOnly 'org.junit.platform:junit-platform-runner:1.8.2' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0' } test { diff --git a/RMI_Demo/start/build.gradle b/RMI_Demo/start/build.gradle index aef603f3e..c56669ba1 100644 --- a/RMI_Demo/start/build.gradle +++ b/RMI_Demo/start/build.gradle @@ -15,9 +15,9 @@ repositories { } dependencies { - testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2' + testImplementation 'org.junit.jupiter:junit-jupiter:5.9.0' testRuntimeOnly 'org.junit.platform:junit-platform-runner:1.8.2' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0' } test { diff --git a/build.gradle b/build.gradle index 63bb55dac..1d1f842db 100644 --- a/build.gradle +++ b/build.gradle @@ -74,10 +74,11 @@ subprojects { sp -> testLib 'org.mockito:mockito-core:2.22.0' testLib 'org.mockito:mockito-junit-jupiter:2.22.0' testLib "org.hamcrest:hamcrest:2.1" - testLib "org.junit.jupiter:junit-jupiter:5.8.2" + testLib "org.junit.jupiter:junit-jupiter:5.9.0" testLib "org.junit.platform:junit-platform-runner:1.8.2" - testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.8.2" - testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.8.2" + testLib "org.junit-pioneer:junit-pioneer:1.9.1" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.9.0" + testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.9.0" } if (JavaVersion.current() < JavaVersion.VERSION_11) { diff --git a/testify-iiop/build.gradle b/testify-iiop/build.gradle index 7cbb91f6e..5d80407d7 100644 --- a/testify-iiop/build.gradle +++ b/testify-iiop/build.gradle @@ -1,7 +1,7 @@ dependencies { implementation 'junit:junit:4.12' implementation "org.hamcrest:hamcrest:2.1" - implementation "org.junit.jupiter:junit-jupiter:5.8.2" + implementation "org.junit.jupiter:junit-jupiter:5.9.0" implementation project(':yoko-spec-corba') implementation project(':yoko-rmi-spec') implementation project(":yoko-core") diff --git a/testify/build.gradle b/testify/build.gradle index ad058b0bd..2042d3f42 100644 --- a/testify/build.gradle +++ b/testify/build.gradle @@ -1,4 +1,4 @@ dependencies { implementation "org.hamcrest:hamcrest:2.1" - implementation "org.junit.jupiter:junit-jupiter:5.8.2" + implementation "org.junit.jupiter:junit-jupiter:5.9.0" } diff --git a/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/PolicyValue.java b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/PolicyValue.java new file mode 100644 index 000000000..b0ffc6aad --- /dev/null +++ b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/PolicyValue.java @@ -0,0 +1,61 @@ +/* + * Copyright 2023 IBM Corporation and others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an \"AS IS\" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.apache.yoko.orb.PortableServer; + +import org.omg.CORBA.Policy; +import org.omg.PortableServer.IdAssignmentPolicyValue; +import org.omg.PortableServer.IdUniquenessPolicyValue; +import org.omg.PortableServer.ImplicitActivationPolicyValue; +import org.omg.PortableServer.LifespanPolicyValue; +import org.omg.PortableServer.POA; +import org.omg.PortableServer.POAManager; +import org.omg.PortableServer.POAPackage.AdapterAlreadyExists; +import org.omg.PortableServer.POAPackage.InvalidPolicy; +import org.omg.PortableServer.RequestProcessingPolicyValue; +import org.omg.PortableServer.ServantRetentionPolicyValue; + +import java.util.function.Function; +import java.util.stream.Stream; + +public enum PolicyValue { + UNIQUE_ID(poa -> poa.create_id_uniqueness_policy(IdUniquenessPolicyValue.UNIQUE_ID)), + MULTIPLE_ID(poa -> poa.create_id_uniqueness_policy(IdUniquenessPolicyValue.MULTIPLE_ID)), + RETAIN(poa -> poa.create_servant_retention_policy(ServantRetentionPolicyValue.RETAIN)), + NON_RETAIN(poa -> poa.create_servant_retention_policy(ServantRetentionPolicyValue.NON_RETAIN)), + NO_IMPLICIT_ACTIVATION(poa -> poa.create_implicit_activation_policy(ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION)), + IMPLICIT_ACTIVATION(poa -> poa.create_implicit_activation_policy(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION)), + USER_ID(poa -> poa.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID)), + SYSTEM_ID(poa -> poa.create_id_assignment_policy(IdAssignmentPolicyValue.SYSTEM_ID)), + PERSISTENT(poa -> poa.create_lifespan_policy(LifespanPolicyValue.PERSISTENT)), + USE_DEFAULT_SERVANT(poa -> poa.create_request_processing_policy(RequestProcessingPolicyValue.USE_DEFAULT_SERVANT)), + USE_SERVANT_MANAGER(poa -> poa.create_request_processing_policy(RequestProcessingPolicyValue.USE_SERVANT_MANAGER)), + USE_ACTIVE_OBJECT_MAP_ONLY(poa -> poa.create_request_processing_policy(RequestProcessingPolicyValue.USE_ACTIVE_OBJECT_MAP_ONLY)); + + final Function factory; + + PolicyValue(Function factory) { + this.factory = factory; + } + + static POA create_POA(String id, POA parentPoa, POAManager poaMgr, PolicyValue...policies) throws InvalidPolicy, AdapterAlreadyExists { + Policy[] policyList = Stream.of(policies) + .map(policy -> policy.factory.apply(parentPoa)) + .toArray(Policy[]::new); + return parentPoa.create_POA(id, poaMgr, policyList); + } +} diff --git a/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaActivate.java b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaActivate.java index b1af210e7..65c08bd53 100644 --- a/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaActivate.java +++ b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaActivate.java @@ -52,7 +52,7 @@ public class TestPoaActivate { private static Test_impl servant2; @BeforeAll - private static void setup(ORB orb, POA rootPoa) throws Exception { + static void setup(ORB orb, POA rootPoa) throws Exception { rootPoa.the_POAManager().activate(); servant1 = new Test_impl(orb, "obj1", false); servant2 = new Test_impl(orb, "obj2", false); diff --git a/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaCollocated.java b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaCollocated.java new file mode 100644 index 000000000..39cb0e53b --- /dev/null +++ b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaCollocated.java @@ -0,0 +1,136 @@ +/* + * Copyright 2023 IBM Corporation and others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an \"AS IS\" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.apache.yoko.orb.PortableServer; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junitpioneer.jupiter.cartesian.CartesianTest; +import org.junitpioneer.jupiter.cartesian.CartesianTest.Enum; +import org.omg.CORBA.LocalObject; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Request; +import org.omg.PortableServer.ForwardRequest; +import org.omg.PortableServer.POA; +import org.omg.PortableServer.POAManager; +import org.omg.PortableServer.Servant; +import org.omg.PortableServer.ServantActivator; +import org.omg.PortableServer.ServantLocator; +import org.omg.PortableServer.ServantLocatorPackage.CookieHolder; +import test.poa.TestDSIRef_impl; +import test.poa.TestHelper; +import test.poa.Test_impl; +import testify.iiop.annotation.ConfigureOrb; + +import static org.apache.yoko.orb.PortableServer.PolicyValue.MULTIPLE_ID; +import static org.apache.yoko.orb.PortableServer.PolicyValue.NON_RETAIN; +import static org.apache.yoko.orb.PortableServer.PolicyValue.NO_IMPLICIT_ACTIVATION; +import static org.apache.yoko.orb.PortableServer.PolicyValue.PERSISTENT; +import static org.apache.yoko.orb.PortableServer.PolicyValue.RETAIN; +import static org.apache.yoko.orb.PortableServer.PolicyValue.UNIQUE_ID; +import static org.apache.yoko.orb.PortableServer.PolicyValue.USER_ID; +import static org.apache.yoko.orb.PortableServer.PolicyValue.USE_DEFAULT_SERVANT; +import static org.apache.yoko.orb.PortableServer.PolicyValue.USE_SERVANT_MANAGER; +import static org.apache.yoko.orb.PortableServer.PolicyValue.create_POA; + +@ConfigureOrb +public class TestPoaCollocated { + enum ConfigurePoa { + STATIC_DEFAULT_SERVANT (PERSISTENT, USER_ID, NON_RETAIN, NO_IMPLICIT_ACTIVATION, MULTIPLE_ID, USE_DEFAULT_SERVANT), + DYNAMIC_DEFAULT_SERVANT(PERSISTENT, USER_ID, NON_RETAIN, NO_IMPLICIT_ACTIVATION, MULTIPLE_ID, USE_DEFAULT_SERVANT), + SERVANT_LOCATOR (PERSISTENT, USER_ID, NON_RETAIN, NO_IMPLICIT_ACTIVATION, UNIQUE_ID, USE_SERVANT_MANAGER), + SERVANT_ACTIVATOR (PERSISTENT, USER_ID, RETAIN, NO_IMPLICIT_ACTIVATION, UNIQUE_ID, USE_SERVANT_MANAGER); + final PolicyValue[] policyValues; + ConfigurePoa(PolicyValue... policyValues) { this.policyValues = policyValues; } + + void configurePoa(TestPoaCollocated t) throws Exception { + t.poa = create_POA(name(), t.rootPoa, t.rootPoaManager, policyValues); + switch (this) { + case STATIC_DEFAULT_SERVANT: t.poa.set_servant(new Test_impl(t.orb, "defaultStaticServant", false)); return; + case DYNAMIC_DEFAULT_SERVANT: t.poa.set_servant(new TestDSIRef_impl(t.orb, "defaultDSIServant", false)); return; + case SERVANT_LOCATOR: t.poa.set_servant_manager(t.new TestLocator()); return; + case SERVANT_ACTIVATOR: t.poa.set_servant_manager(t.new TestActivator()); return; + } + } + } + enum ChooseTarget { STATIC_SERVANT, DYNAMIC_SERVANT } + enum InvokeMethod { + STATIC_INVOKE { + void invoke(POA poa, String id) { + TestHelper.narrow(poa.create_reference_with_id(id.getBytes(), "IDL:Test:1.0")).aMethod(); + } + }, + DYNAMIC_INVOKE { + void invoke(POA poa, String id) throws Exception { + org.omg.CORBA.Object object = poa.create_reference_with_id(id.getBytes(), "IDL:Test:1.0"); + Request request = object._request("aMethod"); + request.invoke(); // dynamic invocation + if (null != request.env().exception()) throw request.env().exception(); + } + }; + abstract void invoke(POA poa, String id) throws Exception ; + } + + ORB orb; + POA rootPoa; + POAManager rootPoaManager; + POA poa; + + @BeforeEach + void setup(ORB orb, POA rootPoa) { + this.orb = orb; + this.rootPoa = rootPoa; + this.rootPoaManager = rootPoa.the_POAManager(); + // this.poa is configured during each test + } + + @AfterEach + void destroyPoa() { poa.destroy(true, true); } + + @CartesianTest // runs every combination of the three enums + void test(@Enum ConfigurePoa poaConfig, @Enum ChooseTarget target, @Enum InvokeMethod invoker) throws Exception { + poaConfig.configurePoa(this); + invoker.invoke(this.poa, target.name()); + } + + final class TestActivator extends LocalObject implements ServantActivator { + public Servant incarnate(byte[] oid, POA poa) throws ForwardRequest { + switch (ChooseTarget.valueOf(new String(oid))) { + case STATIC_SERVANT: return new Test_impl(orb, "locator_SSI", false); + case DYNAMIC_SERVANT: return new TestDSIRef_impl(orb, "locator_DSI", false); + default: return null; // fail + } + } + + public void etherealize(byte[] oid, POA poa, Servant servant, boolean cleanup, boolean remaining) {} + } + + final class TestLocator extends LocalObject implements ServantLocator { + private final Test_impl test = new Test_impl(orb, "locator_SSI", false); + private final TestDSIRef_impl testDSI = new TestDSIRef_impl(orb, "locator_DSI", false); + + public Servant preinvoke(byte[] oid, POA poa, String operation, CookieHolder the_cookie) { + switch (ChooseTarget.valueOf(new String(oid))) { + case STATIC_SERVANT: return test; + case DYNAMIC_SERVANT: return testDSI; + default: return null; + } + } + + public void postinvoke(byte[] oid, POA poa, String operation, Object the_cookie, Servant the_servant) {} + } +} diff --git a/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaCreate.java b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaCreate.java new file mode 100644 index 000000000..61b8308e9 --- /dev/null +++ b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaCreate.java @@ -0,0 +1,93 @@ +/* + * Copyright 2023 IBM Corporation and others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an \"AS IS\" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.apache.yoko.orb.PortableServer; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.omg.CORBA.Policy; +import org.omg.PortableServer.POA; +import org.omg.PortableServer.POAManager; +import org.omg.PortableServer.POAManagerPackage.State; +import org.omg.PortableServer.POAPackage.AdapterAlreadyExists; +import org.omg.PortableServer.POAPackage.InvalidPolicy; +import testify.iiop.annotation.ConfigureOrb; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; +import static org.omg.PortableServer.ServantRetentionPolicyValue.NON_RETAIN; + +@ConfigureOrb +public class TestPoaCreate { + private static POAManager rootMgr; + + @BeforeAll + static void setup(POA rootPoa) { + rootMgr = rootPoa.the_POAManager(); + } + + @Test + public void testCreatePOA(POA rootPoa) throws Exception { + // Create child POA + POA poa = rootPoa.create_POA("poa1", null, new Policy[]{}); + + // Test: POAManager should NOT be the same as the root's manager + POAManager mgr = poa.the_POAManager(); + assertFalse(mgr._is_equivalent(rootMgr)); + + // Test: POAManager should be in HOLDING state + assertSame(mgr.get_state(), State.HOLDING); + + // Test: Confirm name + String poaName = poa.the_name(); + assertEquals("poa1", poaName); + + // Test: Confirm parent + POA parent = poa.the_parent(); + assertTrue(parent._is_equivalent(rootPoa)); + + assertThrows(AdapterAlreadyExists.class, () -> rootPoa.create_POA("poa1", null, new Policy[]{})); + + //In order to use the NON_RETAIN policy, you must first have a servant manager + Policy[] invalidPolicies = { rootPoa.create_servant_retention_policy(NON_RETAIN) }; + assertThrows(InvalidPolicy.class, () -> rootPoa.create_POA("invalid", null, invalidPolicies)); + + poa.destroy(true, true); + } + + @Test + void testCreateChildOfChildPoa(POA rootPoa) throws Exception{ + // Create another child of root POA + POA poa = rootPoa.create_POA("rootPoa", rootMgr, new Policy[]{}); + + // Test: POAManager should be the same as the root's manager + POAManager mgr = poa.the_POAManager(); + assertTrue(mgr._is_equivalent(rootMgr)); + + // Create child of child POA + POA poa3 = poa.create_POA("child", rootMgr, new Policy[]{}); + + // Test: Confirm parent + POA parent = poa3.the_parent(); + assertTrue(parent._is_equivalent(poa)); + + poa.destroy(true, true); + } +} diff --git a/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaDeactivate.java b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaDeactivate.java new file mode 100644 index 000000000..2ab5e95ae --- /dev/null +++ b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaDeactivate.java @@ -0,0 +1,108 @@ +/* + * Copyright 2023 IBM Corporation and others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an \"AS IS\" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.apache.yoko.orb.PortableServer; + +import org.junit.jupiter.api.Test; +import org.omg.CORBA.OBJECT_NOT_EXIST; +import org.omg.CORBA.ORB; +import org.omg.CORBA.SystemException; +import org.omg.PortableServer.POA; +import test.poa.TestPOA; +import testify.iiop.annotation.ConfigureOrb; + +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; + +@ConfigureOrb +public class TestPoaDeactivate { + @Test + void testDeactivate(ORB orb, POA rootPoa) throws Exception { + test.poa.Test_impl impl = new test.poa.Test_impl(orb, "", false); + test.poa.Test t = impl._this(orb); + t.aMethod(); + byte[] oid = rootPoa.servant_to_id(impl); + rootPoa.deactivate_object(oid); + assertThrows(OBJECT_NOT_EXIST.class, () -> t.aMethod()); + } + + // In this test we want to spawn a thread to call a method on the Test + // interface. This method call should take some time. While the thread + // is calling the method we attempt to deactivate the object. This + // should not complete for some time, since it should wait for all + // outstanding method calls to complete. + @Test + public void testDeactivateWaitsForMethodCallCompletion(ORB orb, POA rootPoa) throws Exception { + Test_impl1 impl = new Test_impl1(rootPoa); + test.poa.Test t = impl._this(orb); + byte[] oid = rootPoa.servant_to_id(impl); + Thread thr = new LongCaller(t); + thr.start(); + impl.blockUntilCalled(); + // Test: deactivate_object while method call is active + rootPoa.deactivate_object(oid); + // Once we've deactivated the object the re-activation shouldn't complete until the method call completes + rootPoa.activate_object_with_id(oid, impl); + // The destroy call shouldn't return until the aMethod call is complete + assertTrue(impl.callComplete()); + + // Wait for the thread to terminate + while (thr.isAlive()) { + try { + thr.join(); + } catch (InterruptedException ignored) { + } + } + rootPoa.deactivate_object(oid); + } + + final static class Test_impl1 extends TestPOA { + private final POA poa; + private boolean called = false; + private boolean finished = false; + Test_impl1(POA poa) { + this.poa = poa; + } + + synchronized public void aMethod() { + called = true; + notify(); + try { wait(1000); } catch (InterruptedException ignored) {} + finished = true; + } + + public POA _default_POA() { return poa; } + synchronized void blockUntilCalled() { + while (!called) { + try { wait(); } catch (InterruptedException ignored) {} + } + } + synchronized boolean callComplete() { return finished; } + } + + final static class LongCaller extends Thread { + private final test.poa.Test test; + LongCaller(test.poa.Test test) { this.test = test; } + public void run() { + try { + test.aMethod(); + } catch (SystemException ex) { + ex.printStackTrace(); + } + } + } +} diff --git a/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaDestroy.java b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaDestroy.java new file mode 100644 index 000000000..7a3f8673a --- /dev/null +++ b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaDestroy.java @@ -0,0 +1,134 @@ +/* + * Copyright 2023 IBM Corporation and others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an \"AS IS\" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.apache.yoko.orb.PortableServer; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Policy; +import org.omg.CORBA.SystemException; +import org.omg.PortableServer.POA; +import org.omg.PortableServer.POAManager; +import org.omg.PortableServer.POAPackage.AdapterNonExistent; +import test.poa.TestPOA; +import testify.iiop.annotation.ConfigureOrb; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; + + +@ConfigureOrb +public class TestPoaDestroy { + private static POAManager rootMgr; + + @BeforeAll + static void setup(POA rootPoa) throws Exception { + rootMgr = rootPoa.the_POAManager(); + } + + @Test + void testDestroyPoa(POA rootPoa) throws Exception { + assertNotNull(rootMgr); + POA poa = rootPoa.create_POA("poa1", rootMgr, new Policy[]{}); + poa.destroy(true, true); + // Ensure parent no longer knows about child + assertThrows(AdapterNonExistent.class, () -> rootPoa.find_POA("poa1", false)); + } + + @Test + void testDestroyPoaWithChild(ORB orb, POA rootPoa) throws Exception { + assertNotNull(rootMgr); + POA poa = rootPoa.create_POA("poa1", rootMgr, new Policy[]{}); + // Create child of child POA + poa.create_POA("child1", rootMgr, new Policy[]{}); + // Test: destroy - should destroy poa1 and poa1/child1 + poa.destroy(true, true); + // Ensure parent no longer knows about child + assertThrows(AdapterNonExistent.class, () -> rootPoa.find_POA("poa1", false)); + } + + @Test + void testDestroyWaitsForMethodCallCompletion(ORB orb, POA rootPoa) throws Exception { + assertNotNull(rootMgr); + + // Create child POA + POA poa1 = rootPoa.create_POA("poa1", rootMgr, new Policy[] { + rootPoa.create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION)}); + + Test_impl1 impl = new Test_impl1(poa1); + test.poa.Test t = impl._this(orb); + Thread thr = new LongCaller(t); + thr.start(); + impl.blockUntilCalled(); + + // Test: Destroy the POA while a method call is active + poa1.destroy(true, true); + + // The destroy call shouldn't return until the aMethod call is complete + assertTrue(impl.callComplete()); + + while (thr.isAlive()) { + try { thr.join(); } catch (InterruptedException ignored) {} + } + } + + final static class Test_impl1 extends TestPOA { + private final POA poa; + private boolean called = false; + private boolean finished = false; + Test_impl1(POA poa) { + this.poa = poa; + } + + synchronized public void aMethod() { + called = true; + notify(); + try { wait(1000); } catch (InterruptedException ignored) {} + finished = true; + } + + public POA _default_POA() { + return poa; + } + + synchronized void blockUntilCalled() { + while (!called) { + try { wait(); } catch (InterruptedException ignored) {} + } + } + synchronized boolean callComplete() { + return finished; + } + } + + final static class LongCaller extends Thread { + private final test.poa.Test t; + LongCaller(test.poa.Test t) { + this.t = t; + } + public void run() { + try { + t.aMethod(); + } catch (SystemException se) { + System.err.println(se.getMessage()); + se.printStackTrace(); + } + } + } +} diff --git a/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaFind.java b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaFind.java new file mode 100644 index 000000000..db0e42bed --- /dev/null +++ b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaFind.java @@ -0,0 +1,49 @@ +/* + * Copyright 2023 IBM Corporation and others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an \"AS IS\" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.apache.yoko.orb.PortableServer; + +import org.junit.jupiter.api.Test; +import org.omg.CORBA.Policy; +import org.omg.PortableServer.POA; +import org.omg.PortableServer.POAManager; +import org.omg.PortableServer.POAPackage.AdapterNonExistent; +import testify.iiop.annotation.ConfigureOrb; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; + +@ConfigureOrb +public class TestPoaFind { + @Test + void testFind(POA rootPoa) throws Exception { + POAManager rootMgr = rootPoa.the_POAManager(); + assertNotNull(rootMgr); + + // Create child POA + POA poa = rootPoa.create_POA("poa1", rootMgr, new Policy[]{}); + + // Test: find_POA + POA poa2 = rootPoa.find_POA("poa1", false); + assertNotNull(poa2); + assertTrue(poa2._is_equivalent(poa)); + + // Test: AdapterNonExistent exception + assertThrows(AdapterNonExistent.class, () -> rootPoa.find_POA("poaX", false)); + } +} diff --git a/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaMisc.java b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaMisc.java new file mode 100644 index 000000000..380edef29 --- /dev/null +++ b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaMisc.java @@ -0,0 +1,299 @@ +/* + * Copyright 2023 IBM Corporation and others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an \"AS IS\" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.apache.yoko.orb.PortableServer; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Object; +import org.omg.PortableServer.POA; +import org.omg.PortableServer.POAManager; +import org.omg.PortableServer.POAPackage.ObjectNotActive; +import org.omg.PortableServer.POAPackage.ServantNotActive; +import org.omg.PortableServer.POAPackage.WrongAdapter; +import org.omg.PortableServer.POAPackage.WrongPolicy; +import test.poa.Test_impl; +import testify.iiop.annotation.ConfigureOrb; +import testify.io.EasyCloseable; + +import java.util.Arrays; + +import static java.util.Objects.requireNonNull; +import static org.apache.yoko.orb.PortableServer.PolicyValue.IMPLICIT_ACTIVATION; +import static org.apache.yoko.orb.PortableServer.PolicyValue.MULTIPLE_ID; +import static org.apache.yoko.orb.PortableServer.PolicyValue.NO_IMPLICIT_ACTIVATION; +import static org.apache.yoko.orb.PortableServer.PolicyValue.PERSISTENT; +import static org.apache.yoko.orb.PortableServer.PolicyValue.RETAIN; +import static org.apache.yoko.orb.PortableServer.PolicyValue.SYSTEM_ID; +import static org.apache.yoko.orb.PortableServer.PolicyValue.UNIQUE_ID; +import static org.apache.yoko.orb.PortableServer.PolicyValue.USER_ID; +import static org.apache.yoko.orb.PortableServer.PolicyValue.USE_DEFAULT_SERVANT; +import static org.apache.yoko.orb.PortableServer.PolicyValue.create_POA; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@ConfigureOrb +public class TestPoaMisc { + static ORB orb; + static POA rootPoa; + static POA childPoa; + static Test_impl servant1; + static Test_impl servant2; + static Test_impl defaultServant; + + enum PoaChoice { + ROOT_POA, CHILD_POA; + POA poa() { return this == ROOT_POA ? rootPoa : childPoa; } + } + + interface Cleanup extends EasyCloseable {} // use this to register try-with-resources + + @BeforeAll + static void setup(ORB orb, POA rootPoa) throws Exception { + TestPoaMisc.orb = orb; + TestPoaMisc.rootPoa = rootPoa; + TestPoaMisc.childPoa = create_POA("child", rootPoa, rootPoa.the_POAManager()); + TestPoaMisc.servant1 = new Test_impl(orb, "test1", false); + TestPoaMisc.servant2 = new Test_impl(orb, "test2", false); + TestPoaMisc.defaultServant = new Test_impl(orb, "default", false); + + } + + @ParameterizedTest @EnumSource(PoaChoice.class) + void testCreateReferenceSystem(PoaChoice which) throws Exception { + POA poa = which.poa(); + POAManager manager = poa.the_POAManager(); + POA system = create_POA("system_id", poa, manager, SYSTEM_ID); + + try (Cleanup x = () -> system.destroy(true, true)) { + // Test: create_reference - should get a new ID for each invocation on POA w/ SYSTEM_ID policy + final byte[] id1 = system.reference_to_id(requireNonNull(system.create_reference("IDL:Test:1.0"))); + final byte[] id2 = system.reference_to_id(requireNonNull(system.create_reference("IDL:Test:1.0"))); + assertFalse(Arrays.equals(id1, id2)); + // Test: create_reference_with_id using a system-generated ID + system.create_reference_with_id(id1, "IDL:Test:1.0"); + // Test: create_reference_with_id using a user-supplied ID + assertThrows(BAD_PARAM.class, () -> system.create_reference_with_id(("id1").getBytes(), "IDL:Test:1.0")); + } + } + + @ParameterizedTest @EnumSource(PoaChoice.class) + void testCreateReferenceUser(PoaChoice which) throws Exception { + POA poa = which.poa(); + POAManager manager = poa.the_POAManager(); + POA user = create_POA("user_id", poa, manager, USER_ID); + try (Cleanup x = () -> user.destroy(true, true)) { + assertThrows(WrongPolicy.class, () -> user.create_reference("IDL:Test:1.0")); + // Test: create_reference_with_id + assertArrayEquals(("id1").getBytes(), user.reference_to_id(requireNonNull(user.create_reference_with_id(("id1").getBytes(), "IDL:Test:1.0")))); + assertArrayEquals(("id2").getBytes(), user.reference_to_id(requireNonNull(user.create_reference_with_id(("id2").getBytes(), "IDL:Test:1.0")))); + } + } + + @ParameterizedTest @EnumSource(PoaChoice.class) + void testServantToIdUnique(PoaChoice which) throws Exception { + POA poa = which.poa(); + POAManager manager = poa.the_POAManager(); + POA unique = create_POA("unique_id", poa, manager, UNIQUE_ID, USER_ID, RETAIN, NO_IMPLICIT_ACTIVATION); + try (Cleanup x = () -> unique.destroy(true, true)) { + assertThrows(ServantNotActive.class, () -> unique.servant_to_id(servant1)); + unique.activate_object_with_id("test1".getBytes(), servant1); + // Test: servant_to_id (UNIQUE_ID policy) + assertArrayEquals("test1".getBytes(), unique.servant_to_id(servant1)); + } + } + + @ParameterizedTest @EnumSource(PoaChoice.class) + void testServantToIdImplicit(PoaChoice which) throws Exception { + POA poa = which.poa(); + POAManager manager = poa.the_POAManager(); + POA implicit = create_POA("implicit", poa, manager, UNIQUE_ID, RETAIN, IMPLICIT_ACTIVATION); + try (Cleanup x = () -> implicit.destroy(true, true)) { + // Test: servant_to_id (IMPLICIT_ACTIVATION) - servant1 should be automatically activated + final byte[] implicitId = implicit.servant_to_id(servant1); + // Test: Now that servant1 is activated, and since we have UNIQUE_ID, we should get the same ID back + assertArrayEquals(implicitId, implicit.servant_to_id(servant1)); + // Test: Implicitly activating servant2 should produce a new ID + assertFalse(Arrays.equals(implicitId, implicit.servant_to_id(servant2))); + } + } + + @ParameterizedTest @EnumSource(PoaChoice.class) + void testServantToIdMultiple(PoaChoice which) throws Exception { + POA poa = which.poa(); + POAManager manager = poa.the_POAManager(); + POA multiple = create_POA("multiple", poa, manager, MULTIPLE_ID, RETAIN, IMPLICIT_ACTIVATION); + try (Cleanup x = () -> multiple.destroy(true, true)) { + // Test: servant_to_id (IMPLICIT_ACTIVATION, MULTIPLE_ID) - servant1 should be automatically activated + final byte[] multipleId1 = multiple.servant_to_id(servant1); + // Test: Since we have MULTIPLE_ID, we should get a new ID + assertFalse(Arrays.equals(multipleId1, multiple.servant_to_id(servant1))); + } + } + + @ParameterizedTest @EnumSource(PoaChoice.class) + void testServantToReferenceUnique(PoaChoice which) throws Exception { + POA poa = which.poa(); + POAManager manager = poa.the_POAManager(); + POA unique = create_POA("unique_id", poa, manager, UNIQUE_ID, USER_ID, RETAIN, NO_IMPLICIT_ACTIVATION); + try (Cleanup x = () -> unique.destroy(true, true)) { + assertThrows(ServantNotActive.class, () -> unique.servant_to_reference(servant1)); + unique.activate_object_with_id("test1".getBytes(), servant1); + assertArrayEquals("test1".getBytes(), unique.reference_to_id(requireNonNull(unique.servant_to_reference(servant1)))); + } + } + + @ParameterizedTest @EnumSource(PoaChoice.class) + void testServantToReferenceImplicit(PoaChoice which) throws Exception { + POA poa = which.poa(); + POAManager manager = poa.the_POAManager(); + POA implicit = create_POA("implicit", poa, manager, UNIQUE_ID, RETAIN, IMPLICIT_ACTIVATION); + try (Cleanup x = () -> implicit.destroy(true, true)) { + // Test: servant_to_reference (IMPLICIT_ACTIVATION) - servant1 should be automatically activated + byte[] serv1_id = implicit.reference_to_id(requireNonNull(implicit.servant_to_reference(servant1))); + // Test: Now that servant1 is activated, and since we have UNIQUE_ID, we should get the same ID back + byte[] serv1_id_again = implicit.reference_to_id(requireNonNull(implicit.servant_to_reference(servant1))); + assertArrayEquals(serv1_id, serv1_id_again); + // Test: Implicitly activating servant2 should produce a new ID + byte[] serv2_id = implicit.reference_to_id(requireNonNull(implicit.servant_to_reference(servant2))); + assertFalse(Arrays.equals(serv1_id, serv2_id)); + } + } + + @ParameterizedTest @EnumSource(PoaChoice.class) + void testServantToReferenceMultiple(PoaChoice which) throws Exception { + POA poa = which.poa(); + POAManager manager = poa.the_POAManager(); + POA multiple = create_POA("multiple", poa, manager, MULTIPLE_ID, RETAIN, IMPLICIT_ACTIVATION); + try (Cleanup x = () -> multiple.destroy(true, true)) { + // Test: servant_to_reference (IMPLICIT_ACTIVATION, MULTIPLE_ID) - servant1 should be automatically activated + byte[] id1 = multiple.reference_to_id(requireNonNull(multiple.servant_to_reference(servant1))); + // Test: Since we have MULTIPLE_ID, we should get a new ID + byte[] id2 = multiple.reference_to_id(requireNonNull(multiple.servant_to_reference(servant1))); + assertFalse(Arrays.equals(id1, id2)); + } + } + + @ParameterizedTest @EnumSource(PoaChoice.class) + void testIdToServantRetain(PoaChoice which) throws Exception { + POA poa = which.poa(); + POAManager manager = poa.the_POAManager(); + POA retain = create_POA("retain", poa, manager, RETAIN, PERSISTENT, USER_ID); + try (Cleanup x = () -> retain.destroy(true, true)) { + assertThrows(ObjectNotActive.class, () -> retain.id_to_servant("bad_id".getBytes())); + + retain.activate_object_with_id("test1".getBytes(), servant1); + retain.activate_object_with_id("test2".getBytes(), servant2); + + // Test: servant_to_id (RETAIN policy) + assertSame(servant1, retain.id_to_servant("test1".getBytes())); + assertSame(servant2, retain.id_to_servant("test2".getBytes())); + } + } + + @ParameterizedTest @EnumSource(PoaChoice.class) + void testIdToServantDefault(PoaChoice which) throws Exception { + POA poa = which.poa(); + POAManager manager = poa.the_POAManager(); + POA defaultPOA = create_POA("default", poa, manager, MULTIPLE_ID, RETAIN, USE_DEFAULT_SERVANT, PERSISTENT, USER_ID); + try (Cleanup y = () -> defaultPOA.destroy(true, true)) { + defaultPOA.set_servant(defaultServant); + // Test: id_to_servant (USE_DEFAULT_SERVANT) + defaultPOA.activate_object_with_id("test1".getBytes(), servant1); + defaultPOA.activate_object_with_id("test2".getBytes(), servant2); + assertSame(servant1, defaultPOA.id_to_servant("test1".getBytes())); + assertSame(servant2, defaultPOA.id_to_servant("test2".getBytes())); + // Test: id_to_servant (USE_DEFAULT_SERVANT) - should return default servant for all unknown IDs + assertSame(defaultPOA.id_to_servant(("test99").getBytes()), defaultServant); + } + } + + @ParameterizedTest @EnumSource(PoaChoice.class) + void testIdToReference(PoaChoice which) throws Exception { + POA poa = which.poa(); + POAManager manager = poa.the_POAManager(); + POA retain = create_POA("retain", poa, manager, RETAIN, PERSISTENT, USER_ID); + try (Cleanup x = () -> retain.destroy(true, true)) { + assertThrows(ObjectNotActive.class, () -> retain.id_to_reference("bad_id".getBytes())); + + retain.activate_object_with_id("test1".getBytes(), servant1); + retain.activate_object_with_id("test2".getBytes(), servant2); + + assertArrayEquals("test1".getBytes(), retain.reference_to_id(requireNonNull(retain.id_to_reference("test1".getBytes())))); + assertArrayEquals("test2".getBytes(), retain.reference_to_id(requireNonNull(retain.id_to_reference("test2".getBytes())))); + } + } + + @ParameterizedTest @EnumSource(PoaChoice.class) + void testReferenceToServantRetain(PoaChoice which) throws Exception { + POA poa = which.poa(); + POAManager manager = poa.the_POAManager(); + POA retain = create_POA("retain", poa, manager, RETAIN, PERSISTENT, USER_ID); + + try (Cleanup x = () -> retain.destroy(true, true)) { + org.omg.CORBA.Object badIdRef = retain.create_reference_with_id("bad_id".getBytes(), "IDL:Test:1.0"); + assertThrows(ObjectNotActive.class, () -> retain.reference_to_servant(badIdRef)); + + retain.activate_object_with_id("test1".getBytes(), servant1); + retain.activate_object_with_id("test2".getBytes(), servant2); + + assertSame(servant1, retain.reference_to_servant(retain.create_reference_with_id("test1".getBytes(), "IDL:Test:1.0"))); + assertSame(servant2, retain.reference_to_servant(retain.create_reference_with_id("test2".getBytes(), "IDL:Test:1.0"))); + } + } + + @ParameterizedTest @EnumSource(PoaChoice.class) + void testReferenceToServantDefault(PoaChoice which) throws Exception { + POA poa = which.poa(); + POAManager manager = poa.the_POAManager(); + + POA defaultPoa = create_POA("default", poa, manager, MULTIPLE_ID, RETAIN, USE_DEFAULT_SERVANT, PERSISTENT, USER_ID); + POA otherPoa = create_POA("retain", poa, manager, RETAIN, PERSISTENT, USER_ID); + + try (Cleanup x = () -> defaultPoa.destroy(true, true); + Cleanup y = () -> otherPoa.destroy(true, true)) { + defaultPoa.set_servant(defaultServant); + // create a reference using a different POA + Object ref = otherPoa.create_reference_with_id("test1".getBytes(), "IDL:Test:1.0"); + assertThrows(WrongAdapter.class, () -> defaultPoa.reference_to_servant(ref)); + + defaultPoa.activate_object_with_id("test1".getBytes(), servant1); + defaultPoa.activate_object_with_id("test2".getBytes(), servant2); + + assertSame(servant1, defaultPoa.reference_to_servant(defaultPoa.create_reference_with_id("test1".getBytes(), "IDL:Test:1.0"))); + assertSame(servant2, defaultPoa.reference_to_servant(defaultPoa.create_reference_with_id("test2".getBytes(), "IDL:Test:1.0"))); + assertSame(defaultServant, defaultPoa.reference_to_servant(defaultPoa.create_reference_with_id("test99".getBytes(), "IDL:Test:1.0"))); + } + } + + @ParameterizedTest @EnumSource(PoaChoice.class) + void testReferenceToId(PoaChoice which) throws Exception{ + POA parentPoa = which.poa(); + POAManager manager = parentPoa.the_POAManager(); + POA subPoa = create_POA("poa", parentPoa, manager, RETAIN, PERSISTENT, USER_ID); + try (Cleanup x = () -> subPoa.destroy(true, true)) { + assertArrayEquals(subPoa.reference_to_id(subPoa.create_reference_with_id("test1".getBytes(), "IDL:Test:1.0")), "test1".getBytes()); + assertArrayEquals(subPoa.reference_to_id(subPoa.create_reference_with_id("test2".getBytes(), "IDL:Test:1.0")), "test2".getBytes()); + assertThrows(WrongAdapter.class, () -> parentPoa.reference_to_id(subPoa.create_reference_with_id("test1".getBytes(), "IDL:Test:1.0"))); + } + } +} diff --git a/yoko-core/src/test/java/org/apache/yoko/PoaTest.java b/yoko-core/src/test/java/org/apache/yoko/PoaTest.java index 62ab15af8..0a8951607 100644 --- a/yoko-core/src/test/java/org/apache/yoko/PoaTest.java +++ b/yoko-core/src/test/java/org/apache/yoko/PoaTest.java @@ -19,17 +19,11 @@ import test.poa.TestAdapterActivatorServer; import test.poa.TestClient; -import test.poa.TestCollocated; -import test.poa.TestCreate; -import test.poa.TestDeactivate; import test.poa.TestDefaultServantServer; -import test.poa.TestDestroy; import test.poa.TestDispatchStrategyClient; import test.poa.TestDispatchStrategyServer; -import test.poa.TestFind; import test.poa.TestLocationForwardClient; import test.poa.TestLocationForwardServerMain; -import test.poa.TestMisc; import test.poa.TestMultipleOrbsClient; import test.poa.TestMultipleOrbsServer; import test.poa.TestMultipleOrbsThreadedClient; @@ -46,30 +40,6 @@ public void setUp() throws Exception { setWaitForFile("Test.ref"); } - public void testDeactivate() throws Exception { - client.invokeMain(TestDeactivate.class); - } - - public void testCollocated() throws Exception { - client.invokeMain(TestCollocated.class); - } - - public void testCreate() throws Exception { - client.invokeMain(TestCreate.class); - } - - public void testDestroy() throws Exception { - client.invokeMain(TestDestroy.class); - } - - public void testFind() throws Exception { - client.invokeMain(TestFind.class); - } - - public void testMisc() throws Exception { - client.invokeMain(TestMisc.class); - } - public void testDefaultServant() throws Exception { runServerClientTest(TestDefaultServantServer.class); } diff --git a/yoko-core/src/test/java/test/poa/TestCollocated.java b/yoko-core/src/test/java/test/poa/TestCollocated.java deleted file mode 100644 index 7f06d9ab5..000000000 --- a/yoko-core/src/test/java/test/poa/TestCollocated.java +++ /dev/null @@ -1,404 +0,0 @@ -/* - * Copyright 2015 IBM Corporation and others. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an \"AS IS\" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package test.poa; - -import static org.junit.Assert.assertTrue; - -import java.util.Properties; - -import org.omg.CORBA.*; -import org.omg.PortableServer.*; -import org.omg.PortableServer.POAPackage.*; -import org.omg.PortableServer.ServantLocatorPackage.*; - -public final class TestCollocated extends test.common.TestBase { - final static class TestLocator_impl extends ServantLocatorPOA { - private ORB orb_; - - private Test_impl test_; - - private TestDSIRef_impl testDSI_; - - TestLocator_impl(ORB orb) { - orb_ = orb; - - test_ = new Test_impl(orb, "locator_SSI", false); - testDSI_ = new TestDSIRef_impl(orb, "locator_DSI", false); - } - - public Servant preinvoke(byte[] oid, POA poa, String operation, - CookieHolder the_cookie) throws ForwardRequest { - String oidString = new String(oid); - - if (oidString.equals("test")) - return test_; - else if (oidString.equals("testDSI")) - return testDSI_; - return null; - } - - public void postinvoke(byte[] oid, POA poa, String operation, - java.lang.Object the_cookie, Servant the_servant) { - } - } - - final static class TestActivator_impl extends ServantActivatorPOA { - private ORB orb_; - - private Test_impl test_; - - private TestDSIRef_impl testDSI_; - - TestActivator_impl(ORB orb) { - orb_ = orb; - - test_ = new Test_impl(orb, "locator_SSI", false); - testDSI_ = new TestDSIRef_impl(orb, "locator_DSI", false); - } - - public Servant incarnate(byte[] oid, POA poa) throws ForwardRequest { - String oidString = new String(oid); - - if (oidString.equals("test")) - return test_; - else if (oidString.equals("testDSI")) - return testDSI_; - - // - // Fail - // - return null; - } - - public void etherealize(byte[] oid, POA poa, Servant servant, - boolean cleanup, boolean remaining) { - String oidString = new String(oid); - - if (!remaining) { - if (oidString.equals("test")) { - servant = null; - test_ = null; - } else if (oidString.equals("testDSI")) { - testDSI_ = null; - } - } - } - } - - static void TestPOA(POA poa) { - byte[] id; - org.omg.CORBA.Object obj; - Request request; - Test test; - - // - // Invoke twice on each object - statically & DII - // - id = ("test").getBytes(); - obj = poa.create_reference_with_id(id, "IDL:Test:1.0"); - test = TestHelper.narrow(obj); - test.aMethod(); - request = obj._request("aMethod"); - request.invoke(); - assertTrue(request.env().exception() == null); - - id = ("testDSI").getBytes(); - obj = poa.create_reference_with_id(id, "IDL:Test:1.0"); - test = TestHelper.narrow(obj); - test.aMethod(); - request = obj._request("aMethod"); - request.invoke(); - assertTrue(request.env().exception() == null); - } - - static void TestDefaultServant(ORB orb, POA root, POAManager manager) { - POA poa; - Servant servant; - Policy[] policies; - - // - // Setup policies for default servant - // - policies = new Policy[6]; - policies[0] = root - .create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.PERSISTENT); - policies[1] = root - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); - policies[2] = root - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.NON_RETAIN); - policies[3] = root - .create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION); - policies[4] = root - .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID); - policies[5] = root - .create_request_processing_policy(org.omg.PortableServer.RequestProcessingPolicyValue.USE_DEFAULT_SERVANT); - - // - // Create POA w/ static Default Servant - // - try { - poa = root.create_POA("defaultSSI", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - Test_impl staticServant = new Test_impl(orb, "defaultStaticServant", - false); - try { - poa.set_servant(staticServant); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - TestPOA(poa); - poa.destroy(true, true); - - // - // Since staticServant is a stack-based servant, we need to deactivate - // it before it goes out of scope - // - byte[] id = null; - try { - id = root.servant_to_id(staticServant); - } catch (ServantNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - try { - root.deactivate_object(id); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - // - // Create POA w/ DSI Default Servant - // - try { - poa = root.create_POA("defaultDSI", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - servant = new TestDSIRef_impl(orb, "defaultDSIServant", false); - try { - poa.set_servant(servant); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - TestPOA(poa); - poa.destroy(true, true); - servant = null; - - // - // Clean up policies - // - for (int i = 0; i < policies.length; i++) - policies[i].destroy(); - } - - static void TestServantLocator(ORB orb, POA root, POAManager manager) { - POA poa; - Servant servant; - Policy[] policies; - - // - // Setup policies for servant locator - // - policies = new Policy[6]; - policies[0] = root - .create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.PERSISTENT); - policies[1] = root - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); - policies[2] = root - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.NON_RETAIN); - policies[3] = root - .create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION); - policies[4] = root - .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.UNIQUE_ID); - policies[5] = root - .create_request_processing_policy(org.omg.PortableServer.RequestProcessingPolicyValue.USE_SERVANT_MANAGER); - - // - // Create POA w/ Servant Locator - // - try { - poa = root.create_POA("servloc", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - TestLocator_impl locatorImpl = new TestLocator_impl(orb); - ServantLocator locator = locatorImpl._this(orb); - try { - poa.set_servant_manager(locator); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - TestPOA(poa); - poa.destroy(true, true); - - // - // Clean up policies - // - for (int i = 0; i < policies.length; i++) - policies[i].destroy(); - - // - // Since locatorImpl is a stack-based servant, we need to deactivate - // it before it goes out of scope - // - byte[] id = null; - try { - id = root.servant_to_id(locatorImpl); - } catch (ServantNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - try { - root.deactivate_object(id); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - } - - static void TestServantActivator(ORB orb, POA root, POAManager manager) { - POA poa; - Servant servant; - Policy[] policies; - - // - // Setup policies for servant activator - // - policies = new Policy[6]; - policies[0] = root - .create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.PERSISTENT); - policies[1] = root - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); - policies[2] = root - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN); - policies[3] = root - .create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION); - policies[4] = root - .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.UNIQUE_ID); - policies[5] = root - .create_request_processing_policy(org.omg.PortableServer.RequestProcessingPolicyValue.USE_SERVANT_MANAGER); - - // - // Create POA w/ Servant Activator - // - try { - poa = root.create_POA("servant", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - TestActivator_impl activatorImpl = new TestActivator_impl(orb); - ServantActivator activator = activatorImpl._this(orb); - try { - poa.set_servant_manager(activator); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - TestPOA(poa); - poa.destroy(true, true); - - // - // Clean up policies - // - for (int i = 0; i < policies.length; i++) - policies[i].destroy(); - - // - // Since activatorImpl is a stack-based servant, we need to deactivate - // it before it goes out of scope - // - byte[] id = null; - try { - id = root.servant_to_id(activatorImpl); - } catch (ServantNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - try { - root.deactivate_object(id); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - } - - public static void main(String[] args) { - java.util.Properties props = new Properties(); - props.putAll(System.getProperties()); - props.put("org.omg.CORBA.ORBClass", "org.apache.yoko.orb.CORBA.ORB"); - props.put("org.omg.CORBA.ORBSingletonClass", - "org.apache.yoko.orb.CORBA.ORBSingleton"); - - ORB orb = null; - - try { - orb = ORB.init(args, props); - - POA root = TestUtil.GetRootPOA(orb); - POAManager manager = root.the_POAManager(); - try { - manager.activate(); - } catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive ex) { - throw new RuntimeException(); - } - - System.out.print("Testing collocated default servant... "); - System.out.flush(); - TestDefaultServant(orb, root, manager); - System.out.println("Done!"); - System.out.print("Testing collocated servant locator... "); - System.out.flush(); - TestServantLocator(orb, root, manager); - System.out.println("Done!"); - System.out.print("Testing collocated servant activator... "); - System.out.flush(); - TestServantActivator(orb, root, manager); - System.out.println("Done!"); - } catch (SystemException ex) { - ex.printStackTrace(); - System.exit(1); - } - - if (orb != null) { - try { - orb.destroy(); - } catch (SystemException ex) { - ex.printStackTrace(); - System.exit(1); - } - } - - System.exit(0); - } -} diff --git a/yoko-core/src/test/java/test/poa/TestCreate.java b/yoko-core/src/test/java/test/poa/TestCreate.java deleted file mode 100644 index 7345848d0..000000000 --- a/yoko-core/src/test/java/test/poa/TestCreate.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright 2015 IBM Corporation and others. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an \"AS IS\" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package test.poa; - -import static org.junit.Assert.assertTrue; - -import java.util.Properties; - -import org.omg.CORBA.*; -import org.omg.PortableServer.*; -import org.omg.PortableServer.POAPackage.*; -import org.omg.PortableServer.POAManagerPackage.*; - -public final class TestCreate extends test.common.TestBase { - static void run(ORB orb, POA root) { - org.omg.CORBA.Object obj; - Policy[] policies = new Policy[0]; - POA poa, parent, poa2, poa3; - POAManager mgr; - String str; - - POAManager rootMgr = root.the_POAManager(); - assertTrue(rootMgr != null); - - // - // Test: POAManager should be in HOLDING state - // - assertTrue(rootMgr.get_state() == State.HOLDING); - - // - // Create child POA - // - try { - poa = root.create_POA("poa1", null, policies); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } - - // - // Test: POAManager should NOT be the same as the root's manager - // - mgr = poa.the_POAManager(); - assertTrue(!mgr._is_equivalent(rootMgr)); - - // - // Test: POAManager should be in HOLDING state - // - assertTrue(mgr.get_state() == State.HOLDING); - - // - // Test: Confirm name - // - str = poa.the_name(); - assertTrue(str.equals("poa1")); - - // - // Test: Confirm parent - // - parent = poa.the_parent(); - assertTrue(parent._is_equivalent(root)); - - // - // Test: AdapterAlreadyExists exception - // - try { - poa2 = root.create_POA("poa1", null, policies); - assertTrue(false); // create_POA should not have succeeded - } catch (AdapterAlreadyExists ex) { - // expected - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - - // - // Test: InvalidPolicy exception - // - Policy[] invalidpolicies = new Policy[1]; - invalidpolicies[0] = root - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.NON_RETAIN); - - try { - poa2 = root.create_POA("invalid", null, invalidpolicies); - assertTrue(false); // create_POA should not have succeeded - } catch (InvalidPolicy ex) { - // expected - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } - - // - // Create another child of root POA - // - try { - poa2 = root.create_POA("poa2", rootMgr, policies); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } - - // - // Test: POAManager should be the same as the root's manager - // - mgr = poa2.the_POAManager(); - assertTrue(mgr._is_equivalent(rootMgr)); - - // - // Create child of child POA - // - try { - poa3 = poa2.create_POA("child", rootMgr, policies); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } - - // - // Test: Confirm parent - // - parent = poa3.the_parent(); - assertTrue(parent._is_equivalent(poa2)); - - poa.destroy(true, true); - poa2.destroy(true, true); - } - - public static void main(String[] args) { - java.util.Properties props = new Properties(); - props.putAll(System.getProperties()); - props.put("org.omg.CORBA.ORBClass", "org.apache.yoko.orb.CORBA.ORB"); - props.put("org.omg.CORBA.ORBSingletonClass", - "org.apache.yoko.orb.CORBA.ORBSingleton"); - - int status = 0; - ORB orb = null; - - try { - // - // Create ORB - // - orb = ORB.init(args, props); - - POA root = TestUtil.GetRootPOA(orb); - - // - // Run the test - // - System.out.print("Testing POA::create_POA()... "); - System.out.flush(); - run(orb, root); - System.out.println("Done!"); - } catch (SystemException ex) { - ex.printStackTrace(); - status = 1; - } - - if (orb != null) { - try { - orb.destroy(); - } catch (SystemException ex) { - ex.printStackTrace(); - status = 1; - } - } - - System.exit(status); - } -} diff --git a/yoko-core/src/test/java/test/poa/TestDSIRef_impl.java b/yoko-core/src/test/java/test/poa/TestDSIRef_impl.java index 1d3cfb857..0bb28dcc5 100644 --- a/yoko-core/src/test/java/test/poa/TestDSIRef_impl.java +++ b/yoko-core/src/test/java/test/poa/TestDSIRef_impl.java @@ -22,7 +22,7 @@ import org.omg.PortableServer.POAPackage.*; import org.omg.PortableServer.ServantLocatorPackage.*; -final class TestDSIRef_impl extends +public final class TestDSIRef_impl extends org.omg.PortableServer.DynamicImplementation { private ORB orb_; @@ -40,7 +40,7 @@ public static void TEST(boolean expr) { throw new test.common.TestException(); } - TestDSIRef_impl(ORB orb, String name, boolean compare) { + public TestDSIRef_impl(ORB orb, String name, boolean compare) { orb_ = orb; name_ = name; compare_ = compare; diff --git a/yoko-core/src/test/java/test/poa/TestDeactivate.java b/yoko-core/src/test/java/test/poa/TestDeactivate.java deleted file mode 100644 index f0f4aeeee..000000000 --- a/yoko-core/src/test/java/test/poa/TestDeactivate.java +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright 2015 IBM Corporation and others. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an \"AS IS\" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package test.poa; - -import static org.junit.Assert.assertTrue; - -import java.util.Properties; - -import org.omg.CORBA.*; -import org.omg.PortableServer.*; -import org.omg.PortableServer.POAPackage.*; - -public final class TestDeactivate extends test.common.TestBase { - final static class Test_impl2 extends TestPOA { - private POA poa_; - - private boolean called_ = false; - - private boolean finished_ = false; - - Test_impl2(POA poa) { - poa_ = poa; - } - - synchronized public void aMethod() { - called_ = true; - notify(); - - try { - wait(1000); - } catch (InterruptedException ex) { - } - finished_ = true; - } - - public POA _default_POA() { - return poa_; - } - - synchronized void blockUntilCalled() { - while (!called_) { - try { - wait(); - } catch (InterruptedException ex) { - } - } - } - - synchronized boolean callComplete() { - return finished_; - } - } - - final static class LongCaller extends Thread { - private Test t_; - - LongCaller(Test t) { - t_ = t; - } - - public void run() { - try { - t_.aMethod(); - } catch (SystemException ex) { - ex.printStackTrace(); - } - } - } - - // - // In this test we want to spawn a thread to call a method on the Test - // interface. This method call should take some time. While the thread - // is calling the method we attempt to deactivate the object. This - // should not complete for some time, since it should wait for all - // outstanding method calls to complete. - // - static void TestDeactivateThreaded(ORB orb, POA root) { - Test_impl2 impl = new Test_impl2(root); - - Test t = impl._this(orb); - - byte[] oid = null; - try { - oid = root.servant_to_id(impl); - } catch (ServantNotActive ex) { - assertTrue(false); - } catch (WrongPolicy ex) { - assertTrue(false); - } - - Thread thr = new LongCaller(t); - - thr.start(); - impl.blockUntilCalled(); - - // - // Test: deactivate_object while method call is active - // - try { - root.deactivate_object(oid); - } catch (ObjectNotActive ex) { - assertTrue(false); - } catch (WrongPolicy ex) { - assertTrue(false); - } - - // - // Once we've deactivated the object the re-activation shouldn't - // complete until the method call completes - // - try { - root.activate_object_with_id(oid, impl); - } catch (ObjectAlreadyActive ex) { - assertTrue(false); - } catch (ServantAlreadyActive ex) { - assertTrue(false); - } catch (WrongPolicy ex) { - assertTrue(false); - } - - // - // The destroy call shouldn't return until the aMethod call is - // complete - // - assertTrue(impl.callComplete()); - - // - // Wait for the thread to terminate - // - while (thr.isAlive()) { - try { - thr.join(); - } catch (InterruptedException ex) { - } - } - - try { - root.deactivate_object(oid); - } catch (ObjectNotActive ex) { - assertTrue(false); - } catch (WrongPolicy ex) { - assertTrue(false); - } - } - - static void TestDeactivateBlocking(ORB orb, POA root) { - Test_impl impl = new Test_impl(orb, "", false); - - Test t = impl._this(orb); - - t.aMethod(); - - byte[] oid = null; - try { - oid = root.servant_to_id(impl); - } catch (ServantNotActive ex) { - assertTrue(false); - } catch (WrongPolicy ex) { - assertTrue(false); - } - - try { - root.deactivate_object(oid); - } catch (ObjectNotActive ex) { - assertTrue(false); - } catch (WrongPolicy ex) { - assertTrue(false); - } - - try { - t.aMethod(); - assertTrue(false); // expected OBJECT_NOT_EXIST - } catch (OBJECT_NOT_EXIST ex) { - // Expected - } - } - - public static void main(String[] args) { - java.util.Properties props = new Properties(); - props.putAll(System.getProperties()); - props.put("org.omg.CORBA.ORBClass", "org.apache.yoko.orb.CORBA.ORB"); - props.put("org.omg.CORBA.ORBSingletonClass", - "org.apache.yoko.orb.CORBA.ORBSingleton"); - - int status = 0; - ORB orb = null; - - try { - // - // Create ORB - // - orb = ORB.init(args, props); - - POA root = TestUtil.GetRootPOA(orb); - - // - // Activate the RootPOA manager - // - POAManager rootMgr = root.the_POAManager(); - assertTrue(rootMgr != null); - - try { - rootMgr.activate(); - } catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive ex) { - assertTrue(false); - } - - System.out.print("Testing deactivate... "); - System.out.flush(); - - // - // Run the tests using the root POA - // - TestDeactivateBlocking(orb, root); - TestDeactivateThreaded(orb, root); - - System.out.println("Done!"); - } catch (SystemException ex) { - ex.printStackTrace(); - status = 1; - } - - if (orb != null) { - try { - orb.destroy(); - } catch (SystemException ex) { - ex.printStackTrace(); - status = 1; - } - } - - System.exit(status); - } -} diff --git a/yoko-core/src/test/java/test/poa/TestDestroy.java b/yoko-core/src/test/java/test/poa/TestDestroy.java deleted file mode 100644 index 5ca56e28e..000000000 --- a/yoko-core/src/test/java/test/poa/TestDestroy.java +++ /dev/null @@ -1,265 +0,0 @@ -/* - * Copyright 2015 IBM Corporation and others. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an \"AS IS\" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package test.poa; - -import static org.junit.Assert.assertTrue; - -import java.util.Properties; - -import org.omg.CORBA.*; -import org.omg.PortableServer.*; -import org.omg.PortableServer.POAPackage.*; -import org.omg.PortableServer.POAManagerPackage.*; - -public final class TestDestroy extends test.common.TestBase { - final static class Test_impl2 extends TestPOA { - private POA poa_; - - private boolean called_ = false; - - private boolean finished_ = false; - - Test_impl2(POA poa) { - poa_ = poa; - } - - synchronized public void aMethod() { - called_ = true; - notify(); - - try { - wait(1000); - } catch (InterruptedException ex) { - } - finished_ = true; - } - - public POA _default_POA() { - return poa_; - } - - synchronized void blockUntilCalled() { - while (!called_) { - try { - wait(); - } catch (InterruptedException ex) { - } - } - } - - synchronized boolean callComplete() { - return finished_; - } - } - - final static class LongCaller extends Thread { - private Test t_; - - LongCaller(Test t) { - t_ = t; - } - - public void run() { - try { - t_.aMethod(); - } catch (SystemException se) { - System.err.println(se.getMessage()); - se.printStackTrace(); - } - } - } - - // - // This is a more rigorous test of POA::destroy. We want to ensure - // that the POA isn't destroyed during a method call. - // - static void TestDestroyThreaded(ORB orb, POA root) { - POAManager rootMgr = root.the_POAManager(); - assertTrue(rootMgr != null); - - Policy[] policies = new Policy[1]; - policies[0] = root - .create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION); - - // - // Create child POA - // - POA poa = null; - try { - poa = root.create_POA("poa1", rootMgr, policies); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } - - Test_impl2 impl = new Test_impl2(poa); - - Test t = impl._this(orb); - - Thread thr = new LongCaller(t); - - thr.start(); - impl.blockUntilCalled(); - - // - // Test: Destroy the POA while a method call is active - // - poa.destroy(true, true); - - // - // The destroy call shouldn't return until the aMethod call is - // complete - // - assertTrue(impl.callComplete()); - - while (thr.isAlive()) { - try { - thr.join(); - } catch (InterruptedException ex) { - } - } - } - - static void TestDestroyBlocking(ORB orb, POA root) { - org.omg.CORBA.Object obj; - Policy[] policies = new Policy[0]; - POA poa, parent, poa2, poa3; - POAManager mgr; - String str; - - POAManager rootMgr = root.the_POAManager(); - assertTrue(rootMgr != null); - - // - // Create child POA - // - try { - poa = root.create_POA("poa1", rootMgr, policies); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } - - // - // Test: destroy - // - poa.destroy(true, true); - - // - // Ensure parent no longer knows about child - // - try { - root.find_POA("poa1", false); - assertTrue(false); // find_POA should not have succeeded - } catch (AdapterNonExistent ex) { - // expected - } - - // - // Create child POA - // - try { - poa = root.create_POA("poa1", rootMgr, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - - // - // Create child of child POA - // - try { - poa2 = poa.create_POA("child1", rootMgr, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - - // - // Test: destroy - should destroy poa1 and poa1/child1 - // - poa.destroy(true, true); - - // - // Ensure parent no longer knows about child - // - try { - root.find_POA("poa1", false); - assertTrue(false); // find_POA should not have succeeded - } catch (AdapterNonExistent ex) { - // expected - } - - // - // XXX Test: etherealize w/ servant manager - // - } - - public static void main(String[] args) { - java.util.Properties props = new Properties(); - props.putAll(System.getProperties()); - props.put("org.omg.CORBA.ORBClass", "org.apache.yoko.orb.CORBA.ORB"); - props.put("org.omg.CORBA.ORBSingletonClass", - "org.apache.yoko.orb.CORBA.ORBSingleton"); - - int status = 0; - ORB orb = null; - - try { - // - // Create ORB - // - orb = ORB.init(args, props); - - POA root = TestUtil.GetRootPOA(orb); - - POAManager rootMgr = root.the_POAManager(); - assertTrue(rootMgr != null); - - try { - rootMgr.activate(); - } catch (AdapterInactive ex) { - throw new RuntimeException(); - } - - System.out.print("Testing POA::destroy... "); - System.out.flush(); - TestDestroyBlocking(orb, root); - TestDestroyThreaded(orb, root); - System.out.println("Done!"); - } catch (SystemException ex) { - ex.printStackTrace(); - status = 1; - } - - if (orb != null) { - try { - orb.destroy(); - } catch (SystemException ex) { - ex.printStackTrace(); - status = 1; - } - } - - System.exit(status); - } -} diff --git a/yoko-core/src/test/java/test/poa/TestFind.java b/yoko-core/src/test/java/test/poa/TestFind.java deleted file mode 100644 index 300310d46..000000000 --- a/yoko-core/src/test/java/test/poa/TestFind.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright 2015 IBM Corporation and others. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an \"AS IS\" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package test.poa; - -import static org.junit.Assert.assertTrue; - -import java.util.Properties; - -import org.omg.CORBA.*; -import org.omg.PortableServer.*; -import org.omg.PortableServer.POAPackage.*; - -public final class TestFind extends test.common.TestBase { - static void run(ORB orb, POA root) { - org.omg.CORBA.Object obj; - Policy[] policies = new Policy[0]; - POA poa, parent, poa2, poa3; - POAManager mgr; - String str; - - POAManager rootMgr = root.the_POAManager(); - assertTrue(rootMgr != null); - - // - // Create child POA - // - try { - poa = root.create_POA("poa1", rootMgr, policies); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } - - // - // Test: find_POA - // - try { - poa2 = root.find_POA("poa1", false); - } catch (AdapterNonExistent ex) { - throw new RuntimeException(); - } - assertTrue(poa2 != null); - assertTrue(poa2._is_equivalent(poa)); - - // - // Test: AdapterNonExistent exception - // - try { - poa2 = root.find_POA("poaX", false); - assertTrue(false); // find_POA should not have succeeded - } catch (AdapterNonExistent ex) { - // expected - } - - // - // Create child POA - // - try { - poa2 = root.create_POA("poa2", rootMgr, policies); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } - - // - // Test: Confirm parent knows about child - // - try { - poa3 = root.find_POA("poa2", false); - } catch (AdapterNonExistent ex) { - throw new RuntimeException(); - } - - assertTrue(poa3 != null); - assertTrue(poa3._is_equivalent(poa2)); - } - - public static void main(String[] args) { - java.util.Properties props = new Properties(); - props.putAll(System.getProperties()); - props.put("org.omg.CORBA.ORBClass", "org.apache.yoko.orb.CORBA.ORB"); - props.put("org.omg.CORBA.ORBSingletonClass", - "org.apache.yoko.orb.CORBA.ORBSingleton"); - - int status = 0; - ORB orb = null; - - try { - // - // Create ORB - // - orb = ORB.init(args, props); - - POA root = TestUtil.GetRootPOA(orb); - - // - // Run the test - // - System.out.print("Testing POA::find_POA... "); - System.out.flush(); - run(orb, root); - System.out.println("Done!"); - } catch (SystemException ex) { - ex.printStackTrace(); - status = 1; - } - - if (orb != null) { - try { - orb.destroy(); - } catch (SystemException ex) { - ex.printStackTrace(); - status = 1; - } - } - - System.exit(status); - } -} diff --git a/yoko-core/src/test/java/test/poa/TestMisc.java b/yoko-core/src/test/java/test/poa/TestMisc.java deleted file mode 100644 index b3de9e853..000000000 --- a/yoko-core/src/test/java/test/poa/TestMisc.java +++ /dev/null @@ -1,1124 +0,0 @@ -/* - * Copyright 2015 IBM Corporation and others. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an \"AS IS\" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package test.poa; - -import static org.junit.Assert.assertTrue; - -import java.util.Arrays; -import java.util.Properties; - -import org.omg.CORBA.*; -import org.omg.PortableServer.*; -import org.omg.PortableServer.POAPackage.*; - -public final class TestMisc extends test.common.TestBase { - static void TestCreateReference(ORB orb, POA root) { - org.omg.CORBA.Object obj; - POA user, system; - byte[] id1, id2, tmpid; - Policy[] policies; - - POAManager manager = root.the_POAManager(); - - policies = new Policy[1]; - policies[0] = root - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); - try { - user = root.create_POA("user_id", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - - policies = new Policy[1]; - policies[0] = root - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.SYSTEM_ID); - try { - system = root.create_POA("system_id", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - - // - // Test: create_reference with wrong POA policies - // - try { - obj = user.create_reference("IDL:Test:1.0"); - assertTrue(false); // create_reference should not have succeeded - } catch (WrongPolicy ex) { - // expected - } - - // - // Test: create_reference - should get a new ID for each invocation - // on POA w/ SYSTEM_ID policy - // - try { - obj = system.create_reference("IDL:Test:1.0"); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertTrue(obj != null); - try { - id1 = system.reference_to_id(obj); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } - try { - obj = system.create_reference("IDL:Test:1.0"); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertTrue(obj != null); - try { - id2 = system.reference_to_id(obj); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertTrue(!Arrays.equals(id1, id2)); - - // - // Test: create_reference_with_id using a system-generated ID - // - try { - obj = system.create_reference_with_id(id1, "IDL:Test:1.0"); - } catch (BAD_PARAM ex) { - assertTrue(false); // create_reference_with_id should have succeeded - } - - id1 = ("id1").getBytes(); - - // - // Test: create_reference_with_id using a user-generated ID - // - try { - obj = system.create_reference_with_id(id1, "IDL:Test:1.0"); - assertTrue(false); // create_reference_with_id should have not - // succeeded - } catch (BAD_PARAM ex) { - // Expected - } - - // - // Test: create_reference_with_id - // - obj = user.create_reference_with_id(id1, "IDL:Test:1.0"); - assertTrue(obj != null); - try { - tmpid = user.reference_to_id(obj); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertTrue(Arrays.equals(id1, tmpid)); - id2 = ("id2").getBytes(); - obj = user.create_reference_with_id(id2, "IDL:Test:1.0"); - assertTrue(obj != null); - try { - tmpid = user.reference_to_id(obj); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertTrue(Arrays.equals(id2, tmpid)); - - user.destroy(true, true); - system.destroy(true, true); - } - - static void TestServantToId(ORB orb, POA root) { - org.omg.CORBA.Object obj; - POA unique, implicit, multiple; - byte[] id1, id2, tmpid; - Policy[] policies; - Test_impl servant1; - Test_impl servant2; - - POAManager manager = root.the_POAManager(); - - // - // Create POA w/ UNIQUE_ID, NO_IMPLICIT_ACTIVATION - // - policies = new Policy[4]; - policies[0] = root - .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.UNIQUE_ID); - policies[1] = root - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); - policies[2] = root - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN); - policies[3] = root - .create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION); - try { - unique = root.create_POA("unique_id", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - - // - // Create POA w/ UNIQUE_ID, IMPLICIT_ACTIVATION - // - policies = new Policy[3]; - policies[0] = root - .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.UNIQUE_ID); - policies[1] = root - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN); - policies[2] = root - .create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION); - try { - implicit = root.create_POA("implicit", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - - // - // Create POA w/ MULTIPLE_ID, IMPLICIT_ACTIVATION - // - policies = new Policy[3]; - policies[0] = root - .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID); - policies[1] = root - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN); - policies[2] = root - .create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION); - try { - multiple = root.create_POA("multiple", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - - servant1 = new Test_impl(orb, "test1", false); - servant2 = new Test_impl(orb, "test2", false); - - // - // Test: ServantNotActive exception - // - try { - unique.servant_to_id(servant1); - assertTrue(false); // servant_to_id should not have succeeded - } catch (ServantNotActive ex) { - // expected - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - id1 = ("test1").getBytes(); - try { - unique.activate_object_with_id(id1, servant1); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ServantAlreadyActive ex) { - throw new RuntimeException(); - } catch (ObjectAlreadyActive ex) { - throw new RuntimeException(); - } - - // - // Test: servant_to_id (UNIQUE_ID policy) - // - try { - tmpid = unique.servant_to_id(servant1); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ServantNotActive ex) { - throw new RuntimeException(); - } - assertTrue(Arrays.equals(id1, tmpid)); - - // - // Test: servant_to_id (IMPLICIT_ACTIVATION) - servant1 should - // be automatically activated - // - try { - id1 = implicit.servant_to_id(servant1); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ServantNotActive ex) { - throw new RuntimeException(); - } - - // - // Test: Now that servant1 is activated, and since we have UNIQUE_ID, - // we should get the same ID back - // - try { - tmpid = implicit.servant_to_id(servant1); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ServantNotActive ex) { - throw new RuntimeException(); - } - assertTrue(Arrays.equals(id1, tmpid)); - - // - // Test: Implicitly activating servant2 should produce a new ID - // - try { - id2 = implicit.servant_to_id(servant2); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ServantNotActive ex) { - throw new RuntimeException(); - } - assertTrue(!Arrays.equals(id1, id2)); - - // - // Test: servant_to_id (IMPLICIT_ACTIVATION, MULTIPLE_ID) - servant1 - // should be automatically activated - // - try { - id1 = multiple.servant_to_id(servant1); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ServantNotActive ex) { - throw new RuntimeException(); - } - - // - // Test: Since we have MULTIPLE_ID, we should get a new ID - // - try { - tmpid = multiple.servant_to_id(servant1); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ServantNotActive ex) { - throw new RuntimeException(); - } - assertTrue(!Arrays.equals(id1, tmpid)); - - unique.destroy(true, true); - implicit.destroy(true, true); - multiple.destroy(true, true); - } - - static void TestIdToServant(ORB orb, POA root) { - org.omg.CORBA.Object obj; - POA retain, defaultPOA; - byte[] id1, id2, tmpid; - Policy[] policies; - Test_impl def; - Test_impl servant1; - Test_impl servant2; - Servant tmpservant; - - POAManager manager = root.the_POAManager(); - - // - // Create POA w/ RETAIN - // - policies = new Policy[3]; - policies[0] = root - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN); - policies[1] = root - .create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.PERSISTENT); - policies[2] = root - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); - try { - retain = root.create_POA("retain", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - - // - // Create POA w/ USE_DEFAULT_SERVANT - // - policies = new Policy[5]; - policies[0] = root - .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID); - policies[1] = root - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN); - policies[2] = root - .create_request_processing_policy(org.omg.PortableServer.RequestProcessingPolicyValue.USE_DEFAULT_SERVANT); - policies[3] = root - .create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.PERSISTENT); - policies[4] = root - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); - - try { - defaultPOA = root.create_POA("default", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - def = new Test_impl(orb, "default", false); - try { - defaultPOA.set_servant(def); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - servant1 = new Test_impl(orb, "test1", false); - servant2 = new Test_impl(orb, "test2", false); - - // - // Test: ObjectNotActive exception - // - try { - tmpid = ("bad_id").getBytes(); - retain.id_to_servant(tmpid); - assertTrue(false); // id_to_servant should not have succeeded - } catch (ObjectNotActive ex) { - // expected - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - id1 = ("test1").getBytes(); - id2 = ("test2").getBytes(); - try { - retain.activate_object_with_id(id1, servant1); - retain.activate_object_with_id(id2, servant2); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ServantAlreadyActive ex) { - throw new RuntimeException(); - } catch (ObjectAlreadyActive ex) { - throw new RuntimeException(); - } - - // - // Test: servant_to_id (RETAIN policy) - // - try { - tmpservant = retain.id_to_servant(id1); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } - assertTrue(servant1 == tmpservant); - try { - tmpservant = retain.id_to_servant(id2); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } - assertTrue(servant2 == tmpservant); - - // - // Test: id_to_servant (USE_DEFAULT_SERVANT) - // - try { - defaultPOA.activate_object_with_id(id1, servant1); - defaultPOA.activate_object_with_id(id2, servant2); - } catch (ServantAlreadyActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ObjectAlreadyActive ex) { - throw new RuntimeException(); - } - try { - tmpservant = defaultPOA.id_to_servant(id1); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } - assertTrue(servant1 == tmpservant); - try { - tmpservant = defaultPOA.id_to_servant(id2); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } - assertTrue(servant2 == tmpservant); - - // - // Test: id_to_servant (USE_DEFAULT_SERVANT) - should return - // default servant for all unknown IDs - // - tmpid = ("test99").getBytes(); - try { - tmpservant = defaultPOA.id_to_servant(tmpid); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } - assertTrue(tmpservant == def); - tmpservant = null; - - retain.destroy(true, true); - defaultPOA.destroy(true, true); - } - - static void TestServantToReference(ORB orb, POA root) { - org.omg.CORBA.Object obj; - POA unique, implicit, multiple; - byte[] id1, id2, tmpid1, tmpid2; - Policy[] policies; - Test_impl servant1; - Test_impl servant2; - - POAManager manager = root.the_POAManager(); - - // - // Create POA w/ UNIQUE_ID, NO_IMPLICIT_ACTIVATION - // - policies = new Policy[4]; - policies[0] = root - .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.UNIQUE_ID); - policies[1] = root - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); - policies[2] = root - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN); - policies[3] = root - .create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION); - try { - unique = root.create_POA("unique_id", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - - // - // Create POA w/ UNIQUE_ID, IMPLICIT_ACTIVATION - // - policies = new Policy[3]; - policies[0] = root - .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.UNIQUE_ID); - policies[1] = root - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN); - policies[2] = root - .create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION); - try { - implicit = root.create_POA("implicit", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - - // - // Create POA w/ MULTIPLE_ID, IMPLICIT_ACTIVATION - // - policies = new Policy[3]; - policies[0] = root - .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID); - policies[1] = root - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN); - policies[2] = root - .create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION); - try { - multiple = root.create_POA("multiple", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - - servant1 = new Test_impl(orb, "test1", false); - servant2 = new Test_impl(orb, "test2", false); - - // - // Test: ServantNotActive exception - // - try { - unique.servant_to_reference(servant1); - assertTrue(false); // servant_to_reference should not have succeeded - } catch (ServantNotActive ex) { - // expected - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - id1 = ("test1").getBytes(); - try { - unique.activate_object_with_id(id1, servant1); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ServantAlreadyActive ex) { - throw new RuntimeException(); - } catch (ObjectAlreadyActive ex) { - throw new RuntimeException(); - } - - // - // Test: servant_to_reference (UNIQUE_ID policy) - // - try { - obj = unique.servant_to_reference(servant1); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ServantNotActive ex) { - throw new RuntimeException(); - } - assertTrue(obj != null); - try { - tmpid1 = unique.reference_to_id(obj); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertTrue(Arrays.equals(id1, tmpid1)); - - // - // Test: servant_to_reference (IMPLICIT_ACTIVATION) - servant1 should - // be automatically activated - // - try { - obj = implicit.servant_to_reference(servant1); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ServantNotActive ex) { - throw new RuntimeException(); - } - assertTrue(obj != null); - try { - tmpid1 = implicit.reference_to_id(obj); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - // - // Test: Now that servant1 is activated, and since we have UNIQUE_ID, - // we should get the same ID back - // - try { - obj = implicit.servant_to_reference(servant1); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ServantNotActive ex) { - throw new RuntimeException(); - } - assertTrue(obj != null); - try { - tmpid2 = implicit.reference_to_id(obj); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertTrue(Arrays.equals(tmpid1, tmpid2)); - - // - // Test: Implicitly activating servant2 should produce a new ID - // - try { - obj = implicit.servant_to_reference(servant2); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ServantNotActive ex) { - throw new RuntimeException(); - } - assertTrue(obj != null); - try { - tmpid2 = implicit.reference_to_id(obj); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } - assertTrue(!Arrays.equals(tmpid1, tmpid2)); - - // - // Test: servant_to_reference (IMPLICIT_ACTIVATION, MULTIPLE_ID) - - // servant1 should be automatically activated - // - try { - obj = multiple.servant_to_reference(servant1); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ServantNotActive ex) { - throw new RuntimeException(); - } - assertTrue(obj != null); - try { - tmpid1 = multiple.reference_to_id(obj); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - // - // Test: Since we have MULTIPLE_ID, we should get a new ID - // - try { - obj = multiple.servant_to_reference(servant1); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ServantNotActive ex) { - throw new RuntimeException(); - } - assertTrue(obj != null); - try { - tmpid2 = multiple.reference_to_id(obj); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } - assertTrue(!Arrays.equals(tmpid1, tmpid2)); - - unique.destroy(true, true); - implicit.destroy(true, true); - multiple.destroy(true, true); - } - - static void TestIdToReference(ORB orb, POA root) { - org.omg.CORBA.Object obj; - POA retain, defaultPOA; - byte[] id1, id2, tmpid; - Policy[] policies; - Test_impl servant1; - Test_impl servant2; - - POAManager manager = root.the_POAManager(); - - // - // Create POA w/ RETAIN - // - policies = new Policy[3]; - policies[0] = root - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN); - policies[1] = root - .create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.PERSISTENT); - policies[2] = root - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); - try { - retain = root.create_POA("retain", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - - servant1 = new Test_impl(orb, "test1", false); - servant2 = new Test_impl(orb, "test2", false); - - // - // Test: ObjectNotActive exception - // - try { - tmpid = ("bad_id").getBytes(); - retain.id_to_reference(tmpid); - assertTrue(false); // id_to_reference should not have succeeded - } catch (ObjectNotActive ex) { - // expected - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - id1 = ("test1").getBytes(); - id2 = ("test2").getBytes(); - try { - retain.activate_object_with_id(id1, servant1); - retain.activate_object_with_id(id2, servant2); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ServantAlreadyActive ex) { - throw new RuntimeException(); - } catch (ObjectAlreadyActive ex) { - throw new RuntimeException(); - } - - // - // Test: servant_to_reference - // - try { - obj = retain.id_to_reference(id1); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } - assertTrue(obj != null); - try { - tmpid = retain.reference_to_id(obj); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertTrue(Arrays.equals(id1, tmpid)); - - // - // Test: servant_to_reference - // - try { - obj = retain.id_to_reference(id2); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } - assertTrue(obj != null); - try { - tmpid = retain.reference_to_id(obj); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertTrue(Arrays.equals(id2, tmpid)); - - retain.destroy(true, true); - } - - static void TestReferenceToServant(ORB orb, POA root) { - org.omg.CORBA.Object obj; - POA retain, defaultPOA; - byte[] id1, id2, tmpid; - Policy[] policies; - Test_impl def; - Test_impl servant1; - Test_impl servant2; - Servant tmpservant; - - POAManager manager = root.the_POAManager(); - - // - // Create POA w/ RETAIN - // - policies = new Policy[3]; - policies[0] = root - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN); - policies[1] = root - .create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.PERSISTENT); - policies[2] = root - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); - try { - retain = root.create_POA("retain", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - - // - // Create POA w/ USE_DEFAULT_SERVANT - // - policies = new Policy[5]; - policies[0] = root - .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID); - policies[1] = root - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN); - policies[2] = root - .create_request_processing_policy(org.omg.PortableServer.RequestProcessingPolicyValue.USE_DEFAULT_SERVANT); - policies[3] = root - .create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.PERSISTENT); - policies[4] = root - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); - - try { - defaultPOA = root.create_POA("default", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - def = new Test_impl(orb, "default", false); - try { - defaultPOA.set_servant(def); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - servant1 = new Test_impl(orb, "test1", false); - servant2 = new Test_impl(orb, "test2", false); - - // - // Test: ObjectNotActive exception - // - try { - tmpid = ("bad_id").getBytes(); - obj = retain.create_reference_with_id(tmpid, "IDL:Test:1.0"); - retain.reference_to_servant(obj); - assertTrue(false); // reference_to_servant should not have succeeded - } catch (ObjectNotActive ex) { - // expected - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - id1 = ("test1").getBytes(); - id2 = ("test2").getBytes(); - try { - retain.activate_object_with_id(id1, servant1); - retain.activate_object_with_id(id2, servant2); - } catch (ObjectAlreadyActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ServantAlreadyActive ex) { - throw new RuntimeException(); - } - - // - // Test: reference_to_servant (RETAIN policy) - // - obj = retain.create_reference_with_id(id1, "IDL:Test:1.0"); - try { - tmpservant = retain.reference_to_servant(obj); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } - assertTrue(servant1 == tmpservant); - obj = retain.create_reference_with_id(id2, "IDL:Test:1.0"); - try { - tmpservant = retain.reference_to_servant(obj); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } - assertTrue(servant2 == tmpservant); - - // - // Test: WrongAdapter exception - // - try { - obj = retain.create_reference_with_id(id1, "IDL:Test:1.0"); - defaultPOA.reference_to_servant(obj); - assertTrue(false); // reference_to_servant should not have succeeded - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (WrongAdapter ex) { - // expected - } - - // - // Test: reference_to_servant (USE_DEFAULT_SERVANT) - // - try { - defaultPOA.activate_object_with_id(id1, servant1); - defaultPOA.activate_object_with_id(id2, servant2); - } catch (ObjectAlreadyActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ServantAlreadyActive ex) { - throw new RuntimeException(); - } - obj = defaultPOA.create_reference_with_id(id1, "IDL:Test:1.0"); - try { - tmpservant = defaultPOA.reference_to_servant(obj); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } - assertTrue(servant1 == tmpservant); - obj = defaultPOA.create_reference_with_id(id2, "IDL:Test:1.0"); - try { - tmpservant = defaultPOA.reference_to_servant(obj); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } - assertTrue(servant2 == tmpservant); - - // - // Test: reference_to_servant (USE_DEFAULT_SERVANT) - should return - // default servant for all unknown IDs - // - tmpid = ("test99").getBytes(); - obj = defaultPOA.create_reference_with_id(tmpid, "IDL:Test:1.0"); - try { - tmpservant = defaultPOA.reference_to_servant(obj); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } - assertTrue(tmpservant == def); - tmpservant = null; - - retain.destroy(true, true); - defaultPOA.destroy(true, true); - } - - static void TestReferenceToId(ORB orb, POA root) { - org.omg.CORBA.Object obj; - POA poa; - byte[] id1, id2, tmpid; - Policy[] policies; - - POAManager manager = root.the_POAManager(); - - // - // Create POA - // - policies = new Policy[3]; - policies[0] = root - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN); - policies[1] = root - .create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.PERSISTENT); - policies[2] = root - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); - try { - poa = root.create_POA("poa", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - - id1 = ("test1").getBytes(); - id2 = ("test2").getBytes(); - - // - // Test: reference_to_id - // - obj = poa.create_reference_with_id(id1, "IDL:Test:1.0"); - try { - tmpid = poa.reference_to_id(obj); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertTrue(Arrays.equals(tmpid, id1)); - obj = poa.create_reference_with_id(id2, "IDL:Test:1.0"); - try { - tmpid = poa.reference_to_id(obj); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertTrue(Arrays.equals(tmpid, id2)); - - // - // Test: WrongAdapter exception - // - try { - obj = poa.create_reference_with_id(id1, "IDL:Test:1.0"); - root.reference_to_id(obj); - assertTrue(false); // reference_to_id should not have succeeded - } catch (WrongAdapter ex) { - // expected - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - poa.destroy(true, true); - } - - static void runtests(ORB orb, POA root) { - TestCreateReference(orb, root); - TestServantToId(orb, root); - TestIdToServant(orb, root); - TestServantToReference(orb, root); - TestIdToReference(orb, root); - TestReferenceToServant(orb, root); - TestReferenceToId(orb, root); - } - - public static void main(String[] args) { - java.util.Properties props = new Properties(); - props.putAll(System.getProperties()); - props.put("org.omg.CORBA.ORBClass", "org.apache.yoko.orb.CORBA.ORB"); - props.put("org.omg.CORBA.ORBSingletonClass", - "org.apache.yoko.orb.CORBA.ORBSingleton"); - - int status = 0; - ORB orb = null; - - try { - // - // Create ORB - // - orb = ORB.init(args, props); - - POA root = TestUtil.GetRootPOA(orb); - - System.out.print("Testing miscellaneous POA functions... "); - System.out.flush(); - - // - // Run the tests using the root POA - // - runtests(orb, root); - - // - // Create a child POA and run the tests again using the - // child as the root - // - Policy[] policies = new Policy[0]; - POAManager manager = root.the_POAManager(); - POA child = null; - try { - child = root.create_POA("child", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - runtests(orb, child); - - System.out.println("Done!"); - } catch (SystemException ex) { - ex.printStackTrace(); - status = 1; - } - - if (orb != null) { - try { - orb.destroy(); - } catch (SystemException ex) { - ex.printStackTrace(); - status = 1; - } - } - - System.exit(status); - } -}