]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Add simple multi-threaded test
authortridao <daominhtri0503@gmail.com>
Thu, 6 Jul 2023 21:24:21 +0000 (18:24 -0300)
committertridao <daominhtri0503@gmail.com>
Mon, 17 Jul 2023 02:16:24 +0000 (23:16 -0300)
Signed-off-by: Tri Dao <daominhtri0503@gmail.com>
src/test/objectstore/Fragmentation_simulator.cc

index 1ad71cac40b472e234af0449303be4557e704ba7..d93ca86204c7957b11708edb8fdb60902a4e33ef 100644 (file)
@@ -235,6 +235,58 @@ struct RandomCWGenerator : public FragmentationSimulator::WorkloadGenerator {
   }
 };
 
+// Testing the Imitator with multiple threads
+struct MultiThreadedCWGenerator
+    : public FragmentationSimulator::WorkloadGenerator {
+  std::string name() override { return "MultiThreadedCW"; }
+  int generate_txns(ObjectStore::CollectionHandle &ch,
+                    ObjectStoreImitator *os) override {
+
+    auto t1 = std::thread([&]() {
+      hobject_t h1;
+      h1.oid = fmt::format("obj1");
+      h1.set_hash(1);
+      h1.pool = 1;
+      ghobject_t obj1(h1);
+
+      ObjectStore::Transaction t_create;
+      t_create.create(ch->get_cid(), obj1);
+      os->queue_transaction(ch, std::move(t_create));
+
+      ObjectStore::Transaction t_write;
+      t_write.write(ch->get_cid(), obj1, 0, _1Mb, make_bl(_1Mb, 'a'));
+      os->queue_transaction(ch, std::move(t_write));
+
+      bufferlist bl;
+      os->read(ch, obj1, 0, _1Mb, bl);
+    });
+
+    auto t2 = std::thread([&]() {
+      hobject_t h2;
+      h2.oid = fmt::format("obj2");
+      h2.set_hash(2);
+      h2.pool = 1;
+      ghobject_t obj2(h2);
+
+      ObjectStore::Transaction t_create;
+      t_create.create(ch->get_cid(), obj2);
+      os->queue_transaction(ch, std::move(t_create));
+
+      ObjectStore::Transaction t_write;
+      t_write.write(ch->get_cid(), obj2, 0, _1Mb, make_bl(_1Mb, 'a'));
+      os->queue_transaction(ch, std::move(t_write));
+
+      bufferlist bl;
+      os->read(ch, obj2, 0, _1Mb, bl);
+    });
+
+    t1.join();
+    t2.join();
+
+    return 0;
+  }
+};
+
 // ----------- Tests -----------
 
 TEST_P(FragmentationSimulator, SimpleCWGenerator) {
@@ -249,6 +301,12 @@ TEST_P(FragmentationSimulator, RandomCWGenerator) {
   begin_simulation_with_generators();
 }
 
+TEST_P(FragmentationSimulator, MultiThreadedCWGenerator) {
+  init(GetParam(), _1Mb * 4);
+  add_generator(std::make_shared<MultiThreadedCWGenerator>());
+  begin_simulation_with_generators();
+}
+
 // ----------- main -----------
 
 INSTANTIATE_TEST_SUITE_P(Allocator, FragmentationSimulator,