empiredan commented on code in PR #1617:
URL: 
https://github.com/apache/incubator-pegasus/pull/1617#discussion_r1333858727


##########
src/aio/test/aio.cpp:
##########
@@ -24,196 +24,307 @@
  * THE SOFTWARE.
  */
 
-#include <alloca.h>
 #include <fcntl.h>
+// IWYU pragma: no_include <gtest/gtest-param-test.h>
 // IWYU pragma: no_include <gtest/gtest-message.h>
 // IWYU pragma: no_include <gtest/gtest-test-part.h>
 #include <gtest/gtest.h>
-#include <stdint.h>
+#include <rocksdb/status.h>
 #include <string.h>
+#include <algorithm>
+#include <cstdint>
 #include <list>
 #include <memory>
+#include <random>
 #include <string>
+#include <vector>
 
 #include "aio/aio_task.h"
 #include "aio/file_io.h"
 #include "runtime/task/task_code.h"
 #include "runtime/tool_api.h"
+#include "test_util/test_util.h"
 #include "utils/autoref_ptr.h"
+#include "utils/env.h"
 #include "utils/error_code.h"
-#include "utils/fail_point.h"
 #include "utils/filesystem.h"
 #include "utils/fmt_logging.h"
 #include "utils/ports.h"
-#include "utils/strings.h"
+#include "utils/test_macros.h"
 #include "utils/threadpool_code.h"
 
-namespace dsn {
-class disk_file;
-} // namespace dsn
-
 using namespace ::dsn;
 
 DEFINE_THREAD_POOL_CODE(THREAD_POOL_TEST_SERVER)
 DEFINE_TASK_CODE_AIO(LPC_AIO_TEST, TASK_PRIORITY_COMMON, 
THREAD_POOL_TEST_SERVER);
 
-TEST(core, aio)
+class aio_test : public pegasus::encrypt_data_test_base
 {
-    fail::setup();
-    fail::cfg("aio_pwrite_incomplete", "void()");
-    const char *buffer = "hello, world";
-    int len = (int)strlen(buffer);
+public:
+    void SetUp() override { utils::filesystem::remove_path(kTestFileName); }
 
-    // write
-    auto fp = file::open("tmp", O_RDWR | O_CREAT | O_BINARY, 0666);
+    const std::string kTestFileName = "aio_test.txt";
+};
 
-    std::list<aio_task_ptr> tasks;
-    uint64_t offset = 0;
+// TODO(yingchun): ENCRYPTION: add enable encryption test.
+INSTANTIATE_TEST_CASE_P(, aio_test, ::testing::Values(false));
 
