8000 Bug fix/fix catch test issues (#7044) · sita1999/arangodb@221d036 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 221d036

Browse files
authored
Bug fix/fix catch test issues (arangodb#7044)
1 parent 28e22d6 commit 221d036

File tree

6 files changed

+61
-39
lines changed

6 files changed

+61
-39
lines changed

arangod/Cluster/SynchronizeShard.cpp

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,9 @@ SynchronizeShard::SynchronizeShard(
117117
_result.reset(TRI_ERROR_INTERNAL, error.str());
118118
setState(FAILED);
119119
}
120-
121120
}
122121

123-
class SynchronizeShardCallback : public arangodb::ClusterCommCallback {
1 8000 22+
class SynchronizeShardCallback : public arangodb::ClusterCommCallback {
124123
public:
125124
explicit SynchronizeShardCallback(SynchronizeShard* callie) {};
126125
virtual bool operator()(arangodb::ClusterCommResult*) override final {
@@ -130,8 +129,7 @@ class SynchronizeShardCallback : public arangodb::ClusterCommCallback {
130129

131130
SynchronizeShard::~SynchronizeShard() {}
132131

133-
134-
arangodb::Result getReadLockId (
132+
arangodb::Result getReadLockId(
135133
std::string const& endpoint, std::string const& database,
136134
std::string const& clientId, double timeout, uint64_t& id) {
137135

@@ -168,10 +166,8 @@ arangodb::Result getReadLockId (
168166
}
169167

170168
return arangodb::Result();
171-
172169
}
173170

174-
175171
arangodb::Result collectionCount(
176172
std::shared_ptr<arangodb::LogicalCollection> const& col, uint64_t& c) {
177173

@@ -204,10 +200,10 @@ arangodb::Result collectionCount(
204200
return opResult.result;
205201
}
206202

207-
arangodb::Result addShardFollower (
203+
arangodb::Result addShardFollower(
208204
std::string const& endpoint, std::string const& database,
209205
std::string const& shard, uint64_t lockJobId,
210-
std::string const& clientId, double timeout = 120.0 ) {
206+
std::string const& clientId, double timeout = 120.0) {
211207

212208
LOG_TOPIC(DEBUG, Logger::MAINTENANCE)
213209
<< "addShardFollower: tell the leader to put us into the follower list...";
@@ -291,12 +287,10 @@ arangodb::Result addShardFollower (
291287
}
292288
}
293289

294-
295-
arangodb::Result removeShardFollower (
290+
arangodb::Result removeShardFollower(
296291
std::string const& endpoint, std::string const& database,
297292
std::string const& shard, std::string const& clientId, double timeout = 120.0) {
298293

299-
300294
LOG_TOPIC(WARN, Logger::MAINTENANCE) <<
301295
"removeShardFollower: tell the leader to take us off the follower list...";
302296

@@ -332,10 +326,9 @@ arangodb::Result removeShardFollower (
332326

333327
LOG_TOPIC(WARN, Logger::MAINTENANCE) << "removeShardFollower: success" ;
334328
return arangodb::Result();
335-
336329
}
337330

338-
arangodb::Result cancelReadLockOnLeader (
331+
arangodb::Result cancelReadLockOnLeader(
339332
std::string const& endpoint, std::string const& database,
340333
uint64_t lockJobId, std::string const& clientId,
341334
double timeout = 10.0) {
@@ -370,10 +363,8 @@ arangodb::Result cancelReadLockOnLeader (
370363

371364
LOG_TOPIC(DEBUG, Logger::MAINTENANCE) << "cancelReadLockOnLeader: success";
372365
return arangodb::Result();
373-
374366
}
375367

376-
377368
arangodb::Result cancelBarrier(
378369
std::string const& endpoint, std::string const& database,
379370
int64_t barrierId, std::string const& clientId,
@@ -412,10 +403,8 @@ arangodb::Result cancelBarrier(
412403

413404
LOG_TOPIC(DEBUG, Logger::MAINTENANCE) << "cancelBarrier: success";
414405
return arangodb::Result();
415-
416406
}
417407

418-
419408
arangodb::Result SynchronizeShard::getReadLock(
420409
std::string const& endpoint, std::string const& database,
421410
std::string const& collection, std::string const& clientId,
@@ -516,7 +505,6 @@ arangodb::Result SynchronizeShard::startReadLockOnLeader(
516505
result = getReadLock(endpoint, database, collection, clientId, rlid, timeout);
517506

518507
return result;
519-
520508
}
521509

522510
enum ApplierType {
@@ -546,8 +534,6 @@ arangodb::Result replicationSynchronize(
546534

547535
std::shared_ptr<InitialSyncer> syncer;
548536

549-
config.toJson();
550-
551537
if (applierType == APPLIER_DATABASE) {
552538
// database-specific synchronization
553539
syncer.reset(new DatabaseInitialSyncer(vocbase, configuration));
@@ -608,7 +594,6 @@ arangodb::Result replicationSynchronize(
608594

609595

610596
arangodb::Result replicationSynchronizeFinalize(VPackSlice const& conf) {
611-
612597
auto const database = conf.get(DATABASE).copyString();
613598
auto const collection = conf.get(COLLECTION).copyString();
614599
auto const leaderId = conf.get(LEADER_ID).copyString();
@@ -645,9 +630,7 @@ arangodb::Result replicationSynchronizeFinalize(VPackSlice const& conf) {
645630
return r;
646631
}
647632

648-
649633
bool SynchronizeShard::first() {
650-
651634
std::string database = _description.get(DATABASE);
652635
std::string planId = _description.get(COLLECTION);
653636
std::string shard = _description.get(SHARD);
@@ -669,7 +652,7 @@ bool SynchronizeShard::first() {
669652
while(true) {
670653

671654
if (isStopping()) {
672-
_result.reset(TRI_ERROR_INTERNAL, "shutting down");
655+
_result.reset(TRI_ERROR_SHUTTING_DOWN);
673656
return false;
674657
}
675658

arangod/Sharding/ShardingInfo.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "Logger/Logger.h"
3131
#include "Sharding/ShardingFeature.h"
3232
#include "Sharding/ShardingStrategy.h"
33+
#include "Sharding/ShardingStrategyDefault.h"
3334
#include "Utils/CollectionNameResolver.h"
3435
#include "VocBase/KeyGenerator.h"
3536
#include "VocBase/LogicalCollection.h"
@@ -175,9 +176,14 @@ ShardingInfo::ShardingInfo(arangodb::velocypack::Slice info, LogicalCollection*
175176
}
176177
}
177178
}
178-
179+
179180
// set the sharding strategy
180-
_shardingStrategy = application_features::ApplicationServer::getFeature<ShardingFeature>("Sharding")->fromVelocyPack(info, this);
181+
if (!ServerState::instance()->isRunningInCluster()) {
182+
// shortcut, so we do not need to set up the whole application server for testing
183+
_shardingStrategy = std::make_unique<ShardingStrategyNone>();
184+
} else {
185+
_shardingStrategy = application_features::ApplicationServer::getFeature<ShardingFeature>("Sharding")->fromVelocyPack(info, this);
186+
}
181187
TRI_ASSERT(_shardingStrategy != nullptr);
182188
}
183189

arangod/VocBase/LogicalCollection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ChecksumResult : public Result {
7474
velocypack::Builder _builder;
7575
};
7676

77-
class LogicalCollection: public LogicalDataSource {
77+
class LogicalCollection : public LogicalDataSource {
7878
friend struct ::TRI_vocbase_t;
7979

8080
public:

arangod/VocBase/LogicalDataSource.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ class LogicalDataSource {
135135
bool deleted() const noexcept { return _deleted; }
136136
virtual Result drop() = 0;
137137
std::string const& guid() const noexcept { return _guid; }
138-
TRI_voc_cid_t const& id() const noexcept { return _id; } // reference required for ShardDistributionReporterTest
138+
TRI_voc_cid_t id() const noexcept { return _id; }
139139
std::string const& name() const noexcept { return _name; }
140140
TRI_voc_cid_t planId() const noexcept { return _planId; }
141141
uint64_t planVersion() const noexcept { return _planVersion; }
142142
virtual Result rename(std::string&& newName, bool doSync) = 0;
143143
bool system() const noexcept { return _system; }
144-
144+
145145
//////////////////////////////////////////////////////////////////////////////
146146
/// @brief append a jSON definition of the data-source to the 'builder'
147147
/// @param the buffer to append to, must be an open object

tests/RocksDBEngine/IndexEstimatorTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "catch.hpp"
3131

3232
#include "RocksDBEngine/RocksDBCuckooIndexEstimator.h"
33+
#include "RocksDBEngine/RocksDBFormat.h"
34+
#include "RocksDBEngine/RocksDBTypes.h"
3335

3436
using namespace arangodb;
3537

@@ -41,6 +43,7 @@ using namespace arangodb;
4143

4244
TEST_CASE("IndexEstimator", "[rocksdb][indexestimator]") {
4345
// @brief Test insert unique correctness
46+
rocksutils::setRocksDBKeyFormatEndianess(RocksDBEndianness::Little);
4447

4548
SECTION("test_unique_values") {
4649
std::vector<uint64_t> toInsert(100);

tests/Sharding/ShardDistributionReporterTest.cpp

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@
2828
#include "catch.hpp"
2929
#include "fakeit.hpp"
3030

31+
#include "ApplicationFeatures/ApplicationServer.h"
3132
#include "Cluster/ClusterComm.h"
33+
#include "RestServer/DatabaseFeature.h"
34+
#include "RestServer/QueryRegistryFeature.h"
3235
#include "Sharding/ShardDistributionReporter.h"
3336
#include "SimpleHttpClient/SimpleHttpResult.h"
37+
#include "StorageEngine/EngineSelectorFeature.h"
3438
#include "VocBase/LogicalCollection.h"
3539
#include "VocBase/ticks.h"
40+
#include "tests/IResearch/StorageEngineMock.h"
3641

3742
#include <velocypack/Builder.h>
3843
#include <velocypack/Slice.h>
@@ -94,6 +99,21 @@ static std::shared_ptr<VPackBuilder> buildCountBody(uint64_t count) {
9499
}
95100

96101
SCENARIO("The shard distribution can be reported", "[cluster][shards]") {
102+
arangodb::application_features::ApplicationServer server(nullptr, nullptr);
103+
StorageEngineMock engine(server);
104+
arangodb::EngineSelectorFeature::ENGINE = &engine;
105+
std::vector<std::pair<arangodb::application_features::ApplicationFeature*, bool>> features;
106+
features.emplace_back(new arangodb::DatabaseFeature(server), false); // required for TRI_vocbase_t::dropCollection(...)
107+
features.emplace_back(new arangodb::QueryRegistryFeature(server), false); // required for TRI_vocbase_t instantiation
108+
109+
for (auto& f: features) {
110+
arangodb::application_features::ApplicationServer::server->addFeature(f.first);
111+
}
112+
113+
for (auto& f: features) {
114+
f.first->prepare();
115+
}
116+
97117
fakeit::Mock<ClusterComm> commMock;
98118
ClusterComm& cc = commMock.get();
99119

@@ -106,12 +126,8 @@ SCENARIO("The shard distribution can be reported", "[cluster][shards]") {
106126
std::shared_ptr<CollectionInfoCurrent> cic(&cicInst,
107127
[](CollectionInfoCurrent*) {});
108128

109-
fakeit::Mock<LogicalCollection> colMock;
110-
LogicalCollection& col = colMock.get();
111-
112129
std::string dbname = "UnitTestDB";
113130
std::string colName = "UnitTestCollection";
114-
TRI_voc_cid_t cid = 1337;
115131
std::string cidString = "1337";
116132

117133
std::string s1 = "s1234";
@@ -125,6 +141,10 @@ SCENARIO("The shard distribution can be reported", "[cluster][shards]") {
125141
std::string dbserver1short = "DBServer1";
126142
std::string dbserver2short = "DBServer2";
127143
std::string dbserver3short = "DBServer3";
144+
145+
TRI_vocbase_t vocbase(TRI_vocbase_type_e::TRI_VOCBASE_TYPE_NORMAL, 1, "testVocbase");
146+
auto json = arangodb::velocypack::Parser::fromJson("{ \"cid\" : \"1337\", \"name\": \"UnitTestCollection\" }");
147+
arangodb::LogicalCollection col(vocbase, json->slice(), true);
128148

129149
// Fake the aliases
130150
auto aliases =
@@ -135,6 +155,8 @@ SCENARIO("The shard distribution can be reported", "[cluster][shards]") {
135155
// Fake the shard map
136156
auto shards = std::make_shared<ShardMap>();
137157
ShardMap currentShards;
158+
159+
col.setShardMap(shards);
138160

139161
// Fake the collections
140162
std::vector<std::shared_ptr<LogicalCollection>> allCollections;
@@ -167,12 +189,6 @@ SCENARIO("The shard distribution can be reported", "[cluster][shards]") {
167189
return cic;
168190
});
169191

170-
const_cast<std::string&>(col.name()).assign(colName);
171-
fakeit::When(
172-
ConstOverloadedMethod(colMock, shardIds, std::shared_ptr<ShardMap>()))
173-
.AlwaysReturn(shards);
174-
const_cast<TRI_voc_cid_t&>(col.id()) = cid;
175-
176192
ShardDistributionReporter testee(
177193
std::shared_ptr<ClusterComm>(&cc, [](ClusterComm*) {}), &ci);
178194

@@ -227,6 +243,8 @@ SCENARIO("The shard distribution can be reported", "[cluster][shards]") {
227243
std::vector<ServerID>{dbserver2, dbserver1, dbserver3});
228244
shards->emplace(s3,
229245
std::vector<ServerID>{dbserver3, dbserver1, dbserver2});
246+
247+
col.setShardMap(shards);
230248

231249
currentShards.emplace(
232250
s1, std::vector<ServerID>{dbserver1, dbserver2, dbserver3});
@@ -843,6 +861,8 @@ SCENARIO("The shard distribution can be reported", "[cluster][shards]") {
843861
WHEN("testing distribution for database") {
844862
GIVEN("A single collection of three shards, and 3 replicas") {
845863
shards->emplace(s1, std::vector<ServerID>{dbserver1, dbserver2, dbserver3});
864+
865+
col.setShardMap(shards);
846866

847867
currentShards.emplace(s1, std::vector<ServerID>{dbserver1});
848868

@@ -946,6 +966,8 @@ SCENARIO("The shard distribution can be reported", "[cluster][shards]") {
946966
WHEN("testing collection distribution for database") {
947967
GIVEN("A single collection of three shards, and 3 replicas") {
948968
shards->emplace(s1, std::vector<ServerID>{dbserver1, dbserver2, dbserver3});
969+
970+
col.setShardMap(shards);
949971

950972
currentShards.emplace(s1, std::vector<ServerID>{dbserver1});
951973

@@ -1088,6 +1110,8 @@ SCENARIO("The shard distribution can be reported", "[cluster][shards]") {
10881110
WHEN("testing distribution for database") {
10891111
GIVEN("An unhealthy cluster") {
10901112
shards->emplace(s1, std::vector<ServerID>{dbserver1, dbserver2, dbserver3});
1113+
1114+
col.setShardMap(shards);
10911115

10921116
currentShards.emplace(s1, std::vector<ServerID>{dbserver1});
10931117

@@ -1411,6 +1435,8 @@ SCENARIO("The shard distribution can be reported", "[cluster][shards]") {
14111435
WHEN("testing collection distribution for database") {
14121436
GIVEN("An unhealthy cluster") {
14131437
shards->emplace(s1, std::vector<ServerID>{dbserver1, dbserver2, dbserver3});
1438+
1439+
col.setShardMap(shards);
14141440

14151441
currentShards.emplace(s1, std::vector<ServerID>{dbserver1});
14161442

@@ -1879,6 +1905,10 @@ SCENARIO("The shard distribution can be reported", "[cluster][shards]") {
18791905
}*/
18801906
}
18811907
}
1908+
1909+
for (auto& f: features) {
1910+
f.first->unprepare();
1911+
}
18821912
}
18831913

18841914
// -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)
0