Skip to content

Commit

Permalink
Test collocated invocations with normalized IPv6 addresses (#3436)
Browse files Browse the repository at this point in the history
Fix #3154
  • Loading branch information
pepone authored Jan 28, 2025
1 parent 78506e7 commit c8e6761
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
32 changes: 31 additions & 1 deletion cpp/test/Ice/operations/Collocated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "TestHelper.h"
#include "TestI.h"

#include <iostream>

using namespace std;

class Collocated : public Test::TestHelper
Expand All @@ -12,14 +14,40 @@ 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<MyDerivedClassI>(), 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)
{
Ice::PropertiesPtr properties = createTestProperties(argc, 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<MyDerivedClassI>(), Ice::stringToIdentity("test"));
// adapter->activate(); // Don't activate OA to ensure collocation is used.
Expand All @@ -28,6 +56,8 @@ Collocated::run(int argc, char** argv)

Test::MyClassPrx allTests(Test::TestHelper*);
allTests(this);

testCollocatedIPv6Invocation(this);
}

DEFINE_TEST(Collocated)
24 changes: 23 additions & 1 deletion csharp/test/Ice/operations/Collocated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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<int> Main(string[] args) =>
Expand Down
27 changes: 27 additions & 0 deletions java/test/src/main/java/test/Ice/operations/Collocated.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
}
}

0 comments on commit c8e6761

Please sign in to comment.