Skip to content

Commit

Permalink
Support GetVersion
Browse files Browse the repository at this point in the history
Fixes: milvus-io#220

Signed-off-by: Ji Bin <[email protected]>
  • Loading branch information
matrixji committed Mar 22, 2023
1 parent 6c6f87c commit c65a769
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 62 deletions.
33 changes: 0 additions & 33 deletions cmake/CPM.cmake

This file was deleted.

62 changes: 42 additions & 20 deletions cmake/ThirdPartyPackages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,33 @@

include_guard(GLOBAL)

include(CPM)
include(FetchContent)

set(GRPC_VERSION 1.49.1)
set(NLOHMANN_JSON_VERSION 3.11.2)
set(GOOGLETEST_VERSION 1.12.1)

# grpc
FetchContent_Declare(
grpc
GIT_REPOSITORY https://github.com/grpc/grpc.git
GIT_TAG v${GRPC_VERSION}
)

# nlohmann_json
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v${NLOHMANN_JSON_VERSION}
)

# googletest
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-${GOOGLETEST_VERSION}
)


# grpc
if ("${MILVUS_WITH_GRPC}" STREQUAL "pakcage")
Expand All @@ -27,20 +53,17 @@ else ()
else ()
set(OPENSSL_NO_ASM_TXT "NO")
endif ()
CPMAddPackage(
NAME grpc
VERSION 1.49.1
GITHUB_REPOSITORY grpc/grpc
EXCLUDE_FROM_ALL YES
OPTIONS
"gRPC_SSL_PROVIDER module"
"gRPC_PROTOBUF_PROVIDER module"
"gRPC_BUILD_TESTS OFF"
"RE2_BUILD_TESTING OFF"
"ABSL_PROPAGATE_CXX_STD ON"
"OPENSSL_NO_ASM ${OPENSSL_NO_ASM_TXT}"
)
if (grpc_ADDED)
if (NOT grpc_POPULATED)
FetchContent_Populate(grpc)
if (WIN32)
set(OPENSSL_NO_ASM YES CACHE INTERNAL "")
endif()
set(gRPC_SSL_PROVIDER "module" CACHE INTERNAL "")
set(gRPC_PROTOBUF_PROVIDER "module" CACHE INTERNAL "")
set(gRPC_BUILD_TESTS OFF CACHE INTERNAL "")
set(RE2_BUILD_TESTING OFF CACHE INTERNAL "")
set(ABSL_PROPAGATE_CXX_STD ON CACHE INTERNAL "")
add_subdirectory(${grpc_SOURCE_DIR} ${grpc_BINARY_DIR} EXCLUDE_FROM_ALL)
add_library(gRPC::grpc++ ALIAS grpc++)
endif ()
endif ()
Expand All @@ -50,9 +73,8 @@ endif ()
if ("${MILVUS_WITH_NLOHMANN_JSON}" STREQUAL "package")
find_package(nlohmann_json REQUIRED)
else ()
CPMAddPackage(
NAME nlohmann_json
VERSION 3.11.2
GITHUB_REPOSITORY nlohmann/json
)
if (NOT nlohmann_json_POPULATED)
FetchContent_Populate(nlohmann_json)
add_subdirectory(${nlohmann_json_SOURCE_DIR} ${nlohmann_json_BINARY_DIR} EXCLUDE_FROM_ALL)
endif ()
endif ()
13 changes: 13 additions & 0 deletions src/impl/MilvusClientImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ MilvusClientImpl::Disconnect() {
return Status::OK();
}

Status
MilvusClientImpl::GetVersion(std::string& version) {
auto pre = []() {
proto::milvus::GetVersionRequest rpc_request;
return rpc_request;
};

auto post = [&version](const proto::milvus::GetVersionResponse& response) { version = response.version(); };

return apiHandler<proto::milvus::GetVersionRequest, proto::milvus::GetVersionResponse>(
pre, &MilvusConnection::GetVersion, post);
}

