Skip to content

Commit

Permalink
More bi-dir testing (#2911)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Oct 17, 2024
1 parent 32594ec commit 9a6db1d
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 65 deletions.
8 changes: 5 additions & 3 deletions cpp/test/Ice/ami/AllTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1279,11 +1279,13 @@ allTests(TestHelper* helper, bool collocated)
}
cout << "ok" << endl;

cout << "testing bidir... " << flush;
cout << "testing bi-dir... " << flush;
auto adapter = communicator->createObjectAdapter("");
auto replyI = make_shared<PingReplyI>();
auto reply = uncheckedCast<PingReplyPrx>(adapter->addWithUUID(replyI));
adapter->activate();
auto reply = adapter->addWithUUID<PingReplyPrx>(replyI);

map<string, string> context{{"ONE", ""}};
p->pingBiDir(reply, context);

p->ice_getConnection()->setAdapter(adapter);
p->pingBiDir(reply);
Expand Down
2 changes: 1 addition & 1 deletion cpp/test/Ice/ami/Test.ice
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface TestIntf
bool supportsAMD();
bool supportsFunctionalTests();

void pingBiDir(PingReply* reply);
["amd"] void pingBiDir(PingReply* reply);
}

interface TestIntfController
Expand Down
42 changes: 39 additions & 3 deletions cpp/test/Ice/ami/TestI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,45 @@ TestIntfI::supportsFunctionalTests(const Ice::Current&)
}

void
TestIntfI::pingBiDir(optional<Test::PingReplyPrx> reply, const Ice::Current& current)
{
reply->ice_fixed(current.con)->replyAsync().get();
TestIntfI::pingBiDirAsync(
optional<Test::PingReplyPrx> reply,
std::function<void()> response,
std::function<void(std::exception_ptr)> exception,
const Ice::Current& current)
{
reply = reply->ice_fixed(current.con);
const bool expectSuccess = current.ctx.find("ONE") == current.ctx.end();

reply->ice_fixed(current.con)
->replyAsync(
[expectSuccess, response, exception]()
{
try
{
test(expectSuccess);
response();
}
catch (...)
{
exception(std::current_exception());
}
},
[expectSuccess, response, exception](exception_ptr ex)
{
try
{
test(!expectSuccess);
rethrow_exception(ex);
}
catch (const Ice::ObjectNotExistException&)
{
response();
}
catch (...)
{
exception(std::current_exception());
}
});
}

void
Expand Down
6 changes: 5 additions & 1 deletion cpp/test/Ice/ami/TestI.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ class TestIntfI final : public Test::TestIntf
bool supportsAMD(const Ice::Current&) final;
bool supportsFunctionalTests(const Ice::Current&) final;

void pingBiDir(std::optional<Test::PingReplyPrx>, const Ice::Current&) final;
void pingBiDirAsync(
std::optional<Test::PingReplyPrx>,
std::function<void()>,
std::function<void(std::exception_ptr)>,
const Ice::Current&) final;

private:
int _batchCount;
Expand Down
29 changes: 17 additions & 12 deletions csharp/test/Ice/ami/AllTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -865,21 +865,26 @@ public static async Task allTestsAsync(global::Test.TestHelper helper, bool coll
s2.SetResult(1);
Task.WaitAll(t1, t2, t3, t4);
}

if (!collocated)
{
ObjectAdapter adapter = communicator.createObjectAdapter("");
var replyI = new PingReplyI();
var reply = Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI));

p.ice_getConnection().setAdapter(adapter);
p.pingBiDir(reply);
test(replyI.checkReceived());
adapter.destroy();
}
}
output.WriteLine("ok");

if (!collocated)
{
output.Write("testing bi-dir... ");
ObjectAdapter adapter = communicator.createObjectAdapter("");
var replyI = new PingReplyI();
var reply = Test.PingReplyPrxHelper.uncheckedCast(adapter.addWithUUID(replyI));

var context = new Dictionary<string, string> { ["ONE"] = "" };
await p.pingBiDirAsync(reply, context);

p.ice_getConnection().setAdapter(adapter);
await p.pingBiDirAsync(reply);
test(replyI.checkReceived());
adapter.destroy();
output.WriteLine("ok");
}

