Format all the memgraph and test source files (#97)
This commit is contained in:
@@ -36,8 +36,7 @@ auto rand_gen_bool(size_t n = 1) {
|
||||
|
||||
// Checks for all owned keys if their data is data.
|
||||
template <typename TAccessor>
|
||||
void check_present_same(TAccessor &acc, size_t data,
|
||||
std::vector<size_t> &owned) {
|
||||
void check_present_same(TAccessor &acc, size_t data, std::vector<size_t> &owned) {
|
||||
for (auto num : owned) {
|
||||
MG_ASSERT(acc.find(num)->second == data, "My data is present and my");
|
||||
}
|
||||
@@ -45,8 +44,7 @@ void check_present_same(TAccessor &acc, size_t data,
|
||||
|
||||
// Checks for all owned.second keys if their data is owned.first.
|
||||
template <typename TAccessor>
|
||||
void check_present_same(TAccessor &acc,
|
||||
std::pair<size_t, std::vector<size_t>> &owned) {
|
||||
void check_present_same(TAccessor &acc, std::pair<size_t, std::vector<size_t>> &owned) {
|
||||
check_present_same(acc, owned.first, owned.second);
|
||||
}
|
||||
|
||||
@@ -55,8 +53,7 @@ template <typename TAccessor>
|
||||
void check_size_list(TAccessor &acc, long long size) {
|
||||
// check size
|
||||
|
||||
MG_ASSERT(acc.size() == size, "Size should be {}, but size is {}", size,
|
||||
acc.size());
|
||||
MG_ASSERT(acc.size() == size, "Size should be {}, but size is {}", size, acc.size());
|
||||
|
||||
// check count
|
||||
|
||||
@@ -65,16 +62,14 @@ void check_size_list(TAccessor &acc, long long size) {
|
||||
for ([[gnu::unused]] auto elem : acc) {
|
||||
++iterator_counter;
|
||||
}
|
||||
MG_ASSERT(static_cast<int64_t>(iterator_counter) == size,
|
||||
"Iterator count should be {}, but size is {}", size,
|
||||
MG_ASSERT(static_cast<int64_t>(iterator_counter) == size, "Iterator count should be {}, but size is {}", size,
|
||||
iterator_counter);
|
||||
}
|
||||
template <typename TAccessor>
|
||||
void check_size(TAccessor &acc, long long size) {
|
||||
// check size
|
||||
|
||||
MG_ASSERT(acc.size() == size, "Size should be {}, but size is {}", size,
|
||||
acc.size());
|
||||
MG_ASSERT(acc.size() == size, "Size should be {}, but size is {}", size, acc.size());
|
||||
|
||||
// check count
|
||||
|
||||
@@ -84,8 +79,7 @@ void check_size(TAccessor &acc, long long size) {
|
||||
++iterator_counter;
|
||||
}
|
||||
MG_ASSERT(static_cast<int64_t>(iterator_counter) == size)
|
||||
<< "Iterator count should be " << size << ", but size is "
|
||||
<< iterator_counter;
|
||||
<< "Iterator count should be " << size << ", but size is " << iterator_counter;
|
||||
}
|
||||
|
||||
// Checks if order in list is maintened. It expects map
|
||||
@@ -95,8 +89,7 @@ void check_order(TAccessor &acc) {
|
||||
auto last = acc.begin()->first;
|
||||
for (auto elem : acc) {
|
||||
if (!(last <= elem))
|
||||
std::cout << "Order isn't maintained. Before was: " << last
|
||||
<< " next is " << elem.first << "\n";
|
||||
std::cout << "Order isn't maintained. Before was: " << last << " next is " << elem.first << "\n";
|
||||
last = elem.first;
|
||||
}
|
||||
}
|
||||
@@ -104,9 +97,7 @@ void check_order(TAccessor &acc) {
|
||||
|
||||
void check_zero(size_t key_range, long array[], const char *str) {
|
||||
for (int i = 0; i < static_cast<int>(key_range); i++) {
|
||||
MG_ASSERT(array[i] == 0,
|
||||
"{} doesn't hold it's guarantees. It has {} extra elements.", str,
|
||||
array[i]);
|
||||
MG_ASSERT(array[i] == 0, "{} doesn't hold it's guarantees. It has {} extra elements.", str, array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,8 +110,7 @@ void check_set(DynamicBitset<> &db, std::vector<bool> &set) {
|
||||
// Runs given function in threads_no threads and returns vector of futures for
|
||||
// their results.
|
||||
template <class R, typename S, class FunT>
|
||||
std::vector<std::future<std::pair<size_t, R>>> run(size_t threads_no,
|
||||
S &skiplist, FunT f) {
|
||||
std::vector<std::future<std::pair<size_t, R>>> run(size_t threads_no, S &skiplist, FunT f) {
|
||||
std::vector<std::future<std::pair<size_t, R>>> futures;
|
||||
|
||||
for (size_t thread_i = 0; thread_i < threads_no; ++thread_i) {
|
||||
@@ -136,15 +126,13 @@ std::vector<std::future<std::pair<size_t, R>>> run(size_t threads_no,
|
||||
// Runs given function in threads_no threads and returns vector of futures for
|
||||
// their results.
|
||||
template <class R>
|
||||
std::vector<std::future<std::pair<size_t, R>>> run(size_t threads_no,
|
||||
std::function<R(size_t)> f) {
|
||||
std::vector<std::future<std::pair<size_t, R>>> run(size_t threads_no, std::function<R(size_t)> f) {
|
||||
std::vector<std::future<std::pair<size_t, R>>> futures;
|
||||
|
||||
for (size_t thread_i = 0; thread_i < threads_no; ++thread_i) {
|
||||
std::packaged_task<std::pair<size_t, R>()> task([f, thread_i]() {
|
||||
return std::pair<size_t, R>(thread_i, f(thread_i));
|
||||
}); // wrap the function
|
||||
futures.push_back(task.get_future()); // get a future
|
||||
std::packaged_task<std::pair<size_t, R>()> task(
|
||||
[f, thread_i]() { return std::pair<size_t, R>(thread_i, f(thread_i)); }); // wrap the function
|
||||
futures.push_back(task.get_future()); // get a future
|
||||
std::thread(std::move(task)).detach();
|
||||
}
|
||||
return futures;
|
||||
@@ -160,8 +148,7 @@ auto collect(std::vector<std::future<R>> &collect) {
|
||||
return collection;
|
||||
}
|
||||
|
||||
std::vector<bool> collect_set(
|
||||
std::vector<std::future<std::pair<size_t, std::vector<bool>>>> &&futures) {
|
||||
std::vector<bool> collect_set(std::vector<std::future<std::pair<size_t, std::vector<bool>>>> &&futures) {
|
||||
std::vector<bool> set;
|
||||
for (auto &data : collect(futures)) {
|
||||
set.resize(data.second.size());
|
||||
|
||||
@@ -21,8 +21,7 @@ class TestData {};
|
||||
|
||||
class TestSession {
|
||||
public:
|
||||
TestSession(TestData *, const io::network::Endpoint &,
|
||||
communication::InputStream *input_stream,
|
||||
TestSession(TestData *, const io::network::Endpoint &, communication::InputStream *input_stream,
|
||||
communication::OutputStream *output_stream)
|
||||
: input_stream_(input_stream), output_stream_(output_stream) {}
|
||||
|
||||
@@ -35,8 +34,7 @@ class TestSession {
|
||||
input_stream_->Resize(size + 2);
|
||||
if (input_stream_->size() < size + 2) return;
|
||||
|
||||
for (int i = 0; i < REPLY; ++i)
|
||||
ASSERT_TRUE(output_stream_->Write(data + 2, size));
|
||||
for (int i = 0; i < REPLY; ++i) ASSERT_TRUE(output_stream_->Write(data + 2, size));
|
||||
|
||||
input_stream_->Shift(size + 2);
|
||||
}
|
||||
@@ -48,8 +46,7 @@ class TestSession {
|
||||
using ContextT = communication::ServerContext;
|
||||
using ServerT = communication::Server<TestSession, TestData>;
|
||||
|
||||
void client_run(int num, const char *interface, uint16_t port,
|
||||
const unsigned char *data, int lo, int hi) {
|
||||
void client_run(int num, const char *interface, uint16_t port, const unsigned char *data, int lo, int hi) {
|
||||
std::stringstream name;
|
||||
name << "Client " << num;
|
||||
unsigned char buffer[SIZE * REPLY], head[2];
|
||||
|
||||
@@ -22,14 +22,11 @@ class TestData {};
|
||||
|
||||
class TestSession {
|
||||
public:
|
||||
TestSession(TestData *, const io::network::Endpoint &,
|
||||
communication::InputStream *input_stream,
|
||||
TestSession(TestData *, const io::network::Endpoint &, communication::InputStream *input_stream,
|
||||
communication::OutputStream *output_stream)
|
||||
: input_stream_(input_stream), output_stream_(output_stream) {}
|
||||
|
||||
void Execute() {
|
||||
output_stream_->Write(input_stream_->data(), input_stream_->size());
|
||||
}
|
||||
void Execute() { output_stream_->Write(input_stream_->data(), input_stream_->size()); }
|
||||
|
||||
communication::InputStream *input_stream_;
|
||||
communication::OutputStream *output_stream_;
|
||||
@@ -63,15 +60,13 @@ TEST(Network, SocketReadHangOnConcurrentConnections) {
|
||||
int N = (std::thread::hardware_concurrency() + 1) / 2;
|
||||
int Nc = N * 3;
|
||||
communication::ServerContext context;
|
||||
communication::Server<TestSession, TestData> server(endpoint, &data, &context,
|
||||
-1, "Test", N);
|
||||
communication::Server<TestSession, TestData> server(endpoint, &data, &context, -1, "Test", N);
|
||||
ASSERT_TRUE(server.Start());
|
||||
|
||||
const auto &ep = server.endpoint();
|
||||
// start clients
|
||||
std::vector<std::thread> clients;
|
||||
for (int i = 0; i < Nc; ++i)
|
||||
clients.push_back(std::thread(client_run, i, interface, ep.port));
|
||||
for (int i = 0; i < Nc; ++i) clients.push_back(std::thread(client_run, i, interface, ep.port));
|
||||
|
||||
// wait for 2s and stop clients
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
|
||||
@@ -28,9 +28,7 @@ TEST(Network, Server) {
|
||||
const auto &ep = server.endpoint();
|
||||
// start clients
|
||||
std::vector<std::thread> clients;
|
||||
for (int i = 0; i < N; ++i)
|
||||
clients.push_back(
|
||||
std::thread(client_run, i, interface, ep.port, data, 30000, SIZE));
|
||||
for (int i = 0; i < N; ++i) clients.push_back(std::thread(client_run, i, interface, ep.port, data, 30000, SIZE));
|
||||
|
||||
// cleanup clients
|
||||
for (int i = 0; i < N; ++i) clients[i].join();
|
||||
|
||||
@@ -33,8 +33,7 @@ TEST(Network, SessionLeak) {
|
||||
const auto &ep = server.endpoint();
|
||||
int testlen = 3000;
|
||||
for (int i = 0; i < N; ++i) {
|
||||
clients.push_back(
|
||||
std::thread(client_run, i, interface, ep.port, data, testlen, testlen));
|
||||
clients.push_back(std::thread(client_run, i, interface, ep.port, data, testlen, testlen));
|
||||
std::this_thread::sleep_for(10ms);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,14 +42,12 @@ int main() {
|
||||
for (int i = 0; i < kNumThreadsFind; ++i) {
|
||||
threads_find.push_back(std::thread([&list, &run, &modify_done, i] {
|
||||
std::mt19937 gen(3137 + i);
|
||||
std::uniform_int_distribution<uint64_t> dist(
|
||||
0, kNumThreadsInsert * kMaxNum - 1);
|
||||
std::uniform_int_distribution<uint64_t> dist(0, kNumThreadsInsert * kMaxNum - 1);
|
||||
while (run.load(std::memory_order_relaxed)) {
|
||||
auto acc = list.access();
|
||||
auto num = dist(gen);
|
||||
auto it = acc.find(num);
|
||||
if (modify_done.load(std::memory_order_relaxed) &&
|
||||
num >= kNumThreadsRemove * kMaxNum) {
|
||||
if (modify_done.load(std::memory_order_relaxed) && num >= kNumThreadsRemove * kMaxNum) {
|
||||
MG_ASSERT(it != acc.end());
|
||||
MG_ASSERT(*it == num);
|
||||
}
|
||||
@@ -70,8 +68,7 @@ int main() {
|
||||
}
|
||||
|
||||
MG_ASSERT(list.size() == (kNumThreadsInsert - kNumThreadsRemove) * kMaxNum);
|
||||
for (uint64_t i = kMaxNum * kNumThreadsRemove;
|
||||
i < kMaxNum * kNumThreadsInsert; ++i) {
|
||||
for (uint64_t i = kMaxNum * kNumThreadsRemove; i < kMaxNum * kNumThreadsInsert; ++i) {
|
||||
auto acc = list.access();
|
||||
auto it = acc.find(i);
|
||||
MG_ASSERT(it != acc.end());
|
||||
|
||||
@@ -120,8 +120,7 @@ TEST(Storage, LabelPropertyIndex) {
|
||||
ASSERT_TRUE(*ret);
|
||||
}
|
||||
{
|
||||
auto ret = vertex.SetProperty(
|
||||
prop, storage::PropertyValue(vertex.Gid().AsInt()));
|
||||
auto ret = vertex.SetProperty(prop, storage::PropertyValue(vertex.Gid().AsInt()));
|
||||
ASSERT_TRUE(ret.HasValue());
|
||||
ASSERT_TRUE(*ret);
|
||||
}
|
||||
@@ -165,8 +164,7 @@ TEST(Storage, LabelPropertyIndex) {
|
||||
ASSERT_TRUE(*ret);
|
||||
}
|
||||
{
|
||||
auto ret = vertex.SetProperty(
|
||||
prop, storage::PropertyValue(vertex.Gid().AsInt()));
|
||||
auto ret = vertex.SetProperty(prop, storage::PropertyValue(vertex.Gid().AsInt()));
|
||||
ASSERT_TRUE(ret.HasValue());
|
||||
ASSERT_TRUE(*ret);
|
||||
}
|
||||
|
||||
@@ -40,10 +40,8 @@ class StorageUniqueConstraints : public ::testing::Test {
|
||||
storage::Gid gids[kNumThreads];
|
||||
};
|
||||
|
||||
void SetProperties(storage::Storage *storage, storage::Gid gid,
|
||||
const std::vector<PropertyId> &properties,
|
||||
const std::vector<PropertyValue> &values,
|
||||
bool *commit_status) {
|
||||
void SetProperties(storage::Storage *storage, storage::Gid gid, const std::vector<PropertyId> &properties,
|
||||
const std::vector<PropertyValue> &values, bool *commit_status) {
|
||||
ASSERT_EQ(properties.size(), values.size());
|
||||
auto acc = storage->Access();
|
||||
auto vertex = acc.FindVertex(gid, storage::View::OLD);
|
||||
@@ -60,8 +58,7 @@ void SetProperties(storage::Storage *storage, storage::Gid gid,
|
||||
*commit_status = !acc.Commit().HasError();
|
||||
}
|
||||
|
||||
void AddLabel(storage::Storage *storage, storage::Gid gid, LabelId label,
|
||||
bool *commit_status) {
|
||||
void AddLabel(storage::Storage *storage, storage::Gid gid, LabelId label, bool *commit_status) {
|
||||
auto acc = storage->Access();
|
||||
auto vertex = acc.FindVertex(gid, storage::View::OLD);
|
||||
ASSERT_TRUE(vertex);
|
||||
@@ -77,8 +74,7 @@ TEST_F(StorageUniqueConstraints, ChangeProperties) {
|
||||
{
|
||||
auto res = storage.CreateUniqueConstraint(label, {prop1, prop2, prop3});
|
||||
ASSERT_TRUE(res.HasValue());
|
||||
ASSERT_EQ(res.GetValue(),
|
||||
storage::UniqueConstraints::CreationStatus::SUCCESS);
|
||||
ASSERT_EQ(res.GetValue(), storage::UniqueConstraints::CreationStatus::SUCCESS);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -97,15 +93,13 @@ TEST_F(StorageUniqueConstraints, ChangeProperties) {
|
||||
// There is fixed set of property values that is tried to be set to all
|
||||
// vertices in all iterations.
|
||||
{
|
||||
std::vector<PropertyValue> values{PropertyValue(1), PropertyValue(2),
|
||||
PropertyValue(3)};
|
||||
std::vector<PropertyValue> values{PropertyValue(1), PropertyValue(2), PropertyValue(3)};
|
||||
for (int iter = 0; iter < 20; ++iter) {
|
||||
bool status[kNumThreads];
|
||||
std::vector<std::thread> threads;
|
||||
threads.reserve(kNumThreads);
|
||||
for (int i = 0; i < kNumThreads; ++i) {
|
||||
threads.emplace_back(SetProperties, &storage, gids[i], properties,
|
||||
values, &status[i]);
|
||||
threads.emplace_back(SetProperties, &storage, gids[i], properties, values, &status[i]);
|
||||
}
|
||||
int count_ok = 0;
|
||||
for (int i = 0; i < kNumThreads; ++i) {
|
||||
@@ -121,14 +115,11 @@ TEST_F(StorageUniqueConstraints, ChangeProperties) {
|
||||
{
|
||||
for (int iter = 0; iter < 20; ++iter) {
|
||||
bool status[kNumThreads];
|
||||
std::vector<PropertyValue> values{PropertyValue(iter),
|
||||
PropertyValue(iter + 1),
|
||||
PropertyValue(iter + 2)};
|
||||
std::vector<PropertyValue> values{PropertyValue(iter), PropertyValue(iter + 1), PropertyValue(iter + 2)};
|
||||
std::vector<std::thread> threads;
|
||||
threads.reserve(kNumThreads);
|
||||
for (int i = 0; i < kNumThreads; ++i) {
|
||||
threads.emplace_back(SetProperties, &storage, gids[i], properties,
|
||||
values, &status[i]);
|
||||
threads.emplace_back(SetProperties, &storage, gids[i], properties, values, &status[i]);
|
||||
}
|
||||
int count_ok = 0;
|
||||
for (int i = 0; i < kNumThreads; ++i) {
|
||||
@@ -148,11 +139,8 @@ TEST_F(StorageUniqueConstraints, ChangeProperties) {
|
||||
std::vector<std::thread> threads;
|
||||
threads.reserve(kNumThreads);
|
||||
for (int i = 0; i < kNumThreads; ++i) {
|
||||
std::vector<PropertyValue> values{PropertyValue(value++),
|
||||
PropertyValue(value++),
|
||||
PropertyValue(value++)};
|
||||
threads.emplace_back(SetProperties, &storage, gids[i], properties,
|
||||
values, &status[i]);
|
||||
std::vector<PropertyValue> values{PropertyValue(value++), PropertyValue(value++), PropertyValue(value++)};
|
||||
threads.emplace_back(SetProperties, &storage, gids[i], properties, values, &status[i]);
|
||||
}
|
||||
int count_ok = 0;
|
||||
for (int i = 0; i < kNumThreads; ++i) {
|
||||
@@ -168,8 +156,7 @@ TEST_F(StorageUniqueConstraints, ChangeLabels) {
|
||||
{
|
||||
auto res = storage.CreateUniqueConstraint(label, {prop1, prop2, prop3});
|
||||
ASSERT_TRUE(res.HasValue());
|
||||
ASSERT_EQ(res.GetValue(),
|
||||
storage::UniqueConstraints::CreationStatus::SUCCESS);
|
||||
ASSERT_EQ(res.GetValue(), storage::UniqueConstraints::CreationStatus::SUCCESS);
|
||||
}
|
||||
|
||||
// In the first part of the test, each transaction tries to add the same label
|
||||
|
||||
Reference in New Issue
Block a user