Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hdfs-fs-cache-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 <string>
16 #include <gtest/gtest.h>
17 #include <gutil/strings/substitute.h>
18 
19 #include "runtime/hdfs-fs-cache.h"
20 #include "common/names.h"
21 
22 using namespace strings;
23 
24 namespace impala {
25 void ValidateNameNode(const string& path, const string& expected_namenode,
26  const string& expected_error) {
27  string err;
28  string namenode = HdfsFsCache::GetNameNodeFromPath(path, &err);
29  if (err.empty()) {
30  EXPECT_EQ(namenode, expected_namenode);
31  } else {
32  EXPECT_EQ(err, expected_error);
33  }
34 }
35 
36 TEST(HdfsFsCacheTest, Basic) {
37  // Validate qualified paths for various FileSystems
38  ValidateNameNode(string("hdfs://localhost:25000/usr/hive"),
39  string("hdfs://localhost:25000/"), string(""));
40  ValidateNameNode(string("hdfs://nameservice1/usr/hive"),
41  string("hdfs://nameservice1/"), string(""));
42  ValidateNameNode(string("s3a://hdfsbucket/usr/hive"),
43  string("s3a://hdfsbucket/"), string(""));
44  ValidateNameNode(string("hdfs://testserver/"), string("hdfs://testserver/"),
45  string(""));
46 
47  // Validate local path
48  ValidateNameNode(string("file:///usr/hive"), string("file:///"), string(""));
49  ValidateNameNode(string("file:/usr/hive"), string("file:///"), string(""));
50 
51  // Validate unqualified path
52  ValidateNameNode(string("/usr/hive"), string("default"), string(""));
53 
54  // Validate invalid path
55  string path("://usr/hive");
56  ValidateNameNode(string("://usr/hive"), string(""),
57  Substitute("Path missing scheme: $0", path));
58  path = string("hdfs://test_invalid_path");
59  ValidateNameNode(path, string(""),
60  Substitute("Path missing '/' after authority: $0", path));
61 }
62 
63 }
64 
65 int main(int argc, char **argv) {
66  ::testing::InitGoogleTest(&argc, argv);
67  return RUN_ALL_TESTS();
68 }
69 
string path("/usr/lib/sasl2:/usr/lib64/sasl2:/usr/local/lib/sasl2:/usr/lib/x86_64-linux-gnu/sasl2")
TEST(HdfsFsCacheTest, Basic)
void ValidateNameNode(const string &path, const string &expected_namenode, const string &expected_error)
int main(int argc, char **argv)