diff options
author | mokhotskii <[email protected]> | 2022-07-12 16:44:12 +0300 |
---|---|---|
committer | mokhotskii <[email protected]> | 2022-07-12 16:44:12 +0300 |
commit | 46a572da307020692dcad5c8d18a6fae230051f9 (patch) | |
tree | 1c852f6588745c8fed892bc89c227e1448bffe9c | |
parent | 333180ae363efddee661d8f17c96baee771b79e2 (diff) |
Fix typos in http proxy json2proto convertions
Fix typos in http proxy json2proto convertions
-rw-r--r-- | CMakeLists.darwin.txt | 1 | ||||
-rw-r--r-- | CMakeLists.linux.txt | 1 | ||||
-rw-r--r-- | ydb/core/http_proxy/http_req.h | 4 | ||||
-rw-r--r-- | ydb/core/http_proxy/json_proto_conversion.h | 26 | ||||
-rw-r--r-- | ydb/core/http_proxy/ut/CMakeLists.darwin.txt | 45 | ||||
-rw-r--r-- | ydb/core/http_proxy/ut/CMakeLists.linux.txt | 49 | ||||
-rw-r--r-- | ydb/core/http_proxy/ut/CMakeLists.txt | 13 | ||||
-rw-r--r-- | ydb/core/http_proxy/ut/json_proto_conversion_ut.cpp | 76 | ||||
-rw-r--r-- | ydb/public/api/protos/draft/datastreams.proto | 8 |
9 files changed, 205 insertions, 18 deletions
diff --git a/CMakeLists.darwin.txt b/CMakeLists.darwin.txt index e8822457113..0b29b5b528c 100644 --- a/CMakeLists.darwin.txt +++ b/CMakeLists.darwin.txt @@ -1038,6 +1038,7 @@ add_subdirectory(ydb/core/grpc_services/ut) add_subdirectory(ydb/core/grpc_streaming/ut) add_subdirectory(ydb/core/grpc_streaming/ut/grpc) add_subdirectory(ydb/core/health_check/ut) +add_subdirectory(ydb/core/http_proxy/ut) add_subdirectory(ydb/core/keyvalue/ut) add_subdirectory(ydb/core/kqp/ut) add_subdirectory(ydb/core/metering/ut) diff --git a/CMakeLists.linux.txt b/CMakeLists.linux.txt index 5e3a848703b..6f7f4d4fa07 100644 --- a/CMakeLists.linux.txt +++ b/CMakeLists.linux.txt @@ -1058,6 +1058,7 @@ add_subdirectory(ydb/core/grpc_services/ut) add_subdirectory(ydb/core/grpc_streaming/ut) add_subdirectory(ydb/core/grpc_streaming/ut/grpc) add_subdirectory(ydb/core/health_check/ut) +add_subdirectory(ydb/core/http_proxy/ut) add_subdirectory(ydb/core/keyvalue/ut) add_subdirectory(ydb/core/kqp/ut) add_subdirectory(ydb/core/metering/ut) diff --git a/ydb/core/http_proxy/http_req.h b/ydb/core/http_proxy/http_req.h index 0fc93910c4d..acbe13634ef 100644 --- a/ydb/core/http_proxy/http_req.h +++ b/ydb/core/http_proxy/http_req.h @@ -47,7 +47,7 @@ private: struct THttpResponseData { - NYdb::EStatus Status = NYdb::EStatus::SUCCESS; + NYdb::EStatus Status{NYdb::EStatus::SUCCESS}; NJson::TJsonValue Body; TString ErrorText; @@ -84,7 +84,7 @@ struct THttpRequestContext { TString SourceAddress; TString MethodName; TString ApiVersion; - MimeTypes ContentType; + MimeTypes ContentType{MIME_UNKNOWN}; TString IamToken; TString SerializedUserToken; diff --git a/ydb/core/http_proxy/json_proto_conversion.h b/ydb/core/http_proxy/json_proto_conversion.h index 5f9be4972eb..4399cfef9b6 100644 --- a/ydb/core/http_proxy/json_proto_conversion.h +++ b/ydb/core/http_proxy/json_proto_conversion.h @@ -5,7 +5,9 @@ #include <library/cpp/protobuf/json/json_output_create.h> #include <library/cpp/protobuf/json/proto2json.h> #include <library/cpp/protobuf/json/proto2json_printer.h> +#include <library/cpp/string_utils/base64/base64.h> #include <ydb/library/naming_conventions/naming_conventions.h> +#include <ydb/public/sdk/cpp/client/ydb_datastreams/datastreams.h> namespace NKikimr::NHttpProxy { @@ -143,44 +145,44 @@ void JsonToProto(const NJson::TJsonValue& jsonValue, NProtoBuf::Message* message Y_ENSURE(fieldDescriptor->cpp_type() == google::protobuf::FieldDescriptor::CPPTYPE_STRING, "Base64 transformer is only applicable to strings"); - reflection->AddString(message, fieldDescriptor, Base64Decode(value.GetString())); + reflection->AddString(message, fieldDescriptor, Base64Decode(elem.GetString())); break; } case Ydb::DataStreams::V1::TRANSFORM_DOUBLE_S_TO_INT_MS: { - reflection->SetInt64(message, fieldDescriptor, value.GetDouble() * 1000); + reflection->AddInt64(message, fieldDescriptor, elem.GetDouble() * 1000); break; } case Ydb::DataStreams::V1::TRANSFORM_EMPTY_TO_NOTHING: case Ydb::DataStreams::V1::TRANSFORM_NONE: { switch (fieldDescriptor->cpp_type()) { case google::protobuf::FieldDescriptor::CPPTYPE_INT32: - reflection->AddInt32(message, fieldDescriptor, value.GetInteger()); + reflection->AddInt32(message, fieldDescriptor, elem.GetInteger()); break; case google::protobuf::FieldDescriptor::CPPTYPE_INT64: - reflection->AddInt64(message, fieldDescriptor, value.GetInteger()); + reflection->AddInt64(message, fieldDescriptor, elem.GetInteger()); break; case google::protobuf::FieldDescriptor::CPPTYPE_UINT32: - reflection->AddUInt32(message, fieldDescriptor, value.GetUInteger()); + reflection->AddUInt32(message, fieldDescriptor, elem.GetUInteger()); break; case google::protobuf::FieldDescriptor::CPPTYPE_UINT64: - reflection->AddUInt64(message, fieldDescriptor, value.GetUInteger()); + reflection->AddUInt64(message, fieldDescriptor, elem.GetUInteger()); break; case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE: - reflection->AddDouble(message, fieldDescriptor, value.GetDouble()); + reflection->AddDouble(message, fieldDescriptor, elem.GetDouble()); break; case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT: - reflection->AddFloat(message, fieldDescriptor, value.GetDouble()); + reflection->AddFloat(message, fieldDescriptor, elem.GetDouble()); break; case google::protobuf::FieldDescriptor::CPPTYPE_BOOL: - reflection->AddFloat(message, fieldDescriptor, value.GetBoolean()); + reflection->AddBool(message, fieldDescriptor, elem.GetBoolean()); break; case google::protobuf::FieldDescriptor::CPPTYPE_ENUM: { const NProtoBuf::EnumValueDescriptor* enumValueDescriptor = - fieldDescriptor->enum_type()->FindValueByName(value.GetString()); + fieldDescriptor->enum_type()->FindValueByName(elem.GetString()); i32 number{0}; if (enumValueDescriptor == nullptr && - TryFromString(value.GetString(), number)) { + TryFromString(elem.GetString(), number)) { enumValueDescriptor = fieldDescriptor->enum_type()->FindValueByNumber(number); } @@ -190,7 +192,7 @@ void JsonToProto(const NJson::TJsonValue& jsonValue, NProtoBuf::Message* message } break; case google::protobuf::FieldDescriptor::CPPTYPE_STRING: - reflection->AddString(message, fieldDescriptor, value.GetString()); + reflection->AddString(message, fieldDescriptor, elem.GetString()); break; case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE: { NProtoBuf::Message *msg = reflection->AddMessage(message, fieldDescriptor); diff --git a/ydb/core/http_proxy/ut/CMakeLists.darwin.txt b/ydb/core/http_proxy/ut/CMakeLists.darwin.txt new file mode 100644 index 00000000000..8167941b471 --- /dev/null +++ b/ydb/core/http_proxy/ut/CMakeLists.darwin.txt @@ -0,0 +1,45 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_executable(ydb-core-http_proxy-ut) +target_include_directories(ydb-core-http_proxy-ut PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/core/http_proxy +) +target_link_libraries(ydb-core-http_proxy-ut PUBLIC + contrib-libs-cxxsupp + yutil + library-cpp-cpuid_check + cpp-testing-unittest_main + ydb-core-http_proxy + library-cpp-resource + cpp-client-ydb_types +) +target_link_options(ydb-core-http_proxy-ut PRIVATE + -Wl,-no_deduplicate + -Wl,-sdk_version,10.15 + -fPIC + -fPIC + -framework + CoreFoundation +) +target_sources(ydb-core-http_proxy-ut PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/core/http_proxy/ut/json_proto_conversion_ut.cpp +) +add_test( + NAME + ydb-core-http_proxy-ut + COMMAND + ydb-core-http_proxy-ut + --print-before-suite + --print-before-test + --fork-tests + --print-times + --show-fails +) +vcs_info(ydb-core-http_proxy-ut) diff --git a/ydb/core/http_proxy/ut/CMakeLists.linux.txt b/ydb/core/http_proxy/ut/CMakeLists.linux.txt new file mode 100644 index 00000000000..939fa4ae389 --- /dev/null +++ b/ydb/core/http_proxy/ut/CMakeLists.linux.txt @@ -0,0 +1,49 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_executable(ydb-core-http_proxy-ut) +target_include_directories(ydb-core-http_proxy-ut PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/core/http_proxy +) +target_link_libraries(ydb-core-http_proxy-ut PUBLIC + contrib-libs-cxxsupp + yutil + cpp-malloc-tcmalloc + libs-tcmalloc-no_percpu_cache + library-cpp-cpuid_check + cpp-testing-unittest_main + ydb-core-http_proxy + library-cpp-resource + cpp-client-ydb_types +) +target_link_options(ydb-core-http_proxy-ut PRIVATE + -ldl + -lrt + -Wl,--no-as-needed + -fPIC + -fPIC + -lpthread + -lrt + -ldl +) +target_sources(ydb-core-http_proxy-ut PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/core/http_proxy/ut/json_proto_conversion_ut.cpp +) +add_test( + NAME + ydb-core-http_proxy-ut + COMMAND + ydb-core-http_proxy-ut + --print-before-suite + --print-before-test + --fork-tests + --print-times + --show-fails +) +vcs_info(ydb-core-http_proxy-ut) diff --git a/ydb/core/http_proxy/ut/CMakeLists.txt b/ydb/core/http_proxy/ut/CMakeLists.txt new file mode 100644 index 00000000000..fc7b1ee73ce --- /dev/null +++ b/ydb/core/http_proxy/ut/CMakeLists.txt @@ -0,0 +1,13 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + +if (APPLE) + include(CMakeLists.darwin.txt) +elseif (UNIX AND NOT APPLE) + include(CMakeLists.linux.txt) +endif() diff --git a/ydb/core/http_proxy/ut/json_proto_conversion_ut.cpp b/ydb/core/http_proxy/ut/json_proto_conversion_ut.cpp new file mode 100644 index 00000000000..eaf335c5747 --- /dev/null +++ b/ydb/core/http_proxy/ut/json_proto_conversion_ut.cpp @@ -0,0 +1,76 @@ +#include <library/cpp/testing/unittest/registar.h> +#include "json_proto_conversion.h" + +Y_UNIT_TEST_SUITE(JsonProtoConversion) { + +Y_UNIT_TEST(JsonToProtoSingleValue) { + { + Ydb::DataStreams::V1::DeleteStreamRequest message; + NJson::TJsonValue jsonValue; + jsonValue["EnforceConsumerDeletion"] = true; + jsonValue["StreamName"] = "stream"; + NKikimr::NHttpProxy::JsonToProto(jsonValue, &message); + + UNIT_ASSERT_VALUES_EQUAL(message.stream_name(), "stream"); + UNIT_ASSERT_VALUES_EQUAL(message.enforce_consumer_deletion(), true); + } + { + Ydb::DataStreams::V1::DeleteStreamRequest message; + NJson::TJsonValue jsonValue; + jsonValue["EnforceConsumerDeletion"] = false; + jsonValue["StreamName"] = "not_stream"; + NKikimr::NHttpProxy::JsonToProto(jsonValue, &message); + + UNIT_ASSERT_VALUES_EQUAL(message.stream_name(), "not_stream"); + UNIT_ASSERT_VALUES_EQUAL(message.enforce_consumer_deletion(), false); + } +} + +Y_UNIT_TEST(JsonToProtoArray) { + { + Ydb::DataStreams::V1::PutRecordsRequest message; + NJson::TJsonValue jsonValue; + jsonValue["StreamName"] = "stream"; + auto& records = jsonValue["Records"]; + NJson::TJsonValue record; + record["Data"] = "MTIzCg=="; + record["ExplicitHashKey"] = "exp0"; + record["PartitionKey"] = "part0"; + records.AppendValue(record); + record["Data"] = "NDU2Cg=="; + record["ExplicitHashKey"] = "exp1"; + record["PartitionKey"] = "part1"; + records.AppendValue(record); + + NKikimr::NHttpProxy::JsonToProto(jsonValue, &message); + + UNIT_ASSERT_VALUES_EQUAL(message.stream_name(), "stream"); + + UNIT_ASSERT_VALUES_EQUAL(message.records(0).explicit_hash_key(), "exp0"); + UNIT_ASSERT_VALUES_EQUAL(message.records(0).partition_key(), "part0"); + UNIT_ASSERT_VALUES_EQUAL(message.records(0).data(), "123\n"); + UNIT_ASSERT_VALUES_EQUAL(message.records(1).explicit_hash_key(), "exp1"); + UNIT_ASSERT_VALUES_EQUAL(message.records(1).partition_key(), "part1"); + UNIT_ASSERT_VALUES_EQUAL(message.records(1).data(), "456\n"); + } + + { + Ydb::DataStreams::V1::EnhancedMetrics message; + NJson::TJsonValue jsonValue; + const auto N{5}; + for (int i = 0; i < N; ++i) { + auto str = TStringBuilder() << "metric_" << i; + jsonValue["shard_level_metrics"].AppendValue(str); + } + + NKikimr::NHttpProxy::JsonToProto(jsonValue, &message); + + for (int i = 0; i < N; ++i) { + auto str = TStringBuilder() << "metric_" << i; + UNIT_ASSERT_VALUES_EQUAL(message.shard_level_metrics(i), str); + } + } + +} + +} // Y_UNIT_TEST_SUITE(JsonProtoConversion) diff --git a/ydb/public/api/protos/draft/datastreams.proto b/ydb/public/api/protos/draft/datastreams.proto index 01a0e5ec704..967e3450203 100644 --- a/ydb/public/api/protos/draft/datastreams.proto +++ b/ydb/public/api/protos/draft/datastreams.proto @@ -8,7 +8,7 @@ import "google/protobuf/descriptor.proto"; package Ydb.DataStreams.V1; option java_package = "com.yandex.ydb.datastreams.v1"; -// Extsions to simplify json <-> proto conversion +// Extensions to simplify json <-> proto conversion enum EFieldTransformationType { TRANSFORM_NONE = 0; TRANSFORM_BASE64 = 1; @@ -80,7 +80,7 @@ message StreamDescription { DELETING = 2; // Stream is ready for read & write operations or deletion ACTIVE = 3; - // Shards in the stream are being merged ot split + // Shards in the stream are being merged on split UPDATING = 4; } @@ -299,7 +299,7 @@ message ListStreamsRequest { string exclusive_start_stream_name = 2; // Max number of entries to return int32 limit = 3; - // Will make recurse listing if set to true. Otherwise will return only streams from root directory. + // Will make recursive listing if set to true. Otherwise will return only streams from root directory. bool recurse = 4; } @@ -661,7 +661,7 @@ message DescribeStreamSummaryResponse { } message DescribeStreamSummaryResult { - // Stream description sumary + // Stream description summary StreamDescriptionSummary stream_description_summary = 1; } |