Status
MilvusClientImpl::CreateCollection(const CollectionSchema& schema) {
auto pre = [&schema]() {
Expand Down
3 changes: 3 additions & 0 deletions src/impl/MilvusClientImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class MilvusClientImpl : public MilvusClient {
Status
Disconnect() final;

Status
GetVersion(std::string& version) final;

Status
CreateCollection(const CollectionSchema& schema) final;

Expand Down
6 changes: 6 additions & 0 deletions src/impl/MilvusConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ MilvusConnection::Disconnect() {
return Status::OK();
}

Status
MilvusConnection::GetVersion(const proto::milvus::GetVersionRequest& request,
proto::milvus::GetVersionResponse& response, const GrpcContextOptions& options) {
return grpcCall("GetVersion", &Stub::GetVersion, request, response, options);
}

Status
MilvusConnection::CreateCollection(const proto::milvus::CreateCollectionRequest& request,
proto::common::Status& response, const GrpcContextOptions& options) {
Expand Down
3 changes: 3 additions & 0 deletions src/impl/MilvusConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class MilvusConnection {
Status
Disconnect();

Status
GetVersion(const proto::milvus::GetVersionRequest& request, proto::milvus::GetVersionResponse& response,
const GrpcContextOptions& options);
Status
CreateCollection(const proto::milvus::CreateCollectionRequest& request, proto::common::Status& response,
const GrpcContextOptions& options);
Expand Down
10 changes: 10 additions & 0 deletions src/include/milvus/MilvusClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ class MilvusClient {
virtual Status
Disconnect() = 0;

/**
* Get milvus server version
*
* @param [out] version version string
* @return Status operation successfully or not
*
*/
virtual Status
GetVersion(std::string& version) = 0;

/**
* Create a collection with schema.
*
Expand Down
15 changes: 6 additions & 9 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@ include_directories(${milvus_proto_BINARY_DIR})
if ("${MILVUS_WITH_GTEST}" STREQUAL "pakcage")
find_package(GTest REQUIRED)
else ()
CPMAddPackage(
NAME googletest
GIT_TAG release-1.12.1
VERSION 1.12.1
GITHUB_REPOSITORY google/googletest
OPTIONS
"INSTALL_GTEST OFF"
"gtest_force_shared_crt ON"
)
if (NOT googletest_POPULATED)
FetchContent_Populate(googletest)
set(gtest_force_shared_crt ON CACHE INTERNAL "")
set(INSTALL_GTEST OFF CACHE INTERNAL "")
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
endif ()
endif ()

set(GTEST_LIBRARIES gtest)
Expand Down
42 changes: 42 additions & 0 deletions test/it/TestGetVersion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Licensed to the LF AI & Data foundation under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <gtest/gtest.h>

#include "milvus.pb.h"
#include "mocks/MilvusMockedTest.h"

using ::milvus::StatusCode;
using ::milvus::proto::milvus::GetVersionRequest;
using ::testing::_;
using ::testing::Property;

TEST_F(MilvusMockedTest, GetVersionFoo) {
milvus::ConnectParam connect_param{"127.0.0.1", server_.ListenPort()};
client_->Connect(connect_param);

EXPECT_CALL(service_, GetVersion(_, _, _))
.WillOnce([](::grpc::ServerContext*, const GetVersionRequest*,
::milvus::proto::milvus::GetVersionResponse* response) {
response->set_version("2.0.0");
return ::grpc::Status{};
});
std::string version;
auto status = client_->GetVersion(version);

EXPECT_TRUE(status.IsOk());
EXPECT_EQ(version, "2.0.0");
}
3 changes: 3 additions & 0 deletions test/it/mocks/MilvusMockedService.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
#include <gmock/gmock.h>

#include "milvus.grpc.pb.h"
#include "milvus.pb.h"

namespace milvus {
class MilvusMockedService : public ::milvus::proto::milvus::MilvusService::Service {
public:
MOCK_METHOD3(GetVersion, ::grpc::Status(::grpc::ServerContext*, const ::milvus::proto::milvus::GetVersionRequest*,
::milvus::proto::milvus::GetVersionResponse*));
MOCK_METHOD3(CreateCollection,
::grpc::Status(::grpc::ServerContext*, const ::milvus::proto::milvus::CreateCollectionRequest*,
::milvus::proto::common::Status*));
Expand Down
34 changes: 34 additions & 0 deletions test/st/TestGeneric.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the LF AI & Data foundation under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <gtest/gtest.h>

#include "MilvusServerTest.h"
#include "gmock/gmock.h"

using milvus::test::MilvusServerTest;

class MilvusServerTestGeneric : public MilvusServerTest {};

TEST_F(MilvusServerTestGeneric, GetVersion) {
milvus::ConnectParam connect_param{"127.0.0.1", server_.ListenPort()};
client_->Connect(connect_param);

std::string version;
auto status = client_->GetVersion(version);
EXPECT_TRUE(status.IsOk());
EXPECT_THAT(version, testing::StartsWith("v2."));
}

0 comments on commit c65a769

Please sign in to comment.