diff options
author | Haavard <havardpe@yahoo-inc.com> | 2016-08-23 12:13:45 +0000 |
---|---|---|
committer | Haavard <havardpe@yahoo-inc.com> | 2016-08-23 12:13:45 +0000 |
commit | cb47dcb04043330a577f88e112dcc2f2040316c8 (patch) | |
tree | 0cdd446c62d42227a52ab228877d23bad3546945 /config/src/tests/file_acquirer | |
parent | afe2a3933ac429469109047b2e29529ca0be8560 (diff) |
added unit test for rpc file acquirer
Diffstat (limited to 'config/src/tests/file_acquirer')
-rw-r--r-- | config/src/tests/file_acquirer/.gitignore | 1 | ||||
-rw-r--r-- | config/src/tests/file_acquirer/CMakeLists.txt | 8 | ||||
-rw-r--r-- | config/src/tests/file_acquirer/file_acquirer_test.cpp | 44 |
3 files changed, 53 insertions, 0 deletions
diff --git a/config/src/tests/file_acquirer/.gitignore b/config/src/tests/file_acquirer/.gitignore new file mode 100644 index 00000000000..45df7a8e0ab --- /dev/null +++ b/config/src/tests/file_acquirer/.gitignore @@ -0,0 +1 @@ +/config_file_acquirer_test_app diff --git a/config/src/tests/file_acquirer/CMakeLists.txt b/config/src/tests/file_acquirer/CMakeLists.txt new file mode 100644 index 00000000000..1b68d767df7 --- /dev/null +++ b/config/src/tests/file_acquirer/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(config_file_acquirer_test_app TEST + SOURCES + file_acquirer_test.cpp + DEPENDS + config_cloudconfig +) +vespa_add_test(NAME config_file_acquirer_test_app COMMAND config_file_acquirer_test_app) diff --git a/config/src/tests/file_acquirer/file_acquirer_test.cpp b/config/src/tests/file_acquirer/file_acquirer_test.cpp new file mode 100644 index 00000000000..028890a5f44 --- /dev/null +++ b/config/src/tests/file_acquirer/file_acquirer_test.cpp @@ -0,0 +1,44 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/config/file_acquirer/file_acquirer.h> +#include <vespa/fnet/frt/frt.h> +#include <vespa/vespalib/util/stringfmt.h> + +using namespace config; + +struct ServerFixture : FRT_Invokable { + FRT_Supervisor orb; + vespalib::string spec; + void init_rpc() { + FRT_ReflectionBuilder rb(&orb); + rb.DefineMethod("waitFor", "s", "s", true, FRT_METHOD(ServerFixture::RPC_waitFor), this); + rb.MethodDesc("wait for and resolve file reference"); + rb.ParamDesc("file_ref", "file reference to wait for and resolve"); + rb.ReturnDesc("file_path", "actual path to the requested file"); + } + ServerFixture() : orb() { + init_rpc(); + orb.Listen(0); + spec = vespalib::make_string("tcp/localhost:%d", orb.GetListenPort()); + orb.Start(); + } + void RPC_waitFor(FRT_RPCRequest *req) { + FRT_Values ¶ms = *req->GetParams(); + FRT_Values &ret = *req->GetReturn(); + if (strcmp(params[0]._string._str, "my_ref") == 0) { + ret.AddString("my_path"); + } else { + req->SetError(FRTE_RPC_METHOD_FAILED, "invalid file reference"); + } + } + ~ServerFixture() { + orb.ShutDown(true); + } +}; + +TEST_FF("require that files can be acquired over rpc", ServerFixture(), RpcFileAcquirer(f1.spec)) { + EXPECT_EQUAL("my_path", f2.wait_for("my_ref", 60.0)); + EXPECT_EQUAL("", f2.wait_for("bogus_ref", 60.0)); +} + +TEST_MAIN() { TEST_RUN_ALL(); } |