From 26c33e45e09f6c635f6a663f05e9edb51f5461ef Mon Sep 17 00:00:00 2001 From: Benoit Foucher Date: Wed, 10 Jan 2007 10:22:43 +0000 Subject: Fixed bug 1650 --- java/test/Ice/build.xml | 2 + java/test/Ice/servantLocator/AllTests.java | 192 ++++++++++++++++++++++ java/test/Ice/servantLocator/Client.java | 33 ++++ java/test/Ice/servantLocator/CookieI.java | 19 +++ java/test/Ice/servantLocator/ServantLocatorI.java | 134 +++++++++++++++ java/test/Ice/servantLocator/Server.java | 39 +++++ java/test/Ice/servantLocator/Test.ice | 40 +++++ java/test/Ice/servantLocator/TestI.java | 54 ++++++ java/test/Ice/servantLocator/build.xml | 48 ++++++ java/test/Ice/servantLocator/run.py | 46 ++++++ 10 files changed, 607 insertions(+) create mode 100644 java/test/Ice/servantLocator/AllTests.java create mode 100644 java/test/Ice/servantLocator/Client.java create mode 100644 java/test/Ice/servantLocator/CookieI.java create mode 100644 java/test/Ice/servantLocator/ServantLocatorI.java create mode 100644 java/test/Ice/servantLocator/Server.java create mode 100644 java/test/Ice/servantLocator/Test.ice create mode 100644 java/test/Ice/servantLocator/TestI.java create mode 100644 java/test/Ice/servantLocator/build.xml create mode 100755 java/test/Ice/servantLocator/run.py (limited to 'java/test') diff --git a/java/test/Ice/build.xml b/java/test/Ice/build.xml index bdcdfa92e18..755ac9195df 100644 --- a/java/test/Ice/build.xml +++ b/java/test/Ice/build.xml @@ -32,6 +32,8 @@ + + diff --git a/java/test/Ice/servantLocator/AllTests.java b/java/test/Ice/servantLocator/AllTests.java new file mode 100644 index 00000000000..e4ee71a9e16 --- /dev/null +++ b/java/test/Ice/servantLocator/AllTests.java @@ -0,0 +1,192 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +import Test.*; +import Ice.*; + +public class AllTests +{ + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + public static void + testExceptions(TestIntfPrx obj, boolean collocated) + { + try + { + obj.requestFailedException(); + test(false); + } + catch(ObjectNotExistException ex) + { + if(!collocated) + { + test(ex.id.equals(obj.ice_getIdentity())); + test(ex.facet.equals(obj.ice_getFacet())); + test(ex.operation.equals("requestFailedException")); + } + } + + try + { + obj.unknownUserException(); + test(false); + } + catch(UnknownUserException ex) + { + test(ex.unknown.equals("reason")); + } + + try + { + obj.unknownLocalException(); + test(false); + } + catch(UnknownLocalException ex) + { + test(ex.unknown.equals("reason")); + } + + try + { + obj.unknownException(); + test(false); + } + catch(UnknownException ex) + { + test(ex.unknown.equals("reason")); + } + + // + // User exceptions are checked exceptions + // +// try +// { +// obj.userException(); +// test(false); +// } +// catch(UnknownUserException ex) +// { +// //System.err.println(ex.unknown); +// test(!collocated); +// test(ex.unknown.equals("Test::TestIntfUserException")); +// } +// catch(TestIntfUserException ex) +// { +// test(collocated); +// } + + try + { + obj.localException(); + test(false); + } + catch(UnknownLocalException ex) + { + //System.err.println(ex.unknown); + test(!collocated); + test(ex.unknown.indexOf("Ice.SocketException") >= 0); + } + catch(SocketException ex) + { + test(collocated); + } + + try + { + obj.javaException(); + test(false); + } + catch(UnknownException ex) + { + //System.err.println(ex.unknown); + test(!collocated); + test(ex.unknown.indexOf("java.lang.RuntimeException: message") >= 0); + } + catch(java.lang.RuntimeException ex) + { + test(collocated); + } + } + + public static TestIntfPrx + allTests(Ice.Communicator communicator, boolean collocated) + { + System.out.print("testing stringToProxy... "); + System.out.flush(); + String ref = "asm:default -p 12010 -t 10000"; + Ice.ObjectPrx base = communicator.stringToProxy(ref); + test(base != null); + System.out.println("ok"); + + System.out.print("testing checked cast... "); + System.out.flush(); + TestIntfPrx obj = TestIntfPrxHelper.checkedCast(base); + test(obj != null); + test(obj.equals(base)); + System.out.println("ok"); + + System.out.print("testing servant locator..."); + System.out.flush(); + base = communicator.stringToProxy("category/locate:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(base); + try + { + TestIntfPrxHelper.checkedCast(communicator.stringToProxy("category/unknown:default -p 12010 -t 10000")); + } + catch(ObjectNotExistException ex) + { + } + System.out.println("ok"); + + System.out.print("testing default servant locator..."); + System.out.flush(); + base = communicator.stringToProxy("anothercat/locate:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(base); + base = communicator.stringToProxy("locate:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(base); + try + { + TestIntfPrxHelper.checkedCast(communicator.stringToProxy("anothercat/unknown:default -p 12010 -t 10000")); + } + catch(ObjectNotExistException ex) + { + } + try + { + TestIntfPrxHelper.checkedCast(communicator.stringToProxy("unknown:default -p 12010 -t 10000")); + } + catch(ObjectNotExistException ex) + { + } + System.out.println("ok"); + + System.out.print("testing locate exceptions... "); + System.out.flush(); + base = communicator.stringToProxy("category/locate:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(base); + testExceptions(obj, collocated); + System.out.println("ok"); + + System.out.print("testing finished exceptions... "); + System.out.flush(); + base = communicator.stringToProxy("category/finished:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(base); + testExceptions(obj, collocated); + System.out.println("ok"); + + return obj; + } +} diff --git a/java/test/Ice/servantLocator/Client.java b/java/test/Ice/servantLocator/Client.java new file mode 100644 index 00000000000..403616d3c10 --- /dev/null +++ b/java/test/Ice/servantLocator/Client.java @@ -0,0 +1,33 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +import Test.*; + +public class Client +{ + static class TestClient extends Ice.Application + { + public int + run(String[] args) + { + TestIntfPrx obj = AllTests.allTests(communicator(), false); + obj.shutdown(); + return 0; + } + } + + public static void + main(String[] args) + { + TestClient app = new TestClient(); + int result = app.main("Client", args); + System.gc(); + System.exit(result); + } +} diff --git a/java/test/Ice/servantLocator/CookieI.java b/java/test/Ice/servantLocator/CookieI.java new file mode 100644 index 00000000000..e754004a626 --- /dev/null +++ b/java/test/Ice/servantLocator/CookieI.java @@ -0,0 +1,19 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +import Test.*; + +public final class CookieI extends Cookie +{ + public String + message() + { + return "blahblah"; + } +} diff --git a/java/test/Ice/servantLocator/ServantLocatorI.java b/java/test/Ice/servantLocator/ServantLocatorI.java new file mode 100644 index 00000000000..7fab16bfb87 --- /dev/null +++ b/java/test/Ice/servantLocator/ServantLocatorI.java @@ -0,0 +1,134 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +import Test.*; +import Ice.*; + +public final class ServantLocatorI extends Ice.LocalObjectImpl implements Ice.ServantLocator +{ + public + ServantLocatorI(String category) + { + _category = category; + _deactivated = false; + } + + protected synchronized void + finalize() + throws Throwable + { + test(_deactivated); + } + + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + public Ice.Object + locate(Ice.Current current, Ice.LocalObjectHolder cookie) + { + synchronized(this) + { + test(!_deactivated); + } + + test(current.id.category.equals(_category) || _category.length() == 0); + + if(current.id.name.equals("unknown")) + { + return null; + } + + test(current.id.name.equals("locate") || current.id.name.equals("finished")); + if(current.id.name.equals("locate")) + { + exception(current); + } + + cookie.value = new CookieI(); + + return new TestI(); + } + + public void + finished(Ice.Current current, Ice.Object servant, Ice.LocalObject cookie) + { + synchronized(this) + { + test(!_deactivated); + } + + test(current.id.category.equals(_category) || _category.length() == 0); + test(current.id.name.equals("locate") || current.id.name.equals("finished")); + + if(current.id.name.equals("finished")) + { + exception(current); + } + + Cookie co = (Cookie)cookie; + test(co.message().equals("blahblah")); + } + + public synchronized void + deactivate(String category) + { + synchronized(this) + { + test(!_deactivated); + + _deactivated = true; + } + } + + private void + exception(Ice.Current current) + { + if(current.operation.equals("requestFailedException")) + { + throw new ObjectNotExistException(); + } + else if(current.operation.equals("unknownUserException")) + { + throw new UnknownUserException("reason"); + } + else if(current.operation.equals("unknownLocalException")) + { + throw new UnknownLocalException("reason"); + } + else if(current.operation.equals("unknownException")) + { + throw new UnknownException("reason"); + } + // + // User exceptions are checked exceptions in Java, so it's not + // possible to throw it from the servant locator. + // +// else if(current.operation.equals("userException")) +// { +// throw new TestIntfUserException(); +// } + else if(current.operation.equals("localException")) + { + throw new SocketException(0); + } + else if(current.operation.equals("javaException")) + { + throw new java.lang.RuntimeException("message"); + } + } + + private boolean _deactivated; + private final String _category; +} diff --git a/java/test/Ice/servantLocator/Server.java b/java/test/Ice/servantLocator/Server.java new file mode 100644 index 00000000000..a6e9f74be45 --- /dev/null +++ b/java/test/Ice/servantLocator/Server.java @@ -0,0 +1,39 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +public class Server +{ + static class TestServer extends Ice.Application + { + public int + run(String[] args) + { + communicator().getProperties().setProperty("Ice.OA.TestAdapter.Endpoints", "default -p 12010 -t 10000"); + communicator().getProperties().setProperty("Ice.Warn.Dispatch", "0"); + + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("TestAdapter"); + adapter.addServantLocator(new ServantLocatorI("category"), "category"); + adapter.addServantLocator(new ServantLocatorI(""), ""); + adapter.add(new TestI(), communicator().stringToIdentity("asm")); + + adapter.activate(); + adapter.waitForDeactivate(); + return 0; + } + } + + public static void + main(String[] args) + { + TestServer app = new TestServer(); + int result = app.main("Server", args); + System.gc(); + System.exit(result); + } +} diff --git a/java/test/Ice/servantLocator/Test.ice b/java/test/Ice/servantLocator/Test.ice new file mode 100644 index 00000000000..c32c7e89538 --- /dev/null +++ b/java/test/Ice/servantLocator/Test.ice @@ -0,0 +1,40 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#ifndef TEST_ICE +#define TEST_ICE + +module Test +{ + +exception TestIntfUserException +{ +}; + +interface TestIntf +{ + void requestFailedException(); + void unknownUserException(); + void unknownLocalException(); + void unknownException(); + void localException(); + //void userException(); + void javaException(); + + void shutdown(); +}; + +local class Cookie +{ + ["cpp:const"] string message(); +}; + +}; + +#endif diff --git a/java/test/Ice/servantLocator/TestI.java b/java/test/Ice/servantLocator/TestI.java new file mode 100644 index 00000000000..15520733750 --- /dev/null +++ b/java/test/Ice/servantLocator/TestI.java @@ -0,0 +1,54 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +import Test.*; + +public final class TestI extends _TestIntfDisp +{ + public void + requestFailedException(Ice.Current current) + { + } + + public void + unknownUserException(Ice.Current current) + { + } + + public void + unknownLocalException(Ice.Current current) + { + } + + public void + unknownException(Ice.Current current) + { + } + + public void + localException(Ice.Current current) + { + } + +// public void +// userException(Ice.Current current) +// { +// } + + public void + javaException(Ice.Current current) + { + } + + public void + shutdown(Ice.Current current) + { + current.adapter.deactivate(); + } +} diff --git a/java/test/Ice/servantLocator/build.xml b/java/test/Ice/servantLocator/build.xml new file mode 100644 index 00000000000..7989d984638 --- /dev/null +++ b/java/test/Ice/servantLocator/build.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/test/Ice/servantLocator/run.py b/java/test/Ice/servantLocator/run.py new file mode 100755 index 00000000000..3e6d59ec3a7 --- /dev/null +++ b/java/test/Ice/servantLocator/run.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys + +for toplevel in [".", "..", "../..", "../../..", "../../../.."]: + toplevel = os.path.normpath(toplevel) + if os.path.exists(os.path.join(toplevel, "config", "TestUtil.py")): + break +else: + raise "can't find toplevel directory!" + +sys.path.append(os.path.join(toplevel, "config")) +import TestUtil + +name = os.path.join("Ice", "servantLocator") +nameAMD = os.path.join("Ice", "servantLocatorAMD") +testdir = os.path.join(toplevel, "test", name) +testdirAMD = os.path.join(toplevel, "test", nameAMD) +os.environ["CLASSPATH"] = os.path.join(testdir, "classes") + TestUtil.sep + os.getenv("CLASSPATH", "") + +# +# We need to use mixedClientServerTest so that, when using SSL, the +# server-side SSL configuration properties are defined. This is +# necessary because the client creates object adapters. +# +print "tests with regular server." +classpath = os.getenv("CLASSPATH", "") +TestUtil.mixedClientServerTest() + +print "tests with AMD server." +TestUtil.clientServerTestWithClasspath(\ + os.path.join(testdirAMD, "classes") + TestUtil.sep + classpath,\ + os.path.join(testdir, "classes") + TestUtil.sep + classpath) + +print "tests with collocated server." +TestUtil.collocatedTest() + +sys.exit(0) -- cgit v1.2.3