-    // new write
-    for (int i = 0; i < 100; i++) {
-        auto t = ::dsn::file::write(fp, buffer, len, offset, LPC_AIO_TEST, 
nullptr, nullptr);
-        tasks.push_back(t);
-        offset += len;
-    }
+TEST_P(aio_test, basic)
+{
+    const char *kUnitBuffer = "hello, world";
+    size_t kUnitBufferLength = strlen(kUnitBuffer);

Review Comment:
   ```suggestion
       const size_t kUnitBufferLength = strlen(kUnitBuffer);
   ```



##########
src/aio/test/aio.cpp:
##########
@@ -24,196 +24,307 @@
  * THE SOFTWARE.
  */
 
-#include <alloca.h>
 #include <fcntl.h>
+// IWYU pragma: no_include <gtest/gtest-param-test.h>
 // IWYU pragma: no_include <gtest/gtest-message.h>
 // IWYU pragma: no_include <gtest/gtest-test-part.h>
 #include <gtest/gtest.h>
-#include <stdint.h>
+#include <rocksdb/status.h>
 #include <string.h>
+#include <algorithm>
+#include <cstdint>
 #include <list>
 #include <memory>
+#include <random>
 #include <string>
+#include <vector>
 
 #include "aio/aio_task.h"
 #include "aio/file_io.h"
 #include "runtime/task/task_code.h"
 #include "runtime/tool_api.h"
+#include "test_util/test_util.h"
 #include "utils/autoref_ptr.h"
+#include "utils/env.h"
 #include "utils/error_code.h"
-#include "utils/fail_point.h"
 #include "utils/filesystem.h"
 #include "utils/fmt_logging.h"
 #include "utils/ports.h"
-#include "utils/strings.h"
+#include "utils/test_macros.h"
 #include "utils/threadpool_code.h"
 
-namespace dsn {
-class disk_file;
-} // namespace dsn
-
 using namespace ::dsn;
 
 DEFINE_THREAD_POOL_CODE(THREAD_POOL_TEST_SERVER)
 DEFINE_TASK_CODE_AIO(LPC_AIO_TEST, TASK_PRIORITY_COMMON, 
THREAD_POOL_TEST_SERVER);
 
-TEST(core, aio)
+class aio_test : public pegasus::encrypt_data_test_base
 {
-    fail::setup();
-    fail::cfg("aio_pwrite_incomplete", "void()");
-    const char *buffer = "hello, world";
-    int len = (int)strlen(buffer);
+public:
+    void SetUp() override { utils::filesystem::remove_path(kTestFileName); }
 
-    // write
-    auto fp = file::open("tmp", O_RDWR | O_CREAT | O_BINARY, 0666);
+    const std::string kTestFileName = "aio_test.txt";
+};
 
-    std::list<aio_task_ptr> tasks;
-    uint64_t offset = 0;
+// TODO(yingchun): ENCRYPTION: add enable encryption test.
+INSTANTIATE_TEST_CASE_P(, aio_test, ::testing::Values(false));
 
-    // new write
-    for (int i = 0; i < 100; i++) {
-        auto t = ::dsn::file::write(fp, buffer, len, offset, LPC_AIO_TEST, 
nullptr, nullptr);
-        tasks.push_back(t);
-        offset += len;
-    }
+TEST_P(aio_test, basic)
+{
+    const char *kUnitBuffer = "hello, world";
+    size_t kUnitBufferLength = strlen(kUnitBuffer);
+    int kTotalBufferCount = 100;
+    int kBufferCountPerBatch = 10;

Review Comment:
   ```suggestion
       const int kBufferCountPerBatch = 10;
   ```



##########
src/aio/test/aio.cpp:
##########
@@ -24,196 +24,307 @@
  * THE SOFTWARE.
  */
 
-#include <alloca.h>
 #include <fcntl.h>
+// IWYU pragma: no_include <gtest/gtest-param-test.h>
 // IWYU pragma: no_include <gtest/gtest-message.h>
 // IWYU pragma: no_include <gtest/gtest-test-part.h>
 #include <gtest/gtest.h>
-#include <stdint.h>
+#include <rocksdb/status.h>
 #include <string.h>
+#include <algorithm>
+#include <cstdint>
 #include <list>
 #include <memory>
+#include <random>
 #include <string>
+#include <vector>
 
 #include "aio/aio_task.h"
 #include "aio/file_io.h"
 #include "runtime/task/task_code.h"
 #include "runtime/tool_api.h"
+#include "test_util/test_util.h"
 #include "utils/autoref_ptr.h"
+#include "utils/env.h"
 #include "utils/error_code.h"
-#include "utils/fail_point.h"
 #include "utils/filesystem.h"
 #include "utils/fmt_logging.h"
 #include "utils/ports.h"
-#include "utils/strings.h"
+#include "utils/test_macros.h"
 #include "utils/threadpool_code.h"
 
-namespace dsn {
-class disk_file;
-} // namespace dsn
-
 using namespace ::dsn;
 
 DEFINE_THREAD_POOL_CODE(THREAD_POOL_TEST_SERVER)
 DEFINE_TASK_CODE_AIO(LPC_AIO_TEST, TASK_PRIORITY_COMMON, 
THREAD_POOL_TEST_SERVER);
 
-TEST(core, aio)
+class aio_test : public pegasus::encrypt_data_test_base
 {
-    fail::setup();
-    fail::cfg("aio_pwrite_incomplete", "void()");
-    const char *buffer = "hello, world";
-    int len = (int)strlen(buffer);
+public:
+    void SetUp() override { utils::filesystem::remove_path(kTestFileName); }
 
-    // write
-    auto fp = file::open("tmp", O_RDWR | O_CREAT | O_BINARY, 0666);
+    const std::string kTestFileName = "aio_test.txt";
+};
 
-    std::list<aio_task_ptr> tasks;
-    uint64_t offset = 0;
+// TODO(yingchun): ENCRYPTION: add enable encryption test.
+INSTANTIATE_TEST_CASE_P(, aio_test, ::testing::Values(false));
 
-    // new write
-    for (int i = 0; i < 100; i++) {
-        auto t = ::dsn::file::write(fp, buffer, len, offset, LPC_AIO_TEST, 
nullptr, nullptr);
-        tasks.push_back(t);
-        offset += len;
-    }
+TEST_P(aio_test, basic)
+{
+    const char *kUnitBuffer = "hello, world";
+    size_t kUnitBufferLength = strlen(kUnitBuffer);
+    int kTotalBufferCount = 100;

Review Comment:
   ```suggestion
       const int kTotalBufferCount = 100;
   ```



##########
src/aio/test/aio.cpp:
##########
@@ -296,10 +424,15 @@ TEST(core, dsn_file)
         offset += rin.sz;
     }
 
-    ASSERT_EQ((uint64_t)fin_size, offset);
+    ASSERT_EQ((uint64_t)src_file_size, offset);

Review Comment:
   ```suggestion
       ASSERT_EQ(static_cast<uint64_t>(src_file_size), offset);
   ```



##########
src/aio/test/aio.cpp:
##########
@@ -24,196 +24,307 @@
  * THE SOFTWARE.
  */
 
-#include <alloca.h>
 #include <fcntl.h>
+// IWYU pragma: no_include <gtest/gtest-param-test.h>
 // IWYU pragma: no_include <gtest/gtest-message.h>
 // IWYU pragma: no_include <gtest/gtest-test-part.h>
 #include <gtest/gtest.h>
-#include <stdint.h>
+#include <rocksdb/status.h>
 #include <string.h>
+#include <algorithm>
+#include <cstdint>
 #include <list>
 #include <memory>
+#include <random>
 #include <string>
+#include <vector>
 
 #include "aio/aio_task.h"
 #include "aio/file_io.h"
 #include "runtime/task/task_code.h"
 #include "runtime/tool_api.h"
+#include "test_util/test_util.h"
 #include "utils/autoref_ptr.h"
+#include "utils/env.h"
 #include "utils/error_code.h"
-#include "utils/fail_point.h"
 #include "utils/filesystem.h"
 #include "utils/fmt_logging.h"
 #include "utils/ports.h"
-#include "utils/strings.h"
+#include "utils/test_macros.h"
 #include "utils/threadpool_code.h"
 
-namespace dsn {
-class disk_file;
-} // namespace dsn
-
 using namespace ::dsn;
 
 DEFINE_THREAD_POOL_CODE(THREAD_POOL_TEST_SERVER)
 DEFINE_TASK_CODE_AIO(LPC_AIO_TEST, TASK_PRIORITY_COMMON, 
THREAD_POOL_TEST_SERVER);
 
-TEST(core, aio)
+class aio_test : public pegasus::encrypt_data_test_base
 {
-    fail::setup();
-    fail::cfg("aio_pwrite_incomplete", "void()");
-    const char *buffer = "hello, world";
-    int len = (int)strlen(buffer);
+public:
+    void SetUp() override { utils::filesystem::remove_path(kTestFileName); }
 
-    // write
-    auto fp = file::open("tmp", O_RDWR | O_CREAT | O_BINARY, 0666);
+    const std::string kTestFileName = "aio_test.txt";
+};
 
-    std::list<aio_task_ptr> tasks;
-    uint64_t offset = 0;
+// TODO(yingchun): ENCRYPTION: add enable encryption test.
+INSTANTIATE_TEST_CASE_P(, aio_test, ::testing::Values(false));
 
-    // new write
-    for (int i = 0; i < 100; i++) {
-        auto t = ::dsn::file::write(fp, buffer, len, offset, LPC_AIO_TEST, 
nullptr, nullptr);
-        tasks.push_back(t);
-        offset += len;
-    }
+TEST_P(aio_test, basic)
+{
+    const char *kUnitBuffer = "hello, world";
+    size_t kUnitBufferLength = strlen(kUnitBuffer);
+    int kTotalBufferCount = 100;
+    int kBufferCountPerBatch = 10;
+    int64_t kFileSize = kUnitBufferLength * kTotalBufferCount;

Review Comment:
   ```suggestion
       const int64_t kFileSize = kUnitBufferLength * kTotalBufferCount;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to