From ed713327737b799ff56fbf9812fdf69b60ea0500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Benjamin=20Antal?= Date: Thu, 21 Jul 2022 16:23:27 +0200 Subject: [PATCH] Add dummy storage engine to test --- tests/simulation/CMakeLists.txt | 3 + .../trial_query_storage/messages.hpp | 36 +++++++++ .../query_storage_test.cpp | 73 +++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 tests/simulation/trial_query_storage/messages.hpp create mode 100644 tests/simulation/trial_query_storage/query_storage_test.cpp diff --git a/tests/simulation/CMakeLists.txt b/tests/simulation/CMakeLists.txt index 1463d1a32..246499af6 100644 --- a/tests/simulation/CMakeLists.txt +++ b/tests/simulation/CMakeLists.txt @@ -9,6 +9,7 @@ function(add_simulation_test test_cpp san) get_filename_component(exec_name ${test_cpp} NAME_WE) set(target_name ${test_prefix}${exec_name}) add_executable(${target_name} ${test_cpp}) + # OUTPUT_NAME sets the real name of a target when it is built and can be # used to help create two targets of the same name even though CMake # requires unique logical target names @@ -29,3 +30,5 @@ add_simulation_test(future.cpp thread) add_simulation_test(basic_request.cpp address) add_simulation_test(raft.cpp address) + +add_simulation_test(trial_query_storage/query_storage_test.cpp address) diff --git a/tests/simulation/trial_query_storage/messages.hpp b/tests/simulation/trial_query_storage/messages.hpp new file mode 100644 index 000000000..3dfbdc33a --- /dev/null +++ b/tests/simulation/trial_query_storage/messages.hpp @@ -0,0 +1,36 @@ +// Copyright 2022 Memgraph Ltd. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source +// License, and you may not use this file except in compliance with the Business Source License. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +#pragma once + +#include +#include +#include + +// header + +namespace memgraph::tests::simulation { + +struct Vertex { + std::string key; +}; + +struct ScanVerticesRequest { + int64_t count; + std::optional continuation; +}; + +struct VerticesResponse { + std::vector vertices; + std::optional continuation; +}; + +} // namespace memgraph::tests::simulation diff --git a/tests/simulation/trial_query_storage/query_storage_test.cpp b/tests/simulation/trial_query_storage/query_storage_test.cpp new file mode 100644 index 000000000..5161d07df --- /dev/null +++ b/tests/simulation/trial_query_storage/query_storage_test.cpp @@ -0,0 +1,73 @@ +// Copyright 2022 Memgraph Ltd. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source +// License, and you may not use this file except in compliance with the Business Source License. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +#include + +#include "io/address.hpp" +#include "io/simulator/simulator.hpp" +#include "io/simulator/simulator_config.hpp" +#include "io/simulator/simulator_transport.hpp" +#include "io/transport.hpp" + +#include "messages.hpp" + +namespace memgraph::tests::simulation { +using memgraph::io::Io; +using memgraph::io::simulator::SimulatorTransport; + +void run_server(Io io) { + while (!io.ShouldShutDown()) { + std::cout << "[STORAGE] Is receiving..." << std::endl; + auto request_result = io.ReceiveWithTimeout(100000); + if (request_result.HasError()) { + std::cout << "[STORAGE] Error, continue" << std::endl; + continue; + } + auto request_envelope = request_result.GetValue(); + auto req = std::get(request_envelope.message); + + VerticesResponse response{}; + const int64_t start_index = std::invoke([&req] { + if (req.continuation.has_value()) { + return *req.continuation; + } + return 0L; + }); + for (auto index = start_index; index < start_index + req.count; ++index) { + response.vertices.push_back({std::string("Vertex_") + std::to_string(index)}); + } + io.Send(request_envelope.from_address, request_envelope.request_id, response); + } +} + +int main() { + using memgraph::io::Address; + using memgraph::io::simulator::Simulator; + using memgraph::io::simulator::SimulatorConfig; + auto config = SimulatorConfig{ + .drop_percent = 0, + .perform_timeouts = true, + .scramble_messages = true, + .rng_seed = 0, + }; + auto simulator = Simulator(config); + + auto cli_addr = Address::TestAddress(1); + auto srv_addr = Address::TestAddress(2); + + Io cli_io = simulator.Register(cli_addr); + Io srv_io = simulator.Register(srv_addr); + + auto srv_thread = std::jthread(run_server, std::move(srv_io)); + + return 0; +} +} // namespace memgraph::tests::simulation