diff --git a/tests/macro_benchmark/clients/card_fraud_client.cpp b/tests/macro_benchmark/clients/card_fraud_client.cpp index 3b3be37eb..b30ec7e41 100644 --- a/tests/macro_benchmark/clients/card_fraud_client.cpp +++ b/tests/macro_benchmark/clients/card_fraud_client.cpp @@ -17,23 +17,16 @@ BOOST_CLASS_EXPORT(stats::StatsRes); BOOST_CLASS_EXPORT(stats::BatchStatsReq); BOOST_CLASS_EXPORT(stats::BatchStatsRes); +std::atomic num_pos; +std::atomic num_cards; +std::atomic num_transactions; + class CardFraudClient : public TestClient { public: - CardFraudClient(int id, int num_pos, int num_cards, int num_transactions, - nlohmann::json config) - : TestClient(), - rg_(id), - num_pos_(num_pos), - num_cards_(num_cards), - num_transactions_(num_transactions), - config_(config) {} + CardFraudClient(int id) : TestClient(), rg_(id) {} private: std::mt19937 rg_; - int num_pos_; - int num_cards_; - int num_transactions_; - nlohmann::json config_; auto GetFraudulentTransactions() { return Execute( @@ -67,7 +60,7 @@ class CardFraudClient : public TestClient { auto TepsQuery() { auto result = Execute("MATCH (u)--(v) RETURN count(1)", {}); - DCHECK(result.records[0][0].ValueInt() == num_transactions_ * 2); + DCHECK(result.records[0][0].ValueInt() == num_transactions * 2); } auto CompromisePos(int id) { @@ -79,29 +72,56 @@ class CardFraudClient : public TestClient { {{"id", id}}); } + auto CreateTransaction(int pos_id, int card_id) { + return Execute( + "MATCH (p:Pos {id: $pos_id}), (c:Card {id: $card_id}) " + "CREATE (t:Transaction {id: $tx_id, fraud_reported: false}) " + "CREATE (c)<-[:Using]-(t)-[:At]->(p)", + {{"pos_id", pos_id}, + {"card_id", card_id}, + {"tx_id", num_transactions++}}); + } + + auto CreateTransactionWithoutEdge(int pos_id, int card_id) { + return Execute( + "MATCH (p:Pos {id: $pos_id}), (c:Card {id: $card_id}) " + "CREATE (t:Transaction {id: $tx_id, fraud_reported: false})", + {{"pos_id", pos_id}, + {"card_id", card_id}, + {"tx_id", num_transactions++}}); + } + public: virtual void Step() override { - if (config_["scenario"] == "read_only") { + if (FLAGS_scenario == "read_only") { std::uniform_int_distribution dist(0, 1); if (dist(rg_)) { GetFraudulentTransactions(); } else { GetCompromisedPos(); } - } else if (config_["scenario"] == "read_write") { - std::uniform_int_distribution dist(0, num_pos_ - 1); + } else if (FLAGS_scenario == "read_write") { + std::uniform_int_distribution dist(0, num_pos - 1); int pos_id = dist(rg_); CompromisePos(pos_id); GetFraudulentTransactions(); ResolvePos(pos_id); - } else if (config_["scenario"] == "teps") { + } else if (FLAGS_scenario == "teps") { TepsQuery(); - } else if (config_["scenario"] == "point_lookup") { - std::uniform_int_distribution dist(0, num_transactions_ - 1); + } else if (FLAGS_scenario == "point_lookup") { + std::uniform_int_distribution dist(0, num_transactions - 1); int tx_id = dist(rg_); GetTransaction(tx_id); + } else if (FLAGS_scenario == "create_tx") { + std::uniform_int_distribution dist_pos(0, num_pos - 1); + std::uniform_int_distribution dist_card(0, num_cards - 1); + CreateTransaction(dist_pos(rg_), dist_card(rg_)); + } else if (FLAGS_scenario == "create_tx_without_edge") { + std::uniform_int_distribution dist_pos(0, num_pos - 1); + std::uniform_int_distribution dist_card(0, num_cards - 1); + CreateTransactionWithoutEdge(dist_pos(rg_), dist_card(rg_)); } else { - LOG(FATAL) << "Should not get here!"; + LOG(FATAL) << "Should not get here: unknown scenario!"; } } }; @@ -134,14 +154,11 @@ int main(int argc, char **argv) { stats::InitStatsLogging( fmt::format("client.long_running.{}.{}", FLAGS_group, FLAGS_scenario)); - nlohmann::json config; - std::cin >> config; - BoltClient client(FLAGS_address, FLAGS_port, FLAGS_username, FLAGS_password); - int num_pos = NumNodesWithLabel(client, "Pos"); - int num_cards = NumNodesWithLabel(client, "Card"); - int num_transactions = NumNodesWithLabel(client, "Transaction"); + num_pos.store(NumNodesWithLabel(client, "Pos")); + num_cards.store(NumNodesWithLabel(client, "Card")); + num_transactions.store(NumNodesWithLabel(client, "Transaction")); CreateIndex(client, "Pos", "id"); CreateIndex(client, "Card", "id"); @@ -153,8 +170,7 @@ int main(int argc, char **argv) { std::vector> clients; for (int i = 0; i < FLAGS_num_workers; ++i) { - clients.emplace_back(std::make_unique( - i, num_pos, num_cards, num_transactions, config)); + clients.emplace_back(std::make_unique(i)); } RunMultithreadedTest(clients); diff --git a/tests/macro_benchmark/groups/card_fraud/point_lookup.run.json b/tests/macro_benchmark/groups/card_fraud/point_lookup.run.json deleted file mode 100644 index df7cb6f59..000000000 --- a/tests/macro_benchmark/groups/card_fraud/point_lookup.run.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "scenario": "point_lookup" -} diff --git a/tests/macro_benchmark/groups/card_fraud/read_only.run.json b/tests/macro_benchmark/groups/card_fraud/read_only.run.json deleted file mode 100644 index 291ec5de4..000000000 --- a/tests/macro_benchmark/groups/card_fraud/read_only.run.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "scenario": "read_only" -} diff --git a/tests/macro_benchmark/groups/card_fraud/read_write.run.json b/tests/macro_benchmark/groups/card_fraud/read_write.run.json deleted file mode 100644 index 48c4456e6..000000000 --- a/tests/macro_benchmark/groups/card_fraud/read_write.run.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "scenario": "read_write" -} diff --git a/tests/macro_benchmark/groups/card_fraud/run.json b/tests/macro_benchmark/groups/card_fraud/run.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/tests/macro_benchmark/groups/card_fraud/run.json @@ -0,0 +1 @@ +{} diff --git a/tests/macro_benchmark/groups/card_fraud/teps.run.json b/tests/macro_benchmark/groups/card_fraud/teps.run.json deleted file mode 100644 index 5c30fa972..000000000 --- a/tests/macro_benchmark/groups/card_fraud/teps.run.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "scenario": "teps" -}