-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added list and delete results to cpp (#423)
- Loading branch information
Showing
18 changed files
with
253 additions
and
54 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
packages/angular/projects/aneoconsultingfr/armonik.api.angular/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include "logger/base.h" | ||
#include "objects.pb.h" | ||
#include <grpcpp/channel.h> | ||
#include <memory> | ||
|
||
/** | ||
* @brief Initializes task options creates channel with server address | ||
* | ||
* @param channel The gRPC channel to communicate with the server. | ||
* @param default_task_options The default task options. | ||
*/ | ||
void init(std::shared_ptr<grpc::Channel> &channel, armonik::api::grpc::v1::TaskOptions &task_options, | ||
armonik::api::common::logger::ILogger &logger); |
89 changes: 89 additions & 0 deletions
89
packages/cpp/ArmoniK.Api.Tests/source/ResultsClientTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include <gmock/gmock.h> | ||
#include <gtest/gtest.h> | ||
|
||
#include "common.h" | ||
#include "logger/formatter.h" | ||
#include "logger/logger.h" | ||
#include "logger/writer.h" | ||
|
||
#include "results_service.grpc.pb.h" | ||
#include "submitter/ResultsClient.h" | ||
#include "submitter/SubmitterClient.h" | ||
|
||
using Logger = armonik::api::common::logger::Logger; | ||
|
||
TEST(Results, test_results_created) { | ||
Logger log{armonik::api::common::logger::writer_console(), armonik::api::common::logger::formatter_plain(true)}; | ||
std::shared_ptr<::grpc::Channel> channel; | ||
armonik::api::grpc::v1::TaskOptions task_options; | ||
|
||
init(channel, task_options, log); | ||
|
||
auto client = armonik::api::client::ResultsClient(armonik::api::grpc::v1::results::Results::NewStub(channel)); | ||
auto sub_client = | ||
armonik::api::client::SubmitterClient(armonik::api::grpc::v1::submitter::Submitter::NewStub(channel)); | ||
auto session_id = sub_client.create_session(task_options, {}); | ||
auto map = client.create_results(session_id, std::vector<std::string>{"0", "1", "2", "3"}); | ||
ASSERT_TRUE(!map.empty()); | ||
ASSERT_EQ(map.size(), 4); | ||
} | ||
|
||
TEST(Results, test_results_list) { | ||
Logger log{armonik::api::common::logger::writer_console(), armonik::api::common::logger::formatter_plain(true)}; | ||
std::shared_ptr<::grpc::Channel> channel; | ||
armonik::api::grpc::v1::TaskOptions task_options; | ||
|
||
init(channel, task_options, log); | ||
|
||
auto client = armonik::api::client::ResultsClient(armonik::api::grpc::v1::results::Results::NewStub(channel)); | ||
auto sub_client = | ||
armonik::api::client::SubmitterClient(armonik::api::grpc::v1::submitter::Submitter::NewStub(channel)); | ||
auto session_id = sub_client.create_session(task_options, {}); | ||
auto map = client.create_results(session_id, std::vector<std::string>{"0", "1", "2", "3"}); | ||
ASSERT_TRUE(!map.empty()); | ||
ASSERT_EQ(map.size(), 4); | ||
|
||
armonik::api::grpc::v1::results::Filters filters; | ||
armonik::api::grpc::v1::results::FilterField filter_field; | ||
filter_field.mutable_field()->mutable_result_raw_field()->set_field( | ||
armonik::api::grpc::v1::results::RESULT_RAW_ENUM_FIELD_SESSION_ID); | ||
filter_field.mutable_filter_string()->set_value(session_id); | ||
filter_field.mutable_filter_string()->set_operator_(armonik::api::grpc::v1::FILTER_STRING_OPERATOR_EQUAL); | ||
*filters.mutable_or_()->Add()->mutable_and_()->Add() = filter_field; | ||
int total; | ||
auto list = client.list_results(filters, total); | ||
ASSERT_EQ(list.size(), 4); | ||
ASSERT_EQ(list.size(), total); | ||
} | ||
|
||
TEST(Results, test_results_list_small_page) { | ||
Logger log{armonik::api::common::logger::writer_console(), armonik::api::common::logger::formatter_plain(true)}; | ||
std::shared_ptr<::grpc::Channel> channel; | ||
armonik::api::grpc::v1::TaskOptions task_options; | ||
|
||
init(channel, task_options, log); | ||
|
||
auto client = armonik::api::client::ResultsClient(armonik::api::grpc::v1::results::Results::NewStub(channel)); | ||
auto sub_client = | ||
armonik::api::client::SubmitterClient(armonik::api::grpc::v1::submitter::Submitter::NewStub(channel)); | ||
auto session_id = sub_client.create_session(task_options, {}); | ||
auto map = client.create_results(session_id, std::vector<std::string>{"0", "1", "2", "3", "4"}); | ||
ASSERT_TRUE(!map.empty()); | ||
ASSERT_EQ(map.size(), 5); | ||
|
||
armonik::api::grpc::v1::results::Filters filters; | ||
armonik::api::grpc::v1::results::FilterField filter_field; | ||
filter_field.mutable_field()->mutable_result_raw_field()->set_field( | ||
armonik::api::grpc::v1::results::RESULT_RAW_ENUM_FIELD_SESSION_ID); | ||
filter_field.mutable_filter_string()->set_value(session_id); | ||
filter_field.mutable_filter_string()->set_operator_(armonik::api::grpc::v1::FILTER_STRING_OPERATOR_EQUAL); | ||
*filters.mutable_or_()->Add()->mutable_and_()->Add() = filter_field; | ||
int total; | ||
auto list = client.list_results(filters, total, 0, 2); | ||
ASSERT_EQ(list.size(), 2); | ||
ASSERT_EQ(total, 5); | ||
|
||
list = client.list_results(filters, total, -1, 2); | ||
ASSERT_EQ(list.size(), 5); | ||
ASSERT_EQ(total, 5); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "common.h" | ||
#include "utils/Configuration.h" | ||
#include <grpcpp/create_channel.h> | ||
|
||
/** | ||
* @brief Initializes task options creates channel with server address | ||
* | ||
* @param channel The gRPC channel to communicate with the server. | ||
* @param default_task_options The default task options. | ||
*/ | ||
void init(std::shared_ptr<::grpc::Channel> &channel, armonik::api::grpc::v1::TaskOptions &default_task_options, | ||
armonik::api::common::logger::ILogger &logger) { | ||
|
||
armonik::api::common::utils::Configuration configuration; | ||
// auto server = std::make_shared<EnvConfiguration>(configuration_t); | ||
|
||
configuration.add_json_configuration("appsettings.json").add_env_configuration(); | ||
|
||
std::string server_address = configuration.get("Grpc__EndPoint"); | ||
|
||
logger.info(" Server address {address}", {{"address", server_address}}); | ||
|
||
channel = ::grpc::CreateChannel(server_address, grpc::InsecureChannelCredentials()); | ||
|
||
// stub_ = Submitter::NewStub(channel); | ||
|
||
default_task_options.mutable_options()->insert({"key1", "value1"}); | ||
default_task_options.mutable_options()->insert({"key2", "value2"}); | ||
default_task_options.mutable_max_duration()->set_seconds(3600); | ||
default_task_options.mutable_max_duration()->set_nanos(0); | ||
default_task_options.set_max_retries(1); | ||
default_task_options.set_priority(1); | ||
default_task_options.set_partition_id(""); | ||
default_task_options.set_application_name("my-app"); | ||
default_task_options.set_application_version("1.0"); | ||
default_task_options.set_application_namespace("my-namespace"); | ||
default_task_options.set_application_service("my-service"); | ||
default_task_options.set_engine_type("Unified"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.