Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
error-util-test.cc
Go to the documentation of this file.
1 // Copyright 2015 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 #include <gtest/gtest.h>
16 #include <gutil/strings/substitute.h>
17 
18 #include "error-util.h"
19 #include "gen-cpp/Status_types.h"
20 #include "gen-cpp/ErrorCodes_types.h"
21 
22 namespace impala {
23 
24 TEST(ErrorMsg, GenericFormatting) {
25  ErrorMsg msg(TErrorCode::GENERAL, "This is a test");
26  ASSERT_EQ("This is a test", msg.msg());
27 
28  msg.AddDetail("Detail come here.");
29  msg.AddDetail("Or here.");
30  ASSERT_EQ("This is a test\nDetail come here.\nOr here.\n",
31  msg.GetFullMessageDetails());
32 
33  msg = ErrorMsg(TErrorCode::MISSING_BUILTIN, "fun", "sym");
34  ASSERT_EQ("Builtin 'fun' with symbol 'sym' does not exist. Verify that "
35  "all your impalads are the same version.", msg.msg());
36 }
37 
38 TEST(ErrorMsg, MergeMap) {
39  ErrorLogMap left, right;
40  left[TErrorCode::GENERAL].messages.push_back("1");
41 
42  right[TErrorCode::GENERAL].messages.push_back("2");
43  right[TErrorCode::PARQUET_MULTIPLE_BLOCKS].messages.push_back("p");
44  right[TErrorCode::PARQUET_MULTIPLE_BLOCKS].count = 3;
45 
46  MergeErrorMaps(&left, right);
47  ASSERT_EQ(2, left.size());
48  ASSERT_EQ(2, left[TErrorCode::GENERAL].messages.size());
49 
50  right = ErrorLogMap();
51  right[TErrorCode::PARQUET_MULTIPLE_BLOCKS].messages.push_back("p");
52  right[TErrorCode::PARQUET_MULTIPLE_BLOCKS].count = 3;
53 
54  MergeErrorMaps(&left, right);
55  ASSERT_EQ(2, left.size());
56  ASSERT_EQ(2, left[TErrorCode::GENERAL].messages.size());
57  ASSERT_EQ(6, left[TErrorCode::PARQUET_MULTIPLE_BLOCKS].count);
58 }
59 
60 TEST(ErrorMsg, CountErrors) {
61  ErrorLogMap m;
62  ASSERT_EQ(0, ErrorCount(m));
63  m[TErrorCode::PARQUET_MULTIPLE_BLOCKS].messages.push_back("p");
64  m[TErrorCode::PARQUET_MULTIPLE_BLOCKS].count = 999;
65  ASSERT_EQ(1, ErrorCount(m));
66  m[TErrorCode::GENERAL].messages.push_back("1");
67  m[TErrorCode::GENERAL].messages.push_back("2");
68  ASSERT_EQ(3, ErrorCount(m));
69 }
70 
72  ErrorLogMap m;
73  ASSERT_EQ(0, ErrorCount(m));
74  AppendError(&m, ErrorMsg(TErrorCode::GENERAL, "1"));
75  AppendError(&m, ErrorMsg(TErrorCode::GENERAL, "2"));
76  ASSERT_EQ(2, ErrorCount(m));
77  AppendError(&m, ErrorMsg(TErrorCode::PARQUET_MULTIPLE_BLOCKS, "p1"));
78  ASSERT_EQ(3, ErrorCount(m));
79  AppendError(&m, ErrorMsg(TErrorCode::PARQUET_MULTIPLE_BLOCKS, "p2"));
80  ASSERT_EQ(3, ErrorCount(m));
81 }
82 
83 TEST(ErrorMsg, PrintMap) {
84  ErrorLogMap left;
85  left[TErrorCode::GENERAL].messages.push_back("1");
86  left[TErrorCode::GENERAL].messages.push_back("2");
87  left[TErrorCode::PARQUET_MULTIPLE_BLOCKS].messages.push_back("p");
88  left[TErrorCode::PARQUET_MULTIPLE_BLOCKS].count = 999;
89  ASSERT_EQ("1\n2\np (1 of 999 similar)\n", PrintErrorMapToString(left));
90 }
91 
92 }
93 
94 int main(int argc, char **argv) {
95  ::testing::InitGoogleTest(&argc, argv);
96  return RUN_ALL_TESTS();
97 }
const std::string & msg() const
Returns the formatted error string.
Definition: error-util.h:118
string PrintErrorMapToString(const ErrorLogMap &errors)
Definition: error-util.cc:153
TEST(AtomicTest, Basic)
Definition: atomic-test.cc:28
void MergeErrorMaps(ErrorLogMap *left, const ErrorLogMap &right)
Definition: error-util.cc:159
void AppendError(ErrorLogMap *map, const ErrorMsg &e)
Definition: error-util.cc:177
int main(int argc, char **argv)
void AddDetail(const std::string &d)
Add detail string message.
Definition: error-util.h:108
uint64_t count
size_t ErrorCount(const ErrorLogMap &errors)
Definition: error-util.cc:191
std::string GetFullMessageDetails() const
Definition: error-util.h:128
std::map< TErrorCode::type, TErrorLogEntry > ErrorLogMap
Tracks log messages per error code.
Definition: error-util.h:144