testHadoop.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #Licensed to the Apache Software Foundation (ASF) under one
  2. #or more contributor license agreements. See the NOTICE file
  3. #distributed with this work for additional information
  4. #regarding copyright ownership. The ASF licenses this file
  5. #to you under the Apache License, Version 2.0 (the
  6. #"License"); you may not use this file except in compliance
  7. #with the License. You may obtain a copy of the License at
  8. # http://www.apache.org/licenses/LICENSE-2.0
  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. import unittest, os, sys, re, threading, time
  15. myDirectory = os.path.realpath(sys.argv[0])
  16. rootDirectory = re.sub("/testing/.*", "", myDirectory)
  17. sys.path.append(rootDirectory)
  18. from testing.lib import BaseTestSuite
  19. excludes = []
  20. import tempfile, getpass
  21. from xml.dom import minidom
  22. from hodlib.Hod.hadoop import hadoopConfig
  23. # All test-case classes should have the naming convention test_.*
  24. class test_hadoopConfig(unittest.TestCase):
  25. def setUp(self):
  26. self.__hadoopConfig = hadoopConfig()
  27. self.rootDir = '/tmp/hod-%s' % getpass.getuser()
  28. if not os.path.exists(self.rootDir):
  29. os.mkdir(self.rootDir)
  30. self.testingDir = tempfile.mkdtemp( dir=self.rootDir,
  31. prefix='HadoopTestSuite.test_hadoopConfig')
  32. self.confDir = tempfile.mkdtemp(dir=self.rootDir,
  33. prefix='HadoopTestSuite.test_hadoopConfig')
  34. self.tempDir = '/tmp/hod-%s/something' % getpass.getuser()
  35. self.hadoopSite = os.path.join(self.confDir,'hadoop-site.xml')
  36. self.numNodes = 4
  37. self.hdfsAddr = 'nosuchhost1.apache.org:50505'
  38. self.mapredAddr = 'nosuchhost2.apache.org:50506'
  39. self.finalServerParams = {
  40. 'mapred.child.java.opts' : '-Xmx1024m',
  41. 'mapred.compress.map.output' : 'false',
  42. }
  43. self.serverParams = {
  44. 'mapred.userlog.limit' : '200',
  45. 'mapred.userlog.retain.hours' : '10',
  46. 'mapred.reduce.parallel.copies' : '20',
  47. }
  48. self.clientParams = {
  49. 'mapred.tasktracker.tasks.maximum' : '2',
  50. 'io.sort.factor' : '100',
  51. 'io.sort.mb' : '200',
  52. 'mapred.userlog.limit.kb' : '1024',
  53. 'io.file.buffer.size' : '262144',
  54. }
  55. self.clusterFactor = 1.9
  56. self.mySysDir = '/user/' + getpass.getuser() + '/mapredsystem'
  57. pass
  58. def testSuccess(self):
  59. self.__hadoopConfig.gen_site_conf(
  60. confDir = self.confDir,\
  61. tempDir = self.tempDir,\
  62. numNodes = self.numNodes,\
  63. hdfsAddr = self.hdfsAddr,\
  64. mrSysDir = self.mySysDir,\
  65. mapredAddr = self.mapredAddr,\
  66. clientParams = self.clientParams,\
  67. serverParams = self.serverParams,\
  68. finalServerParams = self.finalServerParams,\
  69. clusterFactor = self.clusterFactor
  70. )
  71. xmldoc = minidom.parse(self.hadoopSite)
  72. xmldoc = xmldoc.childNodes[0] # leave out xml spec
  73. properties = xmldoc.childNodes # children of tag configuration
  74. keyvals = {}
  75. for prop in properties:
  76. if not isinstance(prop,minidom.Comment):
  77. # ---------- tag -------------------- -value elem-- data --
  78. name = prop.getElementsByTagName('name')[0].childNodes[0].data
  79. value = prop.getElementsByTagName('value')[0].childNodes[0].data
  80. keyvals[name] = value
  81. # fs.default.name should start with hdfs://
  82. assert(keyvals['fs.default.name'].startswith('hdfs://'))
  83. assert(keyvals['hadoop.tmp.dir'] == self.tempDir)
  84. assert(keyvals['dfs.client.buffer.dir'] == os.path.join(self.tempDir,
  85. 'dfs', 'tmp'))
  86. # TODO other tests
  87. pass
  88. def tearDown(self):
  89. if os.path.exists(self.hadoopSite): os.unlink(self.hadoopSite)
  90. if os.path.exists(self.confDir) : os.rmdir(self.confDir)
  91. if os.path.exists(self.testingDir) : os.rmdir(self.testingDir)
  92. pass
  93. class HadoopTestSuite(BaseTestSuite):
  94. def __init__(self):
  95. # suite setup
  96. BaseTestSuite.__init__(self, __name__, excludes)
  97. pass
  98. def cleanUp(self):
  99. # suite tearDown
  100. pass
  101. def RunHadoopTests():
  102. suite = HadoopTestSuite()
  103. testResult = suite.runTests()
  104. suite.cleanUp()
  105. return testResult
  106. if __name__ == "__main__":
  107. RunHadoopTests()