8000 Bug fix/implement windows maintenance tests (#9763) · arangodb/arangodb@828e416 · GitHub
[go: up one dir, main page]

Skip to content

Commit 828e416

Browse files
dothebartjsteemann
authored andcommitted
Bug fix/implement windows maintenance tests (#9763)
1 parent 1e9ad7f commit 828e416

File tree

5 files changed

+10958
-20
lines changed

5 files changed

+10958
-20
lines changed

tests/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ endforeach()
77
################################################################################
88
## IResearch
99
################################################################################
10+
if (WINDOWS)
11+
set(RCFILE Maintenance/json.rc)
12+
endif ()
1013

1114
set(ARANGODB_TESTS_SOURCES
1215
Agency/ActiveFailoverTest.cpp
@@ -171,9 +174,7 @@ set(ARANGODB_TESTS_SOURCES
171174
Maintenance/MaintenanceFeatureTest.cpp
172175
Maintenance/MaintenanceRestHandlerTest.cpp
173176
Maintenance/MaintenanceTest.cpp
174-
Network/ConnectionPoolTest.cpp
175-
Network/MethodsTest.cpp
176-
Network/UtilsTest.cpp
177+
${RCFILE}
177178
Mocks/StorageEngineMock.cpp
178179
Mocks/Servers.cpp
179180
Pregel/typedbuffer.cpp

tests/Maintenance/MaintenanceTest.cpp

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,42 @@ char const* dbs2Str =
6868
#include "DBServer0003.json"
6969
;
7070

71+
int loadResources(void) {return 0;}
72+
73+
#else // _WIN32
74+
#include <Windows.h>
75+
#include "jsonresource.h"
76+
LPSTR planStr = nullptr;
77+
LPSTR currentStr = nullptr;
78+
LPSTR supervisionStr = nullptr;
79+
LPSTR dbs0Str = nullptr;
80+
LPSTR dbs1Str = nullptr;
81+
LPSTR dbs2Str = nullptr;
82+
83+
LPSTR getResource(int which) {
84+
HRSRC myResource = ::FindResource(NULL, MAKEINTRESOURCE(which), RT_RCDATA);
85+
HGLOBAL myResourceData = ::LoadResource(NULL, myResource);
86+
return (LPSTR) ::LockResource(myResourceData);
87+
}
88+
int loadResources(void) {
89+
if ((planStr == nullptr) &&
90+
(currentStr == nullptr) &&
91+
(supervisionStr == nullptr) &&
92+
(dbs0Str == nullptr) &&
93+
(dbs1Str == nullptr) &&
94+
(dbs2Str == nullptr)) {
95+
planStr = getResource(IDS_PLAN);
96+
currentStr = getResource(IDS_CURRENT);
97+
dbs0Str = getResource(IDS_DBSERVER0001);
98+
dbs1Str = getResource(IDS_DBSERVER0002);
99+
dbs2Str = getResource(IDS_DBSERVER0003);
100+
supervisionStr = getResource(IDS_SUPERVISION);
101+
}
102+
return 0;
103+
}
104+
105+
#endif // _WIN32
106+
71107
std::map<std::string, std::string> matchShortLongIds(Node const& supervision) {
72108
std::map<std::string, std::string> ret;
73109
for (auto const& dbs : supervision("Health").children()) {
@@ -291,6 +327,7 @@ class LogicalCollection;
291327
class MaintenanceTestActionDescription : public ::testing::Test {
292328
protected:
293329
MaintenanceTestActionDescription() {
330+
loadResources();
294331
plan = createNode(planStr);
295332
originalPlan = plan;
296333
supervision = createNode(supervisionStr);
@@ -324,8 +361,7 @@ TEST_F(MaintenanceTestActionDescription, retrieve_nonassigned_key_from_actiondes
324361
try {
325362
auto bogus = desc.get("bogus");
326363
ASSERT_TRUE(bogus == "bogus");
327-
} catch (std::out_of_range const& e) {
328-
}
364+
} catch (std::out_of_range const&) { }
329365
std::string value;
330366
auto res = desc.get("bogus", value);
331367
ASSERT_TRUE(value.empty());
@@ -339,8 +375,7 @@ TEST_F(MaintenanceTestActionDescription, retrieve_nonassigned_key_from_actiondes
339375
try {
340376
auto bogus = desc.get("bogus");
341377
ASSERT_TRUE(bogus == "bogus");
342-
} catch (std::out_of_range const& e) {
343-
}
378+
} catch (std::out_of_range const&) { }
344379
std::string value;
345380
auto res = desc.get("bogus", value);
346381
ASSERT_TRUE(value == "bogus");
@@ -434,6 +469,7 @@ TEST_F(MaintenanceTestActionDescription, retrieve_array_value_from_actiondescrip
434469

435470
class MaintenanceTestActionPhaseOne : public ::testing::Test {
436471
protected:
472+
int _dummy;
437473
std::shared_ptr<arangodb::options::ProgramOptions> po;
43 6D40 8474
arangodb::application_features::ApplicationServer as;
439475
TestMaintenanceFeature feature;
@@ -443,18 +479,19 @@ class MaintenanceTestActionPhaseOne : public ::testing::Test {
443479

444480
arangodb::MMFilesEngine engine; // arbitrary implementation that has index types registered
445481
arangodb::StorageEngine* origStorageEngine;
446-
482+
447483
MaintenanceTestActionPhaseOne()
448-
: po(std::make_shared<arangodb::options::ProgramOptions>("test", std::string(),
449-
std::string(),
450-
"path")),
451-
as(po, nullptr),
452-
feature(as),
453-
localNodes{{dbsIds[shortNames[0]], createNode(dbs0Str)},
454-
{dbsIds[shortNames[1]], createNode(dbs1Str)},
455-
{dbsIds[shortNames[2]], createNode(dbs2Str)}},
456-
engine(as),
457-
origStorageEngine(arangodb::EngineSelectorFeature::ENGINE) {
484+
: _dummy(loadResources()),
485+
po(std::make_shared<arangodb::options::ProgramOptions>("test", std::string(),
486+
std::string(),
487+
"path")),
488+
as(po, nullptr),
489+
feature(as),
490+
localNodes{{dbsIds[shortNames[0]], createNode(dbs0Str)},
491+
{dbsIds[shortNames[1]], createNode(dbs1Str)},
492+
{dbsIds[shortNames[2]], createNode(dbs2Str)}},
493+
engine(as),
494+
origStorageEngine(arangodb::EngineSelectorFeature::ENGINE) {
458495
arangodb::EngineSelectorFeature::ENGINE = &engine;
459496
}
460497

@@ -836,5 +873,3 @@ TEST_F(MaintenanceTestActionPhaseOne, removed_follower_in_plan_must_be_dropped)
836873
}
837874
}
838875
}
839-
840-
#endif

tests/Maintenance/generateRcFile.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
# this script picks all json-header files, and dumps them into a windows RC file style file
3+
echo > jsonresource.h
4+
(
5+
i=1
6+
for JSON in *.json ; do
7+
RCNAME="#define IDS_$(echo "${JSON}" |sed -e "s;.json;;" -e 's/\(.*\)/\U\1/') ${i}"
8+
echo "${RCNAME}" >> jsonresource.h
9+
i=$(($i + 1))
10+
done
11+
printf '#include "jsonresource.h"\r\n'
12+
for JSON in *.json ; do
13+
RCNAME="IDS_$(echo "${JSON}"|sed -e "s;.json;;" -e 's/\(.*\)/\U\1/')"
14+
15+
printf "${RCNAME} RCDATA\r\n{\r\n"
16+
# first cut off the .h related syntax...
17+
cat "${JSON}" |sed -e 's;^R"=($;;' -e 's;^)="$;;' | \
18+
sed -e 's;";"";g' -e 's;^; ";' -e 's;$;",;'
19+
# then escape quotes (by doubling them) and pre & post pend quotes.
20+
printf '"\\0"\r\n}\r\n'
21+
done
22+
printf "\r\n}\r\n"
23+
) > json.rc

0 commit comments

Comments
 (0)
0