summaryrefslogtreecommitdiffstats
path: root/jrt_test/src/tests/mandatory-methods
diff options
context:
space:
mode:
Diffstat (limited to 'jrt_test/src/tests/mandatory-methods')
-rw-r--r--jrt_test/src/tests/mandatory-methods/.gitignore8
-rw-r--r--jrt_test/src/tests/mandatory-methods/CMakeLists.txt7
-rw-r--r--jrt_test/src/tests/mandatory-methods/DESC10
-rw-r--r--jrt_test/src/tests/mandatory-methods/FILES6
-rw-r--r--jrt_test/src/tests/mandatory-methods/RPCServer.java21
-rw-r--r--jrt_test/src/tests/mandatory-methods/dotest.sh14
-rw-r--r--jrt_test/src/tests/mandatory-methods/extract-reflection.cpp145
-rwxr-xr-xjrt_test/src/tests/mandatory-methods/mandatory-methods_test.sh10
-rw-r--r--jrt_test/src/tests/mandatory-methods/progdefs.sh2
-rw-r--r--jrt_test/src/tests/mandatory-methods/ref.txt26
10 files changed, 249 insertions, 0 deletions
diff --git a/jrt_test/src/tests/mandatory-methods/.gitignore b/jrt_test/src/tests/mandatory-methods/.gitignore
new file mode 100644
index 00000000000..c5d116be3c2
--- /dev/null
+++ b/jrt_test/src/tests/mandatory-methods/.gitignore
@@ -0,0 +1,8 @@
+.depend
+Makefile
+RPCServer.class
+extract-reflection
+out.javaserver.1
+out.txt
+pid.txt
+jrt_test_extract-reflection_app
diff --git a/jrt_test/src/tests/mandatory-methods/CMakeLists.txt b/jrt_test/src/tests/mandatory-methods/CMakeLists.txt
new file mode 100644
index 00000000000..f4496d86cbb
--- /dev/null
+++ b/jrt_test/src/tests/mandatory-methods/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(jrt_test_extract-reflection_app
+ SOURCES
+ extract-reflection.cpp
+ DEPENDS
+)
+vespa_add_test(NAME jrt_test_extract-reflection_app NO_VALGRIND COMMAND sh mandatory-methods_test.sh)
diff --git a/jrt_test/src/tests/mandatory-methods/DESC b/jrt_test/src/tests/mandatory-methods/DESC
new file mode 100644
index 00000000000..2cb4f467a2e
--- /dev/null
+++ b/jrt_test/src/tests/mandatory-methods/DESC
@@ -0,0 +1,10 @@
+Test the mandatory methods of a Java RPC server
+(ping/reflection). This is done by using a C++ client against a
+barebone Java server. The ping method is used to poll the server while
+waiting for it to come up. The reflection methods are used to extract
+reflection information about the mandatory methods, which is checked
+against a checked-in expected result.
+
+This test will break easily if the documentation of the mandatory
+methods is changed or if the method iteration order is changed. This
+will not happen often, and the test is easily updated.
diff --git a/jrt_test/src/tests/mandatory-methods/FILES b/jrt_test/src/tests/mandatory-methods/FILES
new file mode 100644
index 00000000000..4bfb761c16d
--- /dev/null
+++ b/jrt_test/src/tests/mandatory-methods/FILES
@@ -0,0 +1,6 @@
+dotest.sh
+out.txt
+ref.txt
+RPCServer.java
+extract-reflection.cpp
+out.javaserver.1
diff --git a/jrt_test/src/tests/mandatory-methods/RPCServer.java b/jrt_test/src/tests/mandatory-methods/RPCServer.java
new file mode 100644
index 00000000000..a9fe3bae7b0
--- /dev/null
+++ b/jrt_test/src/tests/mandatory-methods/RPCServer.java
@@ -0,0 +1,21 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+import com.yahoo.jrt.*;
+
+public class RPCServer {
+
+ public static void main(String[] args) {
+ if (args.length != 1) {
+ System.err.println("usage: RPCServer <spec>");
+ System.exit(1);
+ }
+ Supervisor orb = new Supervisor(new Transport());
+ try {
+ orb.listen(new Spec(args[0]));
+ } catch (ListenFailedException e) {
+ System.err.println("could not listen at " + args[0]);
+ System.exit(1);
+ }
+ orb.transport().join();
+ }
+}
diff --git a/jrt_test/src/tests/mandatory-methods/dotest.sh b/jrt_test/src/tests/mandatory-methods/dotest.sh
new file mode 100644
index 00000000000..25560a6210d
--- /dev/null
+++ b/jrt_test/src/tests/mandatory-methods/dotest.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+sh $BINREF/progctl.sh progdefs.sh start javaserver 1
+
+./jrt_test_extract-reflection_app tcp/localhost:$PORT_1 verbose > out.txt
+
+sh $BINREF/progctl.sh progdefs.sh stop javaserver 1
+
+if diff -u out.txt ref.txt; then
+ exit 0
+else
+ exit 1
+fi
diff --git a/jrt_test/src/tests/mandatory-methods/extract-reflection.cpp b/jrt_test/src/tests/mandatory-methods/extract-reflection.cpp
new file mode 100644
index 00000000000..7b92997cfdf
--- /dev/null
+++ b/jrt_test/src/tests/mandatory-methods/extract-reflection.cpp
@@ -0,0 +1,145 @@
+// 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/fnet/frt/frt.h>
+
+class RPCInfo : public FastOS_Application
+{
+public:
+
+ void GetReq(FRT_RPCRequest **req, FRT_Supervisor *supervisor)
+ {
+ if ((*req) != NULL)
+ (*req)->SubRef();
+ (*req) = supervisor->AllocRPCRequest();
+ }
+
+ void FreeReqs(FRT_RPCRequest *r1, FRT_RPCRequest *r2)
+ {
+ if (r1 != NULL)
+ r1->SubRef();
+ if (r2 != NULL)
+ r2->SubRef();
+ }
+
+ void DumpMethodInfo(const char *indent, FRT_RPCRequest *info,
+ const char *name)
+ {
+ if (info->IsError()) {
+ printf("%sMETHOD %s\n", indent, name);
+ printf("%s [error(%d): %s]\n\n", indent,
+ info->GetErrorCode(),
+ info->GetErrorMessage());
+ return;
+ }
+
+ const char *desc = info->GetReturn()->GetValue(0)._string._str;
+ const char *arg = info->GetReturn()->GetValue(1)._string._str;
+ const char *ret = info->GetReturn()->GetValue(2)._string._str;
+ uint32_t argCnt = strlen(arg);
+ uint32_t retCnt = strlen(ret);
+ FRT_StringValue *argName = info->GetReturn()->GetValue(3)._string_array._pt;
+ FRT_StringValue *argDesc = info->GetReturn()->GetValue(4)._string_array._pt;
+ FRT_StringValue *retName = info->GetReturn()->GetValue(5)._string_array._pt;
+ FRT_StringValue *retDesc = info->GetReturn()->GetValue(6)._string_array._pt;
+
+ printf("%sMETHOD %s\n", indent, name);
+ printf("%s DESCRIPTION:\n"
+ "%s %s\n", indent, indent, desc);
+
+ if (argCnt > 0) {
+ printf("%s PARAMS:\n", indent);
+ for (uint32_t a = 0; a < argCnt; a++)
+ printf("%s [%c][%s] %s\n", indent, arg[a], argName[a]._str,
+ argDesc[a]._str);
+ }
+
+ if (retCnt > 0) {
+ printf("%s RETURN:\n", indent);
+ for (uint32_t r = 0; r < retCnt; r++)
+ printf("%s [%c][%s] %s\n", indent, ret[r], retName[r]._str,
+ retDesc[r]._str);
+ }
+ printf("\n");
+ }
+
+
+ int Main()
+ {
+ if (_argc < 2) {
+ printf("usage : rpc_info <connectspec> [verbose]\n");
+ return 1;
+ }
+
+ bool verbose = (_argc > 2 && strcmp(_argv[2], "verbose") == 0);
+ FRT_Supervisor supervisor;
+ FRT_Target *target = supervisor.GetTarget(_argv[1]);
+ FRT_RPCRequest *m_list = NULL;
+ FRT_RPCRequest *info = NULL;
+ supervisor.Start();
+
+ for (int i = 0; i < 50; i++) {
+ GetReq(&info, &supervisor);
+ info->SetMethodName("frt.rpc.ping");
+ target->InvokeSync(info, 60.0);
+ if (info->GetErrorCode() != FRTE_RPC_CONNECTION) {
+ break;
+ }
+ FastOS_Thread::Sleep(1000);
+ target->SubRef();
+ target = supervisor.GetTarget(_argv[1]);
+ }
+ if (info->IsError()) {
+ fprintf(stderr, "Error talking to %s\n", _argv[1]);
+ info->Print();
+ FreeReqs(m_list, info);
+ supervisor.ShutDown(true);
+ return 1;
+ }
+
+ GetReq(&m_list, &supervisor);
+ m_list->SetMethodName("frt.rpc.getMethodList");
+ target->InvokeSync(m_list, 60.0);
+
+ if (!m_list->IsError()) {
+
+ uint32_t numMethods = m_list->GetReturn()->GetValue(0)._string_array._len;
+ FRT_StringValue *methods = m_list->GetReturn()->GetValue(0)._string_array._pt;
+ FRT_StringValue *arglist = m_list->GetReturn()->GetValue(1)._string_array._pt;
+ FRT_StringValue *retlist = m_list->GetReturn()->GetValue(2)._string_array._pt;
+
+ for (uint32_t m = 0; m < numMethods; m++) {
+
+ if (verbose) {
+
+ GetReq(&info, &supervisor);
+ info->SetMethodName("frt.rpc.getMethodInfo");
+ info->GetParams()->AddString(methods[m]._str);
+ target->InvokeSync(info, 60.0);
+ DumpMethodInfo("", info, methods[m]._str);
+
+ } else {
+
+ printf("METHOD [%s] <- %s <- [%s]\n",
+ retlist[m]._str, methods[m]._str, arglist[m]._str);
+ }
+ }
+ } else {
+ fprintf(stderr, " [error(%d): %s]\n",
+ m_list->GetErrorCode(),
+ m_list->GetErrorMessage());
+ }
+ FreeReqs(m_list, info);
+ target->SubRef();
+ supervisor.ShutDown(true);
+ return 0;
+ }
+};
+
+
+int
+main(int argc, char **argv)
+{
+ RPCInfo myapp;
+ return myapp.Entry(argc, argv);
+}
diff --git a/jrt_test/src/tests/mandatory-methods/mandatory-methods_test.sh b/jrt_test/src/tests/mandatory-methods/mandatory-methods_test.sh
new file mode 100755
index 00000000000..bf86849d9c1
--- /dev/null
+++ b/jrt_test/src/tests/mandatory-methods/mandatory-methods_test.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+. ../../binref/env.sh
+export PORT_1
+
+$BINREF/compilejava RPCServer.java
+
+sh dotest.sh || (sh $BINREF/progctl.sh progdefs.sh stop all; false)
+sh $BINREF/progctl.sh progdefs.sh stop all
+
diff --git a/jrt_test/src/tests/mandatory-methods/progdefs.sh b/jrt_test/src/tests/mandatory-methods/progdefs.sh
new file mode 100644
index 00000000000..aa7ae4ab3ca
--- /dev/null
+++ b/jrt_test/src/tests/mandatory-methods/progdefs.sh
@@ -0,0 +1,2 @@
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+prog javaserver 1 "tcp/$PORT_1" "$BINREF/runjava RPCServer"
diff --git a/jrt_test/src/tests/mandatory-methods/ref.txt b/jrt_test/src/tests/mandatory-methods/ref.txt
new file mode 100644
index 00000000000..785181bca6d
--- /dev/null
+++ b/jrt_test/src/tests/mandatory-methods/ref.txt
@@ -0,0 +1,26 @@
+METHOD frt.rpc.getMethodInfo
+ DESCRIPTION:
+ Obtain detailed information about a single method
+ PARAMS:
+ [s][methodName] The method we want information about
+ RETURN:
+ [s][desc] Description of what the method does
+ [s][params] Method parameter types
+ [s][return] Method return values
+ [S][paramNames] Method parameter names
+ [S][paramDesc] Method parameter descriptions
+ [S][returnNames] Method return value names
+ [S][returnDesc] Method return value descriptions
+
+METHOD frt.rpc.getMethodList
+ DESCRIPTION:
+ Obtain a list of all available methods
+ RETURN:
+ [S][names] Method names
+ [S][params] Method parameter types
+ [S][return] Method return types
+
+METHOD frt.rpc.ping
+ DESCRIPTION:
+ Method that may be used to check if the server is online
+