diff options
Diffstat (limited to 'java/test')
-rw-r--r-- | java/test/Ice/plugin/Client.java | 197 | ||||
-rw-r--r-- | java/test/Ice/plugin/plugins/BasePlugin.java | 41 | ||||
-rw-r--r-- | java/test/Ice/plugin/plugins/BasePluginFail.java | 45 | ||||
-rw-r--r-- | java/test/Ice/plugin/plugins/PluginFactory.java | 73 | ||||
-rw-r--r-- | java/test/Ice/plugin/plugins/PluginInitializeFailException.java | 18 | ||||
-rw-r--r-- | java/test/Ice/plugin/plugins/PluginInitializeFailFactory.java | 39 | ||||
-rw-r--r-- | java/test/Ice/plugin/plugins/PluginOneFactory.java | 39 | ||||
-rw-r--r-- | java/test/Ice/plugin/plugins/PluginOneFailFactory.java | 64 | ||||
-rw-r--r-- | java/test/Ice/plugin/plugins/PluginThreeFactory.java | 39 | ||||
-rw-r--r-- | java/test/Ice/plugin/plugins/PluginThreeFailFactory.java | 55 | ||||
-rw-r--r-- | java/test/Ice/plugin/plugins/PluginTwoFactory.java | 39 | ||||
-rw-r--r-- | java/test/Ice/plugin/plugins/PluginTwoFailFactory.java | 64 | ||||
-rwxr-xr-x | java/test/Ice/plugin/run.py | 29 |
13 files changed, 742 insertions, 0 deletions
diff --git a/java/test/Ice/plugin/Client.java b/java/test/Ice/plugin/Client.java new file mode 100644 index 00000000000..db43197209c --- /dev/null +++ b/java/test/Ice/plugin/Client.java @@ -0,0 +1,197 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2011 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. +// +// ********************************************************************** + +package test.Ice.plugin; + +import java.io.PrintWriter; + +public class Client extends test.Util.Application +{ + public int run(String[] args) + { + Ice.Communicator communicator = communicator(); + PrintWriter printWriter = getWriter(); + printWriter.print("testing a simple plug-in... "); + printWriter.flush(); + try + { + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(); + initData.properties.setProperty("Ice.Plugin.Test", + "../../../lib/IceTestPlugins.jar:test.Ice.plugin.plugins.PluginFactory " + + "'C:\\Program Files\\' --DatabasePath 'C:\\Program Files\\Application\\db'"); + communicator = Ice.Util.initialize(args, initData); + communicator.destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + test(false); + } + printWriter.println("ok"); + + printWriter.print("testing a simple plug-in that fails to initialize... "); + printWriter.flush(); + communicator = null; + try + { + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(); + initData.properties.setProperty("Ice.Plugin.Test", + "../../../lib/:test.Ice.plugin.plugins.PluginInitializeFailFactory"); + communicator = Ice.Util.initialize(args, initData); + test(false); + } + catch(RuntimeException ex) + { + test(ex.getMessage().equals("PluginInitializeFailException")); + } + test(communicator == null); + printWriter.println("ok"); + + printWriter.print("testing plug-in load order... "); + printWriter.flush(); + try + { + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(); + initData.properties.setProperty("Ice.Plugin.PluginOne", + "../../../lib/:test.Ice.plugin.plugins.PluginOneFactory"); + initData.properties.setProperty("Ice.Plugin.PluginTwo", + "../../../lib/:test.Ice.plugin.plugins.PluginTwoFactory"); + initData.properties.setProperty("Ice.Plugin.PluginThree", + "../../../lib/:test.Ice.plugin.plugins.PluginThreeFactory"); + initData.properties.setProperty("Ice.PluginLoadOrder", "PluginOne, PluginTwo"); // Exclude PluginThree + communicator = Ice.Util.initialize(args, initData); + communicator.destroy(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + test(false); + } + printWriter.println("ok"); + + printWriter.print("testing plug-in manager... "); + printWriter.flush(); + try + { + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(); + initData.properties.setProperty("Ice.Plugin.PluginOne", + "../../../lib/:test.Ice.plugin.plugins.PluginOneFactory"); + initData.properties.setProperty("Ice.Plugin.PluginTwo", + "../../../lib/:test.Ice.plugin.plugins.PluginTwoFactory"); + initData.properties.setProperty("Ice.Plugin.PluginThree", + "../../../lib/:test.Ice.plugin.plugins.PluginThreeFactory"); + initData.properties.setProperty("Ice.PluginLoadOrder", "PluginOne, PluginTwo"); + initData.properties.setProperty("Ice.InitPlugins", "0"); + communicator = Ice.Util.initialize(args, initData); + + Ice.PluginManager pm = communicator.getPluginManager(); + test(pm.getPlugin("PluginOne") != null); + test(pm.getPlugin("PluginTwo") != null); + test(pm.getPlugin("PluginThree") != null); + + MyPlugin p4 = new MyPlugin(); + pm.addPlugin("PluginFour", p4); + test(pm.getPlugin("PluginFour") != null); + + pm.initializePlugins(); + + test(p4.isInitialized()); + + communicator.destroy(); + + test(p4.isDestroyed()); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + test(false); + } + printWriter.println("ok"); + + printWriter.print("testing destroy when a plug-in fails to initialize... "); + printWriter.flush(); + communicator = null; + try + { + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(); + initData.properties.setProperty("Ice.Plugin.PluginOneFail", + "../../../lib/:test.Ice.plugin.plugins.PluginOneFailFactory"); + initData.properties.setProperty("Ice.Plugin.PluginTwoFail", + "../../../lib/:test.Ice.plugin.plugins.PluginTwoFailFactory"); + initData.properties.setProperty("Ice.Plugin.PluginThreeFail", + "../../../lib/:test.Ice.plugin.plugins.PluginThreeFailFactory"); + initData.properties.setProperty("Ice.PluginLoadOrder", "PluginOneFail, PluginTwoFail, PluginThreeFail"); + communicator = Ice.Util.initialize(args, initData); + } + catch(RuntimeException ex) + { + test(ex.getMessage().equals("PluginInitializeFailException")); + } + test(communicator == null); + printWriter.println("ok"); + + System.gc(); + System.runFinalization(); + return 0; + } + + protected Ice.InitializationData getInitData(Ice.StringSeqHolder argsH) + { + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(argsH); + return initData; + } + + private static void test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + public static void main(String[] args) + { + Client app = new Client(); + int result = app.main("Client", args); + System.gc(); + System.exit(result); + } + + static class MyPlugin implements Ice.Plugin + { + public boolean isInitialized() + { + return _initialized; + } + + public boolean isDestroyed() + { + return _destroyed; + } + + public void initialize() + { + _initialized = true; + } + + public void destroy() + { + _destroyed = true; + } + + private boolean _initialized = false; + private boolean _destroyed = false; + } +} diff --git a/java/test/Ice/plugin/plugins/BasePlugin.java b/java/test/Ice/plugin/plugins/BasePlugin.java new file mode 100644 index 00000000000..da0d7000ca6 --- /dev/null +++ b/java/test/Ice/plugin/plugins/BasePlugin.java @@ -0,0 +1,41 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2011 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. +// +// ********************************************************************** + +package test.Ice.plugin.plugins; + +public abstract class BasePlugin implements Ice.Plugin +{ + public BasePlugin(Ice.Communicator communicator) + { + _communicator = communicator; + } + + public boolean isInitialized() + { + return _initialized; + } + + public boolean isDestroyed() + { + return _destroyed; + } + + protected static void test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + protected Ice.Communicator _communicator; + protected boolean _initialized = false; + protected boolean _destroyed = false; + protected BasePlugin _other = null; +} diff --git a/java/test/Ice/plugin/plugins/BasePluginFail.java b/java/test/Ice/plugin/plugins/BasePluginFail.java new file mode 100644 index 00000000000..bba0cc21760 --- /dev/null +++ b/java/test/Ice/plugin/plugins/BasePluginFail.java @@ -0,0 +1,45 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2011 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. +// +// ********************************************************************** + +package test.Ice.plugin.plugins; + +public abstract class BasePluginFail implements Ice.Plugin +{ + public BasePluginFail(Ice.Communicator communicator) + { + _communicator = communicator; + _initialized = false; + _destroyed = false; + } + + public boolean isInitialized() + { + return _initialized; + } + + public boolean isDestroyed() + { + return _destroyed; + } + + protected static void test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + protected Ice.Communicator _communicator; + protected boolean _initialized; + protected boolean _destroyed; + protected BasePluginFail _one; + protected BasePluginFail _two; + protected BasePluginFail _three; +} diff --git a/java/test/Ice/plugin/plugins/PluginFactory.java b/java/test/Ice/plugin/plugins/PluginFactory.java new file mode 100644 index 00000000000..dff16aa61f8 --- /dev/null +++ b/java/test/Ice/plugin/plugins/PluginFactory.java @@ -0,0 +1,73 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2011 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. +// +// ********************************************************************** + +package test.Ice.plugin.plugins; + +public class PluginFactory implements Ice.PluginFactory +{ + public Ice.Plugin create(Ice.Communicator communicator, String name, String[] args) + { + return new Plugin(communicator, args); + } + + static class Plugin implements Ice.Plugin + { + public Plugin(Ice.Communicator communicator, String[] args) + { + _communicator = communicator; + _args = args; + } + + public void initialize() + { + _initialized = true; + test(_args.length == 3); + test(_args[0].equals("C:\\Program Files\\")); + test(_args[1].equals("--DatabasePath")); + test(_args[2].equals("C:\\Program Files\\Application\\db")); + } + + public void destroy() + { + _destroyed = true; + } + + protected void finalize() throws Throwable + { + try + { + if(!_initialized) + { + System.out.println("test.Ice.plugin.plugins.Plugin not initialized"); + } + if(!_destroyed) + { + System.out.println("test.Ice.plugin.plugins.Plugin not destroyed"); + } + } + finally + { + super.finalize(); + } + } + + private static void test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + private Ice.Communicator _communicator; + private String[] _args; + private boolean _initialized = false; + private boolean _destroyed = false; + } +} diff --git a/java/test/Ice/plugin/plugins/PluginInitializeFailException.java b/java/test/Ice/plugin/plugins/PluginInitializeFailException.java new file mode 100644 index 00000000000..ed1700bc4e5 --- /dev/null +++ b/java/test/Ice/plugin/plugins/PluginInitializeFailException.java @@ -0,0 +1,18 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2011 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. +// +// ********************************************************************** + +package test.Ice.plugin.plugins; + +public class PluginInitializeFailException extends java.lang.RuntimeException +{ + public PluginInitializeFailException() + { + super("PluginInitializeFailException"); + } +} diff --git a/java/test/Ice/plugin/plugins/PluginInitializeFailFactory.java b/java/test/Ice/plugin/plugins/PluginInitializeFailFactory.java new file mode 100644 index 00000000000..a2e00176ed0 --- /dev/null +++ b/java/test/Ice/plugin/plugins/PluginInitializeFailFactory.java @@ -0,0 +1,39 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2011 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. +// +// ********************************************************************** + +package test.Ice.plugin.plugins; + +public class PluginInitializeFailFactory implements Ice.PluginFactory +{ + public Ice.Plugin create(Ice.Communicator communicator, String name, String[] args) + { + return new PluginInitializeFail(); + } + + static class PluginInitializeFail implements Ice.Plugin + { + public void initialize() + { + throw new PluginInitializeFailException(); + } + + public void destroy() + { + test(false); + } + + private static void test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + } +} diff --git a/java/test/Ice/plugin/plugins/PluginOneFactory.java b/java/test/Ice/plugin/plugins/PluginOneFactory.java new file mode 100644 index 00000000000..1101ae22f4f --- /dev/null +++ b/java/test/Ice/plugin/plugins/PluginOneFactory.java @@ -0,0 +1,39 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2011 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. +// +// ********************************************************************** + +package test.Ice.plugin.plugins; + +public class PluginOneFactory implements Ice.PluginFactory +{ + public Ice.Plugin create(Ice.Communicator communicator, String name, String[] args) + { + return new PluginOne(communicator); + } + + static class PluginOne extends BasePlugin + { + public PluginOne(Ice.Communicator communicator) + { + super(communicator); + } + + public void initialize() + { + _other = (BasePlugin)_communicator.getPluginManager().getPlugin("PluginTwo"); + test(!_other.isInitialized()); + _initialized = true; + } + + public void destroy() + { + _destroyed = true; + test(_other.isDestroyed()); + } + } +} diff --git a/java/test/Ice/plugin/plugins/PluginOneFailFactory.java b/java/test/Ice/plugin/plugins/PluginOneFailFactory.java new file mode 100644 index 00000000000..84a2db46af2 --- /dev/null +++ b/java/test/Ice/plugin/plugins/PluginOneFailFactory.java @@ -0,0 +1,64 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2011 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. +// +// ********************************************************************** + +package test.Ice.plugin.plugins; + +public class PluginOneFailFactory implements Ice.PluginFactory +{ + public Ice.Plugin create(Ice.Communicator communicator, String name, String[] args) + { + return new PluginOneFail(communicator); + } + + static class PluginOneFail extends BasePluginFail + { + public PluginOneFail(Ice.Communicator communicator) + { + super(communicator); + } + + public void initialize() + { + _two = (BasePluginFail)_communicator.getPluginManager().getPlugin("PluginTwoFail"); + test(!_two.isInitialized()); + _three = (BasePluginFail)_communicator.getPluginManager().getPlugin("PluginThreeFail"); + test(!_three.isInitialized()); + _initialized = true; + } + + public void destroy() + { + test(_two.isDestroyed()); + // + // Not destroyed because initialize fails. + // + test(!_three.isDestroyed()); + _destroyed = true; + } + + protected void finalize() throws Throwable + { + try + { + if(!_initialized) + { + System.out.println(getClass().getName() + " not initialized"); + } + if(!_destroyed) + { + System.out.println(getClass().getName() + " not destroyed"); + } + } + finally + { + super.finalize(); + } + } + } +} diff --git a/java/test/Ice/plugin/plugins/PluginThreeFactory.java b/java/test/Ice/plugin/plugins/PluginThreeFactory.java new file mode 100644 index 00000000000..73eeccabd44 --- /dev/null +++ b/java/test/Ice/plugin/plugins/PluginThreeFactory.java @@ -0,0 +1,39 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2011 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. +// +// ********************************************************************** + +package test.Ice.plugin.plugins; + +public class PluginThreeFactory implements Ice.PluginFactory +{ + public Ice.Plugin create(Ice.Communicator communicator, String name, String[] args) + { + return new PluginThree(communicator); + } + + static class PluginThree extends BasePlugin + { + public PluginThree(Ice.Communicator communicator) + { + super(communicator); + } + + public void initialize() + { + _other = (BasePlugin)_communicator.getPluginManager().getPlugin("PluginTwo"); + test(_other.isInitialized()); + _initialized = true; + } + + public void destroy() + { + _destroyed = true; + test(!_other.isDestroyed()); + } + } +} diff --git a/java/test/Ice/plugin/plugins/PluginThreeFailFactory.java b/java/test/Ice/plugin/plugins/PluginThreeFailFactory.java new file mode 100644 index 00000000000..846675fea12 --- /dev/null +++ b/java/test/Ice/plugin/plugins/PluginThreeFailFactory.java @@ -0,0 +1,55 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2011 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. +// +// ********************************************************************** + +package test.Ice.plugin.plugins; + +public class PluginThreeFailFactory implements Ice.PluginFactory +{ + public Ice.Plugin create(Ice.Communicator communicator, String name, String[] args) + { + return new PluginThreeFail(communicator); + } + + public class PluginThreeFail extends BasePluginFail + { + public PluginThreeFail(Ice.Communicator communicator) + { + super(communicator); + } + + public void initialize() + { + throw new PluginInitializeFailException(); + } + + public void destroy() + { + test(false); + } + + protected void finalize() throws Throwable + { + try + { + if(_initialized) + { + System.out.println(getClass().getName() + " was initialized"); + } + if(_destroyed) + { + System.out.println(getClass().getName() + " was destroyed"); + } + } + finally + { + super.finalize(); + } + } + } +} diff --git a/java/test/Ice/plugin/plugins/PluginTwoFactory.java b/java/test/Ice/plugin/plugins/PluginTwoFactory.java new file mode 100644 index 00000000000..7b8e970f07c --- /dev/null +++ b/java/test/Ice/plugin/plugins/PluginTwoFactory.java @@ -0,0 +1,39 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2011 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. +// +// ********************************************************************** + +package test.Ice.plugin.plugins; + +public class PluginTwoFactory implements Ice.PluginFactory +{ + public Ice.Plugin create(Ice.Communicator communicator, String name, String[] args) + { + return new PluginTwo(communicator); + } + + static class PluginTwo extends BasePlugin + { + public PluginTwo(Ice.Communicator communicator) + { + super(communicator); + } + + public void initialize() + { + _other = (BasePlugin)_communicator.getPluginManager().getPlugin("PluginOne"); + test(_other.isInitialized()); + _initialized = true; + } + + public void destroy() + { + _destroyed = true; + test(!_other.isDestroyed()); + } + } +} diff --git a/java/test/Ice/plugin/plugins/PluginTwoFailFactory.java b/java/test/Ice/plugin/plugins/PluginTwoFailFactory.java new file mode 100644 index 00000000000..80dd2fdf2f2 --- /dev/null +++ b/java/test/Ice/plugin/plugins/PluginTwoFailFactory.java @@ -0,0 +1,64 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2011 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. +// +// ********************************************************************** + +package test.Ice.plugin.plugins; + +public class PluginTwoFailFactory implements Ice.PluginFactory +{ + public Ice.Plugin create(Ice.Communicator communicator, String name, String[] args) + { + return new PluginTwoFail(communicator); + } + + static class PluginTwoFail extends BasePluginFail + { + public PluginTwoFail(Ice.Communicator communicator) + { + super(communicator); + } + + public void initialize() + { + _one = (BasePluginFail)_communicator.getPluginManager().getPlugin("PluginOneFail"); + test(_one.isInitialized()); + _three = (BasePluginFail)_communicator.getPluginManager().getPlugin("PluginThreeFail"); + test(!_three.isInitialized()); + _initialized = true; + } + + public void destroy() + { + test(!_one.isDestroyed()); + // + // Not destroyed because initialize fails. + // + test(!_three.isDestroyed()); + _destroyed = true; + } + + protected void finalize() throws Throwable + { + try + { + if(!_initialized) + { + System.out.println(getClass().getName() + " not initialized"); + } + if(!_destroyed) + { + System.out.println(getClass().getName() + " not destroyed"); + } + } + finally + { + super.finalize(); + } + } + } +} diff --git a/java/test/Ice/plugin/run.py b/java/test/Ice/plugin/run.py new file mode 100755 index 00000000000..e4b27ab1226 --- /dev/null +++ b/java/test/Ice/plugin/run.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2011 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 + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise "can't find toplevel directory!" +sys.path.append(os.path.join(path[0])) +from scripts import * + +print "starting test...", +clientProc = TestUtil.startClient("test.Ice.plugin.Client",startReader=False) +print "ok" +clientProc.startReader() + +clientProc.waitTestSuccess() + |