From 5e82cd16dbbcba7803013fe46d4c5d4868e6b2c9 Mon Sep 17 00:00:00 2001 From: Joe Chacko <143064+joe-chacko@users.noreply.github.com> Date: Thu, 27 Jul 2023 13:24:07 +0100 Subject: [PATCH] TST: port POA activation test to new framework --- .../orb/PortableServer/TestPoaActivate.java | 211 ++++++++ .../test/java/org/apache/yoko/PoaTest.java | 4 - .../src/test/java/test/poa/TestActivate.java | 467 ---------------- .../src/test/java/test/poa/TestMisc.java | 31 +- .../src/test/java/test/poa/TestUtil.java | 13 - .../src/test/java/test/poa/Test_impl.java | 4 +- yoko-core/src/test/java/test/poa/runtest | 498 ------------------ 7 files changed, 229 insertions(+), 999 deletions(-) create mode 100644 yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaActivate.java delete mode 100644 yoko-core/src/test/java/test/poa/TestActivate.java delete mode 100644 yoko-core/src/test/java/test/poa/runtest 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 new file mode 100644 index 000000000..b1af210e7 --- /dev/null +++ b/yoko-core/src/test/java-testify/org/apache/yoko/orb/PortableServer/TestPoaActivate.java @@ -0,0 +1,211 @@ +/* + * Copyright 2023 IBM Corporation and others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an \"AS IS\" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.apache.yoko.orb.PortableServer; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.omg.CORBA.OBJ_ADAPTER; +import org.omg.CORBA.ORB; +import org.omg.CORBA.Policy; +import org.omg.PortableServer.POA; +import org.omg.PortableServer.POAPackage.ObjectNotActive; +import org.omg.PortableServer.POAPackage.ServantAlreadyActive; +import org.omg.PortableServer.POAPackage.WrongPolicy; +import org.omg.PortableServer.Servant; +import org.omg.PortableServer.ServantActivator; +import org.omg.PortableServer.ServantActivatorPOA; +import test.poa.Test_impl; +import testify.iiop.annotation.ConfigureOrb; + +import java.util.Arrays; + +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; +import static org.omg.PortableServer.IdAssignmentPolicyValue.SYSTEM_ID; +import static org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID; +import static org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID; +import static org.omg.PortableServer.IdUniquenessPolicyValue.UNIQUE_ID; +import static org.omg.PortableServer.ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION; +import static org.omg.PortableServer.RequestProcessingPolicyValue.USE_DEFAULT_SERVANT; +import static org.omg.PortableServer.RequestProcessingPolicyValue.USE_SERVANT_MANAGER; +import static org.omg.PortableServer.ServantRetentionPolicyValue.NON_RETAIN; +import static org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN; + +@ConfigureOrb +public class TestPoaActivate { + private static Test_impl servant1; + private static Test_impl servant2; + + @BeforeAll + private 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); + } + + @Test + void testSystemIdPolicy(POA rootPoa) throws Exception { + POA poa = rootPoa.create_POA("system_id", rootPoa.the_POAManager(), new Policy[]{ + rootPoa.create_id_assignment_policy(SYSTEM_ID), + rootPoa.create_id_uniqueness_policy(UNIQUE_ID), + rootPoa.create_servant_retention_policy(RETAIN)}); + byte[] id1 = poa.activate_object(servant1); + byte[] id2 = poa.activate_object(servant2); + assertTrue(!Arrays.equals(id1, id2)); + Servant tmpserv = poa.id_to_servant(id1); + assertTrue(tmpserv == servant1); + tmpserv = poa.id_to_servant(id2); + assertTrue(tmpserv == servant2); + // Should not be able to activate already-activated objects + assertThrows(ServantAlreadyActive.class, () -> poa.activate_object(servant1)); + assertThrows(ServantAlreadyActive.class, () -> poa.activate_object(servant2)); + // Deactivate should succeed on the still-activated objects + poa.deactivate_object(id2); + poa.deactivate_object(id1); + // Now, deactivate should fail + assertThrows(ObjectNotActive.class, () -> poa.deactivate_object(id1)); + assertThrows(ObjectNotActive.class, () -> poa.deactivate_object(id2)); + poa.destroy(true, true); + } + + @Test + void testWrongPolicy(POA rootPoa) throws Exception { + POA poa = rootPoa.create_POA("nonretain", rootPoa.the_POAManager(), new Policy[]{ + rootPoa.create_id_assignment_policy(USER_ID), + rootPoa.create_id_uniqueness_policy(MULTIPLE_ID), + rootPoa.create_servant_retention_policy(NON_RETAIN), + rootPoa.create_request_processing_policy(USE_DEFAULT_SERVANT), + rootPoa.create_implicit_activation_policy(NO_IMPLICIT_ACTIVATION)}); + byte[] id = ("XXX").getBytes(); + assertThrows(WrongPolicy.class, () -> poa.activate_object(servant1)); + assertThrows(WrongPolicy.class, () -> poa.activate_object_with_id(id, servant1)); + assertThrows(WrongPolicy.class, () -> poa.deactivate_object(id)); + poa.destroy(true, true); + } + + @Test + void testMultipleIdPolicy(POA rootPoa) throws Exception { + POA poa = rootPoa.create_POA("multiple_id", rootPoa.the_POAManager(), new Policy[]{ + rootPoa.create_id_assignment_policy(SYSTEM_ID), + rootPoa.create_id_uniqueness_policy(MULTIPLE_ID), + rootPoa.create_servant_retention_policy(RETAIN)}); + + Servant tmpserv; + byte[] id1 = poa.activate_object(servant1); + byte[] id2 = poa.activate_object(servant1); + assertTrue(!Arrays.equals(id1, id2)); + + tmpserv = poa.id_to_servant(id1); + assertTrue(tmpserv == servant1); + + tmpserv = poa.id_to_servant(id2); + assertTrue(tmpserv == servant1); + + poa.deactivate_object(id1); + poa.deactivate_object(id2); + + // Test: confirm servants are no longer active + assertThrows(ObjectNotActive.class, () -> poa.id_to_servant(id1)); + assertThrows(ObjectNotActive.class, () -> poa.id_to_servant(id2)); + + poa.destroy(true, true); + } + + @Test + public void testEtherialize(ORB orb, POA rootPoa) throws Exception { + // A ServantActivator should have etherialize() called + // when (and only when) its servants are deactivated. + POA poa = rootPoa.create_POA("ether", rootPoa.the_POAManager(), new Policy[]{ + rootPoa.create_id_assignment_policy(SYSTEM_ID), + rootPoa.create_id_uniqueness_policy(MULTIPLE_ID), + rootPoa.create_request_processing_policy(USE_SERVANT_MANAGER)}); + + // should throw OBJ_ADAPTER when set to null + assertThrows(OBJ_ADAPTER.class, () -> poa.set_servant_manager(null)); + + TestActivator_impl activatorImpl = new TestActivator_impl(); + ServantActivator activator = activatorImpl._this(orb); + + // otherwise should work + poa.set_servant_manager(activator); + + // + // Test: activate_object w/ MULTIPLE_ID POA + // + + // Test: confirm ServantActivator::etherealize is invoked on deactivate + byte[] id1 = poa.activate_object(servant1); + byte[] id2 = poa.activate_object(servant1); + byte[] id3 = poa.activate_object(servant2); + assertTrue(activatorImpl.isValid()); + activatorImpl.expect(id1, poa, servant1, true); + poa.deactivate_object(id1); + assertTrue(activatorImpl.isValid()); + + activatorImpl.expect(id2, poa, servant1, false); + poa.deactivate_object(id2); + assertTrue(activatorImpl.isValid()); + + activatorImpl.expect(id3, poa, servant2, false); + poa.deactivate_object(id3); + assertTrue(activatorImpl.isValid()); + + poa.destroy(true, true); + assertTrue(activatorImpl.isValid()); + + byte[] id = rootPoa.servant_to_id(activatorImpl); + rootPoa.deactivate_object(id); + assertTrue(activatorImpl.isValid()); + } + + final static class TestActivator_impl extends ServantActivatorPOA { + private byte[] oid; + private POA poa; + private Servant servant; + private boolean remaining; + private boolean valid = true; + private boolean expectingEtherialize; + + void expect(byte[] oid, POA poa, Servant servant, boolean remaining) { + this.oid = oid; + this.poa = poa; + this.servant = servant; + this.remaining = remaining; + this.valid = false; + this.expectingEtherialize = true; + } + + boolean isValid() { return valid; } + + public Servant incarnate(byte[] oid, POA poa) { return null; } + + public void etherealize(byte[] oid, POA poa, Servant servant, boolean cleanup, boolean remaining) { + try { + valid = false; + assertTrue(expectingEtherialize); + assertTrue(Arrays.equals(this.oid, oid)); + assertTrue(this.poa._is_equivalent(poa)); + assertTrue(this.servant == servant); + assertTrue(this.remaining == remaining); + valid = true; + } finally { + expectingEtherialize = false; + } + } + } +} 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 0ae2909f5..62ab15af8 100644 --- a/yoko-core/src/test/java/org/apache/yoko/PoaTest.java +++ b/yoko-core/src/test/java/org/apache/yoko/PoaTest.java @@ -17,7 +17,6 @@ */ package org.apache.yoko; -import test.poa.TestActivate; import test.poa.TestAdapterActivatorServer; import test.poa.TestClient; import test.poa.TestCollocated; @@ -46,9 +45,6 @@ public void setUp() throws Exception { super.setUp(); setWaitForFile("Test.ref"); } - public void testActivate() throws Exception { - client.invokeMain(TestActivate.class); - } public void testDeactivate() throws Exception { client.invokeMain(TestDeactivate.class); diff --git a/yoko-core/src/test/java/test/poa/TestActivate.java b/yoko-core/src/test/java/test/poa/TestActivate.java deleted file mode 100644 index 672ece9cc..000000000 --- a/yoko-core/src/test/java/test/poa/TestActivate.java +++ /dev/null @@ -1,467 +0,0 @@ -/* - * Copyright 2015 IBM Corporation and others. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an \"AS IS\" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package test.poa; - -import static org.junit.Assert.assertTrue; - -import java.util.Properties; - -import org.omg.CORBA.*; -import org.omg.PortableServer.*; -import org.omg.PortableServer.POAPackage.*; - -public final class TestActivate extends test.common.TestBase { - final static class TestActivator_impl extends ServantActivatorPOA { - private byte[] oid_; - - private POA poa_; - - private Servant servant_; - - private boolean remaining_; - - private boolean valid_; - - void expect(byte[] oid, POA poa, Servant servant, boolean remaining) { - oid_ = oid; - poa_ = poa; - servant_ = servant; - remaining_ = remaining; - valid_ = false; - } - - boolean isValid() { - return valid_; - } - - public Servant incarnate(byte[] oid, POA poa) throws ForwardRequest { - return null; - } - - public void etherealize(byte[] oid, POA poa, Servant servant, - boolean cleanup, boolean remaining) { - assertTrue(TestUtil.Compare(oid_, oid)); - assertTrue(poa_._is_equivalent(poa)); - assertTrue(servant_ == servant); - assertTrue(remaining_ == remaining); - valid_ = true; - } - } - - private static void run(ORB orb, POA root) { - org.omg.CORBA.Object obj; - POA system, nonretain, multiple, ether; - byte[] id1, id2, id3; - Policy[] policies; - Test_impl servant1; - Test_impl servant2; - Servant tmpserv; - - POAManager manager = root.the_POAManager(); - - try { - manager.activate(); - } catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive ex) { - throw new RuntimeException(); - } - - // - // Create POAs - // - - policies = new Policy[3]; - policies[0] = root - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.SYSTEM_ID); - policies[1] = root - .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.UNIQUE_ID); - policies[2] = root - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN); - try { - system = root.create_POA("system_id", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - - policies = new Policy[5]; - policies[0] = root - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID); - policies[1] = root - .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID); - policies[2] = root - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.NON_RETAIN); - policies[3] = root - .create_request_processing_policy(org.omg.PortableServer.RequestProcessingPolicyValue.USE_DEFAULT_SERVANT); - policies[4] = root - .create_implicit_activation_policy(org.omg.PortableServer.ImplicitActivationPolicyValue.NO_IMPLICIT_ACTIVATION); - try { - nonretain = root.create_POA("nonretain", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - - policies = new Policy[3]; - policies[0] = root - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.SYSTEM_ID); - policies[1] = root - .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID); - policies[2] = root - .create_servant_retention_policy(org.omg.PortableServer.ServantRetentionPolicyValue.RETAIN); - try { - multiple = root.create_POA("multiple_id", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - - policies = new Policy[3]; - policies[0] = root - .create_id_assignment_policy(org.omg.PortableServer.IdAssignmentPolicyValue.SYSTEM_ID); - policies[1] = root - .create_id_uniqueness_policy(org.omg.PortableServer.IdUniquenessPolicyValue.MULTIPLE_ID); - policies[2] = root - .create_request_processing_policy(org.omg.PortableServer.RequestProcessingPolicyValue.USE_SERVANT_MANAGER); - try { - ether = root.create_POA("ether", manager, policies); - } catch (AdapterAlreadyExists ex) { - throw new RuntimeException(); - } catch (InvalidPolicy ex) { - throw new RuntimeException(); - } - TestActivator_impl activatorImpl = new TestActivator_impl(); - ServantActivator activator = activatorImpl._this(orb); - - // - // Start tests - // - - // - // Test: set_servant_manager with nil argument - // - try { - ether.set_servant_manager(null); - assertTrue(false); // set_servant_manager should not have succeeded - } catch (OBJ_ADAPTER ex) { - // expected - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - try { - ether.set_servant_manager(activator); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - servant1 = new Test_impl(orb, "obj1", false); - servant2 = new Test_impl(orb, "obj2", false); - - // - // Test: activate_object w/ SYSTEM_ID POA - // - - try { - id1 = system.activate_object(servant1); - id2 = system.activate_object(servant2); - } catch (ServantAlreadyActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertTrue(!TestUtil.Compare(id1, id2)); - try { - tmpserv = system.id_to_servant(id1); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - assertTrue(tmpserv == servant1); - try { - tmpserv = system.id_to_servant(id2); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertTrue(tmpserv == servant2); - - // - // Test: ServantAlreadyActive exception - // - try { - system.activate_object(servant1); - assertTrue(false); // activate_object should not have succeeded - } catch (ServantAlreadyActive ex) { - // expected - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - try { - system.activate_object(servant2); - assertTrue(false); // activate_object should not have succeeded - } catch (ServantAlreadyActive ex) { - // expected - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - // - // Test: deactivate_object - // - try { - system.deactivate_object(id2); - system.deactivate_object(id1); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - // - // Test: ObjectNotActive exception - // - try { - system.deactivate_object(id1); - assertTrue(false); // deactivate_object should not have succeeded - } catch (ObjectNotActive ex) { - // expected - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - try { - system.deactivate_object(id2); - assertTrue(false); // deactivate_object should not have succeeded - } catch (ObjectNotActive ex) { - // expected - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - // - // Test: WrongPolicy exception - // - try { - nonretain.activate_object(servant1); - assertTrue(false); // activate_object should not have succeeded - } catch (WrongPolicy ex) { - // expected - } catch (ServantAlreadyActive ex) { - throw new RuntimeException(); - } - - try { - byte[] id = ("XXX").getBytes(); - nonretain.activate_object_with_id(id, servant1); - assertTrue(false); // activate_object_with_id should not have succeeded - } catch (WrongPolicy ex) { - // expected - } catch (ServantAlreadyActive ex) { - throw new RuntimeException(); - } catch (ObjectAlreadyActive ex) { - throw new RuntimeException(); - } - - try { - byte[] id = ("XXX").getBytes(); - nonretain.deactivate_object(id); - assertTrue(false); // deactivate_object should not have succeeded - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - // expected - } - - // - // Test: activate_object w/ MULTIPLE_ID POA - // - - try { - id1 = multiple.activate_object(servant1); - id2 = multiple.activate_object(servant1); - } catch (ServantAlreadyActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertTrue(!TestUtil.Compare(id1, id2)); - try { - tmpserv = multiple.id_to_servant(id1); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertTrue(tmpserv == servant1); - try { - tmpserv = multiple.id_to_servant(id2); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertTrue(tmpserv == servant1); - - // - // Test: confirm servant1 is no longer active - // - try { - multiple.deactivate_object(id1); - multiple.deactivate_object(id2); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - try { - multiple.id_to_servant(id1); - } catch (ObjectNotActive ex) { - // expected - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - try { - multiple.id_to_servant(id2); - } catch (ObjectNotActive ex) { - // expected - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - // - // Test: confirm ServantActivator::etherealize is invoked on - // deactivate - // - try { - id1 = ether.activate_object(servant1); - id2 = ether.activate_object(servant1); - id3 = ether.activate_object(servant2); - } catch (ServantAlreadyActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - activatorImpl.expect(id1, ether, servant1, true); - try { - ether.deactivate_object(id1); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertTrue(activatorImpl.isValid()); - activatorImpl.expect(id2, ether, servant1, false); - try { - ether.deactivate_object(id2); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertTrue(activatorImpl.isValid()); - activatorImpl.expect(id3, ether, servant2, false); - try { - ether.deactivate_object(id3); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - assertTrue(activatorImpl.isValid()); - - system.destroy(true, true); - nonretain.destroy(true, true); - multiple.destroy(true, true); - ether.destroy(true, true); - - // - // Since activatorImpl is a stack-based servant, we need to deactivate - // it before it goes out of scope - // - byte[] id = null; - try { - id = root.servant_to_id(activatorImpl); - } catch (ServantNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - try { - root.deactivate_object(id); - } catch (ObjectNotActive ex) { - throw new RuntimeException(); - } catch (WrongPolicy ex) { - throw new RuntimeException(); - } - - tmpserv = null; - servant1 = null; - servant2 = 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; - - try { - // - // Create ORB - // - orb = ORB.init(args, props); - - POA root = TestUtil.GetRootPOA(orb); - - // - // Run the test - // - System.out.print("Testing servant activator... "); - System.out.flush(); - run(orb, root); - System.out.println("Done!"); - } catch (SystemException ex) { - ex.printStackTrace(); - status = 1; - } - - if (orb != null) { - try { - orb.destroy(); - } catch (SystemException ex) { - ex.printStackTrace(); - status = 1; - } - } - - System.exit(status); - } -} diff --git a/yoko-core/src/test/java/test/poa/TestMisc.java b/yoko-core/src/test/java/test/poa/TestMisc.java index e692c3452..b3de9e853 100644 --- a/yoko-core/src/test/java/test/poa/TestMisc.java +++ b/yoko-core/src/test/java/test/poa/TestMisc.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertTrue; +import java.util.Arrays; import java.util.Properties; import org.omg.CORBA.*; @@ -96,7 +97,7 @@ static void TestCreateReference(ORB orb, POA root) { } catch (WrongPolicy ex) { throw new RuntimeException(); } - assertTrue(!TestUtil.Compare(id1, id2)); + assertTrue(!Arrays.equals(id1, id2)); // // Test: create_reference_with_id using a system-generated ID @@ -132,7 +133,7 @@ static void TestCreateReference(ORB orb, POA root) { } catch (WrongPolicy ex) { throw new RuntimeException(); } - assertTrue(TestUtil.Compare(id1, tmpid)); + assertTrue(Arrays.equals(id1, tmpid)); id2 = ("id2").getBytes(); obj = user.create_reference_with_id(id2, "IDL:Test:1.0"); assertTrue(obj != null); @@ -143,7 +144,7 @@ static void TestCreateReference(ORB orb, POA root) { } catch (WrongPolicy ex) { throw new RuntimeException(); } - assertTrue(TestUtil.Compare(id2, tmpid)); + assertTrue(Arrays.equals(id2, tmpid)); user.destroy(true, true); system.destroy(true, true); @@ -251,7 +252,7 @@ static void TestServantToId(ORB orb, POA root) { } catch (ServantNotActive ex) { throw new RuntimeException(); } - assertTrue(TestUtil.Compare(id1, tmpid)); + assertTrue(Arrays.equals(id1, tmpid)); // // Test: servant_to_id (IMPLICIT_ACTIVATION) - servant1 should @@ -276,7 +277,7 @@ static void TestServantToId(ORB orb, POA root) { } catch (ServantNotActive ex) { throw new RuntimeException(); } - assertTrue(TestUtil.Compare(id1, tmpid)); + assertTrue(Arrays.equals(id1, tmpid)); // // Test: Implicitly activating servant2 should produce a new ID @@ -288,7 +289,7 @@ static void TestServantToId(ORB orb, POA root) { } catch (ServantNotActive ex) { throw new RuntimeException(); } - assertTrue(!TestUtil.Compare(id1, id2)); + assertTrue(!Arrays.equals(id1, id2)); // // Test: servant_to_id (IMPLICIT_ACTIVATION, MULTIPLE_ID) - servant1 @@ -312,7 +313,7 @@ static void TestServantToId(ORB orb, POA root) { } catch (ServantNotActive ex) { throw new RuntimeException(); } - assertTrue(!TestUtil.Compare(id1, tmpid)); + assertTrue(!Arrays.equals(id1, tmpid)); unique.destroy(true, true); implicit.destroy(true, true); @@ -586,7 +587,7 @@ static void TestServantToReference(ORB orb, POA root) { } catch (WrongPolicy ex) { throw new RuntimeException(); } - assertTrue(TestUtil.Compare(id1, tmpid1)); + assertTrue(Arrays.equals(id1, tmpid1)); // // Test: servant_to_reference (IMPLICIT_ACTIVATION) - servant1 should @@ -627,7 +628,7 @@ static void TestServantToReference(ORB orb, POA root) { } catch (WrongPolicy ex) { throw new RuntimeException(); } - assertTrue(TestUtil.Compare(tmpid1, tmpid2)); + assertTrue(Arrays.equals(tmpid1, tmpid2)); // // Test: Implicitly activating servant2 should produce a new ID @@ -647,7 +648,7 @@ static void TestServantToReference(ORB orb, POA root) { } catch (WrongAdapter ex) { throw new RuntimeException(); } - assertTrue(!TestUtil.Compare(tmpid1, tmpid2)); + assertTrue(!Arrays.equals(tmpid1, tmpid2)); // // Test: servant_to_reference (IMPLICIT_ACTIVATION, MULTIPLE_ID) - @@ -687,7 +688,7 @@ static void TestServantToReference(ORB orb, POA root) { } catch (WrongAdapter ex) { throw new RuntimeException(); } - assertTrue(!TestUtil.Compare(tmpid1, tmpid2)); + assertTrue(!Arrays.equals(tmpid1, tmpid2)); unique.destroy(true, true); implicit.destroy(true, true); @@ -769,7 +770,7 @@ static void TestIdToReference(ORB orb, POA root) { } catch (WrongPolicy ex) { throw new RuntimeException(); } - assertTrue(TestUtil.Compare(id1, tmpid)); + assertTrue(Arrays.equals(id1, tmpid)); // // Test: servant_to_reference @@ -789,7 +790,7 @@ static void TestIdToReference(ORB orb, POA root) { } catch (WrongPolicy ex) { throw new RuntimeException(); } - assertTrue(TestUtil.Compare(id2, tmpid)); + assertTrue(Arrays.equals(id2, tmpid)); retain.destroy(true, true); } @@ -1024,7 +1025,7 @@ static void TestReferenceToId(ORB orb, POA root) { } catch (WrongPolicy ex) { throw new RuntimeException(); } - assertTrue(TestUtil.Compare(tmpid, id1)); + assertTrue(Arrays.equals(tmpid, id1)); obj = poa.create_reference_with_id(id2, "IDL:Test:1.0"); try { tmpid = poa.reference_to_id(obj); @@ -1033,7 +1034,7 @@ static void TestReferenceToId(ORB orb, POA root) { } catch (WrongPolicy ex) { throw new RuntimeException(); } - assertTrue(TestUtil.Compare(tmpid, id2)); + assertTrue(Arrays.equals(tmpid, id2)); // // Test: WrongAdapter exception diff --git a/yoko-core/src/test/java/test/poa/TestUtil.java b/yoko-core/src/test/java/test/poa/TestUtil.java index 36135a757..d3768b16f 100644 --- a/yoko-core/src/test/java/test/poa/TestUtil.java +++ b/yoko-core/src/test/java/test/poa/TestUtil.java @@ -47,17 +47,4 @@ static POA GetRootPOA(ORB orb) { return root; } - - static boolean Compare(byte[] id1, byte[] id2) { - // - // TODO: efficient method to doing this? - // - if (id1.length != id2.length) - return false; - for (int i = 0; i < id1.length; i++) - if (id1[i] != id2[i]) - return false; - return true; - // return id1.equals(id2); - } } diff --git a/yoko-core/src/test/java/test/poa/Test_impl.java b/yoko-core/src/test/java/test/poa/Test_impl.java index 29470d55e..2d354b3a3 100644 --- a/yoko-core/src/test/java/test/poa/Test_impl.java +++ b/yoko-core/src/test/java/test/poa/Test_impl.java @@ -20,7 +20,7 @@ import org.omg.CORBA.*; import org.omg.PortableServer.*; -final class Test_impl extends TestPOA { +public final class Test_impl extends TestPOA { // // From TestBase (no multiple inheritance) // @@ -37,7 +37,7 @@ public static void TEST(boolean expr) { private boolean compare_; - Test_impl(ORB orb, String name, boolean compare) { + public Test_impl(ORB orb, String name, boolean compare) { name_ = name; compare_ = compare; diff --git a/yoko-core/src/test/java/test/poa/runtest b/yoko-core/src/test/java/test/poa/runtest deleted file mode 100644 index 140aa3efa..000000000 --- a/yoko-core/src/test/java/test/poa/runtest +++ /dev/null @@ -1,498 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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. -# - -# -# Try to find top-level directory -# -if test -f ob/src/com/ooc/CORBA/ORB.java -then - top_srcdir=ob -elif test -f src/com/ooc/CORBA/ORB.java -then - top_srcdir=. -elif test -f ../src/com/ooc/CORBA/ORB.java -then - top_srcdir=.. -elif test -f ../../src/com/ooc/CORBA/ORB.java -then - top_srcdir=../.. -elif test -f ../../../src/com/ooc/CORBA/ORB.java -then - top_srcdir=../../.. -elif test -f ../../../../src/com/ooc/CORBA/ORB.java -then - top_srcdir=../../../.. -else - $echo "$0: can't find top-level directory" - exit -fi - -# -# Run standard init script -# -. $top_srcdir/config/sh.init -. $top_srcdir/config/testutil.sh - -# -# Set Java CLASSPATH -# -CLASSPATH="$top_srcdir/lib${SEPARATOR}$CLASSPATH" -export CLASSPATH - -# -# Set the "java.endorsed.dirs" property -# -set_java_endorsed_dirs - -# -# Delete old log files -# -rm -f poa.log -rm -f poa_client.log -rm -f poa_server.log - -# -# Run client-only POA tests -# -$echo -$JAVA test.poa.TestActivate 2>&1 | tee -a poa.log -$JAVA test.poa.TestDeactivate 2>&1 | tee -a poa.log -$JAVA test.poa.TestCollocated 2>&1 | tee -a poa.log -$JAVA test.poa.TestCreate 2>&1 | tee -a poa.log -$JAVA test.poa.TestDestroy 2>&1 | tee -a poa.log -$JAVA test.poa.TestFind 2>&1 | tee -a poa.log -$JAVA test.poa.TestMisc 2>&1 | tee -a poa.log - -# -# Set name of reference file -# -ref=Test.ref - -# -# Start TestDefaultServantServer -# -$echo "Testing default servant... \c" -rm -f $ref -( $JAVA test.poa.TestDefaultServantServer & echo $! > srvid ) \ -2>&1 | tee -a poa_server.log & -count=0 -while test ! -s $ref -a $count -lt 8 -do - sleep 1 - count=`expr $count + 1` -done -if test ! -s $ref -then - $echo "Failed!" - $echo "(TestDefaultServantServer was not started)" - exit -fi - -# -# Run client -# -$JAVA test.poa.TestClient 2>&1 | \ -tee -a poa_client.log - -# -# Wait for server deactivation -# -count=0 -while test -r $ref -a $count -lt 3 -do - sleep 1 - count=`expr $count + 1` -done - -if test -r $ref -then - $echo "Failed!" - $echo "(TestDefaultServantServer was not deactivated by client - \c" - $echo "deactivating server now)" - deactivate -else - $echo "Done!" -fi - -# -# Start TestServantActivatorServer -# -$echo "Testing servant activator... \c" -rm -f $ref -( $JAVA test.poa.TestServantActivatorServer & echo $! > srvid ) \ -2>&1 | tee -a poa_server.log & -count=0 -while test ! -s $ref -a $count -lt 8 -do - sleep 1 - count=`expr $count + 1` -done -if test ! -s $ref -then - $echo "Failed!" - $echo "(TestServantActivatorServer was not started)" - exit -fi - -# -# Run client -# -$JAVA test.poa.TestClient 2>&1 | \ -tee -a poa_client.log - -# -# Wait for server deactivation -# -count=0 -while test -r $ref -a $count -lt 3 -do - sleep 1 - count=`expr $count + 1` -done - -if test -r $ref -then - $echo "Failed!" - $echo "(TestServantActivatorServer was not deactivated by client - \c" - $echo "deactivating server now)" - deactivate -else - $echo "Done!" -fi - -# -# Start TestServantLocatorServer -# -$echo "Testing servant locator... \c" -rm -f $ref -( $JAVA test.poa.TestServantLocatorServer & echo $! > srvid ) \ -2>&1 | tee -a poa_server.log & -count=0 -while test ! -s $ref -a $count -lt 8 -do - sleep 1 - count=`expr $count + 1` -done -if test ! -s $ref -then - $echo "Failed!" - $echo "(TestServantLocatorServer was not started)" - exit -fi - -# -# Run client -# -$JAVA test.poa.TestClient 2>&1 | \ -tee -a poa_client.log - -# -# Wait for server deactivation -# -count=0 -while test -r $ref -a $count -lt 3 -do - sleep 1 - count=`expr $count + 1` -done - -if test -r $ref -then - $echo "Failed!" - $echo "(TestServantLocatorServer was not deactivated by client - \c" - $echo "deactivating server now)" - deactivate -else - $echo "Done!" -fi - -# -# Start TestLocationForwardServer -# -$echo "Testing LocationForward... \c" -rm -f $ref -( $JAVA test.poa.TestLocationForwardServerMain & echo $! > srvid ) \ -2>&1 | tee -a poa_server.log & -count=0 -while test ! -s $ref -a $count -lt 8 -do - sleep 1 - count=`expr $count + 1` -done -if test ! -s $ref -then - $echo "Failed!" - $echo "(TestLocationForwardServer was not started)" - exit -fi - -# -# Run client -# -$JAVA test.poa.TestLocationForwardClient 2>&1 | \ -tee -a poa_client.log - -# -# Wait for server deactivation -# -count=0 -while test -r $ref -a $count -lt 3 -do - sleep 1 - count=`expr $count + 1` -done - -if test -r $ref -then - $echo "Failed!" - $echo "(TestLocationForwardServer was not deactivated by client - \c" - $echo "deactivating server now)" - deactivate -else - $echo "Done!" -fi - -# -# Start TestAdapterActivatorServer -# -$echo "Testing adapter activator... \c" -rm -f $ref -( $JAVA test.poa.TestAdapterActivatorServer & echo $! > srvid ) \ -2>&1 | tee -a poa_server.log & -count=0 -while test ! -s $ref -a $count -lt 8 -do - sleep 1 - count=`expr $count + 1` -done -if test ! -s $ref -then - $echo "Failed!" - $echo "(TestAdapterActivatorServer was not started)" - exit -fi - -# -# Run client -# -$JAVA test.poa.TestClient 2>&1 | \ -tee -a poa_client.log - -# -# Wait for server deactivation -# -count=0 -while test -r $ref -a $count -lt 3 -do - sleep 1 - count=`expr $count + 1` -done - -if test -r $ref -then - $echo "Failed!" - $echo "(TestAdapterActivatorServer was not deactivated by client - \c" - $echo "deactivating server now)" - deactivate -else - $echo "Done!" -fi - -# -# Start TestPOAManagerServer -# -$echo "Testing POAManager... \c" -rm -f $ref -( $JAVA test.poa.TestPOAManagerServer & echo $! > srvid ) \ -2>&1 | tee -a poa_server.log & -count=0 -while test ! -s $ref -a $count -lt 16 -do - sleep 1 - count=`expr $count + 1` -done -if test ! -s $ref -then - $echo "Failed!" - $echo "(TestPOAManagerServer was not started)" - exit -fi - -# -# Run client -# -$JAVA test.poa.TestPOAManagerClient 2>&1 | \ -tee -a poa_client.log - -# -# Wait for server deactivation -# -count=0 -while test -r $ref -a $count -lt 3 -do - sleep 1 - count=`expr $count + 1` -done - -if test -r $ref -then - $echo "Failed!" - $echo "(TestPOAManagerServer was not deactivated by client - \c" - $echo "deactivating server now)" - deactivate -else - $echo "Done!" -fi - -# -# Start TestDispatchStrategyServer -# -$echo "Testing dispatch strategies... \c" -rm -f $ref -( $JAVA test.poa.TestDispatchStrategyServer & echo $! > srvid ) \ -2>&1 | tee -a poa_server.log & -count=0 -while test ! -s $ref -a $count -lt 8 -do - sleep 1 - count=`expr $count + 1` -done -if test ! -s $ref -then - $echo "Failed!" - $echo "(TestDispatchStrategyServer was not started)" - exit -fi - -# -# Run client -# -$JAVA test.poa.TestDispatchStrategyClient 2>&1 | \ -tee -a poa_client.log - -# -# Wait for server deactivation -# -count=0 -while test -r $ref -a $count -lt 3 -do - sleep 1 - count=`expr $count + 1` -done - -if test -r $ref -then - $echo "Failed!" - $echo "(TestDispatchStrategyServer was not deactivated by client - \c" - $echo "deactivating server now)" - deactivate -else - $echo "Done!" -fi - -# -# Start TestMultipleOrbsServer -# -$echo "Testing multiple ORB instances (same thread)... \c" -rm -f $ref -( $JAVA test.poa.TestMultipleOrbsServer & echo $! > srvid ) \ -2>&1 | tee -a poa_server.log & -count=0 -while test ! -s $ref -a $count -lt 8 -do - sleep 1 - count=`expr $count + 1` -done -if test ! -s $ref -then - $echo "Failed!" - $echo "(TestMultipleOrbsServer was not started)" - exit -fi - -# -# Run client -# -$JAVA test.poa.TestMultipleOrbsClient 2>&1 | \ -tee -a poa_client.log - -# -# Wait for server deactivation -# -count=0 -while test -r $ref -a $count -lt 3 -do - sleep 1 - count=`expr $count + 1` -done - -if test -r $ref -then - $echo "Failed!" - $echo "(TestMultipleOrbsServer was not deactivated by client - \c" - $echo "deactivating server now)" - deactivate -else - $echo "Done!" -fi - - -# -# Start TestMultipleOrbsThreadedServer -# -$echo "Testing multiple ORB instances (multiple threads)... \c" -rm -f $ref -( $JAVA test.poa.TestMultipleOrbsThreadedServer & echo $! > srvid ) \ -2>&1 | tee -a poa_server.log & -count=0 -while test ! -s $ref -a $count -lt 8 -do - sleep 1 - count=`expr $count + 1` -done -if test ! -s $ref -then - $echo "Failed!" - $echo "(TestMultipleOrbsThreadedServer was not started)" - exit -fi - -# -# Run client -# -$JAVA test.poa.TestMultipleOrbsThreadedClient 2>&1 | \ -tee -a poa_client.log - -# -# Wait for server deactivation -# -count=0 -while test -r $ref -a $count -lt 3 -do - sleep 1 - count=`expr $count + 1` -done - -if test -r $ref -then - $echo "Failed!" - $echo "(TestMultipleOrbsThreadedServer was not deactivated by client - \c" - $echo "deactivating server now)" - deactivate -else - $echo "Done!" -fi