You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by li...@apache.org on 2021/10/25 03:03:20 UTC
[rocketmq-client-cpp] branch main updated: Remove unused test cases
This is an automated email from the ASF dual-hosted git repository.
lizhanhui pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/rocketmq-client-cpp.git
The following commit(s) were added to refs/heads/main by this push:
new 925915f Remove unused test cases
925915f is described below
commit 925915f1f19be67c0ce205757645c5910b2867b5
Author: Li Zhanhui <li...@gmail.com>
AuthorDate: Mon Oct 25 11:03:11 2021 +0800
Remove unused test cases
---
src/test/cpp/ut/grpc/BUILD.bazel | 40 ----------
src/test/cpp/ut/grpc/GrpcThreadPoolTest.cpp | 50 ------------
src/test/cpp/ut/grpc/GrpcTimer.cpp | 116 ----------------------------
3 files changed, 206 deletions(-)
diff --git a/src/test/cpp/ut/grpc/BUILD.bazel b/src/test/cpp/ut/grpc/BUILD.bazel
deleted file mode 100644
index 1383d88..0000000
--- a/src/test/cpp/ut/grpc/BUILD.bazel
+++ /dev/null
@@ -1,40 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) 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.
-#
-load("@rules_cc//cc:defs.bzl", "cc_test")
-cc_test(
- name = "grpc_thread_pool_test",
- srcs = [
- "GrpcThreadPoolTest.cpp",
- ],
- deps = [
- "//api:rocketmq_interface",
- "@com_github_grpc_grpc//:grpc++",
- "@com_google_googletest//:gtest_main",
- ],
-)
-
-cc_test(
- name = "grpc_timer_test",
- srcs = [
- "GrpcTimer.cpp",
- ],
- deps = [
- "//api:rocketmq_interface",
- "@com_github_grpc_grpc//:grpc++",
- "@com_google_googletest//:gtest_main",
- ],
-)
\ No newline at end of file
diff --git a/src/test/cpp/ut/grpc/GrpcThreadPoolTest.cpp b/src/test/cpp/ut/grpc/GrpcThreadPoolTest.cpp
deleted file mode 100644
index b912d06..0000000
--- a/src/test/cpp/ut/grpc/GrpcThreadPoolTest.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) 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 "absl/memory/memory.h"
-#include "absl/synchronization/mutex.h"
-#include "rocketmq/RocketMQ.h"
-#include "src/cpp/server/dynamic_thread_pool.h"
-#include "src/cpp/server/thread_pool_interface.h"
-#include "gtest/gtest.h"
-
-ROCKETMQ_NAMESPACE_BEGIN
-
-TEST(GrpcThreadPoolTest, testSetUp) {
- auto thread_pool = std::unique_ptr<grpc::ThreadPoolInterface>(grpc::CreateDefaultThreadPool());
-
- absl::Mutex mtx;
- absl::CondVar cv;
-
- bool invoked = false;
-
- auto callback = [&]() {
- absl::MutexLock lk(&mtx);
- invoked = true;
- cv.SignalAll();
- };
-
- thread_pool->Add(callback);
-
- if (!invoked) {
- absl::MutexLock lk(&mtx);
- cv.WaitWithTimeout(&mtx, absl::Seconds(3));
- }
-
- ASSERT_TRUE(invoked);
-}
-
-ROCKETMQ_NAMESPACE_END
\ No newline at end of file
diff --git a/src/test/cpp/ut/grpc/GrpcTimer.cpp b/src/test/cpp/ut/grpc/GrpcTimer.cpp
deleted file mode 100644
index 0643271..0000000
--- a/src/test/cpp/ut/grpc/GrpcTimer.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) 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 "absl/time/time.h"
-#include "grpc/grpc.h"
-#include "rocketmq/RocketMQ.h"
-#include "src/core/lib/iomgr/closure.h"
-#include "src/core/lib/iomgr/timer.h"
-#include "gtest/gtest.h"
-#include <atomic>
-#include <functional>
-#include <iostream>
-#include <sys/stat.h>
-#include <thread>
-
-ROCKETMQ_NAMESPACE_BEGIN
-
-struct Timer {
- grpc_timer g_timer;
- absl::Mutex mtx;
- absl::CondVar cv;
- bool invoked{false};
-};
-
-struct PeriodicTimer {
- grpc_timer g_timer;
- absl::Duration initial_delay{absl::Seconds(3)};
- absl::Duration interval{absl::Seconds(1)};
- int times{10};
-};
-
-class GrpcTimerTest : public testing::Test {
-public:
- void SetUp() override {
- grpc_init();
- }
- void TearDown() override {
- grpc_shutdown();
- }
-
- static void schedule(void* arg, grpc_error_handle error) {
- auto timer = static_cast<PeriodicTimer*>(arg);
- if (error == GRPC_ERROR_CANCELLED) {
- std::cout << absl::FormatTime(absl::Now()) << ": job cancelled" << std::endl;
- delete timer;
- return;
- }
-
- std::cout << "Thread-" << std::this_thread::get_id() << ": Periodic Callback" << std::endl;
- grpc_core::ExecCtx exec_ctx;
- std::cout << absl::FormatTime(absl::Now()) << ": Timer->times = " << timer->times << std::endl;
- if (!--timer->times) {
- delete timer;
- std::cout << "Delete periodic timer" << std::endl;
- return;
- }
-
- grpc_timer_init(&timer->g_timer, grpc_core::ExecCtx::Get()->Now() + 1000,
- GRPC_CLOSURE_CREATE(schedule, timer, grpc_schedule_on_exec_ctx));
- }
-};
-
-TEST_F(GrpcTimerTest, testSetUp) {
-}
-
-TEST_F(GrpcTimerTest, testSingleShot) {
- grpc_core::ExecCtx exec_ctx;
- Timer timer;
-
- auto callback = [](void* arg, grpc_error_handle error) {
- std::cout << "Callback" << std::endl;
- auto t = static_cast<Timer*>(arg);
- absl::MutexLock lk(&t->mtx);
- t->invoked = true;
- t->cv.SignalAll();
- };
-
- grpc_timer_init(&timer.g_timer, grpc_core::ExecCtx::Get()->Now() + 500,
- GRPC_CLOSURE_CREATE(callback, &timer, grpc_schedule_on_exec_ctx));
-
- std::cout << "Waiting callback invocation" << std::endl;
-
- while (!timer.invoked) {
- absl::MutexLock lk(&timer.mtx);
- timer.cv.Wait(&timer.mtx);
- }
- ASSERT_TRUE(timer.invoked);
-}
-
-TEST_F(GrpcTimerTest, testMultiShot) {
- grpc_core::ExecCtx exec_ctx;
- auto timer = new PeriodicTimer();
- std::cout << absl::FormatTime(absl::Now()) << ": Arm the timer" << std::endl;
- std::cout << "Now = " << grpc_core::ExecCtx::Get()->Now() << std::endl;
- grpc_timer_init(&timer->g_timer, grpc_core::ExecCtx::Get()->Now() + 3000,
- GRPC_CLOSURE_CREATE(schedule, timer, grpc_schedule_on_exec_ctx));
-
- absl::SleepFor(absl::Seconds(5));
- grpc_timer_cancel(&timer->g_timer);
-}
-
-ROCKETMQ_NAMESPACE_END
\ No newline at end of file