Skip to content
Snippets Groups Projects
Commit 25d4e402 authored by Claudio Bisegni's avatar Claudio Bisegni
Browse files

Merge branch 'feature/rpc_test' into experimental

parents 1b968334 69db4c36
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,7 @@
328CFCA41F7D4167002FEB25 /* QueuePriorityTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 328CFCA21F7D4167002FEB25 /* QueuePriorityTest.cpp */; };
329BF99A20AAFF1B0068F8EB /* DirectIOTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 329BF99820AAFF1B0068F8EB /* DirectIOTest.cpp */; };
32A735331F6C399E00008145 /* PropertyTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 32A735311F6C399E00008145 /* PropertyTest.cpp */; };
32B8223420F6776E002BBCBA /* RPCTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 32B8223220F6776E002BBCBA /* RPCTest.cpp */; };
32C180EF1FAB33CD00AFCC15 /* TestPlugin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 32C180EE1FAB33CD00AFCC15 /* TestPlugin.cpp */; };
32CBCB29205ECF11002FB95F /* ExternalUnitMulticlientTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 32CBCB28205ECF11002FB95F /* ExternalUnitMulticlientTest.cpp */; };
32DA77741F94AD6D00497349 /* TestVariant.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 32DA77731F94AD6D00497349 /* TestVariant.cpp */; };
......@@ -124,6 +125,8 @@
329BF99920AAFF1B0068F8EB /* DirectIOTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DirectIOTest.h; sourceTree = "<group>"; };
32A735311F6C399E00008145 /* PropertyTest.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PropertyTest.cpp; sourceTree = "<group>"; };
32A735321F6C399E00008145 /* PropertyTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PropertyTest.h; sourceTree = "<group>"; };
32B8223220F6776E002BBCBA /* RPCTest.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RPCTest.cpp; sourceTree = "<group>"; };
32B8223320F6776E002BBCBA /* RPCTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RPCTest.h; sourceTree = "<group>"; };
32C180EE1FAB33CD00AFCC15 /* TestPlugin.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TestPlugin.cpp; sourceTree = "<group>"; };
32C180F01FAB439300AFCC15 /* CMakeLists.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
32CBCB28205ECF11002FB95F /* ExternalUnitMulticlientTest.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ExternalUnitMulticlientTest.cpp; sourceTree = "<group>"; };
......@@ -218,6 +221,7 @@
children = (
32C180F01FAB439300AFCC15 /* CMakeLists.txt */,
32639FE81F6AAD990049089C /* main.cpp */,
32B8223120F6774D002BBCBA /* rpc */,
329BF99720AAFF020068F8EB /* direct_io */,
32F8425B20162B32004D582D /* utility */,
32C180EC1FAB33A800AFCC15 /* plugin */,
......@@ -324,6 +328,15 @@
path = direct_io;
sourceTree = "<group>";
};
32B8223120F6774D002BBCBA /* rpc */ = {
isa = PBXGroup;
children = (
32B8223220F6776E002BBCBA /* RPCTest.cpp */,
32B8223320F6776E002BBCBA /* RPCTest.h */,
);
path = rpc;
sourceTree = "<group>";
};
32C180EC1FAB33A800AFCC15 /* plugin */ = {
isa = PBXGroup;
children = (
......@@ -591,6 +604,7 @@
32818B451F828FDB004A409E /* TestBatchCommand.cpp in Sources */,
327A4D241F90CB3200DA800C /* ExternalUnitTest.cpp in Sources */,
32818B431F828FDB004A409E /* TestCommandExecutor.cpp in Sources */,
32B8223420F6776E002BBCBA /* RPCTest.cpp in Sources */,
32DA77781F94B0D300497349 /* ScriptTest.cpp in Sources */,
328CFCA41F7D4167002FEB25 /* QueuePriorityTest.cpp in Sources */,
32CBCB29205ECF11002FB95F /* ExternalUnitMulticlientTest.cpp in Sources */,
......
//
// RPCTest.cpp
// FrameworkTest
//
// Created by Claudio Bisegni on 11/07/2018.
// Copyright © 2018 bisegni. All rights reserved.
//
#include "RPCTest.h"
#include<chaos/common/global.h>
#include<chaos/common/chaos_constants.h>
#include<chaos/common/message/NodeMessageChannel.h>
using namespace chaos::common::data;
using namespace chaos::common::network;
using namespace chaos::common::message;
RpcHandler::RpcHandler() {
//register the action for the response
DeclareAction::addActionDescritionInstance<RpcHandler>(this,
&RpcHandler::actionWithResult,
"test_rpc",
"actionWithResult",
"actionWithResult");
DeclareAction::addActionDescritionInstance<RpcHandler>(this,
&RpcHandler::actionWithNoResult,
"test_rpc",
"actionWithNoResult",
"actionWithNoResult");
}
CDataWrapper *RpcHandler::actionWithResult(CDataWrapper *action_data, bool& detach) {
detach = true;
return action_data;
}
CDataWrapper *RpcHandler::actionWithNoResult(CDataWrapper *action_data, bool& detach) {
return NULL;
}
TEST_F(RPCTest, SendEcho) {
CDWUniquePtr pack(new CDataWrapper());
pack->addStringValue("echo", "value");
MessageChannel *msg_chnl = NetworkBroker::getInstance()->getRawMessageChannel();
ChaosUniquePtr<MessageRequestFuture> future = msg_chnl->sendRequestWithFuture("localhost:8888",
chaos::NodeDomainAndActionRPC::RPC_DOMAIN,
chaos::NodeDomainAndActionRPC::ACTION_ECHO_TEST,
pack.get());
ASSERT_TRUE(future->wait(1000000));
ASSERT_TRUE(future->getResult());
ASSERT_EQ(future->getResult()->getStringValue("echo").compare("value"), 0);
}
TEST_F(RPCTest, ActionResult) {
RpcHandler rpc_handler;
CDWUniquePtr pack(new CDataWrapper());
pack->addStringValue("echo", "value");
NetworkBroker::getInstance()->registerAction(&rpc_handler);
MessageChannel *msg_chnl = NetworkBroker::getInstance()->getRawMessageChannel();
ChaosUniquePtr<MessageRequestFuture> future = msg_chnl->sendRequestWithFuture("localhost:8888",
"test_rpc",
"actionWithResult",
pack.get());
ASSERT_TRUE(future->wait(1000000));
ASSERT_TRUE(future->getResult());
ASSERT_EQ(future->getResult()->getStringValue("echo").compare("value"), 0);
future = msg_chnl->sendRequestWithFuture("localhost:8888",
"test_rpc",
"actionWithNoResult",
pack.get());
ASSERT_TRUE(future->wait(1000000));
ASSERT_FALSE(future->getResult());
NetworkBroker::getInstance()->deregisterAction(&rpc_handler);
}
//
// RPCTest.hpp
// FrameworkTest
//
// Created by Claudio Bisegni on 11/07/2018.
// Copyright © 2018 bisegni. All rights reserved.
//
#ifndef RPCTest_hpp
#define RPCTest_hpp
#include <gtest/gtest.h>
#include <chaos/common/direct_io/DirectIO.h>
#include <chaos/common/network/NetworkBroker.h>
#include <chaos/common/configuration/GlobalConfiguration.h>
#include <chaos/common/utility/InetUtility.h>
#include <chaos/common/action/DeclareAction.h>
class RpcHandler:
public chaos::DeclareAction {
public:
RpcHandler();
protected:
chaos::common::data::CDataWrapper *actionWithResult(chaos::common::data::CDataWrapper *action_data, bool& detach);
chaos::common::data::CDataWrapper *actionWithNoResult(chaos::common::data::CDataWrapper *action_data, bool& detach);
};
class RPCTest:
public testing::Test {
public:
RPCTest(){}
~RPCTest(){}
void SetUp() {
chaos::GlobalConfiguration::getInstance()->preParseStartupParameters();
chaos::GlobalConfiguration::getInstance()->parseStartupParameters(0, NULL);
std::string local_ip = chaos::common::utility::InetUtility::scanForLocalNetworkAddress();
chaos::GlobalConfiguration::getInstance()->addLocalServerAddress(local_ip);
ASSERT_NO_THROW(chaos::common::utility::StartableService::initImplementation(chaos::common::network::NetworkBroker::getInstance(), NULL, "NetworkBroker", __PRETTY_FUNCTION__););
ASSERT_NO_THROW(chaos::common::utility::StartableService::startImplementation(chaos::common::network::NetworkBroker::getInstance(), "NetworkBroker", __PRETTY_FUNCTION__););
}
void TearDown() {
ASSERT_NO_THROW(chaos::common::utility::StartableService::stopImplementation(chaos::common::network::NetworkBroker::getInstance(), "NetworkBroker", __PRETTY_FUNCTION__););
ASSERT_NO_THROW(chaos::common::utility::StartableService::deinitImplementation(chaos::common::network::NetworkBroker::getInstance(), "NetworkBroker", __PRETTY_FUNCTION__););
}
};
#endif /* RPCTest_hpp */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment