diff options
Diffstat (limited to 'messagebus_test/src/tests/error')
-rw-r--r-- | messagebus_test/src/tests/error/.gitignore | 15 | ||||
-rw-r--r-- | messagebus_test/src/tests/error/CMakeLists.txt | 21 | ||||
-rw-r--r-- | messagebus_test/src/tests/error/DESC | 2 | ||||
-rw-r--r-- | messagebus_test/src/tests/error/FILES | 8 | ||||
-rw-r--r-- | messagebus_test/src/tests/error/JavaClient.java | 65 | ||||
-rw-r--r-- | messagebus_test/src/tests/error/JavaServer.java | 47 | ||||
-rw-r--r-- | messagebus_test/src/tests/error/cpp-client.cpp | 75 | ||||
-rw-r--r-- | messagebus_test/src/tests/error/cpp-server.cpp | 73 | ||||
-rwxr-xr-x | messagebus_test/src/tests/error/ctl.sh | 10 | ||||
-rw-r--r-- | messagebus_test/src/tests/error/error.cpp | 49 | ||||
-rwxr-xr-x | messagebus_test/src/tests/error/error_test.sh | 12 | ||||
-rw-r--r-- | messagebus_test/src/tests/error/progdefs.sh | 3 | ||||
-rw-r--r-- | messagebus_test/src/tests/error/routing-template.cfg | 11 |
13 files changed, 391 insertions, 0 deletions
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" |