diff --git a/src/tateyama/proto/session/request.proto b/src/tateyama/proto/session/request.proto index f96cf3e..02ac1a7 100644 --- a/src/tateyama/proto/session/request.proto +++ b/src/tateyama/proto/session/request.proto @@ -2,6 +2,10 @@ syntax = "proto3"; package tateyama.proto.session.request; +option java_multiple_files = false; +option java_package = "com.tsurugidb.session.proto"; +option java_outer_classname = "SessionRequest"; + // the request message to session pseudo service. message Request { // service message version (major) @@ -82,8 +86,11 @@ message SessionSetVariable { // the target variable name, case insensitive. string name = 2; - // the text represented value to set. - string value = 3; + // the value to set, or NOT_SET to unset the variable. + oneof value_opt { + // the text represented value to set. + string value = 3; + } } diff --git a/src/tateyama/session/session.cpp b/src/tateyama/session/session.cpp index 387610e..daf042c 100644 --- a/src/tateyama/session/session.cpp +++ b/src/tateyama/session/session.cpp @@ -324,7 +324,9 @@ tgctl::return_code session_swtch(std::string_view session_ref, std::string_view auto* command = request.mutable_session_set_variable(); command->set_session_specifier(std::string(session_ref)); command->set_name(std::string(set_key)); - command->set_value(std::string(set_value)); + if (!set_value.empty()) { + command->set_value(std::string(set_value)); + } auto response_opt = transport->send<::tateyama::proto::session::response::SessionSetVariable>(request); request.clear_session_set_variable(); diff --git a/src/tateyama/session/session.h b/src/tateyama/session/session.h index a077d2e..ef49daf 100644 --- a/src/tateyama/session/session.h +++ b/src/tateyama/session/session.h @@ -26,6 +26,6 @@ namespace tateyama::session { tgctl::return_code session_list(); tgctl::return_code session_show(std::string_view session_ref); tgctl::return_code session_shutdown(std::string_view session_ref); - tgctl::return_code session_swtch(std::string_view session_ref, std::string_view set_key, std::string_view set_value); + tgctl::return_code session_swtch(std::string_view session_ref, std::string_view set_key, std::string_view set_value = ""); } // tateyama::session diff --git a/src/tateyama/tgctl/tgctl.cpp b/src/tateyama/tgctl/tgctl.cpp index 70410a4..b6fe7d2 100644 --- a/src/tateyama/tgctl/tgctl.cpp +++ b/src/tateyama/tgctl/tgctl.cpp @@ -182,10 +182,13 @@ int tgctl_main(const std::vector& args) { //NOLINT(readability-func return tateyama::session::session_shutdown(args.at(3)); } if (args.at(2) == "set") { - if (args.size() < 6) { - std::cerr << "need to specify session-ref, set-key, and set-value" << std::endl; + if (args.size() < 5) { + std::cerr << "need to specify session-ref and set-key" << std::endl; return tateyama::tgctl::return_code::err; } + if (args.size() < 6) { + return tateyama::session::session_swtch(args.at(3), args.at(4)); + } return tateyama::session::session_swtch(args.at(3), args.at(4), args.at(5)); } std::cerr << "unknown session sub command '" << args.at(2) << "'" << std::endl; diff --git a/test/tateyama/session/session_test.cpp b/test/tateyama/session/session_test.cpp index 683d629..0958db3 100644 --- a/test/tateyama/session/session_test.cpp +++ b/test/tateyama/session/session_test.cpp @@ -304,4 +304,31 @@ TEST_F(session_test, session_set) { EXPECT_EQ("test_value", rq.value()); } +TEST_F(session_test, session_unset) { + std::string command; + FILE *fp; + + { + tateyama::proto::session::response::SessionSetVariable session_set{}; + auto* success = session_set.mutable_success(); + server_mock_->push_response(session_set.SerializeAsString()); + } + + command = "tgctl session set :123456 test_variable --conf "; + command += helper_->conf_file_path(); + std::cout << command << std::endl; + if((fp = popen(command.c_str(), "r")) == nullptr){ + std::cerr << "cannot tgctl session set" << std::endl; + } + auto result = read_pipe(fp); + std::cout << result << std::flush; + + EXPECT_EQ(tateyama::framework::service_id_session, server_mock_->component_id()); + tateyama::proto::session::request::SessionSetVariable rq{}; + server_mock_->request_message(rq); + EXPECT_EQ(":123456", rq.session_specifier()); + EXPECT_EQ("test_variable", rq.name()); + EXPECT_EQ(tateyama::proto::session::request::SessionSetVariable::ValueOptCase::VALUE_OPT_NOT_SET, rq.value_opt_case()); +} + } // namespace tateyama::session