observed_queue_test.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 #include <chrono>
16 #include <string>
17 
18 #include <gtest/gtest.h>
19 #include <gmock/gmock.h>
20 
24 
25 using namespace Aws::DataFlow;
26 
27 
29  auto status_monitor = std::make_shared<StatusMonitor>();
30  observed_queue.setStatusMonitor(status_monitor);
31 
32  EXPECT_EQ(Status::UNAVAILABLE, status_monitor->getStatus());
33  observed_queue.enqueue("hello");
34  EXPECT_EQ(Status::AVAILABLE, status_monitor->getStatus());
35  std::string data;
36  ASSERT_TRUE(observed_queue.dequeue(data, std::chrono::microseconds(0)));
37  EXPECT_EQ("hello", data);
38  EXPECT_TRUE(observed_queue.empty());
39  EXPECT_EQ(Status::UNAVAILABLE, status_monitor->getStatus());
40 }
41 
42 TEST(observed_queue_test, Sanity) {
43  ASSERT_TRUE(true);
44 }
45 
46 TEST(observed_queue_test, enqueue_dequeue_test) {
47  ObservedQueue<std::string> observed_queue;
48  test_enqueue_dequeue(observed_queue);
49 }
50 
51 TEST(observed_queue_test, blocking_enqueue_dequeue_test) {
52  ObservedBlockingQueue<std::string> observed_queue(1);
53  test_enqueue_dequeue(observed_queue);
54 }
55 
56 TEST(observed_queue_test, synchronized_enqueue_dequeue_test) {
58  test_enqueue_dequeue(observed_queue);
59 }
60 
61 TEST(observed_queue_test, enqueue_blocked_dequeue_test) {
62  ObservedBlockingQueue<std::string> observed_queue(1);
63  auto status_monitor = std::make_shared<StatusMonitor>();
64  observed_queue.setStatusMonitor(status_monitor);
65 
66  EXPECT_EQ(Status::UNAVAILABLE, status_monitor->getStatus());
67  EXPECT_TRUE(observed_queue.tryEnqueue("hello", std::chrono::seconds(0)));
68  EXPECT_FALSE(observed_queue.tryEnqueue("fail", std::chrono::seconds(0)));
69  std::string data;
70  ASSERT_TRUE(observed_queue.dequeue(data, std::chrono::microseconds(0)));
71  EXPECT_EQ("hello", data);
72  EXPECT_TRUE(observed_queue.tryEnqueue("hello", std::chrono::seconds(0)));
73 }
virtual void setStatusMonitor(std::shared_ptr< StatusMonitor > status_monitor)=0
void test_enqueue_dequeue(IObservedQueue< std::string > &observed_queue)
bool dequeue(T &data, const std::chrono::microseconds &duration) override
void setStatusMonitor(std::shared_ptr< StatusMonitor > status_monitor) override
bool tryEnqueue(T &value, const std::chrono::microseconds &duration) override
TEST(observed_queue_test, Sanity)
virtual bool dequeue(T &, const std::chrono::microseconds &duration)=0
virtual bool enqueue(T &&value)=0
virtual bool empty() const =0


dataflow_lite
Author(s): AWS RoboMaker
autogenerated on Fri May 7 2021 02:18:22