Codemod: use #include angle brackets in folly and thrift
[folly.git] / folly / experimental / io / test / AsyncIOTest.cpp
index de00065aff0eb1a3d8e10f1c5cfb884018fbcd97..7025eff5218119da823d6c5d85101f52d43762d4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 Facebook, Inc.
+ * Copyright 2014 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "folly/experimental/io/AsyncIO.h"
+#include <folly/experimental/io/AsyncIO.h>
 
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <cstdio>
 #include <memory>
 #include <random>
+#include <thread>
 #include <vector>
 
 #include <glog/logging.h>
 #include <gtest/gtest.h>
 
-#include "folly/experimental/io/FsUtil.h"
-#include "folly/ScopeGuard.h"
-#include "folly/String.h"
+#include <folly/experimental/io/FsUtil.h>
+#include <folly/ScopeGuard.h>
+#include <folly/String.h>
 
 namespace fs = folly::fs;
 using folly::AsyncIO;
@@ -152,20 +153,39 @@ void testReadsSerially(const std::vector<TestSpec>& specs,
 }
 
 void testReadsParallel(const std::vector<TestSpec>& specs,
-                       AsyncIO::PollMode pollMode) {
+                       AsyncIO::PollMode pollMode,
+                       bool multithreaded) {
   AsyncIO aioReader(specs.size(), pollMode);
   std::unique_ptr<AsyncIO::Op[]> ops(new AsyncIO::Op[specs.size()]);
   std::vector<ManagedBuffer> bufs;
+  bufs.reserve(specs.size());
 
   int fd = ::open(tempFile.path().c_str(), O_DIRECT | O_RDONLY);
   PCHECK(fd != -1);
   SCOPE_EXIT {
     ::close(fd);
   };
+
+  std::vector<std::thread> threads;
+  if (multithreaded) {
+    threads.reserve(specs.size());
+  }
   for (int i = 0; i < specs.size(); i++) {
     bufs.push_back(allocateAligned(specs[i].size));
+  }
+  auto submit = [&] (int i) {
     ops[i].pread(fd, bufs[i].get(), specs[i].size, specs[i].start);
     aioReader.submit(&ops[i]);
+  };
+  for (int i = 0; i < specs.size(); i++) {
+    if (multithreaded) {
+      threads.emplace_back([&submit, i] { submit(i); });
+    } else {
+      submit(i);
+    }
+  }
+  for (auto& t : threads) {
+    t.join();
   }
   std::vector<bool> pending(specs.size(), true);
 
@@ -249,7 +269,8 @@ void testReadsQueued(const std::vector<TestSpec>& specs,
 void testReads(const std::vector<TestSpec>& specs,
                AsyncIO::PollMode pollMode) {
   testReadsSerially(specs, pollMode);
-  testReadsParallel(specs, pollMode);
+  testReadsParallel(specs, pollMode, false);
+  testReadsParallel(specs, pollMode, true);
   testReadsQueued(specs, pollMode);
 }
 
@@ -321,7 +342,7 @@ TEST(AsyncIO, ManyAsyncDataNotPollable) {
   {
     std::vector<TestSpec> v;
     for (int i = 0; i < 1000; i++) {
-      v.push_back({kAlign * i, kAlign});
+      v.push_back({off_t(kAlign * i), kAlign});
     }
     testReads(v, AsyncIO::NOT_POLLABLE);
   }
@@ -331,7 +352,7 @@ TEST(AsyncIO, ManyAsyncDataPollable) {
   {
     std::vector<TestSpec> v;
     for (int i = 0; i < 1000; i++) {
-      v.push_back({kAlign * i, kAlign});
+      v.push_back({off_t(kAlign * i), kAlign});
     }
     testReads(v, AsyncIO::POLLABLE);
   }