Skip to content

Commit

Permalink
TST: ported TestServantActivatorServer POA test
Browse files Browse the repository at this point in the history
  • Loading branch information
habiblawal1 committed Aug 7, 2023
1 parent 3f28113 commit 503d2d7
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 233 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* 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.LocalObject;
import org.omg.CORBA.OBJECT_NOT_EXIST;
import org.omg.CORBA.ORB;
import org.omg.PortableServer.ForwardRequest;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAManager;
import org.omg.PortableServer.POAPackage.ObjectAlreadyActive;
import org.omg.PortableServer.POAPackage.ServantAlreadyActive;
import org.omg.PortableServer.POAPackage.WrongPolicy;
import org.omg.PortableServer.Servant;
import org.omg.PortableServer.ServantActivator;
import test.poa.TestDSIRef_impl;
import test.poa.TestHelper;
import test.poa.Test_impl;
import testify.bus.Bus;
import testify.iiop.annotation.ConfigureServer;

import static org.apache.yoko.orb.PortableServer.PolicyValue.PERSISTENT;
import static org.apache.yoko.orb.PortableServer.PolicyValue.USER_ID;
import static org.apache.yoko.orb.PortableServer.PolicyValue.create_POA;
import static org.junit.Assert.assertThrows;

@ConfigureServer
public class TestServantActivatorServer {

private static TestActivator_impl activatorImpl;

@ConfigureServer.BeforeServer
public static void setup(ORB orb, POA root, Bus bus) throws Exception {
POAManager rootMgr = root.the_POAManager();
POA poa = create_POA("persistent", root, rootMgr, PERSISTENT, USER_ID, PolicyValue.USE_SERVANT_MANAGER);
activatorImpl = new TestActivator_impl(orb);
poa.set_servant_manager(activatorImpl);

// Create three references, two good and one bad
bus.put("test1", orb.object_to_string(poa.create_reference_with_id("test1".getBytes(), "IDL:Test:1.0")));
bus.put("testDSI", orb.object_to_string(poa.create_reference_with_id("testDSI".getBytes(), "IDL:Test:1.0")));
bus.put("testNotExist", orb.object_to_string(poa.create_reference_with_id("testNotExist".getBytes(), "IDL:Test:1.0")));

//TODO: Find a way to test this after the ORB is shutdown
// assertTrue(activatorImpl.etherealize_called());
}

@Test
void test1(ORB orb, Bus bus) { TestHelper.narrow(orb.string_to_object(bus.get("test1"))).aMethod(); }

@Test
void testDSI(ORB orb, Bus bus) { TestHelper.narrow(orb.string_to_object(bus.get("testDSI"))).aMethod(); }

@Test
void testNotExist(ORB orb, Bus bus) {
assertThrows(OBJECT_NOT_EXIST.class,
() -> TestHelper.narrow(orb.string_to_object(bus.get("testNotExist"))).aMethod());
}

final static class TestActivator_impl extends LocalObject implements ServantActivator{
private final ORB orb;
private boolean etherealizeCalled = false;

TestActivator_impl(ORB orb) {
this.orb = orb;
}

public org.omg.PortableServer.Servant incarnate(byte[] oid, POA poa) throws ForwardRequest {
String oidString = new String(oid);

// If the user is requesting the object "test" then oblige
org.omg.PortableServer.Servant servant = null;
if (oidString.equals("test1"))
servant = new Test_impl(orb, "test1", false);
else if (oidString.equals("testDSI"))
servant = new TestDSIRef_impl(orb, "", false);

if (servant != null) {
// Verify that POA allows activator to explicitly activate a servant
try {
poa.activate_object_with_id(oid, servant);
} catch (ObjectAlreadyActive | WrongPolicy | ServantAlreadyActive ex) {
throw new RuntimeException();
}
return servant;
}
// Fail if not test1 or testDSI objects
throw new OBJECT_NOT_EXIST();
}

public void etherealize(byte[] oid, POA poa, Servant servant, boolean cleanup, boolean remaining) {
if (remaining) return;
etherealizeCalled = true;
// Etherealize is called when the orb -> shutdown()
// method is called. The ORB shutdown calls
// destroy(true, true) on each POAManagers. The
// cleanup flag should be set to true here.
if (!cleanup) throw new RuntimeException();
if (new String(oid).equals("test")) servant = null;
}

public boolean etherealize_called() {
return etherealizeCalled;
}
}
}
17 changes: 8 additions & 9 deletions yoko-core/src/test/java/org/apache/yoko/PoaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import test.poa.TestMultipleOrbsThreadedServer;
import test.poa.TestPOAManagerClient;
import test.poa.TestPOAManagerServer;
import test.poa.TestServantActivatorServer;
import test.poa.TestServantLocatorServer;

public class PoaTest extends AbstractOrbTestBase {
Expand All @@ -38,14 +37,14 @@ public void setUp() throws Exception {
super.setUp();
setWaitForFile("Test.ref");
}

public void testServantActivatorServer() throws Exception {
runServerClientTest(TestServantActivatorServer.class, TestClient.class);
}

public void testServantLocatorServer() throws Exception {
runServerClientTest(TestServantLocatorServer.class, TestClient.class);
}
//
// public void testServantActivatorServer() throws Exception {
// runServerClientTest(TestServantActivatorServer.class, TestClient.class);
// }
//
// public void testServantLocatorServer() throws Exception {
// runServerClientTest(TestServantLocatorServer.class, TestClient.class);
// }

public void testLocationForwardServer() throws Exception {
runServerClientTest(TestLocationForwardServerMain.class, TestLocationForwardClient.class);
Expand Down
224 changes: 0 additions & 224 deletions yoko-core/src/test/java/test/poa/TestServantActivatorServer.java

This file was deleted.

0 comments on commit 503d2d7

Please sign in to comment.