summaryrefslogtreecommitdiffstats
path: root/messagebus_test
diff options
context:
space:
mode:
authorArnstein Ressem <aressem@gmail.com>2016-09-14 08:45:26 +0200
committerGitHub <noreply@github.com>2016-09-14 08:45:26 +0200
commit4b194fbcf79d5af1731d960ce4abbc2574ba397d (patch)
tree49934000a4d61790615c7c7b71cbe415478c073d /messagebus_test
parent4bf517333b0616ce3e7947c28afb378cd10fe5c9 (diff)
Revert "Revert "Aressem/move messagebus test tests to separate module""
Diffstat (limited to 'messagebus_test')
-rw-r--r--messagebus_test/CMakeLists.txt17
-rw-r--r--messagebus_test/OWNERS3
-rw-r--r--messagebus_test/README1
-rw-r--r--messagebus_test/src/.gitignore8
-rw-r--r--messagebus_test/src/binref/.gitignore5
-rw-r--r--messagebus_test/src/binref/CMakeLists.txt5
-rwxr-xr-xmessagebus_test/src/binref/compilejava.in11
-rw-r--r--messagebus_test/src/binref/env.sh.in2
l---------messagebus_test/src/binref/progctl.sh1
-rwxr-xr-xmessagebus_test/src/binref/runjava.in13
-rw-r--r--messagebus_test/src/tests/compile-cpp/.gitignore4
-rw-r--r--messagebus_test/src/tests/compile-cpp/CMakeLists.txt8
-rw-r--r--messagebus_test/src/tests/compile-cpp/DESC2
-rw-r--r--messagebus_test/src/tests/compile-cpp/FILES1
-rw-r--r--messagebus_test/src/tests/compile-cpp/compile-cpp.cpp16
-rw-r--r--messagebus_test/src/tests/compile-java/.gitignore4
-rw-r--r--messagebus_test/src/tests/compile-java/CMakeLists.txt2
-rw-r--r--messagebus_test/src/tests/compile-java/DESC2
-rw-r--r--messagebus_test/src/tests/compile-java/FILES1
-rw-r--r--messagebus_test/src/tests/compile-java/TestCompile.java9
-rwxr-xr-xmessagebus_test/src/tests/compile-java/compile-java_test.sh12
-rw-r--r--messagebus_test/src/tests/error/.gitignore15
-rw-r--r--messagebus_test/src/tests/error/CMakeLists.txt21
-rw-r--r--messagebus_test/src/tests/error/DESC2
-rw-r--r--messagebus_test/src/tests/error/FILES8
-rw-r--r--messagebus_test/src/tests/error/JavaClient.java65
-rw-r--r--messagebus_test/src/tests/error/JavaServer.java47
-rw-r--r--messagebus_test/src/tests/error/cpp-client.cpp75
-rw-r--r--messagebus_test/src/tests/error/cpp-server.cpp73
-rwxr-xr-xmessagebus_test/src/tests/error/ctl.sh10
-rw-r--r--messagebus_test/src/tests/error/error.cpp49
-rwxr-xr-xmessagebus_test/src/tests/error/error_test.sh12
-rw-r--r--messagebus_test/src/tests/error/progdefs.sh3
-rw-r--r--messagebus_test/src/tests/error/routing-template.cfg11
-rw-r--r--messagebus_test/src/tests/errorcodes/.gitignore7
-rw-r--r--messagebus_test/src/tests/errorcodes/CMakeLists.txt9
-rw-r--r--messagebus_test/src/tests/errorcodes/DESC2
-rw-r--r--messagebus_test/src/tests/errorcodes/DumpCodes.java51
-rw-r--r--messagebus_test/src/tests/errorcodes/FILES5
-rw-r--r--messagebus_test/src/tests/errorcodes/dumpcodes.cpp70
-rwxr-xr-xmessagebus_test/src/tests/errorcodes/errorcodes_test.sh15
-rw-r--r--messagebus_test/src/tests/errorcodes/ref-dump.txt34
-rw-r--r--messagebus_test/src/tests/speed/.gitignore15
-rw-r--r--messagebus_test/src/tests/speed/CMakeLists.txt21
-rw-r--r--messagebus_test/src/tests/speed/DESC4
-rw-r--r--messagebus_test/src/tests/speed/FILES8
-rw-r--r--messagebus_test/src/tests/speed/JavaClient.java137
-rw-r--r--messagebus_test/src/tests/speed/JavaServer.java54
-rw-r--r--messagebus_test/src/tests/speed/cpp-client.cpp146
-rw-r--r--messagebus_test/src/tests/speed/cpp-server.cpp77
-rwxr-xr-xmessagebus_test/src/tests/speed/ctl.sh10
-rw-r--r--messagebus_test/src/tests/speed/progdefs.sh3
-rw-r--r--messagebus_test/src/tests/speed/routing-template.cfg11
-rw-r--r--messagebus_test/src/tests/speed/speed.cpp56
-rwxr-xr-xmessagebus_test/src/tests/speed/speed_test.sh13
-rw-r--r--messagebus_test/src/tests/trace/.gitignore12
-rw-r--r--messagebus_test/src/tests/trace/CMakeLists.txt15
-rw-r--r--messagebus_test/src/tests/trace/DESC1
-rw-r--r--messagebus_test/src/tests/trace/FILES19
-rw-r--r--messagebus_test/src/tests/trace/JavaServer.java97
-rw-r--r--messagebus_test/src/tests/trace/cpp-server.cpp90
-rwxr-xr-xmessagebus_test/src/tests/trace/ctl.sh10
-rw-r--r--messagebus_test/src/tests/trace/progdefs.sh15
-rw-r--r--messagebus_test/src/tests/trace/routing-template.cfg32
-rw-r--r--messagebus_test/src/tests/trace/trace.cpp121
-rwxr-xr-xmessagebus_test/src/tests/trace/trace_test.sh12
66 files changed, 1690 insertions, 0 deletions
diff --git a/messagebus_test/CMakeLists.txt b/messagebus_test/CMakeLists.txt
new file mode 100644
index 00000000000..96dc39327ac
--- /dev/null
+++ b/messagebus_test/CMakeLists.txt
@@ -0,0 +1,17 @@
+vespa_define_module(
+ DEPENDS
+ slobrok_slobrokserver
+ messagebus
+
+ APPS
+ src/binref
+
+ TESTS
+ src/tests/compile-cpp
+ src/tests/compile-java
+ src/tests/error
+ src/tests/errorcodes
+ src/tests/speed
+ src/tests/trace
+)
+
diff --git a/messagebus_test/OWNERS b/messagebus_test/OWNERS
new file mode 100644
index 00000000000..7379f3287ad
--- /dev/null
+++ b/messagebus_test/OWNERS
@@ -0,0 +1,3 @@
+dybis
+baldersheim
+
diff --git a/messagebus_test/README b/messagebus_test/README
new file mode 100644
index 00000000000..7c63f8b1a48
--- /dev/null
+++ b/messagebus_test/README
@@ -0,0 +1 @@
+This is the generic Vespa message bus infrastructure tests that combine C++ and Java.
diff --git a/messagebus_test/src/.gitignore b/messagebus_test/src/.gitignore
new file mode 100644
index 00000000000..8689bfd3624
--- /dev/null
+++ b/messagebus_test/src/.gitignore
@@ -0,0 +1,8 @@
+Makefile.inc
+Makefile.ini
+config.cfg
+config_command.sh
+configure
+project.dsw
+versiontag.mak
+/messagebus_test.mak
diff --git a/messagebus_test/src/binref/.gitignore b/messagebus_test/src/binref/.gitignore
new file mode 100644
index 00000000000..c1b83610972
--- /dev/null
+++ b/messagebus_test/src/binref/.gitignore
@@ -0,0 +1,5 @@
+.depend
+Makefile
+compilejava
+env.sh
+runjava
diff --git a/messagebus_test/src/binref/CMakeLists.txt b/messagebus_test/src/binref/CMakeLists.txt
new file mode 100644
index 00000000000..20594f98d02
--- /dev/null
+++ b/messagebus_test/src/binref/CMakeLists.txt
@@ -0,0 +1,5 @@
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+configure_file(compilejava.in compilejava @ONLY)
+configure_file(runjava.in runjava @ONLY)
+configure_file(env.sh.in env.sh @ONLY)
diff --git a/messagebus_test/src/binref/compilejava.in b/messagebus_test/src/binref/compilejava.in
new file mode 100755
index 00000000000..3dca3c2f3db
--- /dev/null
+++ b/messagebus_test/src/binref/compilejava.in
@@ -0,0 +1,11 @@
+#!/bin/sh
+unset VESPA_LOG_TARGET
+CLASSPATH=@PROJECT_SOURCE_DIR@/messagebus/target/messagebus-jar-with-dependencies.jar
+CLASSPATH=$CLASSPATH:@PROJECT_SOURCE_DIR@/component/target/component.jar
+CLASSPATH=$CLASSPATH:.
+
+if [ $# -lt 1 ]; then
+ echo "usage: compilejava file ..."
+ exit 1
+fi
+exec javac -d . -classpath $CLASSPATH "$@"
diff --git a/messagebus_test/src/binref/env.sh.in b/messagebus_test/src/binref/env.sh.in
new file mode 100644
index 00000000000..d485eb9dfea
--- /dev/null
+++ b/messagebus_test/src/binref/env.sh.in
@@ -0,0 +1,2 @@
+BINREF=@CMAKE_CURRENT_BINARY_DIR@
+export BINREF
diff --git a/messagebus_test/src/binref/progctl.sh b/messagebus_test/src/binref/progctl.sh
new file mode 120000
index 00000000000..2c1fb1d47ce
--- /dev/null
+++ b/messagebus_test/src/binref/progctl.sh
@@ -0,0 +1 @@
+../../../vespalib/src/vespa/vespalib/testkit/progctl.sh \ No newline at end of file
diff --git a/messagebus_test/src/binref/runjava.in b/messagebus_test/src/binref/runjava.in
new file mode 100755
index 00000000000..f6427a1f7cc
--- /dev/null
+++ b/messagebus_test/src/binref/runjava.in
@@ -0,0 +1,13 @@
+#!/bin/sh
+unset VESPA_LOG_TARGET
+unset LD_PRELOAD
+CLASSPATH=@PROJECT_SOURCE_DIR@/messagebus/target/messagebus-jar-with-dependencies.jar
+CLASSPATH=$CLASSPATH:@PROJECT_SOURCE_DIR@/component/target/component.jar
+CLASSPATH=$CLASSPATH:.
+if [ $# -lt 1 ]; then
+ echo "usage: runjava <class> [args]"
+ exit 1
+fi
+CLASS=$1
+shift
+exec java -cp $CLASSPATH $CLASS "$@"
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 <vespa/fastos/fastos.h>
+#include <vespa/log/log.h>
+LOG_SETUP("compile-cpp_test");
+#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/messagebus/routing/route.h>
+
+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..d99e3e841e5
--- /dev/null
+++ b/messagebus_test/src/tests/compile-java/compile-java_test.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+set -e
+
+if [ -z "$SOURCE_DIRECTORY" ]; then
+ SOURCE_DIRECTORY="."
+fi
+
+. ../../binref/env.sh
+
+$BINREF/compilejava $SOURCE_DIRECTORY/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..926047f31cd
--- /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_messagebus-test
+)
+vespa_add_executable(messagebus_test_cpp-server-error_app
+ SOURCES
+ cpp-server.cpp
+ DEPENDS
+ messagebus_messagebus-test
+)
+vespa_add_executable(messagebus_test_cpp-client-error_app
+ SOURCES
+ cpp-client.cpp
+ DEPENDS
+ messagebus_messagebus-test
+)
+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 <vespa/fastos/fastos.h>
+#include <vespa/log/log.h>
+LOG_SETUP("cpp-client");
+#include <vespa/messagebus/messagebus.h>
+#include <vespa/messagebus/sourcesession.h>
+#include <vespa/messagebus/testlib/simplemessage.h>
+#include <vespa/messagebus/testlib/simplereply.h>
+#include <vespa/messagebus/testlib/simpleprotocol.h>
+#include <vespa/messagebus/rpcmessagebus.h>
+#include <vespa/messagebus/errorcode.h>
+#include <vespa/messagebus/iprotocol.h>
+#include <vespa/messagebus/protocolset.h>
+#include <vespa/messagebus/sourcesessionparams.h>
+#include <vespa/messagebus/testlib/receptor.h>
+#include <vespa/vespalib/util/sync.h>
+
+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 <vespa/fastos/fastos.h>
+#include <vespa/log/log.h>
+LOG_SETUP("cpp-server");
+#include <vespa/messagebus/messagebus.h>
+#include <vespa/messagebus/destinationsession.h>
+#include <vespa/messagebus/testlib/simplemessage.h>
+#include <vespa/messagebus/testlib/simplereply.h>
+#include <vespa/messagebus/testlib/simpleprotocol.h>
+#include <vespa/messagebus/rpcmessagebus.h>
+#include <vespa/messagebus/iprotocol.h>
+#include <vespa/messagebus/protocolset.h>
+#include <vespa/messagebus/emptyreply.h>
+#include <vespa/messagebus/error.h>
+#include <vespa/messagebus/errorcode.h>
+
+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..ca4fc7701e6
--- /dev/null
+++ b/messagebus_test/src/tests/error/ctl.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+if [ -z "$SOURCE_DIRECTORY" ]; then
+ SOURCE_DIRECTORY="."
+fi
+
+. ../../binref/env.sh
+
+exec $SOURCE_DIRECTORY/../../binref/progctl.sh $SOURCE_DIRECTORY/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..749874a5ef2
--- /dev/null
+++ b/messagebus_test/src/tests/error/error.cpp
@@ -0,0 +1,49 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/fastos/fastos.h>
+#include <vespa/log/log.h>
+LOG_SETUP("error_test");
+#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/vespalib/testkit/test_kit.h>
+#include <vespa/messagebus/testlib/slobrok.h>
+#include <vespa/vespalib/util/stringfmt.h>
+
+using namespace mbus;
+using vespalib::make_string;
+
+TEST_SETUP(Test);
+
+int
+Test::Main()
+{
+ TEST_INIT("error_test");
+ Slobrok slobrok;
+ const std::string routing_template = TEST_PATH("routing-template.cfg");
+ const std::string ctl_script = TEST_PATH("ctl.sh");
+
+ { // 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 + " | sed 's#session#cpp/session#' > routing.cfg").c_str()) == 0);
+ }
+ fprintf(stderr, "STARTING CPP-SERVER\n");
+ EXPECT_TRUE(system((ctl_script + " start server cpp").c_str()) == 0);
+ EXPECT_TRUE(system("./messagebus_test_cpp-client-error_app") == 0);
+ EXPECT_TRUE(system("../../binref/runjava JavaClient") == 0);
+ EXPECT_TRUE(system((ctl_script + " stop server cpp").c_str()) == 0);
+ }
+ { // JAVA SERVER
+ { // Make routing config
+ EXPECT_TRUE(system(("cat " + routing_template + " | sed 's#session#java/session#' > routing.cfg").c_str()) == 0);
+ }
+ fprintf(stderr, "STARTING JAVA-SERVER\n");
+ EXPECT_TRUE(system((ctl_script + " start server java").c_str()) == 0);
+ EXPECT_TRUE(system("./messagebus_test_cpp-client-error_app") == 0);
+ EXPECT_TRUE(system("../../binref/runjava JavaClient") == 0);
+ EXPECT_TRUE(system((ctl_script + " stop server java").c_str()) == 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..0c39f3d1ad3
--- /dev/null
+++ b/messagebus_test/src/tests/error/error_test.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+set -e
+
+if [ -z "$SOURCE_DIRECTORY" ]; then
+ SOURCE_DIRECTORY="."
+fi
+
+. ../../binref/env.sh
+
+$BINREF/compilejava $SOURCE_DIRECTORY/JavaServer.java
+$BINREF/compilejava $SOURCE_DIRECTORY/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..47d02d95b93
--- /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..b996c58464c
--- /dev/null
+++ b/messagebus_test/src/tests/errorcodes/CMakeLists.txt
@@ -0,0 +1,9 @@
+# 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
+ messagebus
+)
+vespa_add_test(NAME messagebus_test_dumpcodes_app NO_VALGRIND COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/errorcodes_test.sh
+ DEPENDS messagebus_test_dumpcodes_app)
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 <vespa/fastos/fastos.h>
+#include <vespa/log/log.h>
+LOG_SETUP("dumpcodes");
+#include <vespa/messagebus/errorcode.h>
+#include <string>
+
+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 100755
index 00000000000..e6ecc033ef3
--- /dev/null
+++ b/messagebus_test/src/tests/errorcodes/errorcodes_test.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+set -e
+
+if [ -z "$SOURCE_DIRECTORY" ]; then
+ SOURCE_DIRECTORY="."
+fi
+
+. ../../binref/env.sh
+
+$BINREF/compilejava $SOURCE_DIRECTORY/DumpCodes.java
+
+./messagebus_test_dumpcodes_app > cpp-dump.txt
+$BINREF/runjava DumpCodes > java-dump.txt
+diff -u $SOURCE_DIRECTORY/ref-dump.txt cpp-dump.txt
+diff -u $SOURCE_DIRECTORY/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..5a5f9615c42
--- /dev/null
+++ b/messagebus_test/src/tests/speed/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_speed_test_app
+ SOURCES
+ speed.cpp
+ DEPENDS
+ messagebus_messagebus-test
+)
+vespa_add_executable(messagebus_test_cpp-server-speed_app
+ SOURCES
+ cpp-server.cpp
+ DEPENDS
+ messagebus_messagebus-test
+)
+vespa_add_executable(messagebus_test_cpp-client-speed_app
+ SOURCES
+ cpp-client.cpp
+ DEPENDS
+ messagebus_messagebus-test
+)
+vespa_add_test(NAME messagebus_test_speed_test_app COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/speed_test.sh BENCHMARK
+ DEPENDS messagebus_test_speed_test_app messagebus_test_cpp-server-speed_app messagebus_test_cpp-client-speed_app )
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 <vespa/fastos/fastos.h>
+#include <vespa/log/log.h>
+LOG_SETUP("cpp-client");
+#include <vespa/messagebus/messagebus.h>
+#include <vespa/messagebus/routing/retrytransienterrorspolicy.h>
+#include <vespa/messagebus/rpcmessagebus.h>
+#include <vespa/messagebus/sourcesession.h>
+#include <vespa/messagebus/sourcesessionparams.h>
+#include <vespa/messagebus/testlib/simplemessage.h>
+#include <vespa/messagebus/testlib/simpleprotocol.h>
+#include <vespa/messagebus/testlib/simplereply.h>
+#include <vespa/vespalib/util/sync.h>
+
+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 &params);
+ ~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 &params)
+ : _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<SimpleReply&>(*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 <vespa/fastos/fastos.h>
+#include <vespa/log/log.h>
+LOG_SETUP("cpp-server");
+#include <vespa/messagebus/messagebus.h>
+#include <vespa/messagebus/destinationsession.h>
+#include <vespa/messagebus/testlib/simplemessage.h>
+#include <vespa/messagebus/testlib/simplereply.h>
+#include <vespa/messagebus/testlib/simpleprotocol.h>
+#include <vespa/messagebus/rpcmessagebus.h>
+#include <vespa/messagebus/iprotocol.h>
+#include <vespa/messagebus/protocolset.h>
+
+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<SimpleMessage&>(*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..ca4fc7701e6
--- /dev/null
+++ b/messagebus_test/src/tests/speed/ctl.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+if [ -z "$SOURCE_DIRECTORY" ]; then
+ SOURCE_DIRECTORY="."
+fi
+
+. ../../binref/env.sh
+
+exec $SOURCE_DIRECTORY/../../binref/progctl.sh $SOURCE_DIRECTORY/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..0b2bd600db0
--- /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..1cfe1ff5704
--- /dev/null
+++ b/messagebus_test/src/tests/speed/speed.cpp
@@ -0,0 +1,56 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/fastos/fastos.h>
+#include <vespa/log/log.h>
+LOG_SETUP("speed_test");
+#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/vespalib/testkit/test_kit.h>
+#include <vespa/messagebus/testlib/slobrok.h>
+#include <vespa/vespalib/util/stringfmt.h>
+
+using namespace mbus;
+using vespalib::make_string;
+
+TEST_SETUP(Test);
+
+int
+Test::Main()
+{
+ TEST_INIT("speed_test");
+ Slobrok slobrok;
+
+ const std::string routing_template = TEST_PATH("routing-template.cfg");
+ const std::string ctl_script = TEST_PATH("ctl.sh");
+
+ { // 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 + " | sed 's#session#cpp/session#' > routing.cfg").c_str()), 0);
+ }
+ fprintf(stderr, "STARTING CPP-SERVER\n");
+ EXPECT_EQUAL(system((ctl_script + " start server cpp").c_str()), 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((ctl_script + " stop server cpp").c_str()), 0);
+ }
+ { // JAVA SERVER
+ { // Make routing config
+ EXPECT_EQUAL(system(("cat " + routing_template + " | sed 's#session#java/session#' > routing.cfg").c_str()), 0);
+ }
+ fprintf(stderr, "STARTING JAVA-SERVER\n");
+ EXPECT_EQUAL(system((ctl_script + " start server java").c_str()), 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((ctl_script + " stop server java").c_str()), 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 100755
index 00000000000..1d9ba27f84e
--- /dev/null
+++ b/messagebus_test/src/tests/speed/speed_test.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+set -e
+
+if [ -z "$SOURCE_DIRECTORY" ]; then
+ SOURCE_DIRECTORY="."
+fi
+
+. ../../binref/env.sh
+
+$BINREF/compilejava $SOURCE_DIRECTORY/JavaServer.java
+$BINREF/compilejava $SOURCE_DIRECTORY/JavaClient.java
+
+(ulimit -c; ulimit -H -c; ulimit -c unlimited; $VALGRIND ./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..f43d66d9122
--- /dev/null
+++ b/messagebus_test/src/tests/trace/CMakeLists.txt
@@ -0,0 +1,15 @@
+# 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
+ messagebus_messagebus-test
+)
+vespa_add_executable(messagebus_test_cpp-server-trace_app
+ SOURCES
+ cpp-server.cpp
+ DEPENDS
+ messagebus_messagebus-test
+)
+vespa_add_test(NAME messagebus_test_trace_test_app NO_VALGRIND COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/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 <service prefix>");
+ 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.<Protocol>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 <vespa/fastos/fastos.h>
+#include <vespa/log/log.h>
+LOG_SETUP("cpp-server");
+#include <vespa/messagebus/messagebus.h>
+#include <vespa/messagebus/destinationsession.h>
+#include <vespa/messagebus/testlib/simplemessage.h>
+#include <vespa/messagebus/testlib/simplereply.h>
+#include <vespa/messagebus/testlib/simpleprotocol.h>
+#include <vespa/messagebus/rpcmessagebus.h>
+#include <vespa/messagebus/iprotocol.h>
+#include <vespa/messagebus/protocolset.h>
+#include <vespa/messagebus/emptyreply.h>
+
+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 <service-prefix>\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..ca4fc7701e6
--- /dev/null
+++ b/messagebus_test/src/tests/trace/ctl.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+if [ -z "$SOURCE_DIRECTORY" ]; then
+ SOURCE_DIRECTORY="."
+fi
+
+. ../../binref/env.sh
+
+exec $SOURCE_DIRECTORY/../../binref/progctl.sh $SOURCE_DIRECTORY/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..4071da4beb5
--- /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/routing-template.cfg b/messagebus_test/src/tests/trace/routing-template.cfg
new file mode 100644
index 00000000000..72318131b99
--- /dev/null
+++ b/messagebus_test/src/tests/trace/routing-template.cfg
@@ -0,0 +1,32 @@
+routingtable[1]
+routingtable[0].protocol "Simple"
+routingtable[0].hop[3]
+routingtable[0].hop[0].name "hop1"
+routingtable[0].hop[0].selector "server/[All]/1/[All]/session"
+routingtable[0].hop[0].recipient[2]
+routingtable[0].hop[0].recipient[0] "server/cpp/1/A/session"
+routingtable[0].hop[0].recipient[1] "server/java/1/A/session"
+routingtable[0].hop[1].name "hop2"
+routingtable[0].hop[1].selector "server/[All]/2/[All]/session"
+routingtable[0].hop[1].recipient[4]
+routingtable[0].hop[1].recipient[0] "server/cpp/2/A/session"
+routingtable[0].hop[1].recipient[1] "server/cpp/2/B/session"
+routingtable[0].hop[1].recipient[2] "server/java/2/A/session"
+routingtable[0].hop[1].recipient[3] "server/java/2/B/session"
+routingtable[0].hop[2].name "hop3"
+routingtable[0].hop[2].selector "server/[All]/3/[All]/session"
+routingtable[0].hop[2].recipient[8]
+routingtable[0].hop[2].recipient[0] "server/cpp/3/A/session"
+routingtable[0].hop[2].recipient[1] "server/cpp/3/B/session"
+routingtable[0].hop[2].recipient[2] "server/cpp/3/C/session"
+routingtable[0].hop[2].recipient[3] "server/cpp/3/D/session"
+routingtable[0].hop[2].recipient[4] "server/java/3/A/session"
+routingtable[0].hop[2].recipient[5] "server/java/3/B/session"
+routingtable[0].hop[2].recipient[6] "server/java/3/C/session"
+routingtable[0].hop[2].recipient[7] "server/java/3/D/session"
+routingtable[0].route[1]
+routingtable[0].route[0].name "test"
+routingtable[0].route[0].hop[3]
+routingtable[0].route[0].hop[0] "hop1"
+routingtable[0].route[0].hop[1] "hop2"
+routingtable[0].route[0].hop[2] "hop3"
diff --git a/messagebus_test/src/tests/trace/trace.cpp b/messagebus_test/src/tests/trace/trace.cpp
new file mode 100644
index 00000000000..f25c776ca74
--- /dev/null
+++ b/messagebus_test/src/tests/trace/trace.cpp
@@ -0,0 +1,121 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/fastos/fastos.h>
+#include <vespa/log/log.h>
+LOG_SETUP("trace_test");
+#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/vespalib/testkit/test_kit.h>
+#include <vespa/messagebus/testlib/slobrok.h>
+#include <vespa/vespalib/util/stringfmt.h>
+#include <vespa/messagebus/emptyreply.h>
+#include <vespa/messagebus/messagebus.h>
+#include <vespa/messagebus/sourcesession.h>
+#include <vespa/messagebus/rpcmessagebus.h>
+#include <vespa/messagebus/intermediatesession.h>
+#include <vespa/messagebus/destinationsession.h>
+#include <vespa/messagebus/testlib/slobrok.h>
+#include <vespa/messagebus/testlib/testserver.h>
+#include <vespa/messagebus/routing/routingspec.h>
+#include <vespa/messagebus/testlib/receptor.h>
+#include <vespa/messagebus/sourcesessionparams.h>
+#include <vespa/messagebus/testlib/simplemessage.h>
+#include <vespa/messagebus/testlib/simplereply.h>
+#include <vespa/messagebus/testlib/simpleprotocol.h>
+#include <iostream>
+
+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;
+ const std::string routing_template = TEST_PATH("routing-template.cfg");
+ const std::string ctl_script = TEST_PATH("ctl.sh");
+
+ { // 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);
+ }
+ { // Make routing config
+ EXPECT_TRUE(system(("cat " + routing_template + " > routing.cfg").c_str()) == 0);
+ }
+
+ EXPECT_TRUE(system((ctl_script + " start all").c_str()) == 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((ctl_script + " stop all").c_str()) == 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 100755
index 00000000000..7bd344a8618
--- /dev/null
+++ b/messagebus_test/src/tests/trace/trace_test.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+set -e
+
+if [ -z "$SOURCE_DIRECTORY" ]; then
+ SOURCE_DIRECTORY="."
+fi
+
+. ../../binref/env.sh
+
+$BINREF/compilejava $SOURCE_DIRECTORY/JavaServer.java
+
+$VALGRIND ./messagebus_test_trace_test_app