]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tools: follow current codes to modify UT
authorshangdehao1 <dehao.shang@intel.com>
Sat, 26 Jan 2019 20:53:15 +0000 (04:53 +0800)
committerYuan Zhou <yuan.zhou@intel.com>
Thu, 21 Mar 2019 16:16:29 +0000 (00:16 +0800)
Signed-off-by: Dehao Shang <dehao.shang@intel.com>
src/test/immutable_object_cache/test_DomainSocket.cc
src/test/immutable_object_cache/test_message.cc
src/test/immutable_object_cache/test_multi_session.cc

index a1b25bc44fa0b8f403fa35feb34ac097bb7b6bff..3113bfabffd66a2c555271a4bc0c7515a7541dd3 100644 (file)
@@ -120,34 +120,34 @@ public:
         usleep(1);
       }
 
-      m_cache_client->lookup_object("test_pool", 1, 2, "123456", ctx);
+      m_cache_client->lookup_object("pool_nspace", 1, 2, "object_name", ctx);
       m_send_request_index++;
     }
     m_wait_event.wait();
   }
 
-  bool startup_lookupobject_testing(std::string pool_name, std::string object_id) {
+  bool startup_lookupobject_testing(std::string pool_nspace, std::string object_id) {
     bool hit;
     auto ctx = new LambdaGenContext<std::function<void(ObjectCacheRequest*)>,
         ObjectCacheRequest*>([this, &hit](ObjectCacheRequest* ack){
        hit = ack->m_head.type == RBDSC_READ_REPLY;
        m_wait_event.signal();
     });
-    m_cache_client->lookup_object(pool_name, 1, 2, object_id, ctx);
+    m_cache_client->lookup_object(pool_nspace, 1, 2, object_id, ctx);
     m_wait_event.wait();
     return hit;
   }
 
-  void set_hit_entry_in_fake_lru(std::string oid) {
-    if (m_hit_entry_set.find(oid) == m_hit_entry_set.end()) {
-      m_hit_entry_set.insert(oid);
+  void set_hit_entry_in_fake_lru(std::string cache_file_name) {
+    if (m_hit_entry_set.find(cache_file_name) == m_hit_entry_set.end()) {
+      m_hit_entry_set.insert(cache_file_name);
     }
   }
 };
 
 TEST_F(TestCommunication, test_pingpong) {
 
-  startup_pingpong_testing(10, 16, 0);
+  startup_pingpong_testing(64, 16, 0);
   ASSERT_TRUE(m_send_request_index == m_recv_ack_index);
   startup_pingpong_testing(200, 128, 0);
   ASSERT_TRUE(m_send_request_index == m_recv_ack_index);
@@ -167,9 +167,9 @@ TEST_F(TestCommunication, test_lookup_object) {
   }
   for (uint64_t i = 50; i < 100; i++) {
     if ((random_hit % i) != 0) {
-      ASSERT_FALSE(startup_lookupobject_testing("test_pool", std::to_string(i)));
+      ASSERT_FALSE(startup_lookupobject_testing("test_nspace", std::to_string(i)));
     } else {
-      ASSERT_TRUE(startup_lookupobject_testing("test_pool", std::to_string(i)));
+      ASSERT_TRUE(startup_lookupobject_testing("test_nspace", std::to_string(i)));
     }
   }
 }
index bcaed1d5fc4c368ededba1911da90713a4e0f8a8..124352423053b5a309c1a81aaa814c15329f4f94 100644 (file)
@@ -5,14 +5,16 @@ using namespace ceph::immutable_obj_cache;
 
 TEST(test_for_message, test_1) 
 {
+  std::string pool_nspace("this is a pool namespace");
   std::string oid_name("this is a oid name");
+  std::string cache_file_path("/temp/ceph_immutable_object_cache");
 
   ObjectCacheMsgHeader header;
   header.seq = 1;
   header.type = 2;
   header.version =3;
-  header.data_len = 5;
-  header.reserved = 6;
+  header.data_len = 0;
+  header.reserved = 5;
 
   ObjectCacheRequest req;
 
@@ -23,28 +25,46 @@ TEST(test_for_message, test_1)
 
   req.m_data.m_read_offset = 222222;
   req.m_data.m_read_len = 333333;
+  req.m_data.m_pool_id = 444444;
+  req.m_data.m_snap_id = 555555;
   req.m_data.m_oid = oid_name;
+  req.m_data.m_pool_namespace = pool_nspace;
+  req.m_data.m_cache_path = cache_file_path;
 
+  // ObjectRequest --> bufferlist
   req.encode();
 
   ASSERT_EQ(req.m_head_buffer.length(), sizeof(req.m_head));
 
-
   ObjectCacheRequest* req_decode;
 
-  auto x = req.get_head_buffer();
-  auto z = req.get_data_buffer();
+  auto head_bl = req.get_head_buffer();
+  auto data_bl = req.get_data_buffer();
 
-  req_decode = decode_object_cache_request(x, z);
+  // bufferlist --> ObjectCacheRequest
+  req_decode = decode_object_cache_request(head_bl, data_bl);
 
   ASSERT_EQ(req_decode->m_head.seq, header.seq);
+  ASSERT_EQ(req_decode->m_head.seq, 1);
   ASSERT_EQ(req_decode->m_head.type, header.type);
+  ASSERT_EQ(req_decode->m_head.type, 2);
   ASSERT_EQ(req_decode->m_head.version, header.version);
+  ASSERT_EQ(req_decode->m_head.version, 3);
   ASSERT_EQ(req_decode->m_head.data_len, req.m_data_buffer.length());
+  ASSERT_EQ(req_decode->m_head.data_len, data_bl.length());
   ASSERT_EQ(req_decode->m_head.reserved, header.reserved);
+  ASSERT_EQ(req_decode->m_head.reserved, 5);
 
-
+  ASSERT_EQ(req_decode->m_data.m_read_offset, req.m_data.m_read_offset);
   ASSERT_EQ(req_decode->m_data.m_read_offset, 222222);
+  ASSERT_EQ(req_decode->m_data.m_read_len, req.m_data.m_read_len);
   ASSERT_EQ(req_decode->m_data.m_read_len, 333333);
+  ASSERT_EQ(req_decode->m_data.m_pool_namespace, req.m_data.m_pool_namespace);
+  ASSERT_EQ(req_decode->m_data.m_pool_namespace, pool_nspace);
+  ASSERT_EQ(req_decode->m_data.m_cache_path, req.m_data.m_cache_path);
+  ASSERT_EQ(req_decode->m_data.m_cache_path, cache_file_path);
+  ASSERT_EQ(req_decode->m_data.m_oid, req.m_data.m_oid);
   ASSERT_EQ(req_decode->m_data.m_oid, oid_name);
+
+  delete req_decode;
 }
index a9e0c8fa17bf0d1f6a08cb8c0e4f13f5fdf3adde..7b8cc5cafe937bc38f631c9bc030539947304884 100644 (file)
@@ -114,7 +114,8 @@ public:
     ASSERT_TRUE(session->is_session_work());
   }
 
-  void test_lookup_object(std::string pool, uint64_t index, uint64_t request_num, bool is_last) {
+  void test_lookup_object(std::string pool_nspace, uint64_t index,
+                          uint64_t request_num, bool is_last) {
 
     for (uint64_t i = 0; i < request_num; i++) {
       auto ctx = new LambdaGenContext<std::function<void(ObjectCacheRequest*)>,
@@ -123,7 +124,7 @@ public:
       });
       m_send_request_index++;
       // here just for concurrently testing register + lookup, so fix object id.
-      m_cache_client_vec[index]->lookup_object(pool, 1, 2, "1234", ctx);
+      m_cache_client_vec[index]->lookup_object(pool_nspace, 1, 2, "1234", ctx);
     }
 
     if (is_last) {
@@ -146,7 +147,8 @@ TEST_F(TestMultiSession, test_multi_session) {
     if (m_cache_client_vec[random_index] == nullptr) {
       test_register_client(random_index);
     } else {
-      test_lookup_object(string("test_pool") + std::to_string(random_index), random_index, 32, i == test_times ? true : false);
+      test_lookup_object(string("test_nspace") + std::to_string(random_index),
+                         random_index, 32, i == test_times ? true : false);
     }
   }