zkcpp: added test showing that zkcpp blocks calls forever after session expiration. [#METR-10202]

This commit is contained in:
Michael Kolupaev 2014-04-22 14:46:38 +04:00 committed by Sergey Magidovich
parent 112ca9720b
commit d9f3ec0df8
3 changed files with 44 additions and 7 deletions

View File

@ -26,7 +26,7 @@ typedef std::shared_ptr<boost::ptr_vector<OpResult> > OpResultsPtr;
typedef std::vector<std::string> Strings; typedef std::vector<std::string> Strings;
typedef boost::function<void (WatchEvent::type event, SessionState::type state, typedef boost::function<void (WatchEvent::type event, SessionState::type state,
const std::string & path)> WatchFunction; const std::string & path)> WatchFunction;
struct WatchEventInfo struct WatchEventInfo
{ {

View File

@ -0,0 +1,43 @@
#include <zookeeper/zookeeper.hh>
namespace zk = org::apache::zookeeper;
void stateChanged(zk::WatchEvent::type event, zk::SessionState::type state, const std::string & path)
{
std::cout << "state changed; event: " << zk::WatchEvent::toString(event) << ", state: " << zk::SessionState::toString(state)
<< ", path: " << path << std::endl;
}
int main()
{
zk::ZooKeeper zookeeper;
zookeeper.init("example1:2181,example2:2181,example3:2181", 5000, nullptr);
std::vector<std::string> children;
zk::data::Stat stat;
zk::ReturnCode::type ret = zookeeper.getChildren("/", nullptr, children, stat);
std::cout << "getChildren returned " << zk::ReturnCode::toString(ret) << std::endl;
std::cout << "children of /:" << std::endl;
for (const auto & s : children)
{
std::cout << s << std::endl;
}
std::cout << "break connection to example1:2181,example2:2181,example3:2181 for at least 5 seconds and enter something" << std::endl;
std::string unused;
std::cin >> unused;
children.clear();
std::cout << "will getChildren" << std::endl;
ret = zookeeper.getChildren("/", nullptr, children, stat);
std::cout << "getChildren returned " << zk::ReturnCode::toString(ret) << std::endl;
std::cout << "children of /:" << std::endl;
for (const auto & s : children)
{
std::cout << s << std::endl;
}
return 0;
}

View File

@ -48,12 +48,6 @@ int main(int argc, char ** argv)
while (char * line = readline(":3 ")) while (char * line = readline(":3 "))
{ {
if (zk.disconnected())
{
std::cerr << "Disconnected" << std::endl;
break;
}
try try
{ {
std::stringstream ss(line); std::stringstream ss(line);