output.Write("testing result struct... ");
output.Flush();
{
Expand Down
2 changes: 1 addition & 1 deletion csharp/test/Ice/ami/Test.ice
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interface TestIntf
["amd"] void opWithUEAsyncDispatch()
throws TestIntfException;

void pingBiDir(PingReply* reply);
["amd"] void pingBiDir(PingReply* reply);
}

interface TestIntfController
Expand Down
23 changes: 12 additions & 11 deletions csharp/test/Ice/ami/TestI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,20 @@ public override async Task
await self(current).opWithUEAsync();
}

public override void
pingBiDir(Test.PingReplyPrx reply, Ice.Current current)
public override async Task pingBiDirAsync(Test.PingReplyPrx reply, Ice.Current current)
{
reply = Test.PingReplyPrxHelper.uncheckedCast(reply.ice_fixed(current.con));
Thread dispatchThread = Thread.CurrentThread;
reply.replyAsync().ContinueWith(
(t) =>
{
Thread callbackThread = Thread.CurrentThread;
test(dispatchThread != callbackThread);
test(callbackThread.Name.Contains("Ice.ThreadPool.Server"));
},
reply.ice_scheduler()).Wait();
bool expectSuccess = !current.ctx.ContainsKey("ONE");

try
{
await reply.replyAsync();
test(expectSuccess);
}
catch (ObjectNotExistException)
{
test(!expectSuccess);
}
}

private Test.TestIntfPrx
Expand Down
28 changes: 16 additions & 12 deletions java/test/src/main/java/test/Ice/ami/AllTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -1043,21 +1043,25 @@ public static void allTests(test.TestHelper helper, boolean collocated) {
},
p.ice_executor())
.join();

if (!collocated) {
com.zeroc.Ice.ObjectAdapter adapter = communicator.createObjectAdapter("");
PingReplyI replyI = new PingReplyI();
PingReplyPrx reply = PingReplyPrx.uncheckedCast(adapter.addWithUUID(replyI));
adapter.activate();

p.ice_getConnection().setAdapter(adapter);
p.pingBiDir(reply);
test(replyI.checkReceived());
adapter.destroy();
}
}
out.println("ok");

if (!collocated) {
out.print("testing bi-dir... ");
com.zeroc.Ice.ObjectAdapter adapter = communicator.createObjectAdapter("");
PingReplyI replyI = new PingReplyI();
PingReplyPrx reply = PingReplyPrx.uncheckedCast(adapter.addWithUUID(replyI));

var context = java.util.Map.of("ONE", "");
p.pingBiDir(reply, context);

p.ice_getConnection().setAdapter(adapter);
p.pingBiDir(reply);
test(replyI.checkReceived());
adapter.destroy();
out.println("ok");
}

out.print("testing result struct... ");
out.flush();
{
Expand Down
2 changes: 1 addition & 1 deletion java/test/src/main/java/test/Ice/ami/Test.ice
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interface TestIntf
float opFloat(float f);
double opDouble(double d);

void pingBiDir(PingReply* reply);
["amd"] void pingBiDir(PingReply* reply);
}

interface TestIntfController
Expand Down
23 changes: 12 additions & 11 deletions java/test/src/main/java/test/Ice/ami/TestI.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,19 @@ public double opDouble(double d, com.zeroc.Ice.Current current) {
}

