diff options
author | Matthew Newhook <matthew@zeroc.com> | 2014-09-03 11:01:11 -0230 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2014-09-03 11:01:11 -0230 |
commit | 3b0588532354adf7bf3b86e611a8ae4996bfe6ad (patch) | |
tree | 253961cb83af7bc3b1dfc7633a8f934789476cd1 /java/test | |
parent | More work on ICE-2400: the send log thread now uses a separate communicator t... (diff) | |
download | ice-3b0588532354adf7bf3b86e611a8ae4996bfe6ad.tar.bz2 ice-3b0588532354adf7bf3b86e611a8ae4996bfe6ad.tar.xz ice-3b0588532354adf7bf3b86e611a8ae4996bfe6ad.zip |
- C#, Java: Removed Outgoing, fixed generated code to make synchronous
requests using AMI.
- Java: AsyncResult is now an interface.
- Added --arg to allTests.py.
- Fixed operations, adapterDeactivation and metrics test to work with
background IO.
- Added Collocated interrupt test.
- Added support for batch oneway requests using AMI.
- Added test in operations for batch oneway requests using AMI.
Diffstat (limited to 'java/test')
-rw-r--r-- | java/test/Ice/adapterDeactivation/Collocated.java | 4 | ||||
-rw-r--r-- | java/test/Ice/exceptions/AllTests.java | 25 | ||||
-rw-r--r-- | java/test/Ice/interrupt/AllTests.java | 116 | ||||
-rw-r--r-- | java/test/Ice/interrupt/Collocated.java | 72 | ||||
-rw-r--r-- | java/test/Ice/interrupt/run.py | 3 | ||||
-rw-r--r-- | java/test/Ice/metrics/AllTests.java | 97 | ||||
-rw-r--r-- | java/test/Ice/metrics/Collocated.java | 7 | ||||
-rw-r--r-- | java/test/Ice/operations/AllTests.java | 5 | ||||
-rw-r--r-- | java/test/Ice/operations/BatchOneways.java | 1 | ||||
-rw-r--r-- | java/test/Ice/operations/BatchOnewaysAMI.java | 208 | ||||
-rw-r--r-- | java/test/Ice/operations/Collocated.java | 4 |
11 files changed, 451 insertions, 91 deletions
diff --git a/java/test/Ice/adapterDeactivation/Collocated.java b/java/test/Ice/adapterDeactivation/Collocated.java index 9f8f90bdda6..77c320bc3d3 100644 --- a/java/test/Ice/adapterDeactivation/Collocated.java +++ b/java/test/Ice/adapterDeactivation/Collocated.java @@ -28,6 +28,10 @@ public class Collocated extends test.Util.Application { Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = Ice.Util.createProperties(argsH); + if(initData.properties.getPropertyAsInt("Ice.BackgroundIO") > 0) + { + initData.properties.setProperty("Ice.ThreadPool.Server.Size", "2"); + } initData.properties.setProperty("Ice.Package.Test", "test.Ice.adapterDeactivation"); initData.properties.setProperty("TestAdapter.Endpoints", "default -p 12010"); return initData; diff --git a/java/test/Ice/exceptions/AllTests.java b/java/test/Ice/exceptions/AllTests.java index 282add94c37..f11f576c2fb 100644 --- a/java/test/Ice/exceptions/AllTests.java +++ b/java/test/Ice/exceptions/AllTests.java @@ -1,6 +1,5 @@ // ********************************************************************** // -// Copyright (c) 2003-2014 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. @@ -2281,18 +2280,18 @@ public class AllTests { final Callback_Thrower_throwLocalExceptionI cb = new Callback_Thrower_throwLocalExceptionI(); thrower.begin_throwLocalExceptionIdempotent(new Callback_Thrower_throwLocalExceptionIdempotent() - { - @Override - public void response() - { - cb.response(); - } - - @Override - public void exception(Ice.LocalException exc) - { - cb.exception(exc); - } + { + @Override + public void response() + { + cb.response(); + } + + @Override + public void exception(Ice.LocalException exc) + { + cb.exception(exc); + } }); cb.check(); } diff --git a/java/test/Ice/interrupt/AllTests.java b/java/test/Ice/interrupt/AllTests.java index 1c205b80ac8..0467444cfb9 100644 --- a/java/test/Ice/interrupt/AllTests.java +++ b/java/test/Ice/interrupt/AllTests.java @@ -56,31 +56,7 @@ public class AllTests notify(); } - public synchronized void checkResponse() - { - while(!_response) - { - try - { - wait(); - } - catch(InterruptedException ex) - { - } - } - - _response = false; - } - - public synchronized void response() - { - assert(!_response); - _response = true; - notify(); - } - private boolean _called = false; - private boolean _response = false; } private static void @@ -91,6 +67,18 @@ public class AllTests throw new RuntimeException(); } } + + private static void failIfNotInterrupted() + { + if(Thread.currentThread().isInterrupted()) + { + Thread.interrupted(); + } + else + { + test(false); + } + } public static void allTests(test.Util.Application app, Ice.Communicator communicator, PrintWriter out) @@ -232,48 +220,52 @@ public class AllTests test(false); } - // - // Test interrupt of waitForSent. Here hold the adapter and send a large payload. The - // thread is interrupted in 500ms which should result in a operation interrupted exception. - // - executor.submit(new Runnable() { - @Override - public void run() - { - try - { - Thread.sleep(500); - } - catch(InterruptedException e) + // This section of the test doesn't run when collocated. + if(p.ice_getConnection() != null) + { + // + // Test interrupt of waitForSent. Here hold the adapter and send a large payload. The + // thread is interrupted in 500ms which should result in a operation interrupted exception. + // + executor.submit(new Runnable() { + @Override + public void run() { - test(false); + try + { + Thread.sleep(500); + } + catch(InterruptedException e) + { + test(false); + } + mainThread.interrupt(); } - mainThread.interrupt(); - } - }); + }); - testController.holdAdapter(); - Ice.AsyncResult r = null; - try - { - // The sequence needs to be large enough to fill the write/recv buffers - byte[] seq = new byte[20000000]; - r = p.begin_opWithPayload(seq); + testController.holdAdapter(); + Ice.AsyncResult r = null; + try + { + // The sequence needs to be large enough to fill the write/recv buffers + byte[] seq = new byte[20000000]; + r = p.begin_opWithPayload(seq); + r.waitForSent(); + test(false); + } + catch(Ice.OperationInterruptedException ex) + { + // Expected + } + // + // Resume the adapter. + // + testController.resumeAdapter(); + r.waitForSent(); - test(false); - } - catch(Ice.OperationInterruptedException ex) - { - // Expected + r.waitForCompleted(); + p.end_opWithPayload(r); } - // - // Resume the adapter. - // - testController.resumeAdapter(); - - r.waitForSent(); - r.waitForCompleted(); - p.end_opWithPayload(r); // // The executor is all done. @@ -297,7 +289,7 @@ public class AllTests try { ic.destroy(); - test(false); + failIfNotInterrupted(); } catch(Ice.OperationInterruptedException ex) { diff --git a/java/test/Ice/interrupt/Collocated.java b/java/test/Ice/interrupt/Collocated.java new file mode 100644 index 00000000000..a377024f44b --- /dev/null +++ b/java/test/Ice/interrupt/Collocated.java @@ -0,0 +1,72 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2014 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.interrupt; + +public class Collocated extends test.Util.Application +{ + @Override + public int run(String[] args) + { + Ice.Communicator communicator = communicator(); + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("TestAdapter"); + Ice.ObjectAdapter adapter2 = communicator().createObjectAdapter("ControllerAdapter"); + TestControllerI controller = new TestControllerI(adapter); + adapter.add(new TestI(controller), communicator().stringToIdentity("test")); + adapter.activate(); + adapter2.add(controller, communicator().stringToIdentity("testController")); + adapter2.activate(); + + try + { + AllTests.allTests(this, communicator(), getWriter()); + } + catch (InterruptedException e) + { + e.printStackTrace(); + throw new RuntimeException(); + } + + return 0; + } + + @Override + protected Ice.InitializationData getInitData(Ice.StringSeqHolder argsH) + { + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(argsH); + initData.properties.setProperty("Ice.Package.Test", "test.Ice.interrupt"); + // + // We need to enable the background IO so that Ice is interrupt + // safe for this test. + // + initData.properties.setProperty("Ice.BackgroundIO", "1"); + // + // We need to send messages large enough to cause the transport + // buffers to fill up. + // + initData.properties.setProperty("Ice.MessageSizeMax", "20000"); + + initData.properties.setProperty("TestAdapter.Endpoints", "default -p 12010"); + initData.properties.setProperty("ControllerAdapter.Endpoints", "tcp -p 12011"); + initData.properties.setProperty("ControllerAdapter.ThreadPool.Size", "1"); + + return initData; + } + + public static void main(String[] args) + { + Collocated c = new Collocated(); + int status = c.main("Collocated", args); + + System.gc(); + System.exit(status); + } + +} diff --git a/java/test/Ice/interrupt/run.py b/java/test/Ice/interrupt/run.py index 3cbc4137c5e..012b74ea130 100644 --- a/java/test/Ice/interrupt/run.py +++ b/java/test/Ice/interrupt/run.py @@ -22,3 +22,6 @@ import TestUtil print("tests with regular server.") TestUtil.clientServerTest() + +print("tests with collocated server.") +TestUtil.collocatedTest()
\ No newline at end of file diff --git a/java/test/Ice/metrics/AllTests.java b/java/test/Ice/metrics/AllTests.java index 1a8724a91ab..c24a65b3f9e 100644 --- a/java/test/Ice/metrics/AllTests.java +++ b/java/test/Ice/metrics/AllTests.java @@ -143,17 +143,20 @@ public class AllTests _serverProps = serverProps; } - public synchronized void + public void waitForUpdate() { - while(!_updated) + synchronized(this) { - try - { - wait(); - } - catch(InterruptedException ex) + while(!_updated) { + try + { + wait(); + } + catch(InterruptedException ex) + { + } } } // Ensure that the previous updates were committed, the setProperties call returns before @@ -161,7 +164,10 @@ public class AllTests // a second time, this will block until all the notifications from the first update have // completed. _serverProps.setProperties(new java.util.HashMap<String, String>()); - _updated = false; + synchronized(this) + { + _updated = false; + } } @Override @@ -418,6 +424,12 @@ public class AllTests MetricsPrx metrics = MetricsPrxHelper.checkedCast(communicator.stringToProxy("metrics:default -p 12010")); boolean collocated = metrics.ice_getConnection() == null; + int threadCount = 3; + if(collocated && communicator.getProperties().getPropertyAsInt("Ice.BackgroundIO") > 0) + { + threadCount = 5; + } + out.print("testing metrics admin facet checkedCast... "); out.flush(); Ice.ObjectPrx admin = communicator.getAdmin(); @@ -449,7 +461,8 @@ public class AllTests test(view.get("Connection").length == 1 && view.get("Connection")[0].current == 1 && view.get("Connection")[0].total == 1); } - test(view.get("Thread").length == 1 && view.get("Thread")[0].current == 3 && view.get("Thread")[0].total == 3); + test(view.get("Thread").length == 1 && view.get("Thread")[0].current == threadCount && + view.get("Thread")[0].total == threadCount); out.println("ok"); out.print("testing group by id..."); @@ -465,7 +478,7 @@ public class AllTests metrics.ice_connectionId("Con1").ice_ping(); view = clientMetrics.getMetricsView("View", timestamp); - test(view.get("Thread").length == 3); + test(view.get("Thread").length == threadCount); if(!collocated) { test(view.get("Connection").length == 2); @@ -711,17 +724,20 @@ public class AllTests checkFailure(clientMetrics, "ConnectionEstablishment", m1.id, "Ice::ConnectTimeoutException", 2, out); Connect c = new Connect(metrics); - testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "parent", "Communicator", c, out); - testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "id", "127.0.0.1:12010", c, out); + testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "parent", "Communicator", c, + out); + testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "id", "127.0.0.1:12010", c, + out); testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "endpoint", "tcp -h 127.0.0.1 -p 12010 -t 60000", c, out); testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "endpointType", "1", c, out); - testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "endpointIsDatagram", "false", c, - out); + testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "endpointIsDatagram", "false", + c, out); testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "endpointIsSecure", "false", c, out); - testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "endpointTimeout", "60000", c, out); + testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "endpointTimeout", "60000", c, + out); testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "endpointCompress", "false", c, out); testAttribute(clientMetrics, clientProps, update, "ConnectionEstablishment", "endpointHost", "127.0.0.1", c, @@ -921,6 +937,9 @@ public class AllTests Callback cb = new Callback(); + // + // Twoway tests + // metrics.op(); metrics.end_op(metrics.begin_op()); metrics.begin_op(cb); @@ -1096,6 +1115,54 @@ public class AllTests testAttribute(clientMetrics, clientProps, update, "Invocation", "context.entry2", "", op, out); testAttribute(clientMetrics, clientProps, update, "Invocation", "context.entry3", "", op, out); + // + // Oneway tests + // + clearView(clientProps, serverProps, update); + props.put("IceMX.Metrics.View.Map.Invocation.GroupBy", "operation"); + props.put("IceMX.Metrics.View.Map.Invocation.Map.Remote.GroupBy", "localPort"); + updateProps(clientProps, serverProps, update, props, "Invocation"); + + MetricsPrx metricsOneway = (MetricsPrx)metrics.ice_oneway(); + metricsOneway.op(); + metricsOneway.end_op(metricsOneway.begin_op()); + metricsOneway.begin_op(cb).waitForSent(); + + map = toMap(clientMetrics.getMetricsView("View", timestamp).get("Invocation")); + test(map.size() == 1); + + im1 = (IceMX.InvocationMetrics)map.get("op"); + test(im1.current <= 1 && im1.total == 3 && im1.failures == 0 && im1.retry == 0); + test(!collocated ? (im1.remotes.length == 1) : (im1.collocated.length == 1)); + rim1 = (IceMX.ChildInvocationMetrics)(!collocated ? im1.remotes[0] : im1.collocated[0]); + test(rim1.current <= 1 && rim1.total == 3 && rim1.failures == 0); + test(rim1.size == 63 && rim1.replySize == 0); + + testAttribute(clientMetrics, clientProps, update, "Invocation", "mode", "oneway", new InvokeOp(metricsOneway), + out); + + // + // Batch oneway tests + // + props.put("IceMX.Metrics.View.Map.Invocation.GroupBy", "operation"); + props.put("IceMX.Metrics.View.Map.Invocation.Map.Remote.GroupBy", "localPort"); + updateProps(clientProps, serverProps, update, props, "Invocation"); + + MetricsPrx metricsBatchOneway = (MetricsPrx)metrics.ice_batchOneway(); + metricsBatchOneway.op(); + metricsBatchOneway.end_op(metricsBatchOneway.begin_op()); + //metricsBatchOneway.begin_op(cb).waitForSent(); + + map = toMap(clientMetrics.getMetricsView("View", timestamp).get("Invocation")); + test(map.size() == 1); + + im1 = (IceMX.InvocationMetrics)map.get("op"); + test(im1.current == 0 && im1.total == 2 && im1.failures == 0 && im1.retry == 0); + test(im1.remotes.length == 0); + + testAttribute(clientMetrics, clientProps, update, "Invocation", "mode", "batch-oneway", + new InvokeOp(metricsBatchOneway), out); + out.println("ok"); out.print("testing metrics view enable/disable..."); diff --git a/java/test/Ice/metrics/Collocated.java b/java/test/Ice/metrics/Collocated.java index 69a8896e1b5..6fbfa9f4154 100644 --- a/java/test/Ice/metrics/Collocated.java +++ b/java/test/Ice/metrics/Collocated.java @@ -46,6 +46,13 @@ public class Collocated extends test.Util.Application { Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = Ice.Util.createProperties(argsH); + if(initData.properties.getPropertyAsInt("Ice.BackgroundIO") > 0) + { + // With background IO, collocated invocations are + // dispatched on the server thread pool. This test needs + // at least 3 threads in the server thread pool to work. + initData.properties.setProperty("Ice.ThreadPool.Server.Size", "3"); + } initData.properties.setProperty("Ice.Package.Test", "test.Ice.metrics"); initData.properties.setProperty("Ice.Admin.Endpoints", "tcp"); initData.properties.setProperty("Ice.Admin.InstanceName", "client"); diff --git a/java/test/Ice/operations/AllTests.java b/java/test/Ice/operations/AllTests.java index a22474bbfd6..63866c9e4c0 100644 --- a/java/test/Ice/operations/AllTests.java +++ b/java/test/Ice/operations/AllTests.java @@ -128,6 +128,11 @@ public class AllTests BatchOneways.batchOneways(derived, out); out.println("ok"); + out.print("testing batch AMI oneway operations... "); + out.flush(); + BatchOnewaysAMI.batchOneways(cl, out); + BatchOnewaysAMI.batchOneways(derived, out); + out.println("ok"); return cl; } } diff --git a/java/test/Ice/operations/BatchOneways.java b/java/test/Ice/operations/BatchOneways.java index 8415f3d6ece..fc20955e9d2 100644 --- a/java/test/Ice/operations/BatchOneways.java +++ b/java/test/Ice/operations/BatchOneways.java @@ -61,7 +61,6 @@ class BatchOneways MyClassPrx batch = MyClassPrxHelper.uncheckedCast(p.ice_batchOneway()); batch.ice_flushBatchRequests(); - batch.end_ice_flushBatchRequests(batch.begin_ice_flushBatchRequests()); for(int i = 0 ; i < 30 ; ++i) { diff --git a/java/test/Ice/operations/BatchOnewaysAMI.java b/java/test/Ice/operations/BatchOnewaysAMI.java new file mode 100644 index 00000000000..f11df72b019 --- /dev/null +++ b/java/test/Ice/operations/BatchOnewaysAMI.java @@ -0,0 +1,208 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2014 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.operations; + +import java.io.PrintWriter; + +import Ice.LocalException; +import test.Ice.operations.Test.Callback_MyClass_opByteSOneway; +import test.Ice.operations.Test.MyClassPrx; +import test.Ice.operations.Test.MyClassPrxHelper; + +class BatchOnewaysAMI +{ + private static class Callback + { + Callback() + { + _called = false; + } + + public synchronized void check() + { + while(!_called) + { + try + { + wait(); + } + catch(InterruptedException ex) + { + } + } + + _called = false; + } + + public synchronized void called() + { + assert (!_called); + _called = true; + notify(); + } + + private boolean _called; + } + + private static void test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + static void batchOneways(MyClassPrx p, PrintWriter out) + { + final byte[] bs1 = new byte[10 * 1024]; + final byte[] bs2 = new byte[99 * 1024]; + final byte[] bs3 = new byte[100 * 1024]; + + final Callback cb = new Callback(); + p.begin_opByteSOneway(bs1, new Callback_MyClass_opByteSOneway() + { + @Override + public void exception(LocalException ex) + { + test(false); + } + + @Override + public void response() + { + cb.called(); + } + }); + cb.check(); + p.begin_opByteSOneway(bs2, new Callback_MyClass_opByteSOneway() + { + @Override + public void exception(LocalException ex) + { + test(false); + } + + @Override + public void response() + { + cb.called(); + } + }); + cb.check(); + + p.begin_opByteSOneway(bs3, new Callback_MyClass_opByteSOneway() + { + @Override + public void exception(LocalException ex) + { + test(ex instanceof Ice.MemoryLimitException); + cb.called(); + } + + @Override + public void response() + { + test(false); + } + }); + cb.check(); + + MyClassPrx batch = MyClassPrxHelper.uncheckedCast(p.ice_batchOneway()); + batch.end_ice_flushBatchRequests(batch.begin_ice_flushBatchRequests()); + + for(int i = 0; i < 30; ++i) + { + batch.begin_opByteSOneway(bs1, new Callback_MyClass_opByteSOneway() + { + @Override + public void exception(LocalException ex) + { + test(false); + } + + @Override + public void response() + { + } + }); + } + + if(batch.ice_getConnection() != null) + { + batch.ice_getConnection().end_flushBatchRequests(batch.ice_getConnection().begin_flushBatchRequests()); + + MyClassPrx batch2 = MyClassPrxHelper.uncheckedCast(p.ice_batchOneway()); + + batch.begin_ice_ping(); + batch2.begin_ice_ping(); + batch.end_ice_flushBatchRequests(batch.begin_ice_flushBatchRequests()); + batch.ice_getConnection().close(false); + batch.begin_ice_ping(); + batch2.begin_ice_ping(); + + batch.ice_getConnection(); + batch2.ice_getConnection(); + + batch.begin_ice_ping(); + batch.ice_getConnection().close(false); + batch.begin_ice_ping(new Ice.Callback_Object_ice_ping() + { + + @Override + public void response() + { + test(false); + } + + @Override + public void exception(LocalException ex) + { + test(ex instanceof Ice.CloseConnectionException); + cb.called(); + } + + }); + cb.check(); + batch2.begin_ice_ping(new Ice.Callback_Object_ice_ping() + { + + @Override + public void response() + { + test(false); + } + + @Override + public void exception(LocalException ex) + { + test(ex instanceof Ice.CloseConnectionException); + cb.called(); + } + + }); + cb.check(); + batch.begin_ice_ping(); + batch2.begin_ice_ping(); + } + + Ice.Identity identity = new Ice.Identity(); + identity.name = "invalid"; + Ice.ObjectPrx batch3 = batch.ice_identity(identity); + batch3.begin_ice_ping(); + batch3.end_ice_flushBatchRequests(batch3.begin_ice_flushBatchRequests()); + + // Make sure that a bogus batch request doesn't cause troubles to other + // ones. + batch3.begin_ice_ping(); + batch.begin_ice_ping(); + batch.end_ice_flushBatchRequests(batch.begin_ice_flushBatchRequests()); + batch.begin_ice_ping(); + } +} diff --git a/java/test/Ice/operations/Collocated.java b/java/test/Ice/operations/Collocated.java index c34d07d5f11..278e81a9b65 100644 --- a/java/test/Ice/operations/Collocated.java +++ b/java/test/Ice/operations/Collocated.java @@ -35,6 +35,10 @@ public class Collocated extends test.Util.Application { Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = Ice.Util.createProperties(argsH); + if(initData.properties.getPropertyAsInt("Ice.BackgroundIO") > 0) + { + initData.properties.setProperty("Ice.ThreadPool.Server.Size", "2"); + } initData.properties.setProperty("Ice.Package.Test", "test.Ice.operations"); // |