Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
parallel-executor-test.cc
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 
16 #include <string>
17 #include <gtest/gtest.h>
18 #include <boost/bind.hpp>
19 
21 #include "util/thread.h"
22 
23 #include "common/names.h"
24 
25 using namespace impala;
26 
27 namespace impala {
28 
30  public:
31  Status UpdateFunction(void* value) {
32  long arg = reinterpret_cast<long>(value);
33  EXPECT_FALSE(updates_found_[arg]);
34  updates_found_[arg] = true;
35 
36  double result = 0;
37  // Run something random to keep this cpu a little busy
38  for (int i = 0; i < 10000; ++i) {
39  for (int j = 0; j < 200; ++j) {
40  result += sin(i) + cos(j);
41  }
42  }
43 
44  return Status::OK;
45  }
46 
47  ParallelExecutorTest(int num_updates) {
48  updates_found_.resize(num_updates);
49  }
50 
51  void Validate() {
52  for (int i = 0; i < updates_found_.size(); ++i) {
53  EXPECT_TRUE(updates_found_[i]);
54  }
55  }
56 
57  private:
58  vector<int> updates_found_;
59 };
60 
62  int num_work_items = 100;
63  ParallelExecutorTest test_caller(num_work_items);
64 
65  vector<long> args;
66  for (int i = 0; i < num_work_items; ++i) {
67  args.push_back(i);
68  }
69 
71  bind<Status>(mem_fn(&ParallelExecutorTest::UpdateFunction), &test_caller, _1),
72  reinterpret_cast<void**>(&args[0]), args.size());
73  EXPECT_TRUE(status.ok());
74 
75  test_caller.Validate();
76 }
77 
78 }
79 
80 int main(int argc, char **argv) {
81  ::testing::InitGoogleTest(&argc, argv);
82  InitThreading();
83  return RUN_ALL_TESTS();
84 }
TEST(AtomicTest, Basic)
Definition: atomic-test.cc:28
void InitThreading()
Initialises the threading subsystem. Must be called before a Thread is created.
Definition: thread.cc:261
static const Status OK
Definition: status.h:87
bool ok() const
Definition: status.h:172
int main(int argc, char **argv)
static Status Exec(Function function, void **args, int num_args, StatsMetric< double > *latencies=NULL)
Callers may pass a StatsMetric to gather the latency distribution of task execution.