Skip to content

Commit 55842b1

Browse files
mrambacherigorcanadi
authored andcommitted
Fix the CloudTest
1. Fix merge issues 2. The TwoConcurrentWriters test was failing with an assert caused by the handles_ class member. Changed the handles to be a local variable and fix the tests. All tests pass in debug mode now.
1 parent cad0556 commit 55842b1

File tree

1 file changed

+46
-38
lines changed

1 file changed

+46
-38
lines changed

cloud/db_cloud_test.cc

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -129,30 +129,27 @@ class CloudTest : public testing::Test {
129129

130130
// Open database via the cloud interface
131131
void OpenDB() {
132-
// default column family
133-
ColumnFamilyOptions cfopt = options_;
134-
std::vector<ColumnFamilyDescriptor> column_families;
135-
column_families.emplace_back(
136-
ColumnFamilyDescriptor(kDefaultColumnFamilyName, cfopt));
137-
138-
OpenWithColumnFamilies({kDefaultColumnFamilyName});
132+
std::vector<ColumnFamilyHandle*> handles;
133+
OpenDB(&handles);
134+
// Delete the handle for the default column family because the DBImpl
135+
// always holds a reference to it.
136+
ASSERT_TRUE(handles.size() > 0);
137+
delete handles[0];
139138
}
140139

141-
void CreateColumnFamilies(const std::vector<std::string>& cfs) {
142-
size_t cfi = handles_.size();
143-
handles_.resize(cfi + cfs.size());
144-
for (auto cf : cfs) {
145-
ASSERT_OK(db_->CreateColumnFamily(options_, cf, &handles_[cfi++]));
146-
}
140+
// Open database via the cloud interface
141+
void OpenDB(std::vector<ColumnFamilyHandle*>* handles) {
142+
// default column family
143+
OpenWithColumnFamilies({kDefaultColumnFamilyName}, handles);
147144
}
148145

149-
void OpenWithColumnFamilies(const std::vector<std::string>& cfs) {
146+
void OpenWithColumnFamilies(const std::vector<std::string>& cfs,
147+
std::vector<ColumnFamilyHandle*>* handles) {
150148
ASSERT_TRUE(cloud_env_options_.credentials.HasValid().ok());
151149

152150
// Create new AWS env
153151
CreateCloudEnv();
154152
options_.env = aenv_.get();
155-
156153
// Sleep for a second because S3 is eventual consistency.
157154
std::this_thread::sleep_for(std::chrono::seconds(1));
158155

@@ -163,10 +160,20 @@ class CloudTest : public testing::Test {
163160
}
164161
ASSERT_OK(DBCloud::Open(options_, dbname_, column_families,
165162
persistent_cache_path_, persistent_cache_size_gb_,
166-
&handles_, &db_));
163+
handles, &db_));
167164
ASSERT_OK(db_->GetDbIdentity(dbid_));
168165
}
169166

167+
void CreateColumnFamilies(const std::vector<std::string>& cfs,
168+
std::vector<ColumnFamilyHandle*>* handles) {
169+
ASSERT_NE(db_, nullptr);
170+
size_t cfi = handles->size();
171+
handles->resize(cfi + cfs.size());
172+
for (auto cf : cfs) {
173+
ASSERT_OK(db_->CreateColumnFamily(options_, cf, &handles->at(cfi++)));
174+
}
175+
}
176+
170177
// Creates and Opens a clone
171178
Status CloneDB(const std::string& clone_name,
172179
const std::string& dest_bucket_name,
@@ -233,11 +240,15 @@ class CloudTest : public testing::Test {
233240
return st;
234241
}
235242

236-
void CloseDB() {
237-
for (auto h : handles_) {
243+
void CloseDB(std::vector<ColumnFamilyHandle*>* handles) {
244+
for (auto h : *handles) {
238245
delete h;
239246
}
240-
handles_.clear();
247+
handles->clear();
248+
CloseDB();
249+
}
250+
251+
void CloseDB() {
241252
if (db_) {
242253
db_->Flush(FlushOptions()); // convert pending writes to sst files
243254
delete db_;
@@ -301,8 +312,6 @@ class CloudTest : public testing::Test {
301312
uint64_t persistent_cache_size_gb_;
302313
DBCloud* db_;
303314
std::unique_ptr<CloudEnv> aenv_;
304-
305-
std::vector<ColumnFamilyHandle*> handles_;
306315
};
307316

308317
//
@@ -438,38 +447,39 @@ TEST_F(CloudTest, Newdb) {
438447
}
439448

440449
TEST_F(CloudTest, ColumnFamilies) {
450+
std::vector<ColumnFamilyHandle*> handles;
441451
// Put one key-value
442-
OpenDB();
452+
OpenDB(&handles);
443453

444-
CreateColumnFamilies({"cf1", "cf2"});
454+
CreateColumnFamilies({"cf1", "cf2"}, &handles);
445455

446-
ASSERT_OK(db_->Put(WriteOptions(), handles_[0], "hello", "a"));
447-
ASSERT_OK(db_->Put(WriteOptions(), handles_[1], "hello", "b"));
448-
ASSERT_OK(db_->Put(WriteOptions(), handles_[2], "hello", "c"));
456+
ASSERT_OK(db_->Put(WriteOptions(), handles[0], "hello", "a"));
457+
ASSERT_OK(db_->Put(WriteOptions(), handles[1], "hello", "b"));
458+
ASSERT_OK(db_->Put(WriteOptions(), handles[2], "hello", "c"));
449459

450460
auto validate = [&]() {
451461
std::string value;
452-
ASSERT_OK(db_->Get(ReadOptions(), handles_[0], "hello", &value));
462+
ASSERT_OK(db_->Get(ReadOptions(), handles[0], "hello", &value));
453463
ASSERT_EQ(value, "a");
454-
ASSERT_OK(db_->Get(ReadOptions(), handles_[1], "hello", &value));
464+
ASSERT_OK(db_->Get(ReadOptions(), handles[1], "hello", &value));
455465
ASSERT_EQ(value, "b");
456-
ASSERT_OK(db_->Get(ReadOptions(), handles_[2], "hello", &value));
466+
ASSERT_OK(db_->Get(ReadOptions(), handles[2], "hello", &value));
457467
ASSERT_EQ(value, "c");
458468
};
459469

460470
validate();
461471

462-
CloseDB();
463-
OpenWithColumnFamilies({kDefaultColumnFamilyName, "cf1", "cf2"});
472+
CloseDB(&handles);
473+
OpenWithColumnFamilies({kDefaultColumnFamilyName, "cf1", "cf2"}, &handles);
464474

465475
validate();
466-
CloseDB();
476+
CloseDB(&handles);
467477

468478
// destory local state
469479
DestroyDir(dbname_);
470480

471-
// new aws env
472-
CreateAwsEnv();
481+
// new cloud env
482+
CreateCloudEnv();
473483
options_.env = aenv_.get();
474484

475485
std::vector<std::string> families;
@@ -478,10 +488,9 @@ TEST_F(CloudTest, ColumnFamilies) {
478488
ASSERT_TRUE(families == std::vector<std::string>(
479489
{"cf1", "cf2", kDefaultColumnFamilyName}));
480490

481-
482-
OpenWithColumnFamilies({kDefaultColumnFamilyName, "cf1", "cf2"});
491+
OpenWithColumnFamilies({kDefaultColumnFamilyName, "cf1", "cf2"}, &handles);
483492
validate();
484-
CloseDB();
493+
CloseDB(&handles);
485494
}
486495

487496
//
@@ -1090,7 +1099,6 @@ TEST_F(CloudTest, TwoConcurrentWriters) {
10901099
// S3 bucket
10911100
ASSERT_OK(db1->Put(WriteOptions(), "ShouldNotBeApplied", ""));
10921101
ASSERT_OK(db1->Flush(FlushOptions()));
1093-
10941102
closeDB1();
10951103
closeDB2();
10961104

0 commit comments

Comments
 (0)