Kinetic C/C++ Client
 All Classes Functions Variables Pages
blocking_smoketest.cc
1 /*
2  * kinetic-cpp-client
3  * Copyright (C) 2014 Seagate Technology.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  */
20 
21 #include <memory>
22 
23 #include "gtest/gtest.h"
24 #include "integration_test.h"
25 
26 namespace kinetic {
27 
28 using std::shared_ptr;
29 using std::make_shared;
30 using std::vector;
31 
32 using com::seagate::kinetic::client::proto::Command_Algorithm_CRC32;
33 using com::seagate::kinetic::client::proto::Command_Algorithm_SHA1;
34 
35 TEST_F(IntegrationTest, BlockingSmoketest) {
36  ASSERT_TRUE(blocking_connection_->NoOp().ok());
37 
38  auto record1 = make_shared<KineticRecord>(make_shared<string>("value1"),
39  make_shared<string>("v1"), make_shared<string>("t1"), Command_Algorithm_CRC32);
40  KineticStatus kineticStatus = blocking_connection_->Put("key1", "", WriteMode::IGNORE_VERSION, *record1);
41  ASSERT_TRUE(kineticStatus.ok());
42 
43  auto record2 = make_shared<KineticRecord>(make_shared<string>("value2"),
44  make_shared<string>("v2"), make_shared<string>("t2"), Command_Algorithm_SHA1);
45  ASSERT_TRUE(blocking_connection_->Put(make_shared<string>("key2"), make_shared<string>(""),
46  WriteMode::IGNORE_VERSION, record2).ok());
47 
48  auto record3 = make_shared<KineticRecord>(make_shared<string>("value3"),
49  make_shared<string>("v3"), make_shared<string>("t3"), Command_Algorithm_CRC32);
50  ASSERT_TRUE(blocking_connection_->Put(make_shared<string>("key3"), make_shared<string>(""),
51  WriteMode::IGNORE_VERSION, record3).ok());
52 
53  KeyRangeIterator it = blocking_connection_->IterateKeyRange("key1", true, "key3", false, 1);
54  ASSERT_EQ("key1", *it);
55  ++it;
56  ASSERT_EQ("key2", *it);
57  ++it;
58  ASSERT_EQ(KeyRangeEnd(), it);
59 
60 
61  std::unique_ptr<KineticRecord> result_record;
62  ASSERT_TRUE(blocking_connection_->Get("key2", result_record).ok());
63  EXPECT_EQ("value2", *(result_record->value()));
64  EXPECT_EQ("v2", *(result_record->version()));
65  EXPECT_EQ("t2", *(result_record->tag()));
66  EXPECT_EQ(Command_Algorithm_SHA1, result_record->algorithm());
67 
68  unique_ptr<string> result_key(nullptr);
69  ASSERT_TRUE(blocking_connection_->GetNext("key1", result_key, result_record).ok());
70  EXPECT_EQ("key2", *result_key);
71  EXPECT_EQ("value2", *(result_record->value()));
72  EXPECT_EQ("v2", *(result_record->version()));
73  EXPECT_EQ("t2", *(result_record->tag()));
74  EXPECT_EQ(Command_Algorithm_SHA1, result_record->algorithm());
75 
76  ASSERT_TRUE(blocking_connection_->GetPrevious("key3", result_key, result_record).ok());
77  EXPECT_EQ("key2", *result_key);
78  EXPECT_EQ("value2", *(result_record->value()));
79  EXPECT_EQ("v2", *(result_record->version()));
80  EXPECT_EQ("t2", *(result_record->tag()));
81  EXPECT_EQ(Command_Algorithm_SHA1, result_record->algorithm());
82 
83  unique_ptr<string> result_version(nullptr);
84  ASSERT_TRUE(blocking_connection_->GetVersion("key3", result_version).ok());
85  EXPECT_EQ("v3", *result_version);
86 
87  unique_ptr<vector<string>> actual_keys(new vector<string>);
88  vector<string> expected_keys = {"key2", "key3"};
89  KineticStatus status =
90  blocking_connection_->GetKeyRange("key1", false, "key3", true, false, 2, actual_keys);
91  ASSERT_TRUE(status.ok());
92  EXPECT_EQ(expected_keys, *actual_keys);
93 
94  ASSERT_TRUE(blocking_connection_->Delete("key1", "", WriteMode::IGNORE_VERSION).ok());
95 
96  ASSERT_EQ(blocking_connection_->Get("key1", result_record).statusCode(), StatusCode::REMOTE_NOT_FOUND);
97 
98  ASSERT_TRUE(blocking_connection_->InstantErase("").ok());
99 
100  ASSERT_EQ(blocking_connection_->Get("key3", result_record).statusCode(), StatusCode::REMOTE_NOT_FOUND);
101 
102  blocking_connection_->SetClientClusterVersion(33);
103 
104  ASSERT_EQ(blocking_connection_->Get("key1", result_record).statusCode(),
105  StatusCode::REMOTE_CLUSTER_VERSION_MISMATCH);
106 }
107 
108 } // namespace kinetic