From 783bad638168ee3e64505037c75fa2028ab71c00 Mon Sep 17 00:00:00 2001 From: Arnstein Ressem Date: Mon, 12 Sep 2016 16:26:41 +0200 Subject: In progress moving messagebus/test -> messagebus_test --- messagebus_test/src/tests/compile-cpp/.gitignore | 4 + .../src/tests/compile-cpp/CMakeLists.txt | 8 ++ messagebus_test/src/tests/compile-cpp/DESC | 2 + messagebus_test/src/tests/compile-cpp/FILES | 1 + .../src/tests/compile-cpp/compile-cpp.cpp | 16 +++ messagebus_test/src/tests/compile-java/.gitignore | 4 + .../src/tests/compile-java/CMakeLists.txt | 2 + messagebus_test/src/tests/compile-java/DESC | 2 + messagebus_test/src/tests/compile-java/FILES | 1 + .../src/tests/compile-java/TestCompile.java | 9 ++ .../src/tests/compile-java/compile-java_test.sh | 7 + messagebus_test/src/tests/error/.gitignore | 15 +++ messagebus_test/src/tests/error/CMakeLists.txt | 21 +++ messagebus_test/src/tests/error/DESC | 2 + messagebus_test/src/tests/error/FILES | 8 ++ messagebus_test/src/tests/error/JavaClient.java | 65 +++++++++ messagebus_test/src/tests/error/JavaServer.java | 47 +++++++ messagebus_test/src/tests/error/cpp-client.cpp | 75 +++++++++++ messagebus_test/src/tests/error/cpp-server.cpp | 73 +++++++++++ messagebus_test/src/tests/error/ctl.sh | 4 + messagebus_test/src/tests/error/error.cpp | 45 +++++++ messagebus_test/src/tests/error/error_test.sh | 7 + messagebus_test/src/tests/error/progdefs.sh | 3 + .../src/tests/error/routing-template.cfg | 11 ++ messagebus_test/src/tests/errorcodes/.gitignore | 7 + .../src/tests/errorcodes/CMakeLists.txt | 7 + messagebus_test/src/tests/errorcodes/DESC | 2 + .../src/tests/errorcodes/DumpCodes.java | 51 +++++++ messagebus_test/src/tests/errorcodes/FILES | 5 + messagebus_test/src/tests/errorcodes/dumpcodes.cpp | 70 ++++++++++ .../src/tests/errorcodes/errorcodes_test.sh | 10 ++ messagebus_test/src/tests/errorcodes/ref-dump.txt | 34 +++++ messagebus_test/src/tests/speed/.gitignore | 15 +++ messagebus_test/src/tests/speed/CMakeLists.txt | 17 +++ messagebus_test/src/tests/speed/DESC | 4 + messagebus_test/src/tests/speed/FILES | 8 ++ messagebus_test/src/tests/speed/JavaClient.java | 137 +++++++++++++++++++ messagebus_test/src/tests/speed/JavaServer.java | 54 ++++++++ messagebus_test/src/tests/speed/cpp-client.cpp | 146 +++++++++++++++++++++ messagebus_test/src/tests/speed/cpp-server.cpp | 77 +++++++++++ messagebus_test/src/tests/speed/ctl.sh | 4 + messagebus_test/src/tests/speed/progdefs.sh | 3 + .../src/tests/speed/routing-template.cfg | 11 ++ messagebus_test/src/tests/speed/speed.cpp | 51 +++++++ messagebus_test/src/tests/speed/speed_test.sh | 9 ++ messagebus_test/src/tests/trace/.gitignore | 12 ++ messagebus_test/src/tests/trace/CMakeLists.txt | 13 ++ messagebus_test/src/tests/trace/DESC | 1 + messagebus_test/src/tests/trace/FILES | 19 +++ messagebus_test/src/tests/trace/JavaServer.java | 97 ++++++++++++++ messagebus_test/src/tests/trace/cpp-server.cpp | 90 +++++++++++++ messagebus_test/src/tests/trace/ctl.sh | 4 + messagebus_test/src/tests/trace/progdefs.sh | 15 +++ messagebus_test/src/tests/trace/trace.cpp | 113 ++++++++++++++++ messagebus_test/src/tests/trace/trace_test.sh | 8 ++ 55 files changed, 1526 insertions(+) create mode 100644 messagebus_test/src/tests/compile-cpp/.gitignore create mode 100644 messagebus_test/src/tests/compile-cpp/CMakeLists.txt create mode 100644 messagebus_test/src/tests/compile-cpp/DESC create mode 100644 messagebus_test/src/tests/compile-cpp/FILES create mode 100644 messagebus_test/src/tests/compile-cpp/compile-cpp.cpp create mode 100644 messagebus_test/src/tests/compile-java/.gitignore create mode 100644 messagebus_test/src/tests/compile-java/CMakeLists.txt create mode 100644 messagebus_test/src/tests/compile-java/DESC create mode 100644 messagebus_test/src/tests/compile-java/FILES create mode 100644 messagebus_test/src/tests/compile-java/TestCompile.java create mode 100755 messagebus_test/src/tests/compile-java/compile-java_test.sh create mode 100644 messagebus_test/src/tests/error/.gitignore create mode 100644 messagebus_test/src/tests/error/CMakeLists.txt create mode 100644 messagebus_test/src/tests/error/DESC create mode 100644 messagebus_test/src/tests/error/FILES create mode 100644 messagebus_test/src/tests/error/JavaClient.java create mode 100644 messagebus_test/src/tests/error/JavaServer.java create mode 100644 messagebus_test/src/tests/error/cpp-client.cpp create mode 100644 messagebus_test/src/tests/error/cpp-server.cpp create mode 100755 messagebus_test/src/tests/error/ctl.sh create mode 100644 messagebus_test/src/tests/error/error.cpp create mode 100755 messagebus_test/src/tests/error/error_test.sh create mode 100644 messagebus_test/src/tests/error/progdefs.sh create mode 100644 messagebus_test/src/tests/error/routing-template.cfg create mode 100644 messagebus_test/src/tests/errorcodes/.gitignore create mode 100644 messagebus_test/src/tests/errorcodes/CMakeLists.txt create mode 100644 messagebus_test/src/tests/errorcodes/DESC create mode 100644 messagebus_test/src/tests/errorcodes/DumpCodes.java create mode 100644 messagebus_test/src/tests/errorcodes/FILES create mode 100644 messagebus_test/src/tests/errorcodes/dumpcodes.cpp create mode 100644 messagebus_test/src/tests/errorcodes/errorcodes_test.sh create mode 100644 messagebus_test/src/tests/errorcodes/ref-dump.txt create mode 100644 messagebus_test/src/tests/speed/.gitignore create mode 100644 messagebus_test/src/tests/speed/CMakeLists.txt create mode 100644 messagebus_test/src/tests/speed/DESC create mode 100644 messagebus_test/src/tests/speed/FILES create mode 100644 messagebus_test/src/tests/speed/JavaClient.java create mode 100644 messagebus_test/src/tests/speed/JavaServer.java create mode 100644 messagebus_test/src/tests/speed/cpp-client.cpp create mode 100644 messagebus_test/src/tests/speed/cpp-server.cpp create mode 100755 messagebus_test/src/tests/speed/ctl.sh create mode 100644 messagebus_test/src/tests/speed/progdefs.sh create mode 100644 messagebus_test/src/tests/speed/routing-template.cfg create mode 100644 messagebus_test/src/tests/speed/speed.cpp create mode 100644 messagebus_test/src/tests/speed/speed_test.sh create mode 100644 messagebus_test/src/tests/trace/.gitignore create mode 100644 messagebus_test/src/tests/trace/CMakeLists.txt create mode 100644 messagebus_test/src/tests/trace/DESC create mode 100644 messagebus_test/src/tests/trace/FILES create mode 100644 messagebus_test/src/tests/trace/JavaServer.java create mode 100644 messagebus_test/src/tests/trace/cpp-server.cpp create mode 100755 messagebus_test/src/tests/trace/ctl.sh create mode 100644 messagebus_test/src/tests/trace/progdefs.sh create mode 100644 messagebus_test/src/tests/trace/trace.cpp create mode 100644 messagebus_test/src/tests/trace/trace_test.sh (limited to 'messagebus_test/src/tests') diff --git a/messagebus_test/src/tests/compile-cpp/.gitignore b/messagebus_test/src/tests/compile-cpp/.gitignore new file mode 100644 index 00000000000..14e4fb37c45 --- /dev/null +++ b/messagebus_test/src/tests/compile-cpp/.gitignore @@ -0,0 +1,4 @@ +.depend +Makefile +compile-cpp_test +messagebus_test_compile-cpp_test_app diff --git a/messagebus_test/src/tests/compile-cpp/CMakeLists.txt b/messagebus_test/src/tests/compile-cpp/CMakeLists.txt new file mode 100644 index 00000000000..86e3d7388ab --- /dev/null +++ b/messagebus_test/src/tests/compile-cpp/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(messagebus_test_compile-cpp_test_app TEST + SOURCES + compile-cpp.cpp + DEPENDS + messagebus +) +vespa_add_test(NAME messagebus_test_compile-cpp_test_app NO_VALGRIND COMMAND messagebus_test_compile-cpp_test_app) diff --git a/messagebus_test/src/tests/compile-cpp/DESC b/messagebus_test/src/tests/compile-cpp/DESC new file mode 100644 index 00000000000..465d625ca9e --- /dev/null +++ b/messagebus_test/src/tests/compile-cpp/DESC @@ -0,0 +1,2 @@ +simple compilation test to check dependencies. + diff --git a/messagebus_test/src/tests/compile-cpp/FILES b/messagebus_test/src/tests/compile-cpp/FILES new file mode 100644 index 00000000000..956ce16a56e --- /dev/null +++ b/messagebus_test/src/tests/compile-cpp/FILES @@ -0,0 +1 @@ +compile-cpp.cpp diff --git a/messagebus_test/src/tests/compile-cpp/compile-cpp.cpp b/messagebus_test/src/tests/compile-cpp/compile-cpp.cpp new file mode 100644 index 00000000000..e15b57859b7 --- /dev/null +++ b/messagebus_test/src/tests/compile-cpp/compile-cpp.cpp @@ -0,0 +1,16 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include +#include +LOG_SETUP("compile-cpp_test"); +#include +#include + +TEST_SETUP(Test); + +int +Test::Main() +{ + TEST_INIT("compile-cpp_test"); + mbus::Route r; + TEST_DONE(); +} diff --git a/messagebus_test/src/tests/compile-java/.gitignore b/messagebus_test/src/tests/compile-java/.gitignore new file mode 100644 index 00000000000..d615ebbafe7 --- /dev/null +++ b/messagebus_test/src/tests/compile-java/.gitignore @@ -0,0 +1,4 @@ +*.class +.depend +Makefile +compile-java_test diff --git a/messagebus_test/src/tests/compile-java/CMakeLists.txt b/messagebus_test/src/tests/compile-java/CMakeLists.txt new file mode 100644 index 00000000000..f13175939f6 --- /dev/null +++ b/messagebus_test/src/tests/compile-java/CMakeLists.txt @@ -0,0 +1,2 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_test(NAME messagebus_test_compile-java_test NO_VALGRIND COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/compile-java_test.sh) diff --git a/messagebus_test/src/tests/compile-java/DESC b/messagebus_test/src/tests/compile-java/DESC new file mode 100644 index 00000000000..465d625ca9e --- /dev/null +++ b/messagebus_test/src/tests/compile-java/DESC @@ -0,0 +1,2 @@ +simple compilation test to check dependencies. + diff --git a/messagebus_test/src/tests/compile-java/FILES b/messagebus_test/src/tests/compile-java/FILES new file mode 100644 index 00000000000..5b154bb1605 --- /dev/null +++ b/messagebus_test/src/tests/compile-java/FILES @@ -0,0 +1 @@ +TestCompile.java diff --git a/messagebus_test/src/tests/compile-java/TestCompile.java b/messagebus_test/src/tests/compile-java/TestCompile.java new file mode 100644 index 00000000000..443ae093794 --- /dev/null +++ b/messagebus_test/src/tests/compile-java/TestCompile.java @@ -0,0 +1,9 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +import com.yahoo.messagebus.EmptyReply; + +public class TestCompile { + public static void main(String[] args) { + EmptyReply er = new EmptyReply(); + } +} diff --git a/messagebus_test/src/tests/compile-java/compile-java_test.sh b/messagebus_test/src/tests/compile-java/compile-java_test.sh new file mode 100755 index 00000000000..9b94ffd51a1 --- /dev/null +++ b/messagebus_test/src/tests/compile-java/compile-java_test.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -e +. ../../binref/env.sh + +$BINREF/compilejava TestCompile.java +$BINREF/runjava TestCompile + diff --git a/messagebus_test/src/tests/error/.gitignore b/messagebus_test/src/tests/error/.gitignore new file mode 100644 index 00000000000..20cb631e9e8 --- /dev/null +++ b/messagebus_test/src/tests/error/.gitignore @@ -0,0 +1,15 @@ +*.class +.depend +Makefile +cpp-client +cpp-server +error_test +out.* +pid.* +routing.cfg +slobrok.cfg +/cpp-client-error +/cpp-server-error +messagebus_test_error_test_app +messagebus_test_cpp-client-error_app +messagebus_test_cpp-server-error_app diff --git a/messagebus_test/src/tests/error/CMakeLists.txt b/messagebus_test/src/tests/error/CMakeLists.txt new file mode 100644 index 00000000000..db826155755 --- /dev/null +++ b/messagebus_test/src/tests/error/CMakeLists.txt @@ -0,0 +1,21 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(messagebus_test_error_test_app TEST + SOURCES + error.cpp + DEPENDS + messagebus +) +vespa_add_executable(messagebus_test_cpp-server-error_app + SOURCES + cpp-server.cpp + DEPENDS + messagebus +) +vespa_add_executable(messagebus_test_cpp-client-error_app + SOURCES + cpp-client.cpp + DEPENDS + messagebus +) +vespa_add_test(NAME messagebus_test_error_test_app NO_VALGRIND COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/error_test.sh + DEPENDS messagebus_test_error_test_app messagebus_test_cpp-server-error_app messagebus_test_cpp-client-error_app) diff --git a/messagebus_test/src/tests/error/DESC b/messagebus_test/src/tests/error/DESC new file mode 100644 index 00000000000..171966761ee --- /dev/null +++ b/messagebus_test/src/tests/error/DESC @@ -0,0 +1,2 @@ +Check that java and cpp messagebus components are able to pass errors +to each other and preserve meaning. diff --git a/messagebus_test/src/tests/error/FILES b/messagebus_test/src/tests/error/FILES new file mode 100644 index 00000000000..571002a917f --- /dev/null +++ b/messagebus_test/src/tests/error/FILES @@ -0,0 +1,8 @@ +error.cpp +out.server.cpp +out.server.java +cpp-client.cpp +cpp-server.cpp +JavaClient.java +JavaServer.java +routing-template.cfg diff --git a/messagebus_test/src/tests/error/JavaClient.java b/messagebus_test/src/tests/error/JavaClient.java new file mode 100644 index 00000000000..e263b3597da --- /dev/null +++ b/messagebus_test/src/tests/error/JavaClient.java @@ -0,0 +1,65 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +import com.yahoo.messagebus.*; +import com.yahoo.messagebus.test.*; +import com.yahoo.config.*; +import com.yahoo.messagebus.routing.*; +import com.yahoo.messagebus.network.*; +import com.yahoo.messagebus.network.rpc.*; +import com.yahoo.messagebus.network.rpc.test.*; +import java.util.Arrays; +import java.util.logging.*; + +public class JavaClient { + + private static Logger log = Logger.getLogger(JavaClient.class.getName()); + + public static void main(String[] args) { + try { + RPCMessageBus mb = new RPCMessageBus( + Arrays.asList((Protocol)new SimpleProtocol()), + new RPCNetworkParams() + .setIdentity(new Identity("server/java")) + .setSlobrokConfigId("file:slobrok.cfg"), + "file:routing.cfg"); + + Receptor src = new Receptor(); + Message msg = null; + Reply reply = null; + + SourceSession session = mb.getMessageBus().createSourceSession(src, new SourceSessionParams().setTimeout(300)); + for (int i = 0; i < 10; i++) { + msg = new SimpleMessage("test"); + msg.getTrace().setLevel(9); + session.send(msg, "test"); + reply = src.getReply(60); + if (reply == null) { + System.err.println("JAVA-CLIENT: no reply"); + } else { + System.err.println("JAVA-CLIENT:\n" + reply.getTrace()); + if (reply.getNumErrors() == 2) { + break; + } + } + Thread.sleep(1000); + } + if (reply == null) { + System.err.println("JAVA-CLIENT: no reply"); + System.exit(1); + } + if (reply.getNumErrors() != 2 || + reply.getError(0).getCode() != ErrorCode.APP_FATAL_ERROR + 1 || + reply.getError(1).getCode() != ErrorCode.APP_FATAL_ERROR + 2 || + !reply.getError(0).getMessage().equals("ERR 1") || + !reply.getError(1).getMessage().equals("ERR 2")) + { + System.err.printf("JAVA-CLIENT: wrong errors\n"); + System.exit(1); + } + session.destroy(); + mb.destroy(); + } catch (Exception e) { + log.log(Level.SEVERE, "JAVA-CLIENT: Failed", e); + System.exit(1); + } + } +} diff --git a/messagebus_test/src/tests/error/JavaServer.java b/messagebus_test/src/tests/error/JavaServer.java new file mode 100644 index 00000000000..b5321f41fc3 --- /dev/null +++ b/messagebus_test/src/tests/error/JavaServer.java @@ -0,0 +1,47 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +import com.yahoo.messagebus.*; +import com.yahoo.messagebus.test.*; +import com.yahoo.config.*; +import com.yahoo.messagebus.routing.*; +import com.yahoo.messagebus.network.*; +import com.yahoo.messagebus.network.rpc.*; +import java.util.Arrays; +import java.util.logging.*; + +public class JavaServer implements MessageHandler { + + private static Logger log = Logger.getLogger(JavaServer.class.getName()); + + private DestinationSession session; + + public JavaServer(RPCMessageBus mb) { + session = mb.getMessageBus().createDestinationSession("session", true, this); + } + + public void handleMessage(Message msg) { + Reply reply = new EmptyReply(); + msg.swapState(reply); + reply.addError(new com.yahoo.messagebus.Error(ErrorCode.APP_FATAL_ERROR + 1, "ERR 1")); + reply.addError(new com.yahoo.messagebus.Error(ErrorCode.APP_FATAL_ERROR + 2, "ERR 2")); + session.reply(reply); + } + + public static void main(String[] args) { + try { + RPCMessageBus mb = new RPCMessageBus( + Arrays.asList((Protocol)new SimpleProtocol()), + new RPCNetworkParams() + .setIdentity(new Identity("server/java")) + .setSlobrokConfigId("file:slobrok.cfg"), + "file:routing.cfg"); + JavaServer server = new JavaServer(mb); + System.out.println("java server started"); + while (true) { + Thread.sleep(1000); + } + } catch (Exception e) { + log.log(Level.SEVERE, "JAVA-SERVER: Failed", e); + System.exit(1); + } + } +} diff --git a/messagebus_test/src/tests/error/cpp-client.cpp b/messagebus_test/src/tests/error/cpp-client.cpp new file mode 100644 index 00000000000..4f94a13977c --- /dev/null +++ b/messagebus_test/src/tests/error/cpp-client.cpp @@ -0,0 +1,75 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include +#include +LOG_SETUP("cpp-client"); +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace mbus; + +class App : public FastOS_Application +{ +public: + int Main(); +}; + +int +App::Main() +{ + RPCMessageBus mb(ProtocolSet().add(IProtocol::SP(new SimpleProtocol())), + RPCNetworkParams() + .setIdentity(Identity("server/cpp")) + .setSlobrokConfig("file:slobrok.cfg"), + "file:routing.cfg"); + + Receptor src; + Message::UP msg; + Reply::UP reply; + + SourceSession::UP ss = mb.getMessageBus().createSourceSession(src, SourceSessionParams().setTimeout(300)); + for (int i = 0; i < 10; ++i) { + msg.reset(new SimpleMessage("test")); + msg->getTrace().setLevel(9); + ss->send(std::move(msg), "test"); + reply = src.getReply(600); // 10 minutes timeout + if (reply.get() == 0) { + fprintf(stderr, "CPP-CLIENT: no reply\n"); + } else { + fprintf(stderr, "CPP-CLIENT:\n%s\n", + reply->getTrace().toString().c_str()); + if (reply->getNumErrors() == 2) { + break; + } + } + FastOS_Thread::Sleep(1000); + } + if (reply.get() == 0) { + fprintf(stderr, "CPP-CLIENT: no reply\n"); + return 1; + } + if (reply->getNumErrors() != 2 || + reply->getError(0).getCode() != (ErrorCode::APP_FATAL_ERROR + 1) || + reply->getError(1).getCode() != (ErrorCode::APP_FATAL_ERROR + 2) || + reply->getError(0).getMessage() != "ERR 1" || + reply->getError(1).getMessage() != "ERR 2") + { + fprintf(stderr, "CPP-CLIENT: wrong errors\n"); + return 1; + } + return 0; +} + +int main(int argc, char **argv) { + App app; + return app.Entry(argc, argv); +} diff --git a/messagebus_test/src/tests/error/cpp-server.cpp b/messagebus_test/src/tests/error/cpp-server.cpp new file mode 100644 index 00000000000..2eb929f6ca9 --- /dev/null +++ b/messagebus_test/src/tests/error/cpp-server.cpp @@ -0,0 +1,73 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include +#include +LOG_SETUP("cpp-server"); +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace mbus; + +class Server : public IMessageHandler +{ +private: + DestinationSession::UP _session; +public: + Server(MessageBus &bus); + ~Server(); + void handleMessage(Message::UP msg); +}; + +Server::Server(MessageBus &bus) + : _session(bus.createDestinationSession("session", true, *this)) +{ + fprintf(stderr, "cpp server started\n"); +} + +Server::~Server() +{ + _session.reset(); +} + +void +Server::handleMessage(Message::UP msg) { + Reply::UP reply(new EmptyReply()); + msg->swapState(*reply); + reply->addError(Error(ErrorCode::APP_FATAL_ERROR + 1, "ERR 1")); + reply->addError(Error(ErrorCode::APP_FATAL_ERROR + 2, "ERR 2")); + _session->reply(std::move(reply)); +} + +class App : public FastOS_Application +{ +public: + int Main(); +}; + +int +App::Main() +{ + RPCMessageBus mb(ProtocolSet().add(IProtocol::SP(new SimpleProtocol())), + RPCNetworkParams() + .setIdentity(Identity("server/cpp")) + .setSlobrokConfig("file:slobrok.cfg"), + "file:routing.cfg"); + Server server(mb.getMessageBus()); + while (true) { + FastOS_Thread::Sleep(1000); + } + return 0; +} + +int main(int argc, char **argv) { + App app; + return app.Entry(argc, argv); +} diff --git a/messagebus_test/src/tests/error/ctl.sh b/messagebus_test/src/tests/error/ctl.sh new file mode 100755 index 00000000000..864be4290ed --- /dev/null +++ b/messagebus_test/src/tests/error/ctl.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +exec ../../binref/progctl.sh progdefs.sh "$@" diff --git a/messagebus_test/src/tests/error/error.cpp b/messagebus_test/src/tests/error/error.cpp new file mode 100644 index 00000000000..9b01e5d61d0 --- /dev/null +++ b/messagebus_test/src/tests/error/error.cpp @@ -0,0 +1,45 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include +#include +LOG_SETUP("error_test"); +#include +#include +#include + +using namespace mbus; +using vespalib::make_string; + +TEST_SETUP(Test); + +int +Test::Main() +{ + TEST_INIT("error_test"); + Slobrok slobrok; + { // Make slobrok config + EXPECT_TRUE(system("echo slobrok[1] > slobrok.cfg") == 0); + EXPECT_TRUE(system(make_string("echo 'slobrok[0].connectionspec tcp/localhost:%d' " + ">> slobrok.cfg", slobrok.port()).c_str()) == 0); + } + { // CPP SERVER + { // Make routing config + EXPECT_TRUE(system("cat routing-template.cfg | sed 's#session#cpp/session#' > routing.cfg") == 0); + } + fprintf(stderr, "STARTING CPP-SERVER\n"); + EXPECT_TRUE(system("sh ctl.sh start server cpp") == 0); + EXPECT_TRUE(system("./messagebus_test_cpp-client-error_app") == 0); + EXPECT_TRUE(system("../../binref/runjava JavaClient") == 0); + EXPECT_TRUE(system("sh ctl.sh stop server cpp") == 0); + } + { // JAVA SERVER + { // Make routing config + EXPECT_TRUE(system("cat routing-template.cfg | sed 's#session#java/session#' > routing.cfg") == 0); + } + fprintf(stderr, "STARTING JAVA-SERVER\n"); + EXPECT_TRUE(system("sh ctl.sh start server java") == 0); + EXPECT_TRUE(system("./messagebus_test_cpp-client-error_app") == 0); + EXPECT_TRUE(system("../../binref/runjava JavaClient") == 0); + EXPECT_TRUE(system("sh ctl.sh stop server java") == 0); + } + TEST_DONE(); +} diff --git a/messagebus_test/src/tests/error/error_test.sh b/messagebus_test/src/tests/error/error_test.sh new file mode 100755 index 00000000000..e2b567f5823 --- /dev/null +++ b/messagebus_test/src/tests/error/error_test.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -e +. ../../binref/env.sh + +$BINREF/compilejava JavaServer.java +$BINREF/compilejava JavaClient.java +VESPA_LOG_LEVEL='all -spam' ./messagebus_test_error_test_app diff --git a/messagebus_test/src/tests/error/progdefs.sh b/messagebus_test/src/tests/error/progdefs.sh new file mode 100644 index 00000000000..2f6f37a9425 --- /dev/null +++ b/messagebus_test/src/tests/error/progdefs.sh @@ -0,0 +1,3 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +prog server cpp "" "./messagebus_test_cpp-server-error_app" +prog server java "" "../../binref/runjava JavaServer" diff --git a/messagebus_test/src/tests/error/routing-template.cfg b/messagebus_test/src/tests/error/routing-template.cfg new file mode 100644 index 00000000000..4b938c9cc82 --- /dev/null +++ b/messagebus_test/src/tests/error/routing-template.cfg @@ -0,0 +1,11 @@ +routingtable[1] +routingtable[0].protocol "Simple" +routingtable[0].hop[1] +routingtable[0].hop[0].name "server" +routingtable[0].hop[0].selector "server/session" +routingtable[0].hop[0].recipient[1] +routingtable[0].hop[0].recipient[0] "server/session" +routingtable[0].route[1] +routingtable[0].route[0].name "test" +routingtable[0].route[0].hop[1] +routingtable[0].route[0].hop[0] "server" diff --git a/messagebus_test/src/tests/errorcodes/.gitignore b/messagebus_test/src/tests/errorcodes/.gitignore new file mode 100644 index 00000000000..13957172a38 --- /dev/null +++ b/messagebus_test/src/tests/errorcodes/.gitignore @@ -0,0 +1,7 @@ +.depend +DumpCodes.class +Makefile +cpp-dump.txt +dumpcodes +java-dump.txt +messagebus_test_dumpcodes_app diff --git a/messagebus_test/src/tests/errorcodes/CMakeLists.txt b/messagebus_test/src/tests/errorcodes/CMakeLists.txt new file mode 100644 index 00000000000..3e12ae340d3 --- /dev/null +++ b/messagebus_test/src/tests/errorcodes/CMakeLists.txt @@ -0,0 +1,7 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(messagebus_test_dumpcodes_app TEST + SOURCES + dumpcodes.cpp + DEPENDS +) +vespa_add_test(NAME messagebus_test_dumpcodes_app NO_VALGRIND COMMAND sh errorcodes_test.sh) diff --git a/messagebus_test/src/tests/errorcodes/DESC b/messagebus_test/src/tests/errorcodes/DESC new file mode 100644 index 00000000000..103ebb4698f --- /dev/null +++ b/messagebus_test/src/tests/errorcodes/DESC @@ -0,0 +1,2 @@ +A small test to check that error codes are equal in the Java and C++ +implementations. diff --git a/messagebus_test/src/tests/errorcodes/DumpCodes.java b/messagebus_test/src/tests/errorcodes/DumpCodes.java new file mode 100644 index 00000000000..8eb97813404 --- /dev/null +++ b/messagebus_test/src/tests/errorcodes/DumpCodes.java @@ -0,0 +1,51 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +import com.yahoo.messagebus.ErrorCode; + +public class DumpCodes { + + private static void dump(String desc, int value) { + String name = ErrorCode.getName(value); + System.out.printf("%s => %d => \"%s\"\n", desc, value, + name != null ? name : ""); + } + + public static void main(String[] args) { + dump("NONE", ErrorCode.NONE); + + dump("SEND_QUEUE_FULL", ErrorCode.SEND_QUEUE_FULL); + dump("NO_ADDRESS_FOR_SERVICE", ErrorCode.NO_ADDRESS_FOR_SERVICE); + dump("CONNECTION_ERROR", ErrorCode.CONNECTION_ERROR); + dump("UNKNOWN_SESSION", ErrorCode.UNKNOWN_SESSION); + dump("SESSION_BUSY", ErrorCode.SESSION_BUSY); + dump("SEND_ABORTED", ErrorCode.SEND_ABORTED); + dump("HANDSHAKE_FAILED", ErrorCode.HANDSHAKE_FAILED); + dump("first unused TRANSIENT_ERROR", ErrorCode.TRANSIENT_ERROR + 8); + + dump("SEND_QUEUE_CLOSED", ErrorCode.SEND_QUEUE_CLOSED); + dump("ILLEGAL_ROUTE", ErrorCode.ILLEGAL_ROUTE); + dump("NO_SERVICES_FOR_ROUTE", ErrorCode.NO_SERVICES_FOR_ROUTE); + dump("SERVICE_OOS", ErrorCode.SERVICE_OOS); + dump("ENCODE_ERROR", ErrorCode.ENCODE_ERROR); + dump("NETWORK_ERROR", ErrorCode.NETWORK_ERROR); + dump("UNKNOWN_PROTOCOL", ErrorCode.UNKNOWN_PROTOCOL); + dump("DECODE_ERROR", ErrorCode.DECODE_ERROR); + dump("TIMEOUT", ErrorCode.TIMEOUT); + dump("INCOMPATIBLE_VERSION", ErrorCode.INCOMPATIBLE_VERSION); + dump("UNKNOWN_POLICY", ErrorCode.UNKNOWN_POLICY); + dump("NETWORK_SHUTDOWN", ErrorCode.NETWORK_SHUTDOWN); + dump("POLICY_ERROR", ErrorCode.POLICY_ERROR); + dump("SEQUENCE_ERROR", ErrorCode.SEQUENCE_ERROR); + dump("first unused FATAL_ERROR", ErrorCode.FATAL_ERROR + 15); + + dump("max UNKNOWN below", ErrorCode.TRANSIENT_ERROR - 1); + dump("min TRANSIENT_ERROR", ErrorCode.TRANSIENT_ERROR); + dump("max TRANSIENT_ERROR", ErrorCode.TRANSIENT_ERROR + 49999); + dump("min APP_TRANSIENT_ERROR", ErrorCode.APP_TRANSIENT_ERROR); + dump("max APP_TRANSIENT_ERROR", ErrorCode.APP_TRANSIENT_ERROR + 49999); + dump("min FATAL_ERROR", ErrorCode.FATAL_ERROR); + dump("max FATAL_ERROR", ErrorCode.FATAL_ERROR + 49999); + dump("min APP_FATAL_ERROR", ErrorCode.APP_FATAL_ERROR); + dump("max APP_FATAL_ERROR", ErrorCode.APP_FATAL_ERROR + 49999); + dump("min UNKNOWN above", ErrorCode.ERROR_LIMIT); + } +} diff --git a/messagebus_test/src/tests/errorcodes/FILES b/messagebus_test/src/tests/errorcodes/FILES new file mode 100644 index 00000000000..766402133fb --- /dev/null +++ b/messagebus_test/src/tests/errorcodes/FILES @@ -0,0 +1,5 @@ +dumpcodes.cpp +DumpCodes.java +ref-dump.txt +cpp-dump.txt +java-dump.txt diff --git a/messagebus_test/src/tests/errorcodes/dumpcodes.cpp b/messagebus_test/src/tests/errorcodes/dumpcodes.cpp new file mode 100644 index 00000000000..121d8585726 --- /dev/null +++ b/messagebus_test/src/tests/errorcodes/dumpcodes.cpp @@ -0,0 +1,70 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include +#include +LOG_SETUP("dumpcodes"); +#include +#include + +using namespace mbus; + +class App : public FastOS_Application +{ +public: + void dump(const std::string &desc, uint32_t value); + int Main(); +}; + +void +App::dump(const std::string &desc, uint32_t value) +{ + fprintf(stdout, "%s => %u => \"%s\"\n", desc.c_str(), value, + ErrorCode::getName(value).c_str()); +} + +int +App::Main() +{ + dump("NONE", ErrorCode::NONE); + + dump("SEND_QUEUE_FULL", ErrorCode::SEND_QUEUE_FULL); + dump("NO_ADDRESS_FOR_SERVICE", ErrorCode::NO_ADDRESS_FOR_SERVICE); + dump("CONNECTION_ERROR", ErrorCode::CONNECTION_ERROR); + dump("UNKNOWN_SESSION", ErrorCode::UNKNOWN_SESSION); + dump("SESSION_BUSY", ErrorCode::SESSION_BUSY); + dump("SEND_ABORTED", ErrorCode::SEND_ABORTED); + dump("HANDSHAKE_FAILED", ErrorCode::HANDSHAKE_FAILED); + dump("first unused TRANSIENT_ERROR", ErrorCode::TRANSIENT_ERROR + 8); + + dump("SEND_QUEUE_CLOSED", ErrorCode::SEND_QUEUE_CLOSED); + dump("ILLEGAL_ROUTE", ErrorCode::ILLEGAL_ROUTE); + dump("NO_SERVICES_FOR_ROUTE", ErrorCode::NO_SERVICES_FOR_ROUTE); + dump("SERVICE_OOS", ErrorCode::SERVICE_OOS); + dump("ENCODE_ERROR", ErrorCode::ENCODE_ERROR); + dump("NETWORK_ERROR", ErrorCode::NETWORK_ERROR); + dump("UNKNOWN_PROTOCOL", ErrorCode::UNKNOWN_PROTOCOL); + dump("DECODE_ERROR", ErrorCode::DECODE_ERROR); + dump("TIMEOUT", ErrorCode::TIMEOUT); + dump("INCOMPATIBLE_VERSION", ErrorCode::INCOMPATIBLE_VERSION); + dump("UNKNOWN_POLICY", ErrorCode::UNKNOWN_POLICY); + dump("NETWORK_SHUTDOWN", ErrorCode::NETWORK_SHUTDOWN); + dump("POLICY_ERROR", ErrorCode::POLICY_ERROR); + dump("SEQUENCE_ERROR", ErrorCode::SEQUENCE_ERROR); + dump("first unused FATAL_ERROR", ErrorCode::FATAL_ERROR + 15); + + dump("max UNKNOWN below", ErrorCode::TRANSIENT_ERROR - 1); + dump("min TRANSIENT_ERROR", ErrorCode::TRANSIENT_ERROR); + dump("max TRANSIENT_ERROR", ErrorCode::TRANSIENT_ERROR + 49999); + dump("min APP_TRANSIENT_ERROR", ErrorCode::APP_TRANSIENT_ERROR); + dump("max APP_TRANSIENT_ERROR", ErrorCode::APP_TRANSIENT_ERROR + 49999); + dump("min FATAL_ERROR", ErrorCode::FATAL_ERROR); + dump("max FATAL_ERROR", ErrorCode::FATAL_ERROR + 49999); + dump("min APP_FATAL_ERROR", ErrorCode::APP_FATAL_ERROR); + dump("max APP_FATAL_ERROR", ErrorCode::APP_FATAL_ERROR + 49999); + dump("min UNKNOWN above", ErrorCode::ERROR_LIMIT); + return 0; +} + +int main(int argc, char **argv) { + App app; + return app.Entry(argc, argv); +} diff --git a/messagebus_test/src/tests/errorcodes/errorcodes_test.sh b/messagebus_test/src/tests/errorcodes/errorcodes_test.sh new file mode 100644 index 00000000000..7c30378cd1a --- /dev/null +++ b/messagebus_test/src/tests/errorcodes/errorcodes_test.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e +. ../../binref/env.sh + +$BINREF/compilejava DumpCodes.java + +./messagebus_test_dumpcodes_app > cpp-dump.txt +$BINREF/runjava DumpCodes > java-dump.txt +diff -u ref-dump.txt cpp-dump.txt +diff -u ref-dump.txt java-dump.txt diff --git a/messagebus_test/src/tests/errorcodes/ref-dump.txt b/messagebus_test/src/tests/errorcodes/ref-dump.txt new file mode 100644 index 00000000000..b8038816897 --- /dev/null +++ b/messagebus_test/src/tests/errorcodes/ref-dump.txt @@ -0,0 +1,34 @@ +NONE => 0 => "NONE" +SEND_QUEUE_FULL => 100001 => "SEND_QUEUE_FULL" +NO_ADDRESS_FOR_SERVICE => 100002 => "NO_ADDRESS_FOR_SERVICE" +CONNECTION_ERROR => 100003 => "CONNECTION_ERROR" +UNKNOWN_SESSION => 100004 => "UNKNOWN_SESSION" +SESSION_BUSY => 100005 => "SESSION_BUSY" +SEND_ABORTED => 100006 => "SEND_ABORTED" +HANDSHAKE_FAILED => 100007 => "HANDSHAKE_FAILED" +first unused TRANSIENT_ERROR => 100008 => "UNKNOWN(100008)" +SEND_QUEUE_CLOSED => 200001 => "SEND_QUEUE_CLOSED" +ILLEGAL_ROUTE => 200002 => "ILLEGAL_ROUTE" +NO_SERVICES_FOR_ROUTE => 200003 => "NO_SERVICES_FOR_ROUTE" +SERVICE_OOS => 200004 => "SERVICE_OOS" +ENCODE_ERROR => 200005 => "ENCODE_ERROR" +NETWORK_ERROR => 200006 => "NETWORK_ERROR" +UNKNOWN_PROTOCOL => 200007 => "UNKNOWN_PROTOCOL" +DECODE_ERROR => 200008 => "DECODE_ERROR" +TIMEOUT => 200009 => "TIMEOUT" +INCOMPATIBLE_VERSION => 200010 => "INCOMPATIBLE_VERSION" +UNKNOWN_POLICY => 200011 => "UNKNOWN_POLICY" +NETWORK_SHUTDOWN => 200012 => "NETWORK_SHUTDOWN" +POLICY_ERROR => 200013 => "POLICY_ERROR" +SEQUENCE_ERROR => 200014 => "SEQUENCE_ERROR" +first unused FATAL_ERROR => 200015 => "UNKNOWN(200015)" +max UNKNOWN below => 99999 => "UNKNOWN(99999)" +min TRANSIENT_ERROR => 100000 => "TRANSIENT_ERROR" +max TRANSIENT_ERROR => 149999 => "UNKNOWN(149999)" +min APP_TRANSIENT_ERROR => 150000 => "APP_TRANSIENT_ERROR" +max APP_TRANSIENT_ERROR => 199999 => "UNKNOWN(199999)" +min FATAL_ERROR => 200000 => "FATAL_ERROR" +max FATAL_ERROR => 249999 => "UNKNOWN(249999)" +min APP_FATAL_ERROR => 250000 => "APP_FATAL_ERROR" +max APP_FATAL_ERROR => 299999 => "UNKNOWN(299999)" +min UNKNOWN above => 300000 => "UNKNOWN(300000)" diff --git a/messagebus_test/src/tests/speed/.gitignore b/messagebus_test/src/tests/speed/.gitignore new file mode 100644 index 00000000000..326da75ebb6 --- /dev/null +++ b/messagebus_test/src/tests/speed/.gitignore @@ -0,0 +1,15 @@ +*.class +.depend +Makefile +cpp-client +cpp-server +out.* +pid.* +routing.cfg +slobrok.cfg +speed_test +cpp-client-speed +cpp-server-speed +messagebus_test_speed_test_app +messagebus_test_cpp-client-speed_app +messagebus_test_cpp-server-speed_app diff --git a/messagebus_test/src/tests/speed/CMakeLists.txt b/messagebus_test/src/tests/speed/CMakeLists.txt new file mode 100644 index 00000000000..8e1018ec07c --- /dev/null +++ b/messagebus_test/src/tests/speed/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(messagebus_test_speed_test_app + SOURCES + speed.cpp + DEPENDS +) +vespa_add_test(NAME messagebus_test_speed_test_app COMMAND messagebus_test_speed_test_app BENCHMARK) +vespa_add_executable(messagebus_test_cpp-server-speed_app + SOURCES + cpp-server.cpp + DEPENDS +) +vespa_add_executable(messagebus_test_cpp-client-speed_app + SOURCES + cpp-client.cpp + DEPENDS +) diff --git a/messagebus_test/src/tests/speed/DESC b/messagebus_test/src/tests/speed/DESC new file mode 100644 index 00000000000..10734957438 --- /dev/null +++ b/messagebus_test/src/tests/speed/DESC @@ -0,0 +1,4 @@ +This is a simple test that gives a rough idea of the inherent overhead +in messagebus. It sends simple messages back and forth with the +simplest routing setup possible. This test also tests that messagebus +works across Java and C++. diff --git a/messagebus_test/src/tests/speed/FILES b/messagebus_test/src/tests/speed/FILES new file mode 100644 index 00000000000..09f0a5ec1d3 --- /dev/null +++ b/messagebus_test/src/tests/speed/FILES @@ -0,0 +1,8 @@ +speed.cpp +out.server.cpp +out.server.java +cpp-client.cpp +cpp-server.cpp +JavaClient.java +JavaServer.java +routing-template.cfg diff --git a/messagebus_test/src/tests/speed/JavaClient.java b/messagebus_test/src/tests/speed/JavaClient.java new file mode 100644 index 00000000000..b905ab07e91 --- /dev/null +++ b/messagebus_test/src/tests/speed/JavaClient.java @@ -0,0 +1,137 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +import com.yahoo.messagebus.*; +import com.yahoo.messagebus.test.*; +import com.yahoo.config.*; +import com.yahoo.messagebus.routing.*; +import com.yahoo.messagebus.network.*; +import com.yahoo.messagebus.network.rpc.*; +import java.util.Arrays; +import java.util.logging.*; + +public class JavaClient implements ReplyHandler { + + private static Logger log = Logger.getLogger(JavaClient.class.getName()); + + private static class Counts { + public int okCnt = 0; + public int failCnt = 0; + Counts() {} + Counts(int okCnt, int failCnt) { + this.okCnt = okCnt; + this.failCnt = failCnt; + } + } + + private SourceSession session; + private Counts counts = new Counts(); + private static long mySeq = 100000; + + public JavaClient(RPCMessageBus mb) { + session = mb.getMessageBus().createSourceSession(this, new SourceSessionParams().setTimeout(30)); + } + + public synchronized Counts sample() { + return new Counts(counts.okCnt, counts.failCnt); + } + + public void send() { + send(++mySeq); + } + + public void send(long seq) { + session.send(new MyMessage(seq), "test"); + } + + public void handleReply(Reply reply) { + if ((reply.getProtocol() == SimpleProtocol.NAME) + && (reply.getType() == SimpleProtocol.REPLY) + && (((SimpleReply)reply).getValue().equals("OK"))) + { + synchronized (this) { + counts.okCnt++; + } + } else { + synchronized (this) { + counts.failCnt++; + } + } + try { + send(); + } catch (IllegalStateException ignore) {} // handle paranoia for shutdown source sessions + } + + public void shutdown() { + session.destroy(); + } + + public static void main(String[] args) { + try { + RPCMessageBus mb = new RPCMessageBus( + new MessageBusParams() + .setRetryPolicy(new RetryTransientErrorsPolicy().setBaseDelay(0.1)) + .addProtocol(new SimpleProtocol()), + new RPCNetworkParams() + .setIdentity(new Identity("server/java")) + .setSlobrokConfigId("file:slobrok.cfg"), + "file:routing.cfg"); + JavaClient client = new JavaClient(mb); + + // let the system 'warm up' + Thread.sleep(5000); + + // inject messages into the feedback loop + for (int i = 0; i < 1024; ++i) { + client.send(i); + } + + // let the system 'warm up' + Thread.sleep(5000); + + long start; + long stop; + Counts before; + Counts after; + + start = System.currentTimeMillis(); + before = client.sample(); + Thread.sleep(10000); // Benchmark time + stop = System.currentTimeMillis(); + after = client.sample(); + stop -= start; + double time = (double)stop; + double msgCnt = (double)(after.okCnt - before.okCnt); + double throughput = (msgCnt / time) * 1000.0; + System.out.printf("JAVA-CLIENT: %g msg/s\n", throughput); + client.shutdown(); + mb.destroy(); + if (after.failCnt > before.failCnt) { + System.err.printf("JAVA-CLIENT: FAILED (%d -> %d)\n", + before.failCnt, after.failCnt); + System.exit(1); + } + } catch (Exception e) { + log.log(Level.SEVERE, "JAVA-CLIENT: Failed", e); + System.exit(1); + } + } + + private static class MyMessage extends SimpleMessage { + + final long seqId; + + MyMessage(long seqId) { + super("message"); + this.seqId = seqId; + } + + @Override + public boolean hasSequenceId() { + return true; + } + + @Override + public long getSequenceId() { + return seqId; + } + } +} diff --git a/messagebus_test/src/tests/speed/JavaServer.java b/messagebus_test/src/tests/speed/JavaServer.java new file mode 100644 index 00000000000..afec6dcdba2 --- /dev/null +++ b/messagebus_test/src/tests/speed/JavaServer.java @@ -0,0 +1,54 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +import com.yahoo.messagebus.*; +import com.yahoo.messagebus.test.*; +import com.yahoo.config.*; +import com.yahoo.messagebus.routing.*; +import com.yahoo.messagebus.network.*; +import com.yahoo.messagebus.network.rpc.*; +import java.util.Arrays; +import java.util.logging.*; + +public class JavaServer implements MessageHandler { + + private static Logger log = Logger.getLogger(JavaServer.class.getName()); + + private DestinationSession session; + + public JavaServer(RPCMessageBus mb) { + session = mb.getMessageBus().createDestinationSession("session", true, this); + } + + public void handleMessage(Message msg) { + if ((msg.getProtocol() == SimpleProtocol.NAME) + && (msg.getType() == SimpleProtocol.MESSAGE) + && (((SimpleMessage)msg).getValue().equals("message"))) + { + Reply reply = new SimpleReply("OK"); + msg.swapState(reply); + session.reply(reply); + } else { + Reply reply = new SimpleReply("FAIL"); + msg.swapState(reply); + session.reply(reply); + } + } + + public static void main(String[] args) { + try { + RPCMessageBus mb = new RPCMessageBus( + Arrays.asList((Protocol)new SimpleProtocol()), + new RPCNetworkParams() + .setIdentity(new Identity("server/java")) + .setSlobrokConfigId("file:slobrok.cfg"), + "file:routing.cfg"); + JavaServer server = new JavaServer(mb); + System.out.println("java server started"); + while (true) { + Thread.sleep(1000); + } + } catch (Exception e) { + log.log(Level.SEVERE, "JAVA-SERVER: Failed", e); + System.exit(1); + } + } +} diff --git a/messagebus_test/src/tests/speed/cpp-client.cpp b/messagebus_test/src/tests/speed/cpp-client.cpp new file mode 100644 index 00000000000..c0c9d621a20 --- /dev/null +++ b/messagebus_test/src/tests/speed/cpp-client.cpp @@ -0,0 +1,146 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include +#include +LOG_SETUP("cpp-client"); +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace mbus; + +class Client : public IReplyHandler +{ +private: + vespalib::Lock _lock; + uint32_t _okCnt; + uint32_t _failCnt; + SourceSession::UP _session; + static uint64_t _seq; +public: + Client(MessageBus &bus, const SourceSessionParams ¶ms); + ~Client(); + void send(); + void send(uint64_t seq); + void sample(uint32_t &okCnt, uint32_t &failCnt); + void handleReply(Reply::UP reply); +}; +uint64_t Client::_seq = 100000; + +Client::Client(MessageBus &bus, const SourceSessionParams ¶ms) + : _lock(), + _okCnt(0), + _failCnt(0), + _session(bus.createSourceSession(*this, params)) +{ +} + +Client::~Client() +{ + _session->close(); +} + +void +Client::send() { + send(++_seq); +} + +void +Client::send(uint64_t seq) { + Message::UP msg(new SimpleMessage("message", true, seq)); + _session->send(std::move(msg), "test"); +} + +void +Client::sample(uint32_t &okCnt, uint32_t &failCnt) { + vespalib::LockGuard guard(_lock); + okCnt = _okCnt; + failCnt = _failCnt; +} + +void +Client::handleReply(Reply::UP reply) { + if ((reply->getProtocol() == SimpleProtocol::NAME) + && (reply->getType() == SimpleProtocol::REPLY) + && (static_cast(*reply).getValue() == "OK")) + { + vespalib::LockGuard guard(_lock); + ++_okCnt; + } else { + fprintf(stderr, "BAD REPLY\n"); + for (uint32_t i = 0; i < reply->getNumErrors(); ++i) { + fprintf(stderr, "ERR[%d]: code=%d, msg=%s\n", i, + reply->getError(i).getCode(), + reply->getError(i).getMessage().c_str()); + } + vespalib::LockGuard guard(_lock); + ++_failCnt; + } + send(); +} + +class App : public FastOS_Application +{ +public: + int Main(); +}; + +int +App::Main() +{ + RetryTransientErrorsPolicy::SP retryPolicy(new RetryTransientErrorsPolicy()); + retryPolicy->setBaseDelay(0.1); + RPCMessageBus mb(MessageBusParams().setRetryPolicy(retryPolicy).addProtocol(IProtocol::SP(new SimpleProtocol())), + RPCNetworkParams().setIdentity(Identity("server/cpp")).setSlobrokConfig("file:slobrok.cfg"), + "file:routing.cfg"); + Client client(mb.getMessageBus(), SourceSessionParams().setTimeout(30)); + + // let the system 'warm up' + FastOS_Thread::Sleep(5000); + + // inject messages into the feedback loop + for (uint32_t i = 0; i < 1024; ++i) { + client.send(i); + } + + // let the system 'warm up' + FastOS_Thread::Sleep(5000); + + FastOS_Time start; + FastOS_Time stop; + uint32_t okBefore = 0; + uint32_t okAfter = 0; + uint32_t failBefore = 0; + uint32_t failAfter = 0; + + start.SetNow(); + client.sample(okBefore, failBefore); + FastOS_Thread::Sleep(10000); // Benchmark time + stop.SetNow(); + client.sample(okAfter, failAfter); + stop -= start; + double time = stop.MilliSecs(); + double msgCnt = (double)(okAfter - okBefore); + double throughput = (msgCnt / time) * 1000.0; + fprintf(stdout, "CPP-CLIENT: %g msg/s\n", throughput); + if (failAfter > failBefore) { + fprintf(stderr, "CPP-CLIENT: FAILED (%d -> %d)\n", failBefore, failAfter); + return 1; + } + return 0; +} + +int main(int argc, char **argv) { + fprintf(stderr, "started '%s'\n", argv[0]); + fflush(stderr); + App app; + int r = app.Entry(argc, argv); + fprintf(stderr, "stopping '%s'\n", argv[0]); + fflush(stderr); + return r; +} diff --git a/messagebus_test/src/tests/speed/cpp-server.cpp b/messagebus_test/src/tests/speed/cpp-server.cpp new file mode 100644 index 00000000000..c2cd9bf262a --- /dev/null +++ b/messagebus_test/src/tests/speed/cpp-server.cpp @@ -0,0 +1,77 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include +#include +LOG_SETUP("cpp-server"); +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace mbus; + +class Server : public IMessageHandler +{ +private: + DestinationSession::UP _session; +public: + Server(MessageBus &bus); + ~Server(); + void handleMessage(Message::UP msg); +}; + +Server::Server(MessageBus &bus) + : _session(bus.createDestinationSession("session", true, *this)) +{ + fprintf(stderr, "cpp server started\n"); +} + +Server::~Server() +{ + _session.reset(); +} + +void +Server::handleMessage(Message::UP msg) { + if ((msg->getProtocol() == SimpleProtocol::NAME) + && (msg->getType() == SimpleProtocol::MESSAGE) + && (static_cast(*msg).getValue() == "message")) + { + Reply::UP reply(new SimpleReply("OK")); + msg->swapState(*reply); + _session->reply(std::move(reply)); + } else { + Reply::UP reply(new SimpleReply("FAIL")); + msg->swapState(*reply); + _session->reply(std::move(reply)); + } +} + +class App : public FastOS_Application +{ +public: + int Main(); +}; + +int +App::Main() +{ + RPCMessageBus mb(ProtocolSet().add(IProtocol::SP(new SimpleProtocol())), + RPCNetworkParams() + .setIdentity(Identity("server/cpp")) + .setSlobrokConfig("file:slobrok.cfg"), + "file:routing.cfg"); + Server server(mb.getMessageBus()); + while (true) { + FastOS_Thread::Sleep(1000); + } + return 0; +} + +int main(int argc, char **argv) { + App app; + return app.Entry(argc, argv); +} diff --git a/messagebus_test/src/tests/speed/ctl.sh b/messagebus_test/src/tests/speed/ctl.sh new file mode 100755 index 00000000000..864be4290ed --- /dev/null +++ b/messagebus_test/src/tests/speed/ctl.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +exec ../../binref/progctl.sh progdefs.sh "$@" diff --git a/messagebus_test/src/tests/speed/progdefs.sh b/messagebus_test/src/tests/speed/progdefs.sh new file mode 100644 index 00000000000..4e0390142cf --- /dev/null +++ b/messagebus_test/src/tests/speed/progdefs.sh @@ -0,0 +1,3 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +prog server cpp "" "./messagebus_test_cpp-server-speed_app" +prog server java "" "../../binref/runjava JavaServer" diff --git a/messagebus_test/src/tests/speed/routing-template.cfg b/messagebus_test/src/tests/speed/routing-template.cfg new file mode 100644 index 00000000000..4b938c9cc82 --- /dev/null +++ b/messagebus_test/src/tests/speed/routing-template.cfg @@ -0,0 +1,11 @@ +routingtable[1] +routingtable[0].protocol "Simple" +routingtable[0].hop[1] +routingtable[0].hop[0].name "server" +routingtable[0].hop[0].selector "server/session" +routingtable[0].hop[0].recipient[1] +routingtable[0].hop[0].recipient[0] "server/session" +routingtable[0].route[1] +routingtable[0].route[0].name "test" +routingtable[0].route[0].hop[1] +routingtable[0].route[0].hop[0] "server" diff --git a/messagebus_test/src/tests/speed/speed.cpp b/messagebus_test/src/tests/speed/speed.cpp new file mode 100644 index 00000000000..31ea419ce5c --- /dev/null +++ b/messagebus_test/src/tests/speed/speed.cpp @@ -0,0 +1,51 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include +#include +LOG_SETUP("speed_test"); +#include +#include +#include + +using namespace mbus; +using vespalib::make_string; + +TEST_SETUP(Test); + +int +Test::Main() +{ + TEST_INIT("speed_test"); + Slobrok slobrok; + { // Make slobrok config + EXPECT_EQUAL(system("echo slobrok[1] > slobrok.cfg"), 0); + EXPECT_EQUAL(system(make_string("echo 'slobrok[0].connectionspec tcp/localhost:%d' " + ">> slobrok.cfg", slobrok.port()).c_str()), 0); + } + { // CPP SERVER + { // Make routing config + EXPECT_EQUAL(system("cat routing-template.cfg | sed 's#session#cpp/session#' > routing.cfg"), 0); + } + fprintf(stderr, "STARTING CPP-SERVER\n"); + EXPECT_EQUAL(system("sh ctl.sh start server cpp"), 0); + fprintf(stderr, "STARTING CPP-CLIENT\n"); + EXPECT_EQUAL(system("./messagebus_test_cpp-client-speed_app"), 0); + fprintf(stderr, "STARTING JAVA-CLIENT\n"); + EXPECT_EQUAL(system("../../binref/runjava JavaClient"), 0); + fprintf(stderr, "STOPPING\n"); + EXPECT_EQUAL(system("sh ctl.sh stop server cpp"), 0); + } + { // JAVA SERVER + { // Make routing config + EXPECT_EQUAL(system("cat routing-template.cfg | sed 's#session#java/session#' > routing.cfg"), 0); + } + fprintf(stderr, "STARTING JAVA-SERVER\n"); + EXPECT_EQUAL(system("sh ctl.sh start server java"), 0); + fprintf(stderr, "STARTING CPP-CLIENT\n"); + EXPECT_EQUAL(system("./messagebus_test_cpp-client-speed_app"), 0); + fprintf(stderr, "STARTING JAVA-CLIENT\n"); + EXPECT_EQUAL(system("../../binref/runjava JavaClient"), 0); + fprintf(stderr, "STOPPING\n"); + EXPECT_EQUAL(system("sh ctl.sh stop server java"), 0); + } + TEST_DONE(); +} diff --git a/messagebus_test/src/tests/speed/speed_test.sh b/messagebus_test/src/tests/speed/speed_test.sh new file mode 100644 index 00000000000..77eb7e63e0c --- /dev/null +++ b/messagebus_test/src/tests/speed/speed_test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +. ../../binref/env.sh + +$BINREF/compilejava JavaServer.java +$BINREF/compilejava JavaClient.java + +(ulimit -c; ulimit -H -c; ulimit -c unlimited; ./messagebus_test_speed_test_app) diff --git a/messagebus_test/src/tests/trace/.gitignore b/messagebus_test/src/tests/trace/.gitignore new file mode 100644 index 00000000000..1be907ec2f8 --- /dev/null +++ b/messagebus_test/src/tests/trace/.gitignore @@ -0,0 +1,12 @@ +*.class +.depend +Makefile +cpp-server +out.* +pid.* +routing.cfg +slobrok.cfg +trace_test +/cpp-server-trace +messagebus_test_trace_test_app +messagebus_test_cpp-server-trace_app diff --git a/messagebus_test/src/tests/trace/CMakeLists.txt b/messagebus_test/src/tests/trace/CMakeLists.txt new file mode 100644 index 00000000000..af539fa2818 --- /dev/null +++ b/messagebus_test/src/tests/trace/CMakeLists.txt @@ -0,0 +1,13 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(messagebus_test_trace_test_app TEST + SOURCES + trace.cpp + DEPENDS +) +vespa_add_executable(messagebus_test_cpp-server-trace_app + SOURCES + cpp-server.cpp + DEPENDS +) +vespa_add_test(NAME messagebus_test_trace_test_app NO_VALGRIND COMMAND sh trace_test.sh + DEPENDS messagebus_test_trace_test_app messagebus_test_cpp-server-trace_app) diff --git a/messagebus_test/src/tests/trace/DESC b/messagebus_test/src/tests/trace/DESC new file mode 100644 index 00000000000..452e75aefea --- /dev/null +++ b/messagebus_test/src/tests/trace/DESC @@ -0,0 +1 @@ +trace test. Take a look at trace.cpp for details. diff --git a/messagebus_test/src/tests/trace/FILES b/messagebus_test/src/tests/trace/FILES new file mode 100644 index 00000000000..891e4df6273 --- /dev/null +++ b/messagebus_test/src/tests/trace/FILES @@ -0,0 +1,19 @@ +trace.cpp +cpp-server.cpp +JavaServer.java +routing.cfg +out.server.cpp1 +out.server.cpp2 +out.server.cpp3 +out.server.cpp4 +out.server.cpp5 +out.server.cpp6 +out.server.cpp7 +out.server.java1 +out.server.java2 +out.server.java3 +out.server.java4 +out.server.java5 +out.server.java6 +out.server.java7 +progdefs.sh diff --git a/messagebus_test/src/tests/trace/JavaServer.java b/messagebus_test/src/tests/trace/JavaServer.java new file mode 100644 index 00000000000..5dfe15e3d0b --- /dev/null +++ b/messagebus_test/src/tests/trace/JavaServer.java @@ -0,0 +1,97 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +import com.yahoo.messagebus.*; +import com.yahoo.messagebus.test.*; +import com.yahoo.config.*; +import com.yahoo.messagebus.routing.*; +import com.yahoo.messagebus.network.*; +import com.yahoo.messagebus.network.rpc.*; +import java.util.Arrays; +import java.util.logging.*; + +public class JavaServer implements MessageHandler, ReplyHandler { + + private static Logger log = Logger.getLogger(JavaServer.class.getName()); + + private IntermediateSession session; + private String name; + + public JavaServer(RPCMessageBus mb, String name) { + session = mb.getMessageBus().createIntermediateSession("session", true, this, this); + this.name = name; + } + + public void handleMessage(Message msg) { + msg.getTrace().trace(1, name + " (message)", false); + if (msg.getRoute() == null || !msg.getRoute().hasHops()) { + System.out.println("**** Server '" + name + "' replying."); + Reply reply = new EmptyReply(); + msg.swapState(reply); + handleReply(reply); + } else { + System.out.println("**** Server '" + name + "' forwarding message."); + session.forward(msg); + } + } + + public void handleReply(Reply reply) { + reply.getTrace().trace(1, name + " (reply)", false); + session.forward(reply); + } + + public static void main(String[] args) { + if (args.length != 1) { + System.err.println("usage: JavaServer "); + System.exit(1); + } + String name = args[0]; + SimpleProtocol protocol = new SimpleProtocol(); + protocol.addPolicyFactory("All", new SimpleProtocol.PolicyFactory() { + @Override + public RoutingPolicy create(String param) { + return new AllPolicy(); + } + }); + try { + RPCMessageBus mb = new RPCMessageBus( + Arrays.asList(protocol), + new RPCNetworkParams() + .setIdentity(new Identity(name)) + .setSlobrokConfigId("file:slobrok.cfg"), + "file:routing.cfg"); + JavaServer server = new JavaServer(mb, name); + System.out.printf("java server started name=%s\n", name); + while (true) { + Thread.sleep(1000); + } + } catch (Exception e) { + log.log(Level.SEVERE, "JAVA-SERVER: Failed", e); + System.exit(1); + } + } + + private static class AllPolicy implements RoutingPolicy { + + @Override + public void select(RoutingContext ctx) { + ctx.addChildren(ctx.getMatchedRecipients()); + } + + @Override + public void merge(RoutingContext ctx) { + EmptyReply ret = new EmptyReply(); + for (RoutingNodeIterator it = ctx.getChildIterator(); + it.isValid(); it.next()) { + Reply reply = it.getReplyRef(); + for (int i = 0; i < reply.getNumErrors(); ++i) { + ret.addError(reply.getError(i)); + } + } + ctx.setReply(ret); + } + + @Override + public void destroy() { + + } + } +} diff --git a/messagebus_test/src/tests/trace/cpp-server.cpp b/messagebus_test/src/tests/trace/cpp-server.cpp new file mode 100644 index 00000000000..76e20bc3cfd --- /dev/null +++ b/messagebus_test/src/tests/trace/cpp-server.cpp @@ -0,0 +1,90 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include +#include +LOG_SETUP("cpp-server"); +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace mbus; + +class Server : public IMessageHandler, + public IReplyHandler +{ +private: + IntermediateSession::UP _session; + std::string _name; +public: + Server(MessageBus &bus, const std::string &name); + ~Server(); + void handleMessage(Message::UP msg); + void handleReply(Reply::UP reply); +}; + +Server::Server(MessageBus &bus, const std::string &name) + : _session(bus.createIntermediateSession("session", true, *this, *this)), + _name(name) +{ + fprintf(stderr, "cpp server started: %s\n", _name.c_str()); +} + +Server::~Server() +{ + _session.reset(); +} + +void +Server::handleMessage(Message::UP msg) { + msg->getTrace().trace(1, _name + " (message)", false); + if (!msg->getRoute().hasHops()) { + fprintf(stderr, "**** Server '%s' replying.\n", _name.c_str()); + Reply::UP reply(new EmptyReply()); + msg->swapState(*reply); + handleReply(std::move(reply)); + } else { + fprintf(stderr, "**** Server '%s' forwarding message.\n", _name.c_str()); + _session->forward(std::move(msg)); + } +} + +void +Server::handleReply(Reply::UP reply) { + reply->getTrace().trace(1, _name + " (reply)", false); + _session->forward(std::move(reply)); +} + +class App : public FastOS_Application +{ +public: + int Main(); +}; + +int +App::Main() +{ + if (_argc != 2) { + fprintf(stderr, "usage: %s \n", _argv[0]); + return 1; + } + RPCMessageBus mb(ProtocolSet().add(IProtocol::SP(new SimpleProtocol())), + RPCNetworkParams() + .setIdentity(Identity(_argv[1])) + .setSlobrokConfig("file:slobrok.cfg"), + "file:routing.cfg"); + Server server(mb.getMessageBus(), _argv[1]); + while (true) { + FastOS_Thread::Sleep(1000); + } + return 0; +} + +int main(int argc, char **argv) { + App app; + return app.Entry(argc, argv); +} diff --git a/messagebus_test/src/tests/trace/ctl.sh b/messagebus_test/src/tests/trace/ctl.sh new file mode 100755 index 00000000000..864be4290ed --- /dev/null +++ b/messagebus_test/src/tests/trace/ctl.sh @@ -0,0 +1,4 @@ +#!/bin/bash +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +exec ../../binref/progctl.sh progdefs.sh "$@" diff --git a/messagebus_test/src/tests/trace/progdefs.sh b/messagebus_test/src/tests/trace/progdefs.sh new file mode 100644 index 00000000000..fd35b6503e2 --- /dev/null +++ b/messagebus_test/src/tests/trace/progdefs.sh @@ -0,0 +1,15 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +prog server cpp1 "" "./messagebus_test_cpp-server-trace_app server/cpp/1/A" +prog server cpp2 "" "./messagebus_test_cpp-server-trace_app server/cpp/2/A" +prog server cpp3 "" "./messagebus_test_cpp-server-trace_app server/cpp/2/B" +prog server cpp4 "" "./messagebus_test_cpp-server-trace_app server/cpp/3/A" +prog server cpp5 "" "./messagebus_test_cpp-server-trace_app server/cpp/3/B" +prog server cpp6 "" "./messagebus_test_cpp-server-trace_app server/cpp/3/C" +prog server cpp7 "" "./messagebus_test_cpp-server-trace_app server/cpp/3/D" +prog server java1 "" "../../binref/runjava JavaServer server/java/1/A" +prog server java2 "" "../../binref/runjava JavaServer server/java/2/A" +prog server java3 "" "../../binref/runjava JavaServer server/java/2/B" +prog server java4 "" "../../binref/runjava JavaServer server/java/3/A" +prog server java5 "" "../../binref/runjava JavaServer server/java/3/B" +prog server java6 "" "../../binref/runjava JavaServer server/java/3/C" +prog server java7 "" "../../binref/runjava JavaServer server/java/3/D" diff --git a/messagebus_test/src/tests/trace/trace.cpp b/messagebus_test/src/tests/trace/trace.cpp new file mode 100644 index 00000000000..94550460c84 --- /dev/null +++ b/messagebus_test/src/tests/trace/trace.cpp @@ -0,0 +1,113 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include +#include +LOG_SETUP("trace_test"); +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace mbus; +using vespalib::make_string; + +TEST_SETUP(Test); + +bool +waitSlobrok(RPCMessageBus &mbus, const std::string &pattern) +{ + for (int i = 0; i < 30000; i++) { + slobrok::api::MirrorAPI::SpecList res = mbus.getRPCNetwork().getMirror().lookup(pattern); + if (res.size() > 0) { + return true; + } + FastOS_Thread::Sleep(10); + } + return false; +} + +int +Test::Main() +{ + TEST_INIT("trace_test"); + Slobrok slobrok; + { // Make slobrok config + EXPECT_TRUE(system("echo slobrok[1] > slobrok.cfg") == 0); + EXPECT_TRUE(system(make_string("echo 'slobrok[0].connectionspec tcp/localhost:%d' " + ">> slobrok.cfg", slobrok.port()).c_str()) == 0); + } + EXPECT_TRUE(system("sh ctl.sh start all") == 0); + RPCMessageBus mb(ProtocolSet().add(IProtocol::SP(new SimpleProtocol())), + RPCNetworkParams().setSlobrokConfig("file:slobrok.cfg"), + "file:routing.cfg"); + EXPECT_TRUE(waitSlobrok(mb, "server/cpp/1/A/session")); + EXPECT_TRUE(waitSlobrok(mb, "server/cpp/2/A/session")); + EXPECT_TRUE(waitSlobrok(mb, "server/cpp/2/B/session")); + EXPECT_TRUE(waitSlobrok(mb, "server/cpp/3/A/session")); + EXPECT_TRUE(waitSlobrok(mb, "server/cpp/3/B/session")); + EXPECT_TRUE(waitSlobrok(mb, "server/cpp/3/C/session")); + EXPECT_TRUE(waitSlobrok(mb, "server/cpp/3/D/session")); + EXPECT_TRUE(waitSlobrok(mb, "server/java/1/A/session")); + EXPECT_TRUE(waitSlobrok(mb, "server/java/2/A/session")); + EXPECT_TRUE(waitSlobrok(mb, "server/java/2/B/session")); + EXPECT_TRUE(waitSlobrok(mb, "server/java/3/A/session")); + EXPECT_TRUE(waitSlobrok(mb, "server/java/3/B/session")); + EXPECT_TRUE(waitSlobrok(mb, "server/java/3/C/session")); + EXPECT_TRUE(waitSlobrok(mb, "server/java/3/D/session")); + + TraceNode e3 = TraceNode() + .addChild(TraceNode().addChild("server/cpp/3/A (message)").addChild("server/cpp/3/A (reply)")) + .addChild(TraceNode().addChild("server/cpp/3/B (message)").addChild("server/cpp/3/B (reply)")) + .addChild(TraceNode().addChild("server/cpp/3/C (message)").addChild("server/cpp/3/C (reply)")) + .addChild(TraceNode().addChild("server/cpp/3/D (message)").addChild("server/cpp/3/D (reply)")) + .addChild(TraceNode().addChild("server/java/3/A (message)").addChild("server/java/3/A (reply)")) + .addChild(TraceNode().addChild("server/java/3/B (message)").addChild("server/java/3/B (reply)")) + .addChild(TraceNode().addChild("server/java/3/C (message)").addChild("server/java/3/C (reply)")) + .addChild(TraceNode().addChild("server/java/3/D (message)").addChild("server/java/3/D (reply)")).setStrict(false); + TraceNode e2 = TraceNode() + .addChild(TraceNode().addChild("server/cpp/2/A (message)").addChild(e3).addChild("server/cpp/2/A (reply)")) + .addChild(TraceNode().addChild("server/cpp/2/B (message)").addChild(e3).addChild("server/cpp/2/B (reply)")) + .addChild(TraceNode().addChild("server/java/2/A (message)").addChild(e3).addChild("server/java/2/A (reply)")) + .addChild(TraceNode().addChild("server/java/2/B (message)").addChild(e3).addChild("server/java/2/B (reply)")).setStrict(false); + TraceNode expect = TraceNode() + .addChild(TraceNode().addChild("server/cpp/1/A (message)").addChild(e2).addChild("server/cpp/1/A (reply)")) + .addChild(TraceNode().addChild("server/java/1/A (message)").addChild(e2).addChild("server/java/1/A (reply)")).setStrict(false); + expect.normalize(); + + Receptor src; + Reply::UP reply; + SourceSession::UP ss = mb.getMessageBus().createSourceSession(src, SourceSessionParams()); + for (int i = 0; i < 50; ++i) { + Message::UP msg(new SimpleMessage("test")); + msg->getTrace().setLevel(1); + ss->send(std::move(msg), "test"); + reply = src.getReply(10); + if (reply.get() != NULL) { + reply->getTrace().getRoot().normalize(); + // resending breaks the trace, so retry until it has expected form + if (!reply->hasErrors() && reply->getTrace().getRoot().encode() == expect.encode()) { + break; + } + } + std::cout << "Attempt " << i << " got errors, retrying in 1 second.." << std::endl; + FastOS_Thread::Sleep(1000); + } + + EXPECT_TRUE(!reply->hasErrors()); + EXPECT_EQUAL(reply->getTrace().getRoot().encode(), expect.encode()); + EXPECT_TRUE(system("sh ctl.sh stop all") == 0); + TEST_DONE(); +} diff --git a/messagebus_test/src/tests/trace/trace_test.sh b/messagebus_test/src/tests/trace/trace_test.sh new file mode 100644 index 00000000000..63005385332 --- /dev/null +++ b/messagebus_test/src/tests/trace/trace_test.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +. ../../binref/env.sh + +$BINREF/compilejava JavaServer.java + +./messagebus_test_trace_test_app -- cgit v1.2.3