hdfs_ext_test.cc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. //#include "expect.h"
  19. #include "hdfspp_mini_dfs.h"
  20. #include "hdfspp/hdfs_ext.h"
  21. namespace hdfs {
  22. class HdfsExtTest: public ::testing::Test {
  23. public:
  24. MiniCluster cluster;
  25. };
  26. // Make sure we can set up a mini-cluster and connect to it
  27. TEST_F(HdfsExtTest, TestGetBlockLocations) {
  28. HdfsHandle connection = cluster.connect_c();
  29. EXPECT_NE(nullptr, connection.handle());
  30. hdfsBlockLocations * blocks = nullptr;
  31. // Free a null pointer
  32. int result = hdfsFreeBlockLocations(blocks);
  33. EXPECT_EQ(0, result);
  34. // Test non-extant files
  35. result = hdfsGetBlockLocations(connection, "non_extant_file", &blocks);
  36. EXPECT_NE(0, result); // Should be an error
  37. // Test an extant file
  38. std::string filename = connection.newFile(1024);
  39. result = hdfsGetBlockLocations(connection, filename.c_str(), &blocks);
  40. EXPECT_EQ(0, result);
  41. EXPECT_EQ(1024, blocks->fileLength);
  42. EXPECT_EQ(1, blocks->num_blocks);
  43. EXPECT_EQ(0, blocks->isUnderConstruction);
  44. EXPECT_NE(0, blocks->isLastBlockComplete);
  45. EXPECT_EQ(1024, blocks->blocks->num_bytes);
  46. EXPECT_EQ(0, blocks->blocks->start_offset);
  47. EXPECT_EQ(1, blocks->blocks->num_locations);
  48. EXPECT_NE(nullptr, blocks->blocks->locations->hostname);
  49. EXPECT_NE(nullptr, blocks->blocks->locations->ip_address);
  50. EXPECT_NE(0, blocks->blocks->locations->xfer_port);
  51. result = hdfsFreeBlockLocations(blocks);
  52. EXPECT_EQ(0, result);
  53. }
  54. }
  55. int main(int argc, char *argv[]) {
  56. // The following line must be executed to initialize Google Mock
  57. // (and Google Test) before running the tests.
  58. ::testing::InitGoogleMock(&argc, argv);
  59. int exit_code = RUN_ALL_TESTS();
  60. google::protobuf::ShutdownProtobufLibrary();
  61. return exit_code;
  62. }