From 275a1dab1f429489d60bac787f4f7ac06cb60c5d Mon Sep 17 00:00:00 2001 From: habib Date: Thu, 27 Jul 2023 19:52:45 +0100 Subject: [PATCH 01/11] TST: initial port of POA invoke tests w/o refactor --- .../orb/PortableServer/TestPoaActivate.java | 2 +- .../PortableServer/TestPoaCollocated.java} | 321 ++++++++---------- .../orb/PortableServer/TestPoaCreate.java | 30 ++ .../PortableServer/TestPoaDeactivate.java} | 235 +++++-------- .../orb/PortableServer/TestPoaDestroy.java} | 271 +++++++-------- .../yoko/orb/PortableServer/TestPoaFind.java} | 80 ++--- .../yoko/orb/PortableServer/TestPoaMisc.java | 40 +++ .../test/java/org/apache/yoko/PoaTest.java | 25 -- .../test/java/test/poa/TestDSIRef_impl.java | 4 +- .../src/test/java/test/poa/TestMisc.java | 62 +--- 10 files changed, 445 insertions(+), 625 deletions(-) rename yoko-core/src/test/{java/test/poa/TestCollocated.java => java-testify/org/apache/yoko/orb/PortableServer/TestPoaCollocated.java} (70%) create mode 100644 yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaCreate.java rename yoko-core/src/test/{java/test/poa/TestDeactivate.java => java-testify/org/apache/yoko/orb/PortableServer/TestPoaDeactivate.java} (56%) rename yoko-core/src/test/{java/test/poa/TestDestroy.java => java-testify/org/apache/yoko/orb/PortableServer/TestPoaDestroy.java} (62%) rename yoko-core/src/test/{java/test/poa/TestFind.java => java-testify/org/apache/yoko/orb/PortableServer/TestPoaFind.java} (54%) create mode 100644 yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaMisc.java 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/test/poa/TestCollocated.java b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaCollocated.java similarity index 70% rename from yoko-core/src/test/java/test/poa/TestCollocated.java rename to yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaCollocated.java index 7f06d9ab5..7db472262 100644 --- a/yoko-core/src/test/java/test/poa/TestCollocated.java +++ b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaCollocated.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 IBM Corporation and others. + * 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. @@ -15,96 +15,40 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package test.poa; +package org.apache.yoko.orb.PortableServer; + +import org.junit.jupiter.api.Test; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Policy; +import org.omg.CORBA.Request; +import org.omg.PortableServer.ForwardRequest; +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.POAPackage.ObjectNotActive; +import org.omg.PortableServer.POAPackage.ServantNotActive; +import org.omg.PortableServer.POAPackage.WrongPolicy; +import org.omg.PortableServer.Servant; +import org.omg.PortableServer.ServantActivator; +import org.omg.PortableServer.ServantActivatorPOA; +import org.omg.PortableServer.ServantLocator; +import org.omg.PortableServer.ServantLocatorPOA; +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.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; - } - } - } - } - +@ConfigureOrb +public class TestPoaCollocated { static void TestPOA(POA poa) { byte[] id; org.omg.CORBA.Object obj; Request request; - Test test; + test.poa.Test test; // // Invoke twice on each object - statically & DII @@ -126,7 +70,10 @@ static void TestPOA(POA poa) { assertTrue(request.env().exception() == null); } - static void TestDefaultServant(ORB orb, POA root, POAManager manager) { + @Test + public void testCollocated(ORB orb, POA rootPoa) throws Exception { + POAManager manager = rootPoa.the_POAManager(); + manager.activate(); POA poa; Servant servant; Policy[] policies; @@ -135,24 +82,24 @@ static void TestDefaultServant(ORB orb, POA root, POAManager manager) { // Setup policies for default servant // policies = new Policy[6]; - policies[0] = root + policies[0] = rootPoa .create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.PERSISTENT); - policies[1] = root + policies[1] = rootPoa .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); - policies[2] = root + policies[2] = rootPoa .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.NON_RETAIN); - policies[3] = root + policies[3] = rootPoa .create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION); - policies[4] = root + policies[4] = rootPoa .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID); - policies[5] = root + policies[5] = rootPoa .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); + poa = rootPoa.create_POA("defaultSSI", manager, policies); } catch (AdapterAlreadyExists ex) { throw new RuntimeException(); } catch (InvalidPolicy ex) { @@ -174,14 +121,14 @@ static void TestDefaultServant(ORB orb, POA root, POAManager manager) { // byte[] id = null; try { - id = root.servant_to_id(staticServant); + id = rootPoa.servant_to_id(staticServant); } catch (ServantNotActive ex) { throw new RuntimeException(); } catch (WrongPolicy ex) { throw new RuntimeException(); } try { - root.deactivate_object(id); + rootPoa.deactivate_object(id); } catch (ObjectNotActive ex) { throw new RuntimeException(); } catch (WrongPolicy ex) { @@ -192,7 +139,7 @@ static void TestDefaultServant(ORB orb, POA root, POAManager manager) { // Create POA w/ DSI Default Servant // try { - poa = root.create_POA("defaultDSI", manager, policies); + poa = rootPoa.create_POA("defaultDSI", manager, policies); } catch (AdapterAlreadyExists ex) { throw new RuntimeException(); } catch (InvalidPolicy ex) { @@ -213,35 +160,32 @@ static void TestDefaultServant(ORB orb, POA root, POAManager manager) { // 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; + POA poa1; + Servant servant1; + Policy[] policies1; // // Setup policies for servant locator // - policies = new Policy[6]; - policies[0] = root + policies1 = new Policy[6]; + policies1[0] = rootPoa .create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.PERSISTENT); - policies[1] = root + policies1[1] = rootPoa .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); - policies[2] = root + policies1[2] = rootPoa .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.NON_RETAIN); - policies[3] = root + policies1[3] = rootPoa .create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION); - policies[4] = root + policies1[4] = rootPoa .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.UNIQUE_ID); - policies[5] = root + policies1[5] = rootPoa .create_request_processing_policy(org.omg.PortableServer.RequestProcessingPolicyValue.USE_SERVANT_MANAGER); // // Create POA w/ Servant Locator // try { - poa = root.create_POA("servloc", manager, policies); + poa1 = rootPoa.create_POA("servloc", manager, policies1); } catch (AdapterAlreadyExists ex) { throw new RuntimeException(); } catch (InvalidPolicy ex) { @@ -250,67 +194,64 @@ static void TestServantLocator(ORB orb, POA root, POAManager manager) { TestLocator_impl locatorImpl = new TestLocator_impl(orb); ServantLocator locator = locatorImpl._this(orb); try { - poa.set_servant_manager(locator); + poa1.set_servant_manager(locator); } catch (WrongPolicy ex) { throw new RuntimeException(); } - TestPOA(poa); - poa.destroy(true, true); + TestPOA(poa1); + poa1.destroy(true, true); // // Clean up policies // - for (int i = 0; i < policies.length; i++) - policies[i].destroy(); + for (int i = 0; i < policies1.length; i++) + policies1[i].destroy(); // // Since locatorImpl is a stack-based servant, we need to deactivate // it before it goes out of scope // - byte[] id = null; + byte[] id1 = null; try { - id = root.servant_to_id(locatorImpl); + id1 = rootPoa.servant_to_id(locatorImpl); } catch (ServantNotActive ex) { throw new RuntimeException(); } catch (WrongPolicy ex) { throw new RuntimeException(); } try { - root.deactivate_object(id); + rootPoa.deactivate_object(id1); } 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; + POA poa2; + Servant servant2; + Policy[] policies2; // // Setup policies for servant activator // - policies = new Policy[6]; - policies[0] = root + policies2 = new Policy[6]; + policies2[0] = rootPoa .create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.PERSISTENT); - policies[1] = root + policies2[1] = rootPoa .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); - policies[2] = root + policies2[2] = rootPoa .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN); - policies[3] = root + policies2[3] = rootPoa .create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION); - policies[4] = root + policies2[4] = rootPoa .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.UNIQUE_ID); - policies[5] = root + policies2[5] = rootPoa .create_request_processing_policy(org.omg.PortableServer.RequestProcessingPolicyValue.USE_SERVANT_MANAGER); // // Create POA w/ Servant Activator // try { - poa = root.create_POA("servant", manager, policies); + poa2 = rootPoa.create_POA("servant", manager, policies2); } catch (AdapterAlreadyExists ex) { throw new RuntimeException(); } catch (InvalidPolicy ex) { @@ -319,33 +260,33 @@ static void TestServantActivator(ORB orb, POA root, POAManager manager) { TestActivator_impl activatorImpl = new TestActivator_impl(orb); ServantActivator activator = activatorImpl._this(orb); try { - poa.set_servant_manager(activator); + poa2.set_servant_manager(activator); } catch (WrongPolicy ex) { throw new RuntimeException(); } - TestPOA(poa); - poa.destroy(true, true); + TestPOA(poa2); + poa2.destroy(true, true); // // Clean up policies // - for (int i = 0; i < policies.length; i++) - policies[i].destroy(); + for (int i = 0; i < policies2.length; i++) + policies2[i].destroy(); // // Since activatorImpl is a stack-based servant, we need to deactivate // it before it goes out of scope // - byte[] id = null; + byte[] id2 = null; try { - id = root.servant_to_id(activatorImpl); + id2 = rootPoa.servant_to_id(activatorImpl); } catch (ServantNotActive ex) { throw new RuntimeException(); } catch (WrongPolicy ex) { throw new RuntimeException(); } try { - root.deactivate_object(id); + rootPoa.deactivate_object(id2); } catch (ObjectNotActive ex) { throw new RuntimeException(); } catch (WrongPolicy ex) { @@ -353,52 +294,76 @@ static void TestServantActivator(ORB orb, POA root, POAManager 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"); + final static class TestActivator_impl extends ServantActivatorPOA { + private ORB orb_; - ORB orb = null; + private Test_impl test_; - 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(); - } + 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_; - 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); + // + // Fail + // + return null; } - if (orb != null) { - try { - orb.destroy(); - } catch (SystemException ex) { - ex.printStackTrace(); - System.exit(1); + 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; + } } } + } + + 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; + } - System.exit(0); + 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..ec9be8674 --- /dev/null +++ b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaCreate.java @@ -0,0 +1,30 @@ +/* + * 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 test.poa.TestCreate; +import testify.iiop.annotation.ConfigureOrb; + +@ConfigureOrb +public class TestPoaCreate { + @Test + public void testCreate() { +// TestCreate.main(); + } +} diff --git a/yoko-core/src/test/java/test/poa/TestDeactivate.java b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaDeactivate.java similarity index 56% rename from yoko-core/src/test/java/test/poa/TestDeactivate.java rename to yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaDeactivate.java index f0f4aeeee..e910a7363 100644 --- a/yoko-core/src/test/java/test/poa/TestDeactivate.java +++ b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaDeactivate.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 IBM Corporation and others. + * 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. @@ -15,104 +15,86 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package test.poa; +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 org.omg.PortableServer.POAPackage.ObjectAlreadyActive; +import org.omg.PortableServer.POAPackage.ObjectNotActive; +import org.omg.PortableServer.POAPackage.ServantAlreadyActive; +import org.omg.PortableServer.POAPackage.ServantNotActive; +import org.omg.PortableServer.POAPackage.WrongPolicy; +import test.poa.TestPOA; +import test.poa.Test_impl; +import testify.iiop.annotation.ConfigureOrb; import static org.junit.Assert.assertTrue; +// +// 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. +// +@ConfigureOrb +public class TestPoaDeactivate { + @Test + public void testDeactivate(ORB orb, POA rootPoa) { + Test_impl impl = new Test_impl(orb, "", false); -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_; - } + test.poa.Test t = impl._this(orb); - synchronized void blockUntilCalled() { - while (!called_) { - try { - wait(); - } catch (InterruptedException ex) { - } - } - } + t.aMethod(); - synchronized boolean callComplete() { - return finished_; + byte[] oid = null; + try { + oid = rootPoa.servant_to_id(impl); + } catch (ServantNotActive ex) { + assertTrue(false); + } catch (WrongPolicy ex) { + assertTrue(false); } - } - - final static class LongCaller extends Thread { - private Test t_; - LongCaller(Test t) { - t_ = t; + try { + rootPoa.deactivate_object(oid); + } catch (ObjectNotActive ex) { + assertTrue(false); + } catch (WrongPolicy ex) { + assertTrue(false); } - public void run() { - try { - t_.aMethod(); - } catch (SystemException ex) { - ex.printStackTrace(); - } + try { + t.aMethod(); + assertTrue(false); // expected OBJECT_NOT_EXIST + } catch (OBJECT_NOT_EXIST ex) { + // Expected } - } + Test_impl2 impl1 = new Test_impl2(rootPoa); - // - // 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.poa.Test t1 = impl1._this(orb); - Test t = impl._this(orb); - - byte[] oid = null; + byte[] oid1 = null; try { - oid = root.servant_to_id(impl); + oid1 = rootPoa.servant_to_id(impl1); } catch (ServantNotActive ex) { assertTrue(false); } catch (WrongPolicy ex) { assertTrue(false); } - Thread thr = new LongCaller(t); + Thread thr = new LongCaller(t1); thr.start(); - impl.blockUntilCalled(); + impl1.blockUntilCalled(); // // Test: deactivate_object while method call is active // try { - root.deactivate_object(oid); + rootPoa.deactivate_object(oid1); } catch (ObjectNotActive ex) { assertTrue(false); } catch (WrongPolicy ex) { @@ -124,7 +106,7 @@ static void TestDeactivateThreaded(ORB orb, POA root) { // complete until the method call completes // try { - root.activate_object_with_id(oid, impl); + rootPoa.activate_object_with_id(oid1, impl1); } catch (ObjectAlreadyActive ex) { assertTrue(false); } catch (ServantAlreadyActive ex) { @@ -137,7 +119,7 @@ static void TestDeactivateThreaded(ORB orb, POA root) { // The destroy call shouldn't return until the aMethod call is // complete // - assertTrue(impl.callComplete()); + assertTrue(impl1.callComplete()); // // Wait for the thread to terminate @@ -150,7 +132,7 @@ static void TestDeactivateThreaded(ORB orb, POA root) { } try { - root.deactivate_object(oid); + rootPoa.deactivate_object(oid1); } catch (ObjectNotActive ex) { assertTrue(false); } catch (WrongPolicy ex) { @@ -158,92 +140,59 @@ static void TestDeactivateThreaded(ORB orb, POA root) { } } - static void TestDeactivateBlocking(ORB orb, POA root) { - Test_impl impl = new Test_impl(orb, "", false); + final static class Test_impl2 extends TestPOA { + private POA poa_; - Test t = impl._this(orb); + private boolean called_ = false; - t.aMethod(); + private boolean finished_ = false; - byte[] oid = null; - try { - oid = root.servant_to_id(impl); - } catch (ServantNotActive ex) { - assertTrue(false); - } catch (WrongPolicy ex) { - assertTrue(false); + Test_impl2(POA poa) { + poa_ = poa; } - try { - root.deactivate_object(oid); - } catch (ObjectNotActive ex) { - assertTrue(false); - } catch (WrongPolicy ex) { - assertTrue(false); - } + synchronized public void aMethod() { + called_ = true; + notify(); - try { - t.aMethod(); - assertTrue(false); // expected OBJECT_NOT_EXIST - } catch (OBJECT_NOT_EXIST ex) { - // Expected + try { + wait(1000); + } catch (InterruptedException ex) { + } + finished_ = 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); - - // - // Activate the RootPOA manager - // - POAManager rootMgr = root.the_POAManager(); - assertTrue(rootMgr != null); + public POA _default_POA() { + return poa_; + } - try { - rootMgr.activate(); - } catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive ex) { - assertTrue(false); + synchronized void blockUntilCalled() { + while (!called_) { + try { + wait(); + } catch (InterruptedException ex) { + } } + } - System.out.print("Testing deactivate... "); - System.out.flush(); + synchronized boolean callComplete() { + return finished_; + } + } - // - // Run the tests using the root POA - // - TestDeactivateBlocking(orb, root); - TestDeactivateThreaded(orb, root); + final static class LongCaller extends Thread { + private test.poa.Test t_; - System.out.println("Done!"); - } catch (SystemException ex) { - ex.printStackTrace(); - status = 1; + LongCaller(test.poa.Test t) { + t_ = t; } - if (orb != null) { + public void run() { try { - orb.destroy(); + t_.aMethod(); } 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-testify/org/apache/yoko/orb/PortableServer/TestPoaDestroy.java similarity index 62% rename from yoko-core/src/test/java/test/poa/TestDestroy.java rename to yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaDestroy.java index 5ca56e28e..133038a45 100644 --- a/yoko-core/src/test/java/test/poa/TestDestroy.java +++ b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaDestroy.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 IBM Corporation and others. + * 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. @@ -15,142 +15,46 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package test.poa; +package org.apache.yoko.orb.PortableServer; + +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.AdapterAlreadyExists; +import org.omg.PortableServer.POAPackage.AdapterNonExistent; +import org.omg.PortableServer.POAPackage.InvalidPolicy; +import test.poa.TestPOA; +import testify.iiop.annotation.ConfigureOrb; 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.*; +// +// This is a more rigorous test of POA::destroy. We want to ensure +// that the POA isn't destroyed during a method call. +// -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) { +@ConfigureOrb +public class TestPoaDestroy { + @Test + public void testDestroy(ORB orb, POA rootPoa) { org.omg.CORBA.Object obj; Policy[] policies = new Policy[0]; POA poa, parent, poa2, poa3; POAManager mgr; String str; - POAManager rootMgr = root.the_POAManager(); + POAManager rootMgr = rootPoa.the_POAManager(); assertTrue(rootMgr != null); // // Create child POA // try { - poa = root.create_POA("poa1", rootMgr, policies); + poa = rootPoa.create_POA("poa1", rootMgr, policies); } catch (InvalidPolicy ex) { throw new RuntimeException(); } catch (AdapterAlreadyExists ex) { @@ -166,7 +70,7 @@ static void TestDestroyBlocking(ORB orb, POA root) { // Ensure parent no longer knows about child // try { - root.find_POA("poa1", false); + rootPoa.find_POA("poa1", false); assertTrue(false); // find_POA should not have succeeded } catch (AdapterNonExistent ex) { // expected @@ -176,7 +80,7 @@ static void TestDestroyBlocking(ORB orb, POA root) { // Create child POA // try { - poa = root.create_POA("poa1", rootMgr, policies); + poa = rootPoa.create_POA("poa1", rootMgr, policies); } catch (AdapterAlreadyExists ex) { throw new RuntimeException(); } catch (InvalidPolicy ex) { @@ -203,7 +107,7 @@ static void TestDestroyBlocking(ORB orb, POA root) { // Ensure parent no longer knows about child // try { - root.find_POA("poa1", false); + rootPoa.find_POA("poa1", false); assertTrue(false); // find_POA should not have succeeded } catch (AdapterNonExistent ex) { // expected @@ -212,54 +116,107 @@ static void TestDestroyBlocking(ORB orb, POA root) { // // XXX Test: etherealize w/ servant manager // - } + POAManager rootMgr1 = rootPoa.the_POAManager(); + assertTrue(rootMgr1 != null); - 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; + Policy[] policies1 = new Policy[1]; + policies1[0] = rootPoa + .create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION); + // + // Create child POA + // + POA poa1 = null; try { - // - // Create ORB - // - orb = ORB.init(args, props); + poa1 = rootPoa.create_POA("poa1", rootMgr1, policies1); + } catch (InvalidPolicy ex) { + throw new RuntimeException(); + } catch (AdapterAlreadyExists ex) { + throw new RuntimeException(); + } - POA root = TestUtil.GetRootPOA(orb); + Test_impl2 impl = new Test_impl2(poa1); - POAManager rootMgr = root.the_POAManager(); - assertTrue(rootMgr != null); + 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 { - rootMgr.activate(); - } catch (AdapterInactive ex) { - throw new RuntimeException(); + thr.join(); + } catch (InterruptedException ex) { } + } + } + + final static class Test_impl2 extends TestPOA { + private POA poa_; + + private boolean called_ = false; + + private boolean finished_ = false; - 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; + Test_impl2(POA poa) { + poa_ = poa; } - if (orb != null) { + synchronized public void aMethod() { + called_ = true; + notify(); + try { - orb.destroy(); - } catch (SystemException ex) { - ex.printStackTrace(); - status = 1; + wait(1000); + } catch (InterruptedException ex) { } + finished_ = true; + } + + public POA _default_POA() { + return poa_; } - System.exit(status); + synchronized void blockUntilCalled() { + while (!called_) { + try { + wait(); + } catch (InterruptedException ex) { + } + } + } + + synchronized boolean callComplete() { + return finished_; + } + } + + final static class LongCaller extends Thread { + private test.poa.Test t_; + + LongCaller(test.poa.Test t) { + 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/test/poa/TestFind.java b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaFind.java similarity index 54% rename from yoko-core/src/test/java/test/poa/TestFind.java rename to yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaFind.java index 300310d46..dd612d738 100644 --- a/yoko-core/src/test/java/test/poa/TestFind.java +++ b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaFind.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 IBM Corporation and others. + * 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. @@ -15,32 +15,38 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package test.poa; +package org.apache.yoko.orb.PortableServer; + +import org.junit.jupiter.api.Test; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Policy; +import org.omg.PortableServer.POA; +import org.omg.PortableServer.POAManager; +import org.omg.PortableServer.POAPackage.AdapterAlreadyExists; +import org.omg.PortableServer.POAPackage.AdapterNonExistent; +import org.omg.PortableServer.POAPackage.InvalidPolicy; +import testify.iiop.annotation.ConfigureOrb; 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) { +@ConfigureOrb +public class TestPoaFind { + @Test + public void testFind(ORB orb, POA rootPoa) { org.omg.CORBA.Object obj; Policy[] policies = new Policy[0]; POA poa, parent, poa2, poa3; POAManager mgr; String str; - POAManager rootMgr = root.the_POAManager(); + POAManager rootMgr = rootPoa.the_POAManager(); assertTrue(rootMgr != null); // // Create child POA // try { - poa = root.create_POA("poa1", rootMgr, policies); + poa = rootPoa.create_POA("poa1", rootMgr, policies); } catch (InvalidPolicy ex) { throw new RuntimeException(); } catch (AdapterAlreadyExists ex) { @@ -51,7 +57,7 @@ static void run(ORB orb, POA root) { // Test: find_POA // try { - poa2 = root.find_POA("poa1", false); + poa2 = rootPoa.find_POA("poa1", false); } catch (AdapterNonExistent ex) { throw new RuntimeException(); } @@ -62,7 +68,7 @@ static void run(ORB orb, POA root) { // Test: AdapterNonExistent exception // try { - poa2 = root.find_POA("poaX", false); + poa2 = rootPoa.find_POA("poaX", false); assertTrue(false); // find_POA should not have succeeded } catch (AdapterNonExistent ex) { // expected @@ -72,7 +78,7 @@ static void run(ORB orb, POA root) { // Create child POA // try { - poa2 = root.create_POA("poa2", rootMgr, policies); + poa2 = rootPoa.create_POA("poa2", rootMgr, policies); } catch (InvalidPolicy ex) { throw new RuntimeException(); } catch (AdapterAlreadyExists ex) { @@ -83,7 +89,7 @@ static void run(ORB orb, POA root) { // Test: Confirm parent knows about child // try { - poa3 = root.find_POA("poa2", false); + poa3 = rootPoa.find_POA("poa2", false); } catch (AdapterNonExistent ex) { throw new RuntimeException(); } @@ -91,46 +97,4 @@ static void run(ORB orb, POA root) { 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-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..f5e2db618 --- /dev/null +++ b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaMisc.java @@ -0,0 +1,40 @@ +/* + * 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.ORB; +import org.omg.CORBA.Policy; +import org.omg.PortableServer.POA; +import org.omg.PortableServer.POAManager; +import org.omg.PortableServer.POAPackage.AdapterAlreadyExists; +import org.omg.PortableServer.POAPackage.InvalidPolicy; +import test.poa.TestMisc; +import testify.iiop.annotation.ConfigureOrb; + +@ConfigureOrb +public class TestPoaMisc { + @Test + public void testMisc(ORB orb, POA rootPoa) throws RuntimeException, InvalidPolicy, AdapterAlreadyExists { + TestMisc.runtests(orb, rootPoa); + // Create a child POA and run the tests again using the child as the root + POAManager poaManager = rootPoa.the_POAManager(); + POA childPoa = rootPoa.create_POA("child", poaManager, new Policy[0]); + TestMisc.runtests(orb, childPoa); + } +} 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..bd3239f46 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,12 @@ 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 +41,10 @@ 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/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/TestMisc.java b/yoko-core/src/test/java/test/poa/TestMisc.java index b3de9e853..58b19d7d5 100644 --- a/yoko-core/src/test/java/test/poa/TestMisc.java +++ b/yoko-core/src/test/java/test/poa/TestMisc.java @@ -20,7 +20,6 @@ import static org.junit.Assert.assertTrue; import java.util.Arrays; -import java.util.Properties; import org.omg.CORBA.*; import org.omg.PortableServer.*; @@ -1052,7 +1051,7 @@ static void TestReferenceToId(ORB orb, POA root) { poa.destroy(true, true); } - static void runtests(ORB orb, POA root) { + public static void runtests(ORB orb, POA root) { TestCreateReference(orb, root); TestServantToId(orb, root); TestIdToServant(orb, root); @@ -1062,63 +1061,4 @@ static void runtests(ORB orb, POA 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); - } } From 3790f2b4360d71bdfdec030ef1331404f91b7580 Mon Sep 17 00:00:00 2001 From: habib Date: Fri, 28 Jul 2023 12:45:14 +0100 Subject: [PATCH 02/11] TST: refactored and ported POA deactivate test --- .../orb/PortableServer/TestPoaDeactivate.java | 176 +++++------------- 1 file changed, 43 insertions(+), 133 deletions(-) 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 index e910a7363..ee87e174d 100644 --- 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 @@ -22,174 +22,84 @@ import org.omg.CORBA.ORB; import org.omg.CORBA.SystemException; import org.omg.PortableServer.POA; -import org.omg.PortableServer.POAPackage.ObjectAlreadyActive; -import org.omg.PortableServer.POAPackage.ObjectNotActive; -import org.omg.PortableServer.POAPackage.ServantAlreadyActive; -import org.omg.PortableServer.POAPackage.ServantNotActive; -import org.omg.PortableServer.POAPackage.WrongPolicy; import test.poa.TestPOA; -import test.poa.Test_impl; import testify.iiop.annotation.ConfigureOrb; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; -// -// 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. -// + @ConfigureOrb public class TestPoaDeactivate { @Test - public void testDeactivate(ORB orb, POA rootPoa) { - Test_impl impl = new Test_impl(orb, "", false); - + 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()); + } - byte[] oid = null; - try { - oid = rootPoa.servant_to_id(impl); - } catch (ServantNotActive ex) { - assertTrue(false); - } catch (WrongPolicy ex) { - assertTrue(false); - } - - try { - rootPoa.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 - } - Test_impl2 impl1 = new Test_impl2(rootPoa); - - test.poa.Test t1 = impl1._this(orb); - - byte[] oid1 = null; - try { - oid1 = rootPoa.servant_to_id(impl1); - } catch (ServantNotActive ex) { - assertTrue(false); - } catch (WrongPolicy ex) { - assertTrue(false); - } - - Thread thr = new LongCaller(t1); - + // 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 testDeactivateWaitsForMethodCompletion(ORB orb, POA rootPoa) throws Exception { + Test_impl impl = new Test_impl(rootPoa); + test.poa.Test t = impl._this(orb); + byte[] oid = rootPoa.servant_to_id(impl); + Thread thr = new LongCaller(t); thr.start(); - impl1.blockUntilCalled(); - - // + impl.blockUntilCalled(); // Test: deactivate_object while method call is active - // - try { - rootPoa.deactivate_object(oid1); - } catch (ObjectNotActive ex) { - assertTrue(false); - } catch (WrongPolicy ex) { - assertTrue(false); - } + 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()); - // - // Once we've deactivated the object the re-activation shouldn't - // complete until the method call completes - // - try { - rootPoa.activate_object_with_id(oid1, impl1); - } 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(impl1.callComplete()); - - // // Wait for the thread to terminate - // while (thr.isAlive()) { try { thr.join(); - } catch (InterruptedException ex) { + } catch (InterruptedException ignored) { } } - - try { - rootPoa.deactivate_object(oid1); - } catch (ObjectNotActive ex) { - assertTrue(false); - } catch (WrongPolicy ex) { - assertTrue(false); - } + rootPoa.deactivate_object(oid); } - final static class Test_impl2 extends TestPOA { - private POA poa_; - - private boolean called_ = false; - - private boolean finished_ = false; - - Test_impl2(POA poa) { - poa_ = poa; + final static class Test_impl extends TestPOA { + private final POA poa; + private boolean called = false; + private boolean finished = false; + Test_impl(POA poa) { + this.poa = poa; } synchronized public void aMethod() { - called_ = true; + called = true; notify(); - - try { - wait(1000); - } catch (InterruptedException ex) { - } - finished_ = true; - } - - public POA _default_POA() { - return poa_; + try { wait(1000); } catch (InterruptedException ignored) {} + finished = true; } + public POA _default_POA() { return poa; } synchronized void blockUntilCalled() { - while (!called_) { - try { - wait(); - } catch (InterruptedException ex) { - } + while (!called) { + try { wait(); } catch (InterruptedException ignored) {} } } - - synchronized boolean callComplete() { - return finished_; - } + synchronized boolean callComplete() { return finished; } } final static class LongCaller extends Thread { - private test.poa.Test t_; - - LongCaller(test.poa.Test t) { - t_ = t; - } - + private final test.poa.Test test; + LongCaller(test.poa.Test test) { this.test = test; } public void run() { try { - t_.aMethod(); + test.aMethod(); } catch (SystemException ex) { ex.printStackTrace(); } From 4fd65b553f3d61b65d118d01755d07df1dc4d4b8 Mon Sep 17 00:00:00 2001 From: habib Date: Fri, 28 Jul 2023 16:24:19 +0100 Subject: [PATCH 03/11] TST: refactored and ported POA destroy test --- .../orb/PortableServer/TestPoaDeactivate.java | 8 +- .../orb/PortableServer/TestPoaDestroy.java | 177 +++++------------- 2 files changed, 48 insertions(+), 137 deletions(-) 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 index ee87e174d..2ab5e95ae 100644 --- 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 @@ -46,8 +46,8 @@ void testDeactivate(ORB orb, POA rootPoa) throws Exception { // should not complete for some time, since it should wait for all // outstanding method calls to complete. @Test - public void testDeactivateWaitsForMethodCompletion(ORB orb, POA rootPoa) throws Exception { - Test_impl impl = new Test_impl(rootPoa); + 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); @@ -70,11 +70,11 @@ public void testDeactivateWaitsForMethodCompletion(ORB orb, POA rootPoa) throws rootPoa.deactivate_object(oid); } - final static class Test_impl extends TestPOA { + final static class Test_impl1 extends TestPOA { private final POA poa; private boolean called = false; private boolean finished = false; - Test_impl(POA poa) { + Test_impl1(POA poa) { this.poa = poa; } 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 index 133038a45..1ec983815 100644 --- 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 @@ -17,202 +17,113 @@ */ 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.AdapterAlreadyExists; import org.omg.PortableServer.POAPackage.AdapterNonExistent; -import org.omg.PortableServer.POAPackage.InvalidPolicy; import test.poa.TestPOA; import testify.iiop.annotation.ConfigureOrb; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; -// -// This is a more rigorous test of POA::destroy. We want to ensure -// that the POA isn't destroyed during a method call. -// - @ConfigureOrb public class TestPoaDestroy { - @Test - public void testDestroy(ORB orb, POA rootPoa) { - org.omg.CORBA.Object obj; - Policy[] policies = new Policy[0]; - POA poa, parent, poa2, poa3; - POAManager mgr; - String str; - - POAManager rootMgr = rootPoa.the_POAManager(); - assertTrue(rootMgr != null); + private static POAManager rootMgr; - // - // Create child POA - // - try { - poa = rootPoa.create_POA("poa1", rootMgr, policies); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } + @BeforeAll + static void setup(POA rootPoa) throws Exception { + rootMgr = rootPoa.the_POAManager(); + } - // - // Test: destroy - // + @Test + void testDestroyPoa(POA rootPoa) throws Exception { + assertTrue(rootMgr != null); + POA poa = rootPoa.create_POA("poa1", rootMgr, new Policy[]{}); poa.destroy(true, true); - - // // Ensure parent no longer knows about child - // - try { - rootPoa.find_POA("poa1", false); - assertTrue(false); // find_POA should not have succeeded - } catch (AdapterNonExistent ex) { - // expected - } - - // - // Create child POA - // - try { - poa = rootPoa.create_POA("poa1", rootMgr, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } + assertThrows(AdapterNonExistent.class, () -> rootPoa.find_POA("poa1", false)); + } - // + @Test + void testDestroyPoaWithChild(ORB orb, POA rootPoa) throws Exception { + assertTrue(rootMgr != null); + POA poa = rootPoa.create_POA("poa1", rootMgr, new Policy[]{}); // 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(); - } - - // + 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 - // - try { - rootPoa.find_POA("poa1", false); - assertTrue(false); // find_POA should not have succeeded - } catch (AdapterNonExistent ex) { - // expected - } - - // - // XXX Test: etherealize w/ servant manager - // - POAManager rootMgr1 = rootPoa.the_POAManager(); - assertTrue(rootMgr1 != null); + assertThrows(AdapterNonExistent.class, () -> rootPoa.find_POA("poa1", false)); + } - Policy[] policies1 = new Policy[1]; - policies1[0] = rootPoa - .create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION); + @Test + void testDestroyWaitsForMethodCallCompletion(ORB orb, POA rootPoa) throws Exception { + assertTrue(rootMgr != null); - // // Create child POA - // - POA poa1 = null; - try { - poa1 = rootPoa.create_POA("poa1", rootMgr1, policies1); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } - - Test_impl2 impl = new Test_impl2(poa1); + 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 - // + // The destroy call shouldn't return until the aMethod call is complete assertTrue(impl.callComplete()); while (thr.isAlive()) { - try { - thr.join(); - } catch (InterruptedException ex) { - } + try { thr.join(); } catch (InterruptedException ex) {} } } - final static class Test_impl2 extends TestPOA { - private POA poa_; - - private boolean called_ = false; - - private boolean finished_ = false; - - Test_impl2(POA poa) { - poa_ = poa; + final static class Test_impl1 extends TestPOA { + private POA poa; + private boolean called = false; + private boolean finished = false; + Test_impl1(POA poa) { + this.poa = poa; } synchronized public void aMethod() { - called_ = true; + called = true; notify(); - - try { - wait(1000); - } catch (InterruptedException ex) { - } - finished_ = true; + try { wait(1000); } catch (InterruptedException ignored) {} + finished = true; } public POA _default_POA() { - return poa_; + return poa; } synchronized void blockUntilCalled() { - while (!called_) { - try { - wait(); - } catch (InterruptedException ex) { - } + while (!called) { + try { wait(); } catch (InterruptedException ignored) {} } } - synchronized boolean callComplete() { - return finished_; + return finished; } } final static class LongCaller extends Thread { - private test.poa.Test t_; - + private final test.poa.Test t; LongCaller(test.poa.Test t) { - t_ = t; + this.t = t; } - public void run() { try { - t_.aMethod(); + t.aMethod(); } catch (SystemException se) { System.err.println(se.getMessage()); se.printStackTrace(); From 018ff93b9e775eb07894eea4938112bc9ef4c027 Mon Sep 17 00:00:00 2001 From: habib Date: Fri, 28 Jul 2023 17:03:48 +0100 Subject: [PATCH 04/11] TST: refactored and ported POA find test --- .../yoko/orb/PortableServer/TestPoaFind.java | 62 ++----------------- 1 file changed, 5 insertions(+), 57 deletions(-) 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 index dd612d738..e19c2730f 100644 --- 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 @@ -18,83 +18,31 @@ package org.apache.yoko.orb.PortableServer; import org.junit.jupiter.api.Test; -import org.omg.CORBA.ORB; import org.omg.CORBA.Policy; import org.omg.PortableServer.POA; import org.omg.PortableServer.POAManager; -import org.omg.PortableServer.POAPackage.AdapterAlreadyExists; import org.omg.PortableServer.POAPackage.AdapterNonExistent; -import org.omg.PortableServer.POAPackage.InvalidPolicy; import testify.iiop.annotation.ConfigureOrb; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; @ConfigureOrb public class TestPoaFind { @Test - public void testFind(ORB orb, POA rootPoa) { - org.omg.CORBA.Object obj; - Policy[] policies = new Policy[0]; - POA poa, parent, poa2, poa3; - POAManager mgr; - String str; - + void testFind(POA rootPoa) throws Exception { POAManager rootMgr = rootPoa.the_POAManager(); assertTrue(rootMgr != null); - // // Create child POA - // - try { - poa = rootPoa.create_POA("poa1", rootMgr, policies); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } + POA poa = rootPoa.create_POA("poa1", rootMgr, new Policy[]{}); - // // Test: find_POA - // - try { - poa2 = rootPoa.find_POA("poa1", false); - } catch (AdapterNonExistent ex) { - throw new RuntimeException(); - } + POA poa2 = rootPoa.find_POA("poa1", false); assertTrue(poa2 != null); assertTrue(poa2._is_equivalent(poa)); - // // Test: AdapterNonExistent exception - // - try { - poa2 = rootPoa.find_POA("poaX", false); - assertTrue(false); // find_POA should not have succeeded - } catch (AdapterNonExistent ex) { - // expected - } - - // - // Create child POA - // - try { - poa2 = rootPoa.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 = rootPoa.find_POA("poa2", false); - } catch (AdapterNonExistent ex) { - throw new RuntimeException(); - } - - assertTrue(poa3 != null); - assertTrue(poa3._is_equivalent(poa2)); + assertThrows(AdapterNonExistent.class, () -> rootPoa.find_POA("poaX", false)); } } From 37b9250be472008db0cd74deff626086d349efc9 Mon Sep 17 00:00:00 2001 From: habib Date: Fri, 28 Jul 2023 17:40:01 +0100 Subject: [PATCH 05/11] TST: refactored and ported POA create test --- .../orb/PortableServer/TestPoaCreate.java | 72 ++++++- .../test/java/org/apache/yoko/PoaTest.java | 5 - .../src/test/java/test/poa/TestCreate.java | 186 ------------------ 3 files changed, 69 insertions(+), 194 deletions(-) delete mode 100644 yoko-core/src/test/java/test/poa/TestCreate.java 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 index ec9be8674..d7383c486 100644 --- 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 @@ -17,14 +17,80 @@ */ package org.apache.yoko.orb.PortableServer; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import test.poa.TestCreate; +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.assertThrows; +import static org.junit.Assert.assertTrue; + @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 { + assertTrue(rootMgr != null); + + // Test: POAManager should be in HOLDING state +// *** assertTrue(rootMgr.get_state() == State.HOLDING); + + // 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(); + assertTrue(!mgr._is_equivalent(rootMgr)); + + // Test: POAManager should be in HOLDING state + assertTrue(mgr.get_state() == State.HOLDING); + + // Test: Confirm name + String poaName = poa.the_name(); + assertTrue(poaName.equals("poa1")); + + // Test: Confirm parent + POA parent = poa.the_parent(); + assertTrue(parent._is_equivalent(rootPoa)); + + // Test: AdapterAlreadyExists exception + assertThrows(AdapterAlreadyExists.class, () -> rootPoa.create_POA("poa1", null, new Policy[]{})); + + // Test: InvalidPolicy exception + Policy[] invalidPolicies = new Policy[] { + rootPoa.create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.NON_RETAIN)}; + assertThrows(InvalidPolicy.class, () -> rootPoa.create_POA("invalid", null, invalidPolicies)); + + poa.destroy(true, true); + } + @Test - public void testCreate() { -// TestCreate.main(); + void testCreateChildOfChildPoa(POA rootPoa) throws Exception{ + // Create another child of root POA + POA poa = rootPoa.create_POA("poa", 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/org/apache/yoko/PoaTest.java b/yoko-core/src/test/java/org/apache/yoko/PoaTest.java index bd3239f46..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,7 +19,6 @@ import test.poa.TestAdapterActivatorServer; import test.poa.TestClient; -import test.poa.TestCreate; import test.poa.TestDefaultServantServer; import test.poa.TestDispatchStrategyClient; import test.poa.TestDispatchStrategyServer; @@ -41,10 +40,6 @@ public void setUp() throws Exception { setWaitForFile("Test.ref"); } - public void testCreate() throws Exception { - client.invokeMain(TestCreate.class); - } - public void testDefaultServant() throws Exception { runServerClientTest(TestDefaultServantServer.class); } 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); - } -} From 25b645fa4c397a20fcc996c656784638ceb52196 Mon Sep 17 00:00:00 2001 From: habib Date: Mon, 31 Jul 2023 15:43:13 +0100 Subject: [PATCH 06/11] TST: refactor assertions --- .../orb/PortableServer/TestPoaCreate.java | 21 ++++++++----------- .../orb/PortableServer/TestPoaDestroy.java | 11 +++++----- .../yoko/orb/PortableServer/TestPoaFind.java | 5 +++-- 3 files changed, 18 insertions(+), 19 deletions(-) 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 index d7383c486..189615bae 100644 --- 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 @@ -27,8 +27,12 @@ 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 { @@ -41,35 +45,28 @@ static void setup(POA rootPoa) { @Test public void testCreatePOA(POA rootPoa) throws Exception { - assertTrue(rootMgr != null); - - // Test: POAManager should be in HOLDING state -// *** assertTrue(rootMgr.get_state() == State.HOLDING); - // 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(); - assertTrue(!mgr._is_equivalent(rootMgr)); + assertFalse(mgr._is_equivalent(rootMgr)); // Test: POAManager should be in HOLDING state - assertTrue(mgr.get_state() == State.HOLDING); + assertSame(mgr.get_state(), State.HOLDING); // Test: Confirm name String poaName = poa.the_name(); - assertTrue(poaName.equals("poa1")); + assertEquals("poa1", poaName); // Test: Confirm parent POA parent = poa.the_parent(); assertTrue(parent._is_equivalent(rootPoa)); - // Test: AdapterAlreadyExists exception assertThrows(AdapterAlreadyExists.class, () -> rootPoa.create_POA("poa1", null, new Policy[]{})); - // Test: InvalidPolicy exception - Policy[] invalidPolicies = new Policy[] { - rootPoa.create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.NON_RETAIN)}; + //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); 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 index 1ec983815..7a3f8673a 100644 --- 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 @@ -28,6 +28,7 @@ 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; @@ -43,7 +44,7 @@ static void setup(POA rootPoa) throws Exception { @Test void testDestroyPoa(POA rootPoa) throws Exception { - assertTrue(rootMgr != null); + assertNotNull(rootMgr); POA poa = rootPoa.create_POA("poa1", rootMgr, new Policy[]{}); poa.destroy(true, true); // Ensure parent no longer knows about child @@ -52,7 +53,7 @@ void testDestroyPoa(POA rootPoa) throws Exception { @Test void testDestroyPoaWithChild(ORB orb, POA rootPoa) throws Exception { - assertTrue(rootMgr != null); + assertNotNull(rootMgr); POA poa = rootPoa.create_POA("poa1", rootMgr, new Policy[]{}); // Create child of child POA poa.create_POA("child1", rootMgr, new Policy[]{}); @@ -64,7 +65,7 @@ void testDestroyPoaWithChild(ORB orb, POA rootPoa) throws Exception { @Test void testDestroyWaitsForMethodCallCompletion(ORB orb, POA rootPoa) throws Exception { - assertTrue(rootMgr != null); + assertNotNull(rootMgr); // Create child POA POA poa1 = rootPoa.create_POA("poa1", rootMgr, new Policy[] { @@ -83,12 +84,12 @@ void testDestroyWaitsForMethodCallCompletion(ORB orb, POA rootPoa) throws Except assertTrue(impl.callComplete()); while (thr.isAlive()) { - try { thr.join(); } catch (InterruptedException ex) {} + try { thr.join(); } catch (InterruptedException ignored) {} } } final static class Test_impl1 extends TestPOA { - private POA poa; + private final POA poa; private boolean called = false; private boolean finished = false; Test_impl1(POA poa) { 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 index e19c2730f..db0e42bed 100644 --- 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 @@ -24,6 +24,7 @@ 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; @@ -32,14 +33,14 @@ public class TestPoaFind { @Test void testFind(POA rootPoa) throws Exception { POAManager rootMgr = rootPoa.the_POAManager(); - assertTrue(rootMgr != null); + assertNotNull(rootMgr); // Create child POA POA poa = rootPoa.create_POA("poa1", rootMgr, new Policy[]{}); // Test: find_POA POA poa2 = rootPoa.find_POA("poa1", false); - assertTrue(poa2 != null); + assertNotNull(poa2); assertTrue(poa2._is_equivalent(poa)); // Test: AdapterNonExistent exception From e3e2c7bc6847015ca199376626c54cb2cc390943 Mon Sep 17 00:00:00 2001 From: habib Date: Mon, 31 Jul 2023 18:56:56 +0100 Subject: [PATCH 07/11] TST: refactored TestPoaMisc --- .../yoko/orb/PortableServer/Policies.java | 36 + .../orb/PortableServer/TestPoaCreate.java | 2 +- .../yoko/orb/PortableServer/TestPoaMisc.java | 523 +++++++- .../src/test/java/test/poa/TestMisc.java | 1064 ----------------- 4 files changed, 551 insertions(+), 1074 deletions(-) create mode 100644 yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/Policies.java delete mode 100644 yoko-core/src/test/java/test/poa/TestMisc.java diff --git a/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/Policies.java b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/Policies.java new file mode 100644 index 000000000..f4f0b67ab --- /dev/null +++ b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/Policies.java @@ -0,0 +1,36 @@ +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.RequestProcessingPolicyValue; +import org.omg.PortableServer.ServantRetentionPolicyValue; + +import java.util.function.Function; +import java.util.stream.Stream; + +public enum Policies { + UNIQUE_ID(poa -> poa.create_id_uniqueness_policy(IdUniquenessPolicyValue.UNIQUE_ID)), + RETAIN(poa -> poa.create_servant_retention_policy(ServantRetentionPolicyValue.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)), + MULTIPLE_ID(poa -> poa.create_id_uniqueness_policy(IdUniquenessPolicyValue.MULTIPLE_ID)), + + PERSISTENT(poa -> poa.create_lifespan_policy(LifespanPolicyValue.PERSISTENT)), + USE_DEFAULT_SERVANT(poa -> poa.create_request_processing_policy(RequestProcessingPolicyValue.USE_DEFAULT_SERVANT)); + final Function factory; + + Policies(Function factory) { + this.factory = factory; + } + static Policy[] of(POA poa, Policies... policies) { + return Stream.of(policies) + .map(policy -> policy.factory.apply(poa)) + .toArray(Policy[]::new); + } +} 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 index 189615bae..61b8308e9 100644 --- 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 @@ -75,7 +75,7 @@ public void testCreatePOA(POA rootPoa) throws Exception { @Test void testCreateChildOfChildPoa(POA rootPoa) throws Exception{ // Create another child of root POA - POA poa = rootPoa.create_POA("poa", rootMgr, new Policy[]{}); + 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(); 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 index f5e2db618..aa1b20066 100644 --- 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 @@ -17,24 +17,529 @@ */ package org.apache.yoko.orb.PortableServer; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.omg.CORBA.BAD_PARAM; import org.omg.CORBA.ORB; import org.omg.CORBA.Policy; import org.omg.PortableServer.POA; import org.omg.PortableServer.POAManager; -import org.omg.PortableServer.POAPackage.AdapterAlreadyExists; -import org.omg.PortableServer.POAPackage.InvalidPolicy; -import test.poa.TestMisc; +import org.omg.PortableServer.POAPackage.ObjectAlreadyActive; +import org.omg.PortableServer.POAPackage.ObjectNotActive; +import org.omg.PortableServer.POAPackage.ServantAlreadyActive; +import org.omg.PortableServer.POAPackage.ServantNotActive; +import org.omg.PortableServer.POAPackage.WrongAdapter; +import org.omg.PortableServer.POAPackage.WrongPolicy; +import org.omg.PortableServer.Servant; +import test.poa.Test_impl; import testify.iiop.annotation.ConfigureOrb; +import java.util.Arrays; + +import static java.util.Objects.requireNonNull; +import static org.apache.yoko.orb.PortableServer.Policies.IMPLICIT_ACTIVATION; +import static org.apache.yoko.orb.PortableServer.Policies.MULTIPLE_ID; +import static org.apache.yoko.orb.PortableServer.Policies.NO_IMPLICIT_ACTIVATION; +import static org.apache.yoko.orb.PortableServer.Policies.PERSISTENT; +import static org.apache.yoko.orb.PortableServer.Policies.RETAIN; +import static org.apache.yoko.orb.PortableServer.Policies.UNIQUE_ID; +import static org.apache.yoko.orb.PortableServer.Policies.USER_ID; +import static org.apache.yoko.orb.PortableServer.Policies.USE_DEFAULT_SERVANT; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + @ConfigureOrb public class TestPoaMisc { + static POA rootPoa; + static POA childPoa; + + @BeforeAll + static void setup(POA rootPoa) throws Exception { + TestPoaMisc.rootPoa = rootPoa; + childPoa = rootPoa.create_POA("child", rootPoa.the_POAManager(), Policies.of(rootPoa)); + } + + @Test + public void testMiscRootPoa(ORB orb) throws Exception { + runTests(orb, rootPoa); + } + @Test - public void testMisc(ORB orb, POA rootPoa) throws RuntimeException, InvalidPolicy, AdapterAlreadyExists { - TestMisc.runtests(orb, rootPoa); - // Create a child POA and run the tests again using the child as the root - POAManager poaManager = rootPoa.the_POAManager(); - POA childPoa = rootPoa.create_POA("child", poaManager, new Policy[0]); - TestMisc.runtests(orb, childPoa); + public void testMiscChildPoa(ORB orb) throws Exception { + runTests(orb, childPoa); + } + + void runTests(ORB orb, POA root) throws Exception { + testCreateReference(root); + testServantToId(orb, root); + testIdToServant(orb, root); + testServantToReference(orb, root); + testIdToReference(orb, root); + testReferenceToServant(orb, root); + testReferenceToId(root); + } + + void testCreateReference(POA poa) throws Exception { + POAManager manager = poa.the_POAManager(); + POA user = poa.create_POA("user_id", manager, Policies.of(poa, Policies.USER_ID)); + POA system = poa.create_POA("system_id", manager, Policies.of(poa, Policies.SYSTEM_ID)); + + try { + assertThrows(WrongPolicy.class, () -> user.create_reference("IDL:Test:1.0")); + + // 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-generated ID + final byte[] userId1 = ("id1").getBytes(); + assertThrows(BAD_PARAM.class, () -> system.create_reference_with_id(userId1, "IDL:Test:1.0")); + + // Test: create_reference_with_id + assertArrayEquals(userId1, + user.reference_to_id(requireNonNull(user.create_reference_with_id(userId1, "IDL:Test:1.0")))); + final byte[] userId2 = ("id2").getBytes(); + assertArrayEquals(userId2, + user.reference_to_id(requireNonNull(user.create_reference_with_id(userId2, "IDL:Test:1.0")))); + } finally { + user.destroy(true, true); + system.destroy(true, true); + } + } + + void testServantToId(ORB orb, POA poa) throws Exception { + POAManager manager = poa.the_POAManager(); + + + POA unique = poa.create_POA("unique_id", manager, Policies.of(poa, UNIQUE_ID, USER_ID, RETAIN, NO_IMPLICIT_ACTIVATION)); + POA implicit = poa.create_POA("implicit", manager, Policies.of(poa, UNIQUE_ID, RETAIN, IMPLICIT_ACTIVATION)); + POA multiple = poa.create_POA("multiple", manager, Policies.of(poa, MULTIPLE_ID, RETAIN, IMPLICIT_ACTIVATION)); + + try { + Test_impl servant1 = new Test_impl(orb, "test1", false); + Test_impl servant2 = new Test_impl(orb, "test2", false); + + 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)); + + // 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))); + + // 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))); + } finally { + unique.destroy(true, true); + implicit.destroy(true, true); + multiple.destroy(true, true); + } + } + + void testIdToServant(ORB orb, POA poa) throws Exception { + POAManager manager = poa.the_POAManager(); + POA retain = poa.create_POA("retain", manager, Policies.of(poa, RETAIN, PERSISTENT, USER_ID)); + POA defaultPOA = poa.create_POA("default", manager, Policies.of(poa, MULTIPLE_ID, RETAIN, USE_DEFAULT_SERVANT, PERSISTENT, USER_ID)); + try { + Test_impl def = new Test_impl(orb, "default", false); + defaultPOA.set_servant(def); + + Test_impl servant1 = new Test_impl(orb, "test1", false); + Test_impl servant2 = new Test_impl(orb, "test2", false); + + assertThrows(ObjectNotActive.class, () -> retain.id_to_servant("bad_id".getBytes())); + + final byte[] id1 = "test1".getBytes(); + final byte[] id2 = "test2".getBytes(); + + retain.activate_object_with_id(id1, servant1); + retain.activate_object_with_id(id2, servant2); + + // Test: servant_to_id (RETAIN policy) + Servant tmpservant = retain.id_to_servant(id1); + assertSame(servant1, tmpservant); + + tmpservant = retain.id_to_servant(id2); + assertSame(servant2, tmpservant); + + // Test: id_to_servant (USE_DEFAULT_SERVANT) + defaultPOA.activate_object_with_id(id1, servant1); + defaultPOA.activate_object_with_id(id2, servant2); + + tmpservant = defaultPOA.id_to_servant(id1); + assertSame(servant1, tmpservant); + + tmpservant = defaultPOA.id_to_servant(id2); + assertSame(servant2, tmpservant); + + // Test: id_to_servant (USE_DEFAULT_SERVANT) - should return default servant for all unknown IDs + tmpservant = defaultPOA.id_to_servant(("test99").getBytes()); + assertSame(tmpservant, def); + } finally { + retain.destroy(true, true); + defaultPOA.destroy(true, true); + } + } + + void testServantToReference(ORB orb, POA root) throws Exception{ + POAManager manager = root.the_POAManager(); + POA unique = root.create_POA("unique_id", manager, Policies.of(root, UNIQUE_ID, USER_ID, RETAIN, NO_IMPLICIT_ACTIVATION)); + POA implicit = root.create_POA("implicit", manager, Policies.of(root, UNIQUE_ID, RETAIN, IMPLICIT_ACTIVATION)); + POA multiple = root.create_POA("multiple", manager, Policies.of(root, MULTIPLE_ID, RETAIN, IMPLICIT_ACTIVATION)); + + Test_impl servant1 = new Test_impl(orb, "test1", false); + Test_impl servant2 = new Test_impl(orb, "test2", false); + try { + assertThrows(ServantNotActive.class, () -> unique.servant_to_reference(servant1)); + + byte[] id1 = "test1".getBytes(); + unique.activate_object_with_id(id1, servant1); + + // Test: servant_to_reference (UNIQUE_ID policy) + byte[] tmpid1 = unique.reference_to_id(requireNonNull(unique.servant_to_reference(servant1))); + assertArrayEquals(id1, tmpid1); + + // Test: servant_to_reference (IMPLICIT_ACTIVATION) - servant1 should be automatically activated + tmpid1 = 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[] tmpid2 = implicit.reference_to_id(requireNonNull(implicit.servant_to_reference(servant1))); + assertArrayEquals(tmpid1, tmpid2); + + // Test: Implicitly activating servant2 should produce a new ID + tmpid2 = implicit.reference_to_id(requireNonNull(implicit.servant_to_reference(servant2))); + assertFalse(Arrays.equals(tmpid1, tmpid2)); + + // Test: servant_to_reference (IMPLICIT_ACTIVATION, MULTIPLE_ID) - servant1 should be automatically activated + tmpid1 = multiple.reference_to_id(requireNonNull(multiple.servant_to_reference(servant1))); + + // Test: Since we have MULTIPLE_ID, we should get a new ID + tmpid2 = multiple.reference_to_id(requireNonNull(multiple.servant_to_reference(servant1))); + assertFalse(Arrays.equals(tmpid1, tmpid2)); + } finally { + unique.destroy(true, true); + implicit.destroy(true, true); + multiple.destroy(true, true); + } } + + void testIdToReference(ORB orb, POA root) throws Exception{ + 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 + // + retain = root.create_POA("retain", manager, Policies.of(root, RETAIN, PERSISTENT, USER_ID)); + + + 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); + fail(); // 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(); + } + assertNotNull(obj); + try { + tmpid = retain.reference_to_id(obj); + } catch (WrongAdapter ex) { + throw new RuntimeException(); + } catch (WrongPolicy ex) { + throw new RuntimeException(); + } + assertArrayEquals(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(); + } + assertNotNull(obj); + try { + tmpid = retain.reference_to_id(obj); + } catch (WrongAdapter ex) { + throw new RuntimeException(); + } catch (WrongPolicy ex) { + throw new RuntimeException(); + } + assertArrayEquals(id2, tmpid); + + retain.destroy(true, true); + } + + void testReferenceToServant(ORB orb, POA root) throws Exception{ + 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 + retain = root.create_POA("retain", manager, Policies.of(root, RETAIN, PERSISTENT, USER_ID)); + + + // Create POA w/ USE_DEFAULT_SERVANT + defaultPOA = root.create_POA("default", manager, Policies.of(root, MULTIPLE_ID, RETAIN, USE_DEFAULT_SERVANT, PERSISTENT, USER_ID)); + + 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); + fail(); // 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(); + } + assertSame(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(); + } + assertSame(servant2, tmpservant); + + // + // Test: WrongAdapter exception + // + try { + obj = retain.create_reference_with_id(id1, "IDL:Test:1.0"); + defaultPOA.reference_to_servant(obj); + fail(); // 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(); + } + assertSame(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(); + } + assertSame(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(); + } + assertSame(tmpservant, def); + tmpservant = null; + + retain.destroy(true, true); + defaultPOA.destroy(true, true); + } + + void testReferenceToId(POA root) throws Exception{ + org.omg.CORBA.Object obj; + POA poa; + byte[] id1, id2, tmpid; + Policy[] policies; + + POAManager manager = root.the_POAManager(); + + // Create POA + poa = root.create_POA("poa", manager, Policies.of(root, RETAIN, PERSISTENT, USER_ID)); + + + 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(); + } + assertArrayEquals(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(); + } + assertArrayEquals(tmpid, id2); + + // + // Test: WrongAdapter exception + // + try { + obj = poa.create_reference_with_id(id1, "IDL:Test:1.0"); + root.reference_to_id(obj); + fail(); // reference_to_id should not have succeeded + } catch (WrongAdapter ex) { + // expected + } catch (WrongPolicy ex) { + throw new RuntimeException(); + } + + poa.destroy(true, true); + } + + + } 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 58b19d7d5..000000000 --- a/yoko-core/src/test/java/test/poa/TestMisc.java +++ /dev/null @@ -1,1064 +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 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); - } - - public 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); - } - -} From 526fda98f3969e254b3a3b10a61ac738d06ec503 Mon Sep 17 00:00:00 2001 From: Joe Chacko <143064+joe-chacko@users.noreply.github.com> Date: Tue, 1 Aug 2023 12:22:37 +0100 Subject: [PATCH 08/11] TST: simplified TestPoaMisc --- .../{Policies.java => PolicyValue.java} | 36 +- .../yoko/orb/PortableServer/TestPoaMisc.java | 604 ++++++------------ 2 files changed, 208 insertions(+), 432 deletions(-) rename yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/{Policies.java => PolicyValue.java} (56%) diff --git a/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/Policies.java b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/PolicyValue.java similarity index 56% rename from yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/Policies.java rename to yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/PolicyValue.java index f4f0b67ab..ef9c9dbc5 100644 --- a/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/Policies.java +++ b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/PolicyValue.java @@ -1,3 +1,20 @@ +/* + * 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; @@ -6,31 +23,36 @@ 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 Policies { +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)), 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)), - MULTIPLE_ID(poa -> poa.create_id_uniqueness_policy(IdUniquenessPolicyValue.MULTIPLE_ID)), - PERSISTENT(poa -> poa.create_lifespan_policy(LifespanPolicyValue.PERSISTENT)), USE_DEFAULT_SERVANT(poa -> poa.create_request_processing_policy(RequestProcessingPolicyValue.USE_DEFAULT_SERVANT)); + final Function factory; - Policies(Function factory) { + PolicyValue(Function factory) { this.factory = factory; } - static Policy[] of(POA poa, Policies... policies) { - return Stream.of(policies) - .map(policy -> policy.factory.apply(poa)) + + 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/TestPoaMisc.java b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaMisc.java index aa1b20066..380edef29 100644 --- 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 @@ -18,528 +18,282 @@ package org.apache.yoko.orb.PortableServer; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; +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.Policy; +import org.omg.CORBA.Object; import org.omg.PortableServer.POA; import org.omg.PortableServer.POAManager; -import org.omg.PortableServer.POAPackage.ObjectAlreadyActive; import org.omg.PortableServer.POAPackage.ObjectNotActive; -import org.omg.PortableServer.POAPackage.ServantAlreadyActive; import org.omg.PortableServer.POAPackage.ServantNotActive; import org.omg.PortableServer.POAPackage.WrongAdapter; import org.omg.PortableServer.POAPackage.WrongPolicy; -import org.omg.PortableServer.Servant; 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.Policies.IMPLICIT_ACTIVATION; -import static org.apache.yoko.orb.PortableServer.Policies.MULTIPLE_ID; -import static org.apache.yoko.orb.PortableServer.Policies.NO_IMPLICIT_ACTIVATION; -import static org.apache.yoko.orb.PortableServer.Policies.PERSISTENT; -import static org.apache.yoko.orb.PortableServer.Policies.RETAIN; -import static org.apache.yoko.orb.PortableServer.Policies.UNIQUE_ID; -import static org.apache.yoko.orb.PortableServer.Policies.USER_ID; -import static org.apache.yoko.orb.PortableServer.Policies.USE_DEFAULT_SERVANT; +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.assertNotNull; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.fail; @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; - @BeforeAll - static void setup(POA rootPoa) throws Exception { - TestPoaMisc.rootPoa = rootPoa; - childPoa = rootPoa.create_POA("child", rootPoa.the_POAManager(), Policies.of(rootPoa)); + enum PoaChoice { + ROOT_POA, CHILD_POA; + POA poa() { return this == ROOT_POA ? rootPoa : childPoa; } } - @Test - public void testMiscRootPoa(ORB orb) throws Exception { - runTests(orb, rootPoa); - } + interface Cleanup extends EasyCloseable {} // use this to register try-with-resources - @Test - public void testMiscChildPoa(ORB orb) throws Exception { - runTests(orb, childPoa); - } + @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); - void runTests(ORB orb, POA root) throws Exception { - testCreateReference(root); - testServantToId(orb, root); - testIdToServant(orb, root); - testServantToReference(orb, root); - testIdToReference(orb, root); - testReferenceToServant(orb, root); - testReferenceToId(root); } - void testCreateReference(POA poa) throws Exception { + @ParameterizedTest @EnumSource(PoaChoice.class) + void testCreateReferenceSystem(PoaChoice which) throws Exception { + POA poa = which.poa(); POAManager manager = poa.the_POAManager(); - POA user = poa.create_POA("user_id", manager, Policies.of(poa, Policies.USER_ID)); - POA system = poa.create_POA("system_id", manager, Policies.of(poa, Policies.SYSTEM_ID)); - - try { - assertThrows(WrongPolicy.class, () -> user.create_reference("IDL:Test:1.0")); + 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")); + } + } - // Test: create_reference_with_id using a user-generated ID - final byte[] userId1 = ("id1").getBytes(); - assertThrows(BAD_PARAM.class, () -> system.create_reference_with_id(userId1, "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(userId1, - user.reference_to_id(requireNonNull(user.create_reference_with_id(userId1, "IDL:Test:1.0")))); - final byte[] userId2 = ("id2").getBytes(); - assertArrayEquals(userId2, - user.reference_to_id(requireNonNull(user.create_reference_with_id(userId2, "IDL:Test:1.0")))); - } finally { - user.destroy(true, true); - system.destroy(true, true); + 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")))); } } - void testServantToId(ORB orb, POA poa) throws Exception { + @ParameterizedTest @EnumSource(PoaChoice.class) + void testServantToIdUnique(PoaChoice which) throws Exception { + POA poa = which.poa(); POAManager manager = poa.the_POAManager(); - - - POA unique = poa.create_POA("unique_id", manager, Policies.of(poa, UNIQUE_ID, USER_ID, RETAIN, NO_IMPLICIT_ACTIVATION)); - POA implicit = poa.create_POA("implicit", manager, Policies.of(poa, UNIQUE_ID, RETAIN, IMPLICIT_ACTIVATION)); - POA multiple = poa.create_POA("multiple", manager, Policies.of(poa, MULTIPLE_ID, RETAIN, IMPLICIT_ACTIVATION)); - - try { - Test_impl servant1 = new Test_impl(orb, "test1", false); - Test_impl servant2 = new Test_impl(orb, "test2", false); - + 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))); - } finally { - unique.destroy(true, true); - implicit.destroy(true, true); - multiple.destroy(true, true); } } - void testIdToServant(ORB orb, POA poa) throws Exception { + @ParameterizedTest @EnumSource(PoaChoice.class) + void testServantToReferenceUnique(PoaChoice which) throws Exception { + POA poa = which.poa(); POAManager manager = poa.the_POAManager(); - POA retain = poa.create_POA("retain", manager, Policies.of(poa, RETAIN, PERSISTENT, USER_ID)); - POA defaultPOA = poa.create_POA("default", manager, Policies.of(poa, MULTIPLE_ID, RETAIN, USE_DEFAULT_SERVANT, PERSISTENT, USER_ID)); - try { - Test_impl def = new Test_impl(orb, "default", false); - defaultPOA.set_servant(def); - - Test_impl servant1 = new Test_impl(orb, "test1", false); - Test_impl servant2 = new Test_impl(orb, "test2", false); - - assertThrows(ObjectNotActive.class, () -> retain.id_to_servant("bad_id".getBytes())); - - final byte[] id1 = "test1".getBytes(); - final byte[] id2 = "test2".getBytes(); - - retain.activate_object_with_id(id1, servant1); - retain.activate_object_with_id(id2, servant2); - - // Test: servant_to_id (RETAIN policy) - Servant tmpservant = retain.id_to_servant(id1); - assertSame(servant1, tmpservant); - - tmpservant = retain.id_to_servant(id2); - assertSame(servant2, tmpservant); - - // Test: id_to_servant (USE_DEFAULT_SERVANT) - defaultPOA.activate_object_with_id(id1, servant1); - defaultPOA.activate_object_with_id(id2, servant2); - - tmpservant = defaultPOA.id_to_servant(id1); - assertSame(servant1, tmpservant); - - tmpservant = defaultPOA.id_to_servant(id2); - assertSame(servant2, tmpservant); - - // Test: id_to_servant (USE_DEFAULT_SERVANT) - should return default servant for all unknown IDs - tmpservant = defaultPOA.id_to_servant(("test99").getBytes()); - assertSame(tmpservant, def); - } finally { - retain.destroy(true, true); - defaultPOA.destroy(true, true); + 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)))); } } - void testServantToReference(ORB orb, POA root) throws Exception{ - POAManager manager = root.the_POAManager(); - POA unique = root.create_POA("unique_id", manager, Policies.of(root, UNIQUE_ID, USER_ID, RETAIN, NO_IMPLICIT_ACTIVATION)); - POA implicit = root.create_POA("implicit", manager, Policies.of(root, UNIQUE_ID, RETAIN, IMPLICIT_ACTIVATION)); - POA multiple = root.create_POA("multiple", manager, Policies.of(root, MULTIPLE_ID, RETAIN, IMPLICIT_ACTIVATION)); - - Test_impl servant1 = new Test_impl(orb, "test1", false); - Test_impl servant2 = new Test_impl(orb, "test2", false); - try { - assertThrows(ServantNotActive.class, () -> unique.servant_to_reference(servant1)); - - byte[] id1 = "test1".getBytes(); - unique.activate_object_with_id(id1, servant1); - - // Test: servant_to_reference (UNIQUE_ID policy) - byte[] tmpid1 = unique.reference_to_id(requireNonNull(unique.servant_to_reference(servant1))); - assertArrayEquals(id1, tmpid1); - + @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 - tmpid1 = implicit.reference_to_id(requireNonNull(implicit.servant_to_reference(servant1))); - + 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[] tmpid2 = implicit.reference_to_id(requireNonNull(implicit.servant_to_reference(servant1))); - assertArrayEquals(tmpid1, tmpid2); - + 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 - tmpid2 = implicit.reference_to_id(requireNonNull(implicit.servant_to_reference(servant2))); - assertFalse(Arrays.equals(tmpid1, tmpid2)); + 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 - tmpid1 = multiple.reference_to_id(requireNonNull(multiple.servant_to_reference(servant1))); - + byte[] id1 = multiple.reference_to_id(requireNonNull(multiple.servant_to_reference(servant1))); // Test: Since we have MULTIPLE_ID, we should get a new ID - tmpid2 = multiple.reference_to_id(requireNonNull(multiple.servant_to_reference(servant1))); - assertFalse(Arrays.equals(tmpid1, tmpid2)); - } finally { - unique.destroy(true, true); - implicit.destroy(true, true); - multiple.destroy(true, true); + byte[] id2 = multiple.reference_to_id(requireNonNull(multiple.servant_to_reference(servant1))); + assertFalse(Arrays.equals(id1, id2)); } } - void testIdToReference(ORB orb, POA root) throws Exception{ - 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 - // - retain = root.create_POA("retain", manager, Policies.of(root, RETAIN, PERSISTENT, USER_ID)); - - - 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); - fail(); // id_to_reference should not have succeeded - } catch (ObjectNotActive ex) { - // expected - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } + @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())); - 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(); - } + retain.activate_object_with_id("test1".getBytes(), servant1); + retain.activate_object_with_id("test2".getBytes(), servant2); - // - // Test: servant_to_reference - // - try { - obj = retain.id_to_reference(id1); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } - assertNotNull(obj); - try { - tmpid = retain.reference_to_id(obj); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertArrayEquals(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(); - } - assertNotNull(obj); - try { - tmpid = retain.reference_to_id(obj); - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); + // Test: servant_to_id (RETAIN policy) + assertSame(servant1, retain.id_to_servant("test1".getBytes())); + assertSame(servant2, retain.id_to_servant("test2".getBytes())); } - assertArrayEquals(id2, tmpid); - - retain.destroy(true, true); } - void testReferenceToServant(ORB orb, POA root) throws Exception{ - 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 - retain = root.create_POA("retain", manager, Policies.of(root, RETAIN, PERSISTENT, USER_ID)); + @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())); - // Create POA w/ USE_DEFAULT_SERVANT - defaultPOA = root.create_POA("default", manager, Policies.of(root, MULTIPLE_ID, RETAIN, USE_DEFAULT_SERVANT, PERSISTENT, USER_ID)); + retain.activate_object_with_id("test1".getBytes(), servant1); + retain.activate_object_with_id("test2".getBytes(), servant2); - def = new Test_impl(orb, "default", false); - try { - defaultPOA.set_servant(def); - } catch (WrongPolicy ex) { - throw new RuntimeException(); + 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())))); } + } - 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); - fail(); // reference_to_servant should not have succeeded - } catch (ObjectNotActive ex) { - // expected - } catch (WrongAdapter ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } + @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); - 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(); - } + 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)); - // - // 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(); - } - assertSame(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(); - } - assertSame(servant2, tmpservant); - - // - // Test: WrongAdapter exception - // - try { - obj = retain.create_reference_with_id(id1, "IDL:Test:1.0"); - defaultPOA.reference_to_servant(obj); - fail(); // reference_to_servant should not have succeeded - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } catch (WrongAdapter ex) { - // expected - } + retain.activate_object_with_id("test1".getBytes(), servant1); + retain.activate_object_with_id("test2".getBytes(), servant2); - // - // 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(); - } - assertSame(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(); + 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"))); } - assertSame(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(); - } - assertSame(tmpservant, def); - tmpservant = null; - - retain.destroy(true, true); - defaultPOA.destroy(true, true); } - void testReferenceToId(POA root) throws Exception{ - org.omg.CORBA.Object obj; - POA poa; - byte[] id1, id2, tmpid; - Policy[] policies; - - POAManager manager = root.the_POAManager(); + @ParameterizedTest @EnumSource(PoaChoice.class) + void testReferenceToServantDefault(PoaChoice which) throws Exception { + POA poa = which.poa(); + POAManager manager = poa.the_POAManager(); - // Create POA - poa = root.create_POA("poa", manager, Policies.of(root, RETAIN, PERSISTENT, USER_ID)); + 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)); - id1 = ("test1").getBytes(); - id2 = ("test2").getBytes(); + defaultPoa.activate_object_with_id("test1".getBytes(), servant1); + defaultPoa.activate_object_with_id("test2".getBytes(), servant2); - // - // 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(); - } - assertArrayEquals(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(); - } - assertArrayEquals(tmpid, id2); - - // - // Test: WrongAdapter exception - // - try { - obj = poa.create_reference_with_id(id1, "IDL:Test:1.0"); - root.reference_to_id(obj); - fail(); // reference_to_id should not have succeeded - } catch (WrongAdapter ex) { - // expected - } catch (WrongPolicy ex) { - throw new RuntimeException(); + 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"))); } - - poa.destroy(true, true); } - - + @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"))); + } + } } From 8e52d0bbd231a3fd818c128f6c069f2f334401d9 Mon Sep 17 00:00:00 2001 From: Joe Chacko <143064+joe-chacko@users.noreply.github.com> Date: Tue, 1 Aug 2023 17:01:29 +0100 Subject: [PATCH 09/11] TST: ported collocated POA tests --- .../yoko/orb/PortableServer/PolicyValue.java | 5 +- .../orb/PortableServer/TestPoaCollocated.java | 415 +++++------------- 2 files changed, 111 insertions(+), 309 deletions(-) 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 index ef9c9dbc5..b0ffc6aad 100644 --- 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 @@ -36,12 +36,15 @@ 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_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; 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 index 7db472262..b82116b69 100644 --- 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 @@ -17,18 +17,16 @@ */ package org.apache.yoko.orb.PortableServer; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import org.omg.CORBA.ORB; -import org.omg.CORBA.Policy; import org.omg.CORBA.Request; import org.omg.PortableServer.ForwardRequest; 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.POAPackage.ObjectNotActive; -import org.omg.PortableServer.POAPackage.ServantNotActive; -import org.omg.PortableServer.POAPackage.WrongPolicy; import org.omg.PortableServer.Servant; import org.omg.PortableServer.ServantActivator; import org.omg.PortableServer.ServantActivatorPOA; @@ -39,331 +37,132 @@ import test.poa.TestHelper; import test.poa.Test_impl; import testify.iiop.annotation.ConfigureOrb; - -import static org.junit.Assert.assertTrue; +import testify.util.function.RawConsumer; + +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 { - static void TestPOA(POA poa) { - byte[] id; - org.omg.CORBA.Object obj; - Request request; - test.poa.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); +class TestPoaCollocated { + enum InvokeAction { + STATIC_INVOKE_STATIC_SERVANT(poa -> invokeStatic(poa, "test")), + STATIC_INVOKE_DYNAMIC_SERVANT(poa -> invokeStatic(poa, "testDSI")), + DYNAMIC_INVOKE_STATIC_SERVANT(poa -> invokeDynamic(poa, "test")), + DYNAMIC_INVOKE_DYNAMIC_SERVANT(poa -> invokeDynamic(poa, "testDSI")); + final RawConsumer invokeAction; + InvokeAction(RawConsumer invokeAction) { this.invokeAction = invokeAction; } + final void run(POA poa) throws Exception { invokeAction.acceptRaw(poa); } + private static void invokeStatic(POA poa, String id) { + TestHelper.narrow(poa.create_reference_with_id(id.getBytes(), "IDL:Test:1.0")).aMethod(); + } + private static void invokeDynamic(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(); + } } - @Test - public void testCollocated(ORB orb, POA rootPoa) throws Exception { - POAManager manager = rootPoa.the_POAManager(); - manager.activate(); - POA poa; - Servant servant; - Policy[] policies; - - // - // Setup policies for default servant - // - policies = new Policy[6]; - policies[0] = rootPoa - .create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.PERSISTENT); - policies[1] = rootPoa - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); - policies[2] = rootPoa - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.NON_RETAIN); - policies[3] = rootPoa - .create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION); - policies[4] = rootPoa - .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID); - policies[5] = rootPoa - .create_request_processing_policy(org.omg.PortableServer.RequestProcessingPolicyValue.USE_DEFAULT_SERVANT); + static ORB orb; + static POA rootPoa; + static POAManager rootPoaManager; + static Test_impl defaultStaticServant; + static Test_impl locatorSSI; + POA poa; + + @BeforeAll + static void setup(ORB orb, POA rootPoa) { + TestPoaCollocated.orb = orb; + TestPoaCollocated.rootPoa = rootPoa; + TestPoaCollocated.rootPoaManager = rootPoa.the_POAManager(); + TestPoaCollocated.defaultStaticServant = new Test_impl(orb, "defaultStaticServant", false); + TestPoaCollocated.locatorSSI = new Test_impl(orb, "locator_SSI", false); + } - // - // Create POA w/ static Default Servant - // - try { - poa = rootPoa.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); + @AfterEach + void destroyPoa() { + if (poa == null) return; poa.destroy(true, true); + poa = null; + } - // - // Since staticServant is a stack-based servant, we need to deactivate - // it before it goes out of scope - // - byte[] id = null; - try { - id = rootPoa.servant_to_id(staticServant); - } catch (ServantNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - try { - rootPoa.deactivate_object(id); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - // - // Create POA w/ DSI Default Servant - // - try { - poa = rootPoa.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; + @AfterAll + static void teardown() throws Exception { + byte[] id = rootPoa.servant_to_id(defaultStaticServant); + rootPoa.deactivate_object(id); + } - // - // Clean up policies - // - for (int i = 0; i < policies.length; i++) - policies[i].destroy(); - POA poa1; - Servant servant1; - Policy[] policies1; + @ParameterizedTest @EnumSource(InvokeAction.class) + public void testStaticDefaultServant(InvokeAction action) throws Exception { + poa = create_POA("defaultSSI", rootPoa, rootPoaManager, PERSISTENT, USER_ID, NON_RETAIN, NO_IMPLICIT_ACTIVATION, MULTIPLE_ID, USE_DEFAULT_SERVANT); + poa.set_servant(defaultStaticServant); + action.run(poa); + } - // - // Setup policies for servant locator - // - policies1 = new Policy[6]; - policies1[0] = rootPoa - .create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.PERSISTENT); - policies1[1] = rootPoa - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); - policies1[2] = rootPoa - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.NON_RETAIN); - policies1[3] = rootPoa - .create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION); - policies1[4] = rootPoa - .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.UNIQUE_ID); - policies1[5] = rootPoa - .create_request_processing_policy(org.omg.PortableServer.RequestProcessingPolicyValue.USE_SERVANT_MANAGER); + @ParameterizedTest @EnumSource(InvokeAction.class) + void testDynamicDefaultServant(InvokeAction action) throws Exception { + poa = create_POA("defaultDSI", rootPoa, rootPoaManager, PERSISTENT, USER_ID, NON_RETAIN, NO_IMPLICIT_ACTIVATION, MULTIPLE_ID, USE_DEFAULT_SERVANT); + poa.set_servant(new TestDSIRef_impl(orb, "defaultDSIServant", false)); + action.run(poa); + } - // - // Create POA w/ Servant Locator - // - try { - poa1 = rootPoa.create_POA("servloc", manager, policies1); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - TestLocator_impl locatorImpl = new TestLocator_impl(orb); + @ParameterizedTest @EnumSource(InvokeAction.class) + void testServantLocator(InvokeAction action) throws Exception { + poa = create_POA("servloc", rootPoa, rootPoaManager, PERSISTENT, USER_ID, NON_RETAIN, NO_IMPLICIT_ACTIVATION, UNIQUE_ID, USE_SERVANT_MANAGER); + TestLocator locatorImpl = new TestLocator(); ServantLocator locator = locatorImpl._this(orb); - try { - poa1.set_servant_manager(locator); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - TestPOA(poa1); - poa1.destroy(true, true); - - // - // Clean up policies - // - for (int i = 0; i < policies1.length; i++) - policies1[i].destroy(); - - // - // Since locatorImpl is a stack-based servant, we need to deactivate - // it before it goes out of scope - // - byte[] id1 = null; - try { - id1 = rootPoa.servant_to_id(locatorImpl); - } catch (ServantNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - try { - rootPoa.deactivate_object(id1); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - POA poa2; - Servant servant2; - Policy[] policies2; - - // - // Setup policies for servant activator - // - policies2 = new Policy[6]; - policies2[0] = rootPoa - .create_lifespan_policy(org.omg.PortableServer.LifespanPolicyValue.PERSISTENT); - policies2[1] = rootPoa - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); - policies2[2] = rootPoa - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN); - policies2[3] = rootPoa - .create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION); - policies2[4] = rootPoa - .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.UNIQUE_ID); - policies2[5] = rootPoa - .create_request_processing_policy(org.omg.PortableServer.RequestProcessingPolicyValue.USE_SERVANT_MANAGER); + poa.set_servant_manager(locator); + action.run(poa); + rootPoa.deactivate_object(rootPoa.servant_to_id(locatorImpl)); + } - // - // Create POA w/ Servant Activator - // - try { - poa2 = rootPoa.create_POA("servant", manager, policies2); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - TestActivator_impl activatorImpl = new TestActivator_impl(orb); + @ParameterizedTest @EnumSource(InvokeAction.class) + void testServantActivator(InvokeAction action) throws Exception { + poa = create_POA("servant", rootPoa, rootPoaManager, PERSISTENT, USER_ID, RETAIN, NO_IMPLICIT_ACTIVATION, UNIQUE_ID, USE_SERVANT_MANAGER); + TestActivator activatorImpl = new TestActivator(); ServantActivator activator = activatorImpl._this(orb); - try { - poa2.set_servant_manager(activator); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - TestPOA(poa2); - poa2.destroy(true, true); - - // - // Clean up policies - // - for (int i = 0; i < policies2.length; i++) - policies2[i].destroy(); - - // - // Since activatorImpl is a stack-based servant, we need to deactivate - // it before it goes out of scope - // - byte[] id2 = null; - try { - id2 = rootPoa.servant_to_id(activatorImpl); - } catch (ServantNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - try { - rootPoa.deactivate_object(id2); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } + poa.set_servant_manager(activator); + action.run(poa); + rootPoa.deactivate_object(rootPoa.servant_to_id(activatorImpl)); } - 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); - } - + final static class TestActivator extends ServantActivatorPOA { 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; - } + switch (new String(oid)) { + case "test": return new Test_impl(orb, "locator_SSI", false); + case "testDSI": return new TestDSIRef_impl(orb, "locator_DSI", false); + default: return null; // fail } } - } - final static class TestLocator_impl extends ServantLocatorPOA { - private ORB orb_; - - private Test_impl test_; - - private TestDSIRef_impl testDSI_; + public void etherealize(byte[] oid, POA poa, Servant servant, boolean cleanup, boolean remaining) {} + } - TestLocator_impl(ORB orb) { - orb_ = orb; + final static class TestLocator extends ServantLocatorPOA { + private final Test_impl test; + private final TestDSIRef_impl testDSI; - test_ = new Test_impl(orb, "locator_SSI", false); - testDSI_ = new TestDSIRef_impl(orb, "locator_DSI", false); + TestLocator() { + 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 Servant preinvoke(byte[] oid, POA poa, String operation, CookieHolder the_cookie) { + switch (new String(oid)) { + case "test": return test; + case "testDSI": return testDSI; + default: return null; + } } - public void postinvoke(byte[] oid, POA poa, String operation, - Object the_cookie, Servant the_servant) { - } + public void postinvoke(byte[] oid, POA poa, String operation, Object the_cookie, Servant the_servant) {} } } From 21f77e76ddb8c6befb5181e0b6c721ae4137caaa Mon Sep 17 00:00:00 2001 From: Joe Chacko <143064+joe-chacko@users.noreply.github.com> Date: Tue, 1 Aug 2023 18:59:55 +0100 Subject: [PATCH 10/11] OPS: add junit-pioneer and upgrade junit --- RMI_Demo/finish/build.gradle | 4 ++-- RMI_Demo/start/build.gradle | 4 ++-- build.gradle | 7 ++++--- testify-iiop/build.gradle | 2 +- testify/build.gradle | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) 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" } From 277b36c0fb6b2959d9185e1cff1ffde9aab149cb Mon Sep 17 00:00:00 2001 From: Joe Chacko <143064+joe-chacko@users.noreply.github.com> Date: Tue, 1 Aug 2023 19:01:43 +0100 Subject: [PATCH 11/11] TST: use @CartesianTest for collocated poa tests --- .../orb/PortableServer/TestPoaCollocated.java | 156 +++++++----------- 1 file changed, 62 insertions(+), 94 deletions(-) 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 index b82116b69..39cb0e53b 100644 --- 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 @@ -17,11 +17,11 @@ */ package org.apache.yoko.orb.PortableServer; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; +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; @@ -29,15 +29,12 @@ import org.omg.PortableServer.POAManager; import org.omg.PortableServer.Servant; import org.omg.PortableServer.ServantActivator; -import org.omg.PortableServer.ServantActivatorPOA; import org.omg.PortableServer.ServantLocator; -import org.omg.PortableServer.ServantLocatorPOA; 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 testify.util.function.RawConsumer; import static org.apache.yoko.orb.PortableServer.PolicyValue.MULTIPLE_ID; import static org.apache.yoko.orb.PortableServer.PolicyValue.NON_RETAIN; @@ -51,94 +48,70 @@ import static org.apache.yoko.orb.PortableServer.PolicyValue.create_POA; @ConfigureOrb -class TestPoaCollocated { - enum InvokeAction { - STATIC_INVOKE_STATIC_SERVANT(poa -> invokeStatic(poa, "test")), - STATIC_INVOKE_DYNAMIC_SERVANT(poa -> invokeStatic(poa, "testDSI")), - DYNAMIC_INVOKE_STATIC_SERVANT(poa -> invokeDynamic(poa, "test")), - DYNAMIC_INVOKE_DYNAMIC_SERVANT(poa -> invokeDynamic(poa, "testDSI")); - final RawConsumer invokeAction; - InvokeAction(RawConsumer invokeAction) { this.invokeAction = invokeAction; } - final void run(POA poa) throws Exception { invokeAction.acceptRaw(poa); } - private static void invokeStatic(POA poa, String id) { - TestHelper.narrow(poa.create_reference_with_id(id.getBytes(), "IDL:Test:1.0")).aMethod(); - } - private static void invokeDynamic(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(); +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 ; + } - static ORB orb; - static POA rootPoa; - static POAManager rootPoaManager; - static Test_impl defaultStaticServant; - static Test_impl locatorSSI; + ORB orb; + POA rootPoa; + POAManager rootPoaManager; POA poa; - @BeforeAll - static void setup(ORB orb, POA rootPoa) { - TestPoaCollocated.orb = orb; - TestPoaCollocated.rootPoa = rootPoa; - TestPoaCollocated.rootPoaManager = rootPoa.the_POAManager(); - TestPoaCollocated.defaultStaticServant = new Test_impl(orb, "defaultStaticServant", false); - TestPoaCollocated.locatorSSI = new Test_impl(orb, "locator_SSI", false); + @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() { - if (poa == null) return; - poa.destroy(true, true); - poa = null; - } - - @AfterAll - static void teardown() throws Exception { - byte[] id = rootPoa.servant_to_id(defaultStaticServant); - rootPoa.deactivate_object(id); - } + void destroyPoa() { poa.destroy(true, true); } - @ParameterizedTest @EnumSource(InvokeAction.class) - public void testStaticDefaultServant(InvokeAction action) throws Exception { - poa = create_POA("defaultSSI", rootPoa, rootPoaManager, PERSISTENT, USER_ID, NON_RETAIN, NO_IMPLICIT_ACTIVATION, MULTIPLE_ID, USE_DEFAULT_SERVANT); - poa.set_servant(defaultStaticServant); - action.run(poa); + @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()); } - @ParameterizedTest @EnumSource(InvokeAction.class) - void testDynamicDefaultServant(InvokeAction action) throws Exception { - poa = create_POA("defaultDSI", rootPoa, rootPoaManager, PERSISTENT, USER_ID, NON_RETAIN, NO_IMPLICIT_ACTIVATION, MULTIPLE_ID, USE_DEFAULT_SERVANT); - poa.set_servant(new TestDSIRef_impl(orb, "defaultDSIServant", false)); - action.run(poa); - } - - @ParameterizedTest @EnumSource(InvokeAction.class) - void testServantLocator(InvokeAction action) throws Exception { - poa = create_POA("servloc", rootPoa, rootPoaManager, PERSISTENT, USER_ID, NON_RETAIN, NO_IMPLICIT_ACTIVATION, UNIQUE_ID, USE_SERVANT_MANAGER); - TestLocator locatorImpl = new TestLocator(); - ServantLocator locator = locatorImpl._this(orb); - poa.set_servant_manager(locator); - action.run(poa); - rootPoa.deactivate_object(rootPoa.servant_to_id(locatorImpl)); - } - - @ParameterizedTest @EnumSource(InvokeAction.class) - void testServantActivator(InvokeAction action) throws Exception { - poa = create_POA("servant", rootPoa, rootPoaManager, PERSISTENT, USER_ID, RETAIN, NO_IMPLICIT_ACTIVATION, UNIQUE_ID, USE_SERVANT_MANAGER); - TestActivator activatorImpl = new TestActivator(); - ServantActivator activator = activatorImpl._this(orb); - poa.set_servant_manager(activator); - action.run(poa); - rootPoa.deactivate_object(rootPoa.servant_to_id(activatorImpl)); - } - - final static class TestActivator extends ServantActivatorPOA { + final class TestActivator extends LocalObject implements ServantActivator { public Servant incarnate(byte[] oid, POA poa) throws ForwardRequest { - switch (new String(oid)) { - case "test": return new Test_impl(orb, "locator_SSI", false); - case "testDSI": return new TestDSIRef_impl(orb, "locator_DSI", false); + 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 } } @@ -146,19 +119,14 @@ public Servant incarnate(byte[] oid, POA poa) throws ForwardRequest { public void etherealize(byte[] oid, POA poa, Servant servant, boolean cleanup, boolean remaining) {} } - final static class TestLocator extends ServantLocatorPOA { - private final Test_impl test; - private final TestDSIRef_impl testDSI; - - TestLocator() { - test = new Test_impl(orb, "locator_SSI", false); - testDSI = new TestDSIRef_impl(orb, "locator_DSI", false); - } + 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 (new String(oid)) { - case "test": return test; - case "testDSI": return testDSI; + switch (ChooseTarget.valueOf(new String(oid))) { + case STATIC_SERVANT: return test; + case DYNAMIC_SERVANT: return testDSI; default: return null; } }