2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* flow.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
2022-03-22 04:36:23 +08:00
|
|
|
* Copyright 2013-2022 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "flow/flow.h"
|
2019-05-11 05:01:52 +08:00
|
|
|
#include "flow/DeterministicRandom.h"
|
2019-02-01 06:45:42 +08:00
|
|
|
#include "flow/UnitTest.h"
|
2020-05-02 04:23:20 +08:00
|
|
|
#include "flow/rte_memcpy.h"
|
2022-06-28 07:05:55 +08:00
|
|
|
#ifdef WITH_FOLLY_MEMCPY
|
|
|
|
#include "folly_memcpy.h"
|
|
|
|
#endif
|
2017-05-26 04:48:44 +08:00
|
|
|
#include <stdarg.h>
|
2019-05-04 08:01:43 +08:00
|
|
|
#include <cinttypes>
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-05-28 02:25:00 +08:00
|
|
|
std::atomic<bool> startSampling = false;
|
2021-06-16 06:03:44 +08:00
|
|
|
LineageReference rootLineage;
|
|
|
|
thread_local LineageReference* currentLineage = &rootLineage;
|
2021-06-04 06:10:04 +08:00
|
|
|
|
|
|
|
LineagePropertiesBase::~LineagePropertiesBase() {}
|
|
|
|
|
2021-07-24 08:18:13 +08:00
|
|
|
#ifdef ENABLE_SAMPLING
|
2021-06-16 06:03:44 +08:00
|
|
|
ActorLineage::ActorLineage() : properties(), parent(*currentLineage) {}
|
2021-07-24 08:18:13 +08:00
|
|
|
#else
|
|
|
|
ActorLineage::ActorLineage() : properties() {}
|
|
|
|
#endif
|
2021-06-04 06:10:04 +08:00
|
|
|
|
|
|
|
ActorLineage::~ActorLineage() {
|
2021-05-28 02:25:00 +08:00
|
|
|
for (auto property : properties) {
|
|
|
|
delete property.properties;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-31 01:21:07 +08:00
|
|
|
#ifdef ENABLE_SAMPLING
|
2021-06-18 07:50:34 +08:00
|
|
|
LineageReference getCurrentLineage() {
|
2021-06-16 06:03:44 +08:00
|
|
|
if (!currentLineage->isValid() || !currentLineage->isAllocated()) {
|
|
|
|
currentLineage->allocate();
|
2021-05-28 02:25:00 +08:00
|
|
|
}
|
2021-06-12 04:01:32 +08:00
|
|
|
return *currentLineage;
|
2021-05-28 02:25:00 +08:00
|
|
|
}
|
|
|
|
|
2021-06-17 09:08:51 +08:00
|
|
|
void sample(LineageReference* lineagePtr);
|
2021-06-08 09:01:14 +08:00
|
|
|
|
2021-06-16 06:03:44 +08:00
|
|
|
void replaceLineage(LineageReference* lineage) {
|
2021-05-28 02:25:00 +08:00
|
|
|
if (!startSampling) {
|
|
|
|
currentLineage = lineage;
|
|
|
|
} else {
|
|
|
|
startSampling = false;
|
2021-06-08 09:01:14 +08:00
|
|
|
sample(currentLineage);
|
2021-05-28 02:25:00 +08:00
|
|
|
currentLineage = lineage;
|
2021-06-04 06:10:04 +08:00
|
|
|
}
|
|
|
|
}
|
2021-07-28 02:26:18 +08:00
|
|
|
#endif
|
2021-06-04 06:10:04 +08:00
|
|
|
|
|
|
|
using namespace std::literals;
|
|
|
|
|
|
|
|
const std::string_view StackLineage::name = "StackLineage"sv;
|
|
|
|
|
2022-02-26 04:54:31 +08:00
|
|
|
#if (defined(__linux__) || defined(__FreeBSD__)) && defined(__AVX__) && !defined(MEMORY_SANITIZER) && !DEBUG_DETERMINISM
|
2020-05-05 05:44:42 +08:00
|
|
|
// For benchmarking; need a version of rte_memcpy that doesn't live in the same compilation unit as the test.
|
2020-05-02 04:23:20 +08:00
|
|
|
void* rte_memcpy_noinline(void* __restrict __dest, const void* __restrict __src, size_t __n) {
|
|
|
|
return rte_memcpy(__dest, __src, __n);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This compilation unit will be linked in to the main binary, so this should override glibc memcpy
|
|
|
|
__attribute__((visibility("default"))) void* memcpy(void* __restrict __dest, const void* __restrict __src, size_t __n) {
|
2020-05-05 05:44:42 +08:00
|
|
|
// folly_memcpy is faster for small copies, but rte seems to win out in most other circumstances
|
2020-05-02 04:23:20 +08:00
|
|
|
return rte_memcpy(__dest, __src, __n);
|
|
|
|
}
|
2020-06-03 07:09:43 +08:00
|
|
|
#else
|
|
|
|
void* rte_memcpy_noinline(void* __restrict __dest, const void* __restrict __src, size_t __n) {
|
|
|
|
return memcpy(__dest, __src, __n);
|
|
|
|
}
|
2020-10-15 04:50:06 +08:00
|
|
|
#endif // (defined (__linux__) || defined (__FreeBSD__)) && defined(__AVX__) && !defined(MEMORY_SANITIZER)
|
2020-05-02 04:23:20 +08:00
|
|
|
|
2021-12-01 12:14:35 +08:00
|
|
|
INetwork* g_network = nullptr;
|
2019-05-11 05:01:52 +08:00
|
|
|
|
2021-12-01 12:14:35 +08:00
|
|
|
FILE* randLog = nullptr;
|
2019-05-24 09:51:59 +08:00
|
|
|
thread_local Reference<IRandom> seededRandom;
|
2021-03-30 03:31:16 +08:00
|
|
|
Reference<IRandom> seededDebugRandom;
|
2017-05-26 04:48:44 +08:00
|
|
|
uint64_t debug_lastLoadBalanceResultEndpointToken = 0;
|
|
|
|
bool noUnseed = false;
|
|
|
|
|
2019-05-11 05:01:52 +08:00
|
|
|
void setThreadLocalDeterministicRandomSeed(uint32_t seed) {
|
2019-05-24 09:51:59 +08:00
|
|
|
seededRandom = Reference<IRandom>(new DeterministicRandom(seed, true));
|
2021-03-30 03:31:16 +08:00
|
|
|
seededDebugRandom = Reference<IRandom>(new DeterministicRandom(seed));
|
|
|
|
}
|
|
|
|
|
|
|
|
Reference<IRandom> debugRandom() {
|
|
|
|
return seededDebugRandom;
|
2019-05-11 05:01:52 +08:00
|
|
|
}
|
|
|
|
|
2019-05-24 09:51:59 +08:00
|
|
|
Reference<IRandom> deterministicRandom() {
|
|
|
|
if (!seededRandom) {
|
2019-06-05 04:40:48 +08:00
|
|
|
seededRandom = Reference<IRandom>(new DeterministicRandom(platform::getRandomSeed(), true));
|
2019-05-11 05:01:52 +08:00
|
|
|
}
|
2019-05-24 09:51:59 +08:00
|
|
|
return seededRandom;
|
2019-05-11 05:01:52 +08:00
|
|
|
}
|
|
|
|
|
2019-05-24 09:51:59 +08:00
|
|
|
Reference<IRandom> nondeterministicRandom() {
|
|
|
|
static thread_local Reference<IRandom> random;
|
2019-05-11 05:01:52 +08:00
|
|
|
if (!random) {
|
2019-05-24 09:51:59 +08:00
|
|
|
random = Reference<IRandom>(new DeterministicRandom(platform::getRandomSeed()));
|
2019-05-11 05:01:52 +08:00
|
|
|
}
|
|
|
|
return random;
|
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
std::string UID::toString() const {
|
|
|
|
return format("%016llx%016llx", part[0], part[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
UID UID::fromString(std::string const& s) {
|
|
|
|
ASSERT(s.size() == 32);
|
|
|
|
uint64_t a = 0, b = 0;
|
2019-05-04 08:01:43 +08:00
|
|
|
int r = sscanf(s.c_str(), "%16" SCNx64 "%16" SCNx64, &a, &b);
|
2017-05-26 04:48:44 +08:00
|
|
|
ASSERT(r == 2);
|
|
|
|
return UID(a, b);
|
|
|
|
}
|
|
|
|
|
2022-05-12 04:23:27 +08:00
|
|
|
UID UID::fromStringThrowsOnFailure(std::string const& s) {
|
|
|
|
if (s.size() != 32) {
|
|
|
|
// invalid string size
|
|
|
|
throw operation_failed();
|
|
|
|
}
|
|
|
|
uint64_t a = 0, b = 0;
|
|
|
|
int r = sscanf(s.c_str(), "%16" SCNx64 "%16" SCNx64, &a, &b);
|
|
|
|
if (r != 2) {
|
|
|
|
throw operation_failed();
|
|
|
|
}
|
|
|
|
return UID(a, b);
|
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
std::string UID::shortString() const {
|
|
|
|
return format("%016llx", part[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void detectFailureAfter(int const& address, double const& delay);
|
|
|
|
|
2021-06-10 02:37:14 +08:00
|
|
|
Optional<uint64_t> parse_with_suffix(std::string const& toparse, std::string const& default_unit) {
|
2017-09-30 01:35:40 +08:00
|
|
|
char* endptr;
|
|
|
|
|
|
|
|
uint64_t ret = strtoull(toparse.c_str(), &endptr, 10);
|
|
|
|
|
|
|
|
if (endptr == toparse.c_str()) {
|
|
|
|
return Optional<uint64_t>();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string unit;
|
|
|
|
|
|
|
|
if (*endptr == '\0') {
|
|
|
|
if (!default_unit.empty()) {
|
|
|
|
unit = default_unit;
|
|
|
|
} else {
|
|
|
|
return Optional<uint64_t>();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unit = endptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!unit.compare("B")) {
|
|
|
|
// Nothing to do
|
|
|
|
} else if (!unit.compare("KB")) {
|
|
|
|
ret *= int64_t(1e3);
|
|
|
|
} else if (!unit.compare("KiB")) {
|
|
|
|
ret *= 1LL << 10;
|
|
|
|
} else if (!unit.compare("MB")) {
|
|
|
|
ret *= int64_t(1e6);
|
|
|
|
} else if (!unit.compare("MiB")) {
|
|
|
|
ret *= 1LL << 20;
|
|
|
|
} else if (!unit.compare("GB")) {
|
|
|
|
ret *= int64_t(1e9);
|
|
|
|
} else if (!unit.compare("GiB")) {
|
|
|
|
ret *= 1LL << 30;
|
|
|
|
} else if (!unit.compare("TB")) {
|
|
|
|
ret *= int64_t(1e12);
|
|
|
|
} else if (!unit.compare("TiB")) {
|
|
|
|
ret *= 1LL << 40;
|
|
|
|
} else {
|
|
|
|
return Optional<uint64_t>();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-04-04 06:24:14 +08:00
|
|
|
// Parses a duration with one of the following suffixes and returns the duration in seconds
|
|
|
|
// s - seconds
|
|
|
|
// m - minutes
|
|
|
|
// h - hours
|
|
|
|
// d - days
|
2021-06-10 02:37:14 +08:00
|
|
|
Optional<uint64_t> parseDuration(std::string const& str, std::string const& defaultUnit) {
|
2020-04-04 06:24:14 +08:00
|
|
|
char* endptr;
|
|
|
|
uint64_t ret = strtoull(str.c_str(), &endptr, 10);
|
|
|
|
|
|
|
|
if (endptr == str.c_str()) {
|
|
|
|
return Optional<uint64_t>();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string unit;
|
|
|
|
if (*endptr == '\0') {
|
|
|
|
if (!defaultUnit.empty()) {
|
|
|
|
unit = defaultUnit;
|
|
|
|
} else {
|
|
|
|
return Optional<uint64_t>();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unit = endptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!unit.compare("s")) {
|
|
|
|
// Nothing to do
|
|
|
|
} else if (!unit.compare("m")) {
|
|
|
|
ret *= 60;
|
|
|
|
} else if (!unit.compare("h")) {
|
|
|
|
ret *= 60 * 60;
|
|
|
|
} else if (!unit.compare("d")) {
|
|
|
|
ret *= 24 * 60 * 60;
|
|
|
|
} else {
|
|
|
|
return Optional<uint64_t>();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-05-05 04:35:25 +08:00
|
|
|
int vsformat(std::string& outputString, const char* form, va_list args) {
|
2017-05-26 04:48:44 +08:00
|
|
|
char buf[200];
|
|
|
|
|
2018-05-03 01:44:38 +08:00
|
|
|
va_list args2;
|
|
|
|
va_copy(args2, args);
|
|
|
|
int size = vsnprintf(buf, sizeof(buf), form, args2);
|
|
|
|
va_end(args2);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
if (size >= 0 && size < sizeof(buf)) {
|
2018-05-05 04:35:25 +08:00
|
|
|
outputString = std::string(buf, size);
|
|
|
|
return size;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
// Microsoft's non-standard vsnprintf doesn't return a correct size, but just an error, so determine the necessary
|
|
|
|
// size
|
2018-05-03 01:44:38 +08:00
|
|
|
va_copy(args2, args);
|
|
|
|
size = _vscprintf(form, args2);
|
|
|
|
va_end(args2);
|
2017-05-26 04:48:44 +08:00
|
|
|
#endif
|
|
|
|
|
2018-05-05 04:35:25 +08:00
|
|
|
if (size < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
TEST(true); // large format result
|
|
|
|
|
2018-05-05 04:35:25 +08:00
|
|
|
outputString.resize(size + 1);
|
|
|
|
size = vsnprintf(&outputString[0], outputString.size(), form, args);
|
|
|
|
if (size < 0 || size >= outputString.size()) {
|
|
|
|
return -1;
|
|
|
|
}
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2018-05-05 04:35:25 +08:00
|
|
|
outputString.resize(size);
|
|
|
|
return size;
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2018-05-03 01:44:38 +08:00
|
|
|
std::string format(const char* form, ...) {
|
|
|
|
va_list args;
|
|
|
|
va_start(args, form);
|
|
|
|
|
2018-05-05 04:35:25 +08:00
|
|
|
std::string str;
|
|
|
|
int result = vsformat(str, form, args);
|
2018-05-03 01:44:38 +08:00
|
|
|
va_end(args);
|
|
|
|
|
2018-05-05 04:35:25 +08:00
|
|
|
ASSERT(result >= 0);
|
|
|
|
return str;
|
2018-05-03 01:44:38 +08:00
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
Standalone<StringRef> strinc(StringRef const& str) {
|
|
|
|
int index;
|
|
|
|
for (index = str.size() - 1; index >= 0; index--)
|
|
|
|
if (str[index] != 255)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Must not be called with a string that consists only of zero or more '\xff' bytes.
|
|
|
|
ASSERT(index >= 0);
|
|
|
|
|
|
|
|
Standalone<StringRef> r = str.substr(0, index + 1);
|
|
|
|
uint8_t* p = mutateString(r);
|
|
|
|
p[r.size() - 1]++;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef strinc(StringRef const& str, Arena& arena) {
|
|
|
|
int index;
|
|
|
|
for (index = str.size() - 1; index >= 0; index--)
|
|
|
|
if (str[index] != 255)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Must not be called with a string that consists only of zero or more '\xff' bytes.
|
|
|
|
ASSERT(index >= 0);
|
|
|
|
|
|
|
|
StringRef r(arena, str.substr(0, index + 1));
|
|
|
|
uint8_t* p = mutateString(r);
|
|
|
|
p[r.size() - 1]++;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2018-01-29 03:52:54 +08:00
|
|
|
StringRef addVersionStampAtEnd(StringRef const& str, Arena& arena) {
|
2018-05-11 08:00:35 +08:00
|
|
|
int32_t size = str.size();
|
|
|
|
uint8_t* s = new (arena) uint8_t[size + 14];
|
2018-01-29 03:52:54 +08:00
|
|
|
memcpy(s, str.begin(), size);
|
|
|
|
memset(&s[size], 0, 10);
|
2018-05-11 08:00:35 +08:00
|
|
|
memcpy(&s[size + 10], &size, 4);
|
|
|
|
return StringRef(s, size + 14);
|
2018-01-29 03:52:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Standalone<StringRef> addVersionStampAtEnd(StringRef const& str) {
|
|
|
|
Standalone<StringRef> r;
|
|
|
|
((StringRef&)r) = addVersionStampAtEnd(str, r.arena());
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2019-04-04 08:37:14 +08:00
|
|
|
namespace {
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2019-04-04 08:37:14 +08:00
|
|
|
std::vector<bool> buggifyActivated{ false, false };
|
|
|
|
std::map<BuggifyType, std::map<std::pair<std::string, int>, int>> typedSBVars;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2019-04-04 08:37:14 +08:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
std::vector<double> P_BUGGIFIED_SECTION_ACTIVATED{ .25, .25 };
|
|
|
|
std::vector<double> P_BUGGIFIED_SECTION_FIRES{ .25, .25 };
|
|
|
|
|
|
|
|
double P_EXPENSIVE_VALIDATION = .05;
|
|
|
|
|
2021-06-10 02:37:14 +08:00
|
|
|
int getSBVar(std::string const& file, int line, BuggifyType type) {
|
2019-04-04 08:37:14 +08:00
|
|
|
if (!buggifyActivated[int(type)])
|
|
|
|
return 0;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
const auto& flPair = std::make_pair(file, line);
|
2019-04-04 08:37:14 +08:00
|
|
|
auto& SBVars = typedSBVars[type];
|
2017-05-26 04:48:44 +08:00
|
|
|
if (!SBVars.count(flPair)) {
|
2019-04-04 08:37:14 +08:00
|
|
|
SBVars[flPair] = deterministicRandom()->random01() < P_BUGGIFIED_SECTION_ACTIVATED[int(type)];
|
2017-05-26 04:48:44 +08:00
|
|
|
g_traceBatch.addBuggify(SBVars[flPair], line, file);
|
|
|
|
if (g_network)
|
|
|
|
g_traceBatch.dump();
|
|
|
|
}
|
|
|
|
|
|
|
|
return SBVars[flPair];
|
|
|
|
}
|
|
|
|
|
2019-06-17 00:52:40 +08:00
|
|
|
void clearBuggifySections(BuggifyType type) {
|
|
|
|
typedSBVars[type].clear();
|
|
|
|
}
|
|
|
|
|
2019-04-04 08:37:14 +08:00
|
|
|
bool validationIsEnabled(BuggifyType type) {
|
|
|
|
return buggifyActivated[int(type)];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isBuggifyEnabled(BuggifyType type) {
|
|
|
|
return buggifyActivated[int(type)];
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2019-04-04 08:37:14 +08:00
|
|
|
void enableBuggify(bool enabled, BuggifyType type) {
|
|
|
|
buggifyActivated[int(type)] = enabled;
|
2019-05-04 08:01:43 +08:00
|
|
|
}
|
2019-02-01 06:45:42 +08:00
|
|
|
|
2019-08-29 05:40:50 +08:00
|
|
|
namespace {
|
|
|
|
// Simple message for flatbuffers unittests
|
|
|
|
struct Int {
|
|
|
|
constexpr static FileIdentifier file_identifier = 12345;
|
|
|
|
uint32_t value;
|
|
|
|
Int() = default;
|
|
|
|
Int(uint32_t value) : value(value) {}
|
|
|
|
template <class Ar>
|
|
|
|
void serialize(Ar& ar) {
|
|
|
|
serializer(ar, value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2019-02-01 06:45:42 +08:00
|
|
|
TEST_CASE("/flow/FlatBuffers/ErrorOr") {
|
|
|
|
{
|
2019-08-29 05:40:50 +08:00
|
|
|
ErrorOr<Int> in(worker_removed());
|
|
|
|
ErrorOr<Int> out;
|
2019-07-13 02:52:53 +08:00
|
|
|
ObjectWriter writer(Unversioned());
|
2019-02-01 06:45:42 +08:00
|
|
|
writer.serialize(in);
|
|
|
|
Standalone<StringRef> copy = writer.toStringRef();
|
2019-07-13 02:52:53 +08:00
|
|
|
ArenaObjectReader reader(copy.arena(), copy, Unversioned());
|
2019-02-01 06:45:42 +08:00
|
|
|
reader.deserialize(out);
|
|
|
|
ASSERT(out.isError());
|
|
|
|
ASSERT(out.getError().code() == in.getError().code());
|
|
|
|
}
|
|
|
|
{
|
2019-08-29 05:40:50 +08:00
|
|
|
ErrorOr<Int> in(deterministicRandom()->randomUInt32());
|
|
|
|
ErrorOr<Int> out;
|
2019-07-13 02:52:53 +08:00
|
|
|
ObjectWriter writer(Unversioned());
|
2019-02-01 06:45:42 +08:00
|
|
|
writer.serialize(in);
|
|
|
|
Standalone<StringRef> copy = writer.toStringRef();
|
2019-07-13 02:52:53 +08:00
|
|
|
ArenaObjectReader reader(copy.arena(), copy, Unversioned());
|
2019-02-01 06:45:42 +08:00
|
|
|
reader.deserialize(out);
|
|
|
|
ASSERT(!out.isError());
|
2019-08-29 05:40:50 +08:00
|
|
|
ASSERT(out.get().value == in.get().value);
|
2019-02-01 06:45:42 +08:00
|
|
|
}
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("/flow/FlatBuffers/Optional") {
|
|
|
|
{
|
2019-08-29 05:40:50 +08:00
|
|
|
Optional<Int> in;
|
|
|
|
Optional<Int> out;
|
2019-07-13 02:52:53 +08:00
|
|
|
ObjectWriter writer(Unversioned());
|
2019-02-01 06:45:42 +08:00
|
|
|
writer.serialize(in);
|
|
|
|
Standalone<StringRef> copy = writer.toStringRef();
|
2019-07-13 02:52:53 +08:00
|
|
|
ArenaObjectReader reader(copy.arena(), copy, Unversioned());
|
2019-02-01 06:45:42 +08:00
|
|
|
reader.deserialize(out);
|
|
|
|
ASSERT(!out.present());
|
|
|
|
}
|
|
|
|
{
|
2019-08-29 05:40:50 +08:00
|
|
|
Optional<Int> in(deterministicRandom()->randomUInt32());
|
|
|
|
Optional<Int> out;
|
2019-07-13 02:52:53 +08:00
|
|
|
ObjectWriter writer(Unversioned());
|
2019-02-01 06:45:42 +08:00
|
|
|
writer.serialize(in);
|
|
|
|
Standalone<StringRef> copy = writer.toStringRef();
|
2019-07-13 02:52:53 +08:00
|
|
|
ArenaObjectReader reader(copy.arena(), copy, Unversioned());
|
2019-02-01 06:45:42 +08:00
|
|
|
reader.deserialize(out);
|
|
|
|
ASSERT(out.present());
|
2019-08-29 05:40:50 +08:00
|
|
|
ASSERT(out.get().value == in.get().value);
|
2019-02-01 06:45:42 +08:00
|
|
|
}
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("/flow/FlatBuffers/Standalone") {
|
|
|
|
{
|
|
|
|
Standalone<StringRef> in(std::string("foobar"));
|
|
|
|
StringRef out;
|
2019-07-13 02:52:53 +08:00
|
|
|
ObjectWriter writer(Unversioned());
|
2019-02-01 06:45:42 +08:00
|
|
|
writer.serialize(in);
|
|
|
|
Standalone<StringRef> copy = writer.toStringRef();
|
2019-07-13 02:52:53 +08:00
|
|
|
ArenaObjectReader reader(copy.arena(), copy, Unversioned());
|
2019-02-01 06:45:42 +08:00
|
|
|
reader.deserialize(out);
|
|
|
|
ASSERT(in == out);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
StringRef in = LiteralStringRef("foobar");
|
|
|
|
Standalone<StringRef> out;
|
2019-07-13 02:52:53 +08:00
|
|
|
ObjectWriter writer(Unversioned());
|
2019-02-01 06:45:42 +08:00
|
|
|
writer.serialize(in);
|
|
|
|
Standalone<StringRef> copy = writer.toStringRef();
|
2019-07-13 02:52:53 +08:00
|
|
|
ArenaObjectReader reader(copy.arena(), copy, Unversioned());
|
2019-02-01 06:45:42 +08:00
|
|
|
reader.deserialize(out);
|
|
|
|
ASSERT(in == out);
|
|
|
|
}
|
|
|
|
return Void();
|
|
|
|
}
|
2022-02-25 22:21:27 +08:00
|
|
|
|
|
|
|
// we need to make sure at least one test of each prefix exists, otherwise
|
|
|
|
// the noSim test fails if we compile without RocksDB
|
|
|
|
TEST_CASE("noSim/noopTest") {
|
|
|
|
return Void();
|
|
|
|
}
|