diff --git a/cpp/test/Ice/operations/Collocated.cpp b/cpp/test/Ice/operations/Collocated.cpp index a582af27dcb..1bc7df25770 100644 --- a/cpp/test/Ice/operations/Collocated.cpp +++ b/cpp/test/Ice/operations/Collocated.cpp @@ -4,6 +4,8 @@ #include "TestHelper.h" #include "TestI.h" +#include + using namespace std; class Collocated : public Test::TestHelper @@ -12,6 +14,33 @@ class Collocated : public Test::TestHelper void run(int, char**) override; }; +namespace +{ + void testCollocatedIPv6Invocation(Test::TestHelper* helper) + { + int port = helper->getTestPort(1); + + string endpoint1 = "tcp -h \"::1\" -p " + to_string(port); + string endpoint2 = "tcp -h \"0:0:0:0:0:0:0:1\" -p " + to_string(port); + + cout << "testing collocated invocation with normalized IPv6 address... " << flush; + Ice::CommunicatorHolder communicator = Ice::initialize(); + communicator->getProperties()->setProperty("TestAdapter.Endpoints", endpoint1); + Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TestAdapter"); + adapter->add(std::make_shared(), Ice::stringToIdentity("test")); + // Don't activate OA to ensure collocation is used. + + auto prx = Ice::ObjectPrx{communicator.communicator(), "test:" + endpoint1}; + prx = prx->ice_invocationTimeout(10ms); + prx->ice_ping(); + + prx = Ice::ObjectPrx{communicator.communicator(), "test:" + endpoint2}; + prx = prx->ice_invocationTimeout(10ms); + prx->ice_ping(); + cout << "ok" << endl; + } +} + void Collocated::run(int argc, char** argv) { @@ -19,7 +48,6 @@ Collocated::run(int argc, char** argv) properties->setProperty("Ice.BatchAutoFlushSize", "100"); Ice::CommunicatorHolder communicator = initialize(argc, argv, properties); communicator->getProperties()->setProperty("TestAdapter.Endpoints", getTestEndpoint()); - communicator->getProperties()->setProperty("TestAdapter.AdapterId", "test"); Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("TestAdapter"); Ice::ObjectPrx prx = adapter->add(std::make_shared(), Ice::stringToIdentity("test")); // adapter->activate(); // Don't activate OA to ensure collocation is used. @@ -28,6 +56,8 @@ Collocated::run(int argc, char** argv) Test::MyClassPrx allTests(Test::TestHelper*); allTests(this); + + testCollocatedIPv6Invocation(this); } DEFINE_TEST(Collocated) diff --git a/csharp/test/Ice/operations/Collocated.cs b/csharp/test/Ice/operations/Collocated.cs index b804c836577..c6589c250d7 100644 --- a/csharp/test/Ice/operations/Collocated.cs +++ b/csharp/test/Ice/operations/Collocated.cs @@ -16,7 +16,6 @@ public override async Task runAsync(string[] args) initData.properties.setProperty("Ice.ThreadPool.Client.SizeWarn", "0"); initData.properties.setProperty("Ice.BatchAutoFlushSize", "100"); using var communicator = initialize(initData); - communicator.getProperties().setProperty("TestAdapter.AdapterId", "test"); communicator.getProperties().setProperty("TestAdapter.Endpoints", getTestEndpoint(0)); ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); ObjectPrx prx = adapter.add(new MyDerivedClassI(), Ice.Util.stringToIdentity("test")); @@ -28,6 +27,29 @@ public override async Task runAsync(string[] args) } await AllTests.allTests(this); + + testCollocatedIPv6Invocation(this); + } + + private static void testCollocatedIPv6Invocation(TestHelper helper) + { + TextWriter output = helper.getWriter(); + int port = helper.getTestPort(1); + output.Write("testing collocated invocation with normalized IPv6 address... "); + output.Flush(); + using var communicator = Ice.Util.initialize(); + communicator.getProperties().setProperty("TestAdapter.Endpoints", $"tcp -h \"0:0:0:0:0:0:0:1\" -p {port}"); + var adapter = communicator.createObjectAdapter("TestAdapter"); + adapter.add(new MyDerivedClassI(), Ice.Util.stringToIdentity("test")); + + var prx = Ice.ObjectPrxHelper.createProxy(communicator, $"test:tcp -h \"::1\" -p {port}"); + prx = prx.ice_invocationTimeout(TimeSpan.FromMilliseconds(10)); + prx.ice_ping(); + + prx = Ice.ObjectPrxHelper.createProxy(communicator, $"test:tcp -h \"0:0:0:0:0:0:0:1\" -p {port}"); + prx = prx.ice_invocationTimeout(TimeSpan.FromMilliseconds(10)); + prx.ice_ping(); + output.WriteLine(); } public static Task Main(string[] args) => diff --git a/java/test/src/main/java/test/Ice/operations/Collocated.java b/java/test/src/main/java/test/Ice/operations/Collocated.java index fda1f8f41f1..a1c34544fb9 100644 --- a/java/test/src/main/java/test/Ice/operations/Collocated.java +++ b/java/test/src/main/java/test/Ice/operations/Collocated.java @@ -2,8 +2,11 @@ package test.Ice.operations; +import com.zeroc.Ice.ObjectPrx; import com.zeroc.Ice.Util; +import java.io.PrintWriter; + public class Collocated extends test.TestHelper { public void run(String[] args) { com.zeroc.Ice.Properties properties = createTestProperties(args); @@ -27,6 +30,30 @@ public void run(String[] args) { throw new RuntimeException(); } AllTests.allTests(this); + testCollocatedIPv6Invocation(this); + } + } + + private static void testCollocatedIPv6Invocation(test.TestHelper helper) { + int port = helper.getTestPort(1); + PrintWriter output = helper.getWriter(); + output.print("testing collocated invocation with normalized IPv6 address... "); + output.flush(); + try (var communicator = com.zeroc.Ice.Util.initialize()) { + communicator + .getProperties() + .setProperty("TestAdapter.Endpoints", "tcp -h \"0:0:0:0:0:0:0:1\" -p " + port); + var adapter = communicator.createObjectAdapter("TestAdapter"); + adapter.add(new MyDerivedClassI(), com.zeroc.Ice.Util.stringToIdentity("test")); + + var prx = ObjectPrx.createProxy(communicator, "test:tcp -h \"::1\" -p " + port); + prx = prx.ice_invocationTimeout(10); + prx.ice_ping(); + + prx = ObjectPrx.createProxy(communicator, "test:tcp -h \"0:0:0:0:0:0:0:1\" -p " + port); + prx = prx.ice_invocationTimeout(10); + prx.ice_ping(); + output.println(); } } }