From db9524b4c3c8769136260a4de8c83563e16a65ed Mon Sep 17 00:00:00 2001 From: Timm Fitschen <t.fitschen@indiscale.com> Date: Sat, 14 Aug 2021 21:40:20 +0200 Subject: [PATCH] WIP: consolidation --- include/caosdb/entity.h | 8 +++---- include/caosdb/transaction.h | 1 + src/caosdb/entity.cpp | 20 ++++++++-------- .../UploadRequestHandler.cpp | 21 ++++++++-------- src/caosdb/transaction.cpp | 2 ++ src/caosdb/transaction_handler.cpp | 14 ++++++----- test/test_entity.cpp | 24 +++++++++---------- test/test_transaction.cpp | 3 ++- 8 files changed, 49 insertions(+), 44 deletions(-) diff --git a/include/caosdb/entity.h b/include/caosdb/entity.h index b576ee8..f6f2204 100644 --- a/include/caosdb/entity.h +++ b/include/caosdb/entity.h @@ -29,12 +29,12 @@ #ifndef CAOSDB_ENTITY_H #define CAOSDB_ENTITY_H -#include "caosdb/data_type.h" // for DataType +#include "caosdb/data_type.h" // for DataType #include "caosdb/entity/v1alpha1/main.pb.h" // for RepeatedPtrField #include "caosdb/logging.h" // for CAOSDB_LOG_WARN #include "caosdb/message_code.h" // for get_message_code #include "caosdb/status_code.h" // for StatusCode -#include "caosdb/value.h" // for Value +#include "caosdb/value.h" // for Value #include <boost/filesystem/operations.hpp> // for exists, is_di... #include <boost/filesystem/path.hpp> // for path #include <boost/log/core/record.hpp> // for record @@ -91,7 +91,7 @@ enum Role { RECORD = EntityRole::ENTITY_ROLE_RECORD, ///< Record PROPERTY = EntityRole::ENTITY_ROLE_PROPERTY, ///< Property FILE = EntityRole::ENTITY_ROLE_FILE, ///< File -} +}; struct FileDescriptor { FileTransmissionId *file_transmission_id; @@ -568,7 +568,7 @@ public: inline auto SetLocalPath(const boost::filesystem::path &local_path) noexcept -> StatusCode { - if (GetRole() != "File") { + if (GetRole() != Role::FILE) { CAOSDB_LOG_WARN(logger_name) << "Entity::SetLocalPath failed. This is not a file entity."; return StatusCode::NOT_A_FILE_ENTITY; diff --git a/include/caosdb/transaction.h b/include/caosdb/transaction.h index 368eb2e..cb9e5d7 100644 --- a/include/caosdb/transaction.h +++ b/include/caosdb/transaction.h @@ -34,6 +34,7 @@ #include <boost/log/sources/record_ostream.hpp> // for basic_record_o... #include <boost/preprocessor/seq/limits/enum_256.hpp> // for BOOST_PP_SEQ_E... #include <boost/preprocessor/seq/limits/size_256.hpp> // for BOOST_PP_SEQ_S... +#include "google/protobuf/generated_message_util.h" // for CreateMessage... #include <google/protobuf/arena.h> // for Arena #include <google/protobuf/util/json_util.h> // for MessageToJsonS... #include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue diff --git a/src/caosdb/entity.cpp b/src/caosdb/entity.cpp index 3603ac3..0763f03 100644 --- a/src/caosdb/entity.cpp +++ b/src/caosdb/entity.cpp @@ -20,12 +20,13 @@ * */ #include "caosdb/entity.h" -#include "caosdb/data_type.h" -#include "caosdb/entity/v1alpha1/main.pb.h" // for Parent, Arena::CreateMay... -#include "caosdb/protobuf_helper.h" // for get_arena -#include "caosdb/value.h" -#include <google/protobuf/arena.h> // for Arena -#include <new> // for operator new +#include "caosdb/data_type.h" // for DataType +#include "caosdb/entity/v1alpha1/main.pb.h" // for Messages +#include "caosdb/protobuf_helper.h" // for get_arena +#include "caosdb/value.h" // for Value +#include <google/protobuf/generated_message_util.h> // for Arena::Create... +#include <google/protobuf/arena.h> // for Arena +#include <new> // for operator new namespace caosdb::entity { using caosdb::entity::v1alpha1::IdResponse; @@ -190,10 +191,9 @@ auto Entity::CreateProtoEntity() -> ProtoEntity * { Entity::Entity(IdResponse *id_response) : Entity() { this->wrapped->set_id(id_response->id()); this->wrapped->mutable_version()->Swap(id_response->mutable_version()); - this->wrapped->mutable_errors()->Swap(id_response->mutable_entity_errors()); - this->wrapped->mutable_warnings()->Swap( - id_response->mutable_entity_warnings()); - this->wrapped->mutable_infos()->Swap(id_response->mutable_entity_infos()); + this->errors.wrapped->Swap(id_response->mutable_errors()); + this->warnings.wrapped->Swap(id_response->mutable_warnings()); + this->infos.wrapped->Swap(id_response->mutable_infos()); } Entity::Entity() : Entity(Entity::CreateProtoEntity()) {} diff --git a/src/caosdb/file_transmission/UploadRequestHandler.cpp b/src/caosdb/file_transmission/UploadRequestHandler.cpp index c96115d..c93ca3a 100644 --- a/src/caosdb/file_transmission/UploadRequestHandler.cpp +++ b/src/caosdb/file_transmission/UploadRequestHandler.cpp @@ -13,16 +13,17 @@ #include <cstdint> // for uint64_t #include <exception> // IWYU pragma: keep // IWYU pragma: no_include <bits/exception.h> -#include <google/protobuf/arena.h> // for Arena -#include <grpcpp/impl/codegen/async_stream.h> // for ClientAsyncWr... -#include <grpcpp/impl/codegen/call_op_set.h> // for WriteOptions -#include <grpcpp/impl/codegen/client_context.h> // for ClientContext -#include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue -#include <grpcpp/impl/codegen/status.h> // for Status -#include <grpcpp/impl/codegen/status_code_enum.h> // for OK, UNAUTHENT... -#include <iostream> // for endl, streamsize -#include <string> // for basic_string -#include <utility> // for move +#include <google/protobuf/arena.h> // for Arena +#include <google/protobuf/generated_message_util.h> // for CreateMessage... +#include <grpcpp/impl/codegen/async_stream.h> // for ClientAsyncWr... +#include <grpcpp/impl/codegen/call_op_set.h> // for WriteOptions +#include <grpcpp/impl/codegen/client_context.h> // for ClientContext +#include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue +#include <grpcpp/impl/codegen/status.h> // for Status +#include <grpcpp/impl/codegen/status_code_enum.h> // for OK, UNAUTHENT... +#include <iostream> // for endl, streamsize +#include <string> // for basic_string +#include <utility> // for move namespace caosdb::transaction { using caosdb::StatusCode; diff --git a/src/caosdb/transaction.cpp b/src/caosdb/transaction.cpp index 377b3b0..214e0a7 100644 --- a/src/caosdb/transaction.cpp +++ b/src/caosdb/transaction.cpp @@ -316,10 +316,12 @@ auto Transaction::ExecuteAsynchronously() noexcept -> StatusCode { } } + CAOSDB_LOG_DEBUG(logger_name) << "RPC Request: " << RequestToString(); handler_ = std::make_unique<EntityTransactionHandler>( &handler_, entity_service.get(), &completion_queue, request, response); this->status = ProcessCalls(); + CAOSDB_LOG_DEBUG(logger_name) << "RPC Response: " << ResponseToString(); // file download afterwards if (status.GetCode() == StatusCode::SUCCESS && !download_files.empty()) { diff --git a/src/caosdb/transaction_handler.cpp b/src/caosdb/transaction_handler.cpp index 61b69a2..8e3f138 100644 --- a/src/caosdb/transaction_handler.cpp +++ b/src/caosdb/transaction_handler.cpp @@ -1,13 +1,15 @@ #include "caosdb/transaction_handler.h" -#include "caosdb/logging.h" // for CAOSDB_LOG_TRACE -#include <boost/log/core/record.hpp> // for record -#include <boost/log/sources/record_ostream.hpp> // for basic_record_... -#include <boost/preprocessor/seq/limits/enum_256.hpp> // for BOOST_PP_SEQ_... -#include <boost/preprocessor/seq/limits/size_256.hpp> // for BOOST_PP_SEQ_... -#include <exception> // IWYU pragma: keep +#include "caosdb/logging.h" // for CAOSDB_LOG_TRACE +#include <boost/log/core/record.hpp> // for record +#include <boost/log/detail/attachable_sstream_buf.hpp> // for basic_ostring... +#include <boost/log/sources/record_ostream.hpp> // for basic_record_... +#include <boost/preprocessor/seq/limits/enum_256.hpp> // for BOOST_PP_SEQ_... +#include <boost/preprocessor/seq/limits/size_256.hpp> // for BOOST_PP_SEQ_... +#include <exception> // IWYU pragma: keep // IWYU pragma: no_include <bits/exception.h> #include <grpcpp/impl/codegen/async_unary_call.h> // for ClientAsyncRes... #include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue +#include <iosfwd> // for streamsize namespace caosdb::transaction { diff --git a/test/test_entity.cpp b/test/test_entity.cpp index 0516aa8..4db2b1b 100644 --- a/test/test_entity.cpp +++ b/test/test_entity.cpp @@ -26,13 +26,13 @@ #include "caosdb/entity/v1alpha1/main.grpc.pb.h" // for EntityTransactionSe... #include "caosdb/entity/v1alpha1/main.pb.h" // for IdResponse, Message #include "caosdb/logging.h" -#include "caosdb/message_code.h" // for MessageCode -#include "caosdb/protobuf_helper.h" // for get_arena -#include "caosdb/status_code.h" // for StatusCode, FILE_DO... -#include "caosdb/transaction.h" // for Transaction -#include "caosdb/value.h" // for Value -#include <boost/log/core/record.hpp> // for record -#include <boost/log/sources/record_ostream.hpp> // for record_pump<>:... +#include "caosdb/message_code.h" // for MessageCode +#include "caosdb/protobuf_helper.h" // for get_arena +#include "caosdb/status_code.h" // for StatusCode, FILE_DO... +#include "caosdb/transaction.h" // for Transaction +#include "caosdb/value.h" // for Value +#include <boost/log/core/record.hpp> // for record +#include <boost/log/sources/record_ostream.hpp> // for record_pump<>:... #include <boost/preprocessor/seq/limits/enum_256.hpp> // for BOOST_PP_SEQ_E... #include <boost/preprocessor/seq/limits/size_256.hpp> // for BOOST_PP_SEQ_S... #include <google/protobuf/arena.h> // for Arena @@ -40,7 +40,7 @@ #include <gtest/gtest-test-part.h> // for TestPartResult, Sui... #include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ #include <memory> // for allocator, shared_ptr -#include <string> // for operator+, string +#include <string> // for operator+, string namespace caosdb::entity { using caosdb::entity::v1alpha1::IdResponse; @@ -176,8 +176,6 @@ TEST(test_entity, test_insert_entity) { EXPECT_EQ(entity.GetRole(), Role::RECORD_TYPE); EXPECT_EQ(entity.GetName(), "entity_name"); - - EXPECT_EQ(transaction.RequestToString(), ""); } TEST(test_entity, test_insert_with_role) { @@ -305,14 +303,14 @@ TEST(test_entity, test_add_file_to_non_file_entity) { TEST(test_entity, test_add_non_existing_file) { Entity entity; - entity.SetRole("File"); + entity.SetRole(Role::FILE); EXPECT_EQ(entity.SetLocalPath("non-existing/path"), StatusCode::FILE_DOES_NOT_EXIST_LOCALLY); } TEST(test_entity, test_add_directory_path) { Entity entity; - entity.SetRole("File"); + entity.SetRole(Role::FILE); EXPECT_EQ(entity.SetLocalPath("./"), StatusCode::PATH_IS_A_DIRECTORY); } @@ -346,7 +344,7 @@ TEST(test_entity, test_role) { TEST(test_entity, test_add_file) { Entity entity; - entity.SetRole("File"); + entity.SetRole(Role::FILE); EXPECT_EQ(entity.SetLocalPath(TEST_DATA_DIR + "/test.json"), StatusCode::SUCCESS); } diff --git a/test/test_transaction.cpp b/test/test_transaction.cpp index 828b183..a93131c 100644 --- a/test/test_transaction.cpp +++ b/test/test_transaction.cpp @@ -41,6 +41,7 @@ using caosdb::configuration::InsecureConnectionConfiguration; using caosdb::connection::Connection; using caosdb::entity::Entity; using ProtoEntity = caosdb::entity::v1alpha1::Entity; +using caosdb::entity::Role; using caosdb::entity::v1alpha1::RetrieveResponse; TEST(test_transaction, create_transaction) { @@ -215,7 +216,7 @@ TEST(test_transaction, test_insert_with_file) { Connection connection(configuration); auto transaction = connection.CreateTransaction(); Entity entity; - entity.SetRole("File"); + entity.SetRole(Role::FILE); entity.SetLocalPath(TEST_DATA_DIR + "/test.json"); EXPECT_TRUE(transaction->GetUploadFiles().empty()); -- GitLab