@Override
public void pingBiDir(PingReplyPrx reply, com.zeroc.Ice.Current current) {
public CompletionStage<Void> pingBiDirAsync(PingReplyPrx reply, com.zeroc.Ice.Current current) {
reply = reply.ice_fixed(current.con);
final Thread dispatchThread = Thread.currentThread();
reply.replyAsync()
.whenCompleteAsync(
(result, ex) -> {
Thread callbackThread = Thread.currentThread();
test(callbackThread != dispatchThread);
test(callbackThread.getName().indexOf("Ice.ThreadPool.Server") != -1);
},
reply.ice_executor())
.join();
boolean expectSuccess = !current.ctx.containsKey("ONE");
return reply.replyAsync()
.handle(
(r, ex) -> {
if (expectSuccess) {
test(ex == null);
} else {
test(ex instanceof com.zeroc.Ice.ObjectNotExistException);
}
return null; // means success
});
}

@Override
Expand Down
6 changes: 4 additions & 2 deletions python/test/Ice/ami/AllTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,12 +629,14 @@ def allTestsFuture(helper, communicator, collocated):
print("ok")

if not collocated:
sys.stdout.write("testing bidir invocation... ")
sys.stdout.write("testing bi-dir... ")
sys.stdout.flush()
adapter = communicator.createObjectAdapter("")
replyI = PingReplyI()
reply = Test.PingReplyPrx.uncheckedCast(adapter.addWithUUID(replyI))
adapter.activate()

context = { "ONE": "" }
p.pingBiDir(reply, context)

p.ice_getConnection().setAdapter(adapter)
p.pingBiDir(reply)
Expand Down
2 changes: 1 addition & 1 deletion python/test/Ice/ami/Test.ice
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ interface TestIntf
bool supportsAMD();
bool supportsFunctionalTests();

void pingBiDir(PingReply* reply);
["amd"] void pingBiDir(PingReply* reply);
}

interface TestIntfController
Expand Down
13 changes: 9 additions & 4 deletions python/test/Ice/ami/TestI.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ def supportsAMD(self, current):
def supportsFunctionalTests(self, current):
return False

def pingBiDir(self, reply, current):
# TODO: verify correct thread with add_done_callback_async
reply.ice_fixed(current.con).replyAsync().result()

async def pingBiDir(self, reply, current):
expectSuccess = "ONE" not in current.ctx
try:
await reply.ice_fixed(current.con).replyAsync()
if not expectSuccess:
raise Test.TestIntfException()
except Ice.ObjectNotExistException:
if expectSuccess:
raise Test.TestIntfException()

class TestIntfII(Test.Outer.Inner.TestIntf):
def op(self, i, current):
Expand Down
28 changes: 28 additions & 0 deletions swift/test/Ice/ami/AllTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,22 @@ func allTests(_ helper: TestHelper, collocated: Bool = false) async throws {

output.writeLine("ok")

if (!collocated) {
output.write("testing bi-dir... ");
let adapter = try communicator.createObjectAdapter("")
let replyI = PingReplyI()
let reply = try uncheckedCast(prx: adapter.addWithUUID(PingReplyDisp(replyI)), type: PingReplyPrx.self)

let context: [String: String] = ["ONE": ""]
try await p.pingBiDir(reply, context: context);

try await p.ice_getConnection()!.setAdapter(adapter)
try await p.pingBiDir(reply);
try test(replyI.checkReceived())
adapter.destroy()
output.writeLine("ok")
}

output.write("testing connection abort... ")
do {
//
Expand Down Expand Up @@ -351,3 +367,15 @@ func allTests(_ helper: TestHelper, collocated: Bool = false) async throws {
}
try await p.shutdown()
}

class PingReplyI: PingReply {
private var _received = false

func checkReceived() -> Bool {
return _received
}

func reply(current: Ice.Current) throws {
_received = true
}
}
12 changes: 10 additions & 2 deletions swift/test/Ice/ami/TestI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,16 @@ class TestI: TestIntf {
}

func pingBiDir(reply: PingReplyPrx?, current: Current) async throws {
if let reply = reply {
try await reply.ice_fixed(current.con!).reply()
let expectSuccess = !current.ctx.keys.contains("ONE")
do {
try await reply!.ice_fixed(current.con!).reply()
if !expectSuccess {
throw TestIntfException()
}
} catch is ObjectNotExistException {
if expectSuccess {
throw TestIntfException()
}
}
}

Expand Down

0 comments on commit 9a6db1d

Please sign in to comment.