summaryrefslogtreecommitdiffstats
path: root/jrt_test/src/tests/rpc-error/test-errors.cpp
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /jrt_test/src/tests/rpc-error/test-errors.cpp
Publish
Diffstat (limited to 'jrt_test/src/tests/rpc-error/test-errors.cpp')
-rw-r--r--jrt_test/src/tests/rpc-error/test-errors.cpp168
1 files changed, 168 insertions, 0 deletions
diff --git a/jrt_test/src/tests/rpc-error/test-errors.cpp b/jrt_test/src/tests/rpc-error/test-errors.cpp
new file mode 100644
index 00000000000..fd167b85085
--- /dev/null
+++ b/jrt_test/src/tests/rpc-error/test-errors.cpp
@@ -0,0 +1,168 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/fnet/frt/frt.h>
+
+
+class TestErrors : public vespalib::TestApp
+{
+private:
+ FRT_Supervisor *client;
+ FRT_Target *target;
+
+public:
+ void init(const char *spec) {
+ client = new FRT_Supervisor;
+ target = client->GetTarget(spec);
+ client->Start();
+ }
+
+ void fini() {
+ target->SubRef();
+ target = NULL;
+ client->ShutDown(true);
+ delete client;
+ client = NULL;
+ }
+
+ void testNoError();
+ void testNoSuchMethod();
+ void testWrongParameters();
+ void testWrongReturnValues();
+ void testMethodFailed();
+ int Main();
+};
+
+
+void
+TestErrors::testNoError()
+{
+ FRT_RPCRequest *req1 = client->AllocRPCRequest();
+ req1->SetMethodName("test");
+ req1->GetParams()->AddInt32(42);
+ req1->GetParams()->AddInt32(0);
+ req1->GetParams()->AddInt8(0);
+ target->InvokeSync(req1, 60.0);
+ EXPECT_TRUE(!req1->IsError());
+ if (EXPECT_TRUE(1 == req1->GetReturn()->GetNumValues())) {
+ EXPECT_TRUE(42 == req1->GetReturn()->GetValue(0)._intval32);
+ } else {
+ EXPECT_TRUE(false);
+ }
+ req1->SubRef();
+}
+
+
+void
+TestErrors::testNoSuchMethod()
+{
+ FRT_RPCRequest *req1 = client->AllocRPCRequest();
+ req1->SetMethodName("bogus");
+ target->InvokeSync(req1, 60.0);
+ EXPECT_TRUE(req1->IsError());
+ EXPECT_TRUE(0 == req1->GetReturn()->GetNumValues());
+ EXPECT_TRUE(FRTE_RPC_NO_SUCH_METHOD == req1->GetErrorCode());
+ req1->SubRef();
+}
+
+
+void
+TestErrors::testWrongParameters()
+{
+ FRT_RPCRequest *req1 = client->AllocRPCRequest();
+ req1->SetMethodName("test");
+ req1->GetParams()->AddInt32(42);
+ req1->GetParams()->AddInt32(0);
+ req1->GetParams()->AddInt32(0);
+ target->InvokeSync(req1, 60.0);
+ EXPECT_TRUE(req1->IsError());
+ EXPECT_TRUE(0 == req1->GetReturn()->GetNumValues());
+ EXPECT_TRUE(FRTE_RPC_WRONG_PARAMS == req1->GetErrorCode());
+ req1->SubRef();
+
+ FRT_RPCRequest *req2 = client->AllocRPCRequest();
+ req2->SetMethodName("test");
+ req2->GetParams()->AddInt32(42);
+ req2->GetParams()->AddInt32(0);
+ target->InvokeSync(req2, 60.0);
+ EXPECT_TRUE(req2->IsError());
+ EXPECT_TRUE(0 == req2->GetReturn()->GetNumValues());
+ EXPECT_TRUE(FRTE_RPC_WRONG_PARAMS == req2->GetErrorCode());
+ req2->SubRef();
+
+ FRT_RPCRequest *req3 = client->AllocRPCRequest();
+ req3->SetMethodName("test");
+ req3->GetParams()->AddInt32(42);
+ req3->GetParams()->AddInt32(0);
+ req3->GetParams()->AddInt8(0);
+ req3->GetParams()->AddInt8(0);
+ target->InvokeSync(req3, 60.0);
+ EXPECT_TRUE(req3->IsError());
+ EXPECT_TRUE(0 == req3->GetReturn()->GetNumValues());
+ EXPECT_TRUE(FRTE_RPC_WRONG_PARAMS == req3->GetErrorCode());
+ req3->SubRef();
+}
+
+
+void
+TestErrors::testWrongReturnValues()
+{
+ FRT_RPCRequest *req1 = client->AllocRPCRequest();
+ req1->SetMethodName("test");
+ req1->GetParams()->AddInt32(42);
+ req1->GetParams()->AddInt32(0);
+ req1->GetParams()->AddInt8(1);
+ target->InvokeSync(req1, 60.0);
+ EXPECT_TRUE(req1->IsError());
+ EXPECT_TRUE(0 == req1->GetReturn()->GetNumValues());
+ EXPECT_TRUE(FRTE_RPC_WRONG_RETURN == req1->GetErrorCode());
+ req1->SubRef();
+}
+
+
+void
+TestErrors::testMethodFailed()
+{
+ FRT_RPCRequest *req1 = client->AllocRPCRequest();
+ req1->SetMethodName("test");
+ req1->GetParams()->AddInt32(42);
+ req1->GetParams()->AddInt32(75000);
+ req1->GetParams()->AddInt8(0);
+ target->InvokeSync(req1, 60.0);
+ EXPECT_TRUE(req1->IsError());
+ EXPECT_TRUE(0 == req1->GetReturn()->GetNumValues());
+ EXPECT_TRUE(75000 == req1->GetErrorCode());
+ req1->SubRef();
+
+ FRT_RPCRequest *req2 = client->AllocRPCRequest();
+ req2->SetMethodName("test");
+ req2->GetParams()->AddInt32(42);
+ req2->GetParams()->AddInt32(75000);
+ req2->GetParams()->AddInt8(1);
+ target->InvokeSync(req2, 60.0);
+ EXPECT_TRUE(req2->IsError());
+ EXPECT_TRUE(0 == req2->GetReturn()->GetNumValues());
+ EXPECT_TRUE(75000 == req2->GetErrorCode());
+ req2->SubRef();
+}
+
+
+int
+TestErrors::Main()
+{
+ if (_argc != 2) {
+ fprintf(stderr, "usage: %s spec", _argv[0]);
+ return 1;
+ }
+ TEST_INIT("test_errors");
+ init(_argv[1]);
+ testNoError();
+ testNoSuchMethod();
+ testWrongParameters();
+ testWrongReturnValues();
+ testMethodFailed();
+ fini();
+ TEST_DONE();
+}
+
+
+TEST_APPHOOK(TestErrors);