-
Notifications
You must be signed in to change notification settings - Fork 592
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Install middleware in ObjectAdapter (C++) (#2283)
- Loading branch information
1 parent
3145575
commit 674707b
Showing
16 changed files
with
491 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright (c) ZeroC, Inc. | ||
|
||
#include "TestHelper.h" | ||
#include "TestI.h" | ||
|
||
using namespace std; | ||
using namespace Test; | ||
|
||
class Middleware final : public Ice::Object | ||
{ | ||
public: | ||
Middleware(Ice::ObjectPtr next, string name, list<string>& inLog, list<string>& outLog) | ||
: _next(std::move(next)), | ||
_name(std::move(name)), | ||
_inLog(inLog), | ||
_outLog(outLog) | ||
{ | ||
} | ||
|
||
void dispatch(Ice::IncomingRequest& request, std::function<void(Ice::OutgoingResponse)> sendResponse) final | ||
{ | ||
_inLog.push_back(_name); | ||
|
||
_next->dispatch( | ||
request, | ||
[this, sendResponse = std::move(sendResponse)](Ice::OutgoingResponse response) | ||
{ | ||
_outLog.push_back(_name); | ||
sendResponse(std::move(response)); | ||
}); | ||
} | ||
|
||
private: | ||
Ice::ObjectPtr _next; | ||
string _name; | ||
list<string>& _inLog; | ||
list<string>& _outLog; | ||
}; | ||
|
||
void | ||
testMiddlewareExecutionOrder(const Ice::CommunicatorPtr& communicator) | ||
{ | ||
cout << "testing middleware execution order... " << flush; | ||
|
||
// Arrange | ||
list<string> inLog; | ||
list<string> outLog; | ||
|
||
Ice::ObjectAdapterPtr oa = communicator->createObjectAdapter(""); | ||
oa->add(make_shared<MyObjectI>(), Ice::Identity{"test", ""}); | ||
|
||
oa->use([&](Ice::ObjectPtr next) { return make_shared<Middleware>(std::move(next), "A", inLog, outLog); }) | ||
->use([&](Ice::ObjectPtr next) { return make_shared<Middleware>(std::move(next), "B", inLog, outLog); }) | ||
->use([&](Ice::ObjectPtr next) { return make_shared<Middleware>(std::move(next), "C", inLog, outLog); }); | ||
|
||
MyObjectPrx p(communicator, "test"); | ||
|
||
// Act | ||
p->ice_ping(); | ||
|
||
// Assert | ||
bool inOk = inLog == list<string>{"A", "B", "C"}; | ||
test(inOk); | ||
bool outOk = outLog == list<string>{"C", "B", "A"}; | ||
test(outOk); | ||
|
||
cout << "ok" << endl; | ||
} | ||
|
||
void | ||
allTests(Test::TestHelper* helper) | ||
{ | ||
Ice::CommunicatorPtr communicator = helper->communicator(); | ||
testMiddlewareExecutionOrder(communicator); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) ZeroC, Inc. | ||
|
||
#include "Test.h" | ||
#include "TestHelper.h" | ||
|
||
using namespace std; | ||
using namespace Test; | ||
|
||
class Client : public Test::TestHelper | ||
{ | ||
public: | ||
void run(int, char**); | ||
}; | ||
|
||
void | ||
Client::run(int argc, char** argv) | ||
{ | ||
Ice::CommunicatorHolder communicator = initialize(argc, argv); | ||
void allTests(Test::TestHelper*); | ||
allTests(this); | ||
} | ||
|
||
DEFINE_TEST(Client) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# | ||
# Copyright (c) ZeroC, Inc. All rights reserved. | ||
# | ||
|
||
$(test)_client_sources = Client.cpp AllTests.cpp Test.ice TestI.cpp | ||
|
||
tests += $(test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) ZeroC, Inc. | ||
|
||
#pragma once | ||
|
||
module Test | ||
{ | ||
interface MyObject | ||
{ | ||
string getName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) ZeroC, Inc. | ||
|
||
#include "TestI.h" | ||
|
||
using namespace std; | ||
|
||
string | ||
MyObjectI::getName(const Ice::Current&) | ||
{ | ||
return "Foo"; | ||
} |
Oops, something went wrong.