PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/hadoop-1.1.2/contrib/hod/testing/testRingmasterRPCs.py

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Python | 171 lines | 154 code | 4 blank | 13 comment | 0 complexity | 1c138c00f7a3816159e382e58386cae8 MD5 | raw file
  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. import logging
  16. myDirectory = os.path.realpath(sys.argv[0])
  17. rootDirectory = re.sub("/testing/.*", "", myDirectory)
  18. sys.path.append(rootDirectory)
  19. from testing.lib import BaseTestSuite
  20. excludes = ['test_MINITEST1', 'test_MINITEST2']
  21. from hodlib.GridServices import *
  22. from hodlib.Common.desc import ServiceDesc
  23. from hodlib.RingMaster.ringMaster import _LogMasterSources
  24. configuration = {
  25. 'hod': {},
  26. 'resource_manager': {
  27. 'id': 'torque',
  28. 'batch-home': '/home/y/'
  29. },
  30. 'ringmaster': {
  31. 'max-connect' : 2,
  32. 'max-master-failures' : 5
  33. },
  34. 'hodring': {
  35. },
  36. 'gridservice-mapred': {
  37. 'id': 'mapred'
  38. } ,
  39. 'gridservice-hdfs': {
  40. 'id': 'hdfs'
  41. },
  42. 'servicedesc' : {} ,
  43. 'nodepooldesc': {} ,
  44. }
  45. # All test-case classes should have the naming convention test_.*
  46. class test_MINITEST1(unittest.TestCase):
  47. def setUp(self):
  48. pass
  49. # All testMethods have to have their names start with 'test'
  50. def testSuccess(self):
  51. pass
  52. def testFailure(self):
  53. pass
  54. def tearDown(self):
  55. pass
  56. class test_Multiple_Workers(unittest.TestCase):
  57. def setUp(self):
  58. self.config = configuration
  59. self.config['ringmaster']['workers_per_ring'] = 2
  60. hdfsDesc = self.config['servicedesc']['hdfs'] = ServiceDesc(self.config['gridservice-hdfs'])
  61. mrDesc = self.config['servicedesc']['mapred'] = ServiceDesc(self.config['gridservice-mapred'])
  62. self.hdfs = Hdfs(hdfsDesc, [], 0, 19, workers_per_ring = \
  63. self.config['ringmaster']['workers_per_ring'])
  64. self.mr = MapReduce(mrDesc, [],1, 19, workers_per_ring = \
  65. self.config['ringmaster']['workers_per_ring'])
  66. self.log = logging.getLogger()
  67. pass
  68. # All testMethods have to have their names start with 'test'
  69. def testWorkersCount(self):
  70. self.serviceDict = {}
  71. self.serviceDict[self.hdfs.getName()] = self.hdfs
  72. self.serviceDict[self.mr.getName()] = self.mr
  73. self.rpcSet = _LogMasterSources(self.serviceDict, self.config, None, self.log, None)
  74. cmdList = self.rpcSet.getCommand('host1')
  75. self.assertEquals(len(cmdList), 2)
  76. self.assertEquals(cmdList[0].dict['argv'][0], 'namenode')
  77. self.assertEquals(cmdList[1].dict['argv'][0], 'namenode')
  78. addParams = ['fs.default.name=host1:51234', 'dfs.http.address=host1:5125' ]
  79. self.rpcSet.addMasterParams('host1', addParams)
  80. # print "NN is launched"
  81. cmdList = self.rpcSet.getCommand('host2')
  82. self.assertEquals(len(cmdList), 1)
  83. self.assertEquals(cmdList[0].dict['argv'][0], 'jobtracker')
  84. addParams = ['mapred.job.tracker=host2:51236',
  85. 'mapred.job.tracker.http.address=host2:51237']
  86. self.rpcSet.addMasterParams('host2', addParams)
  87. # print "JT is launched"
  88. cmdList = self.rpcSet.getCommand('host3')
  89. # Verify the workers count per ring : TTs + DNs
  90. self.assertEquals(len(cmdList),
  91. self.config['ringmaster']['workers_per_ring'] * 2)
  92. pass
  93. def testFailure(self):
  94. pass
  95. def tearDown(self):
  96. pass
  97. class test_GetCommand(unittest.TestCase):
  98. def setUp(self):
  99. self.config = configuration
  100. hdfsDesc = self.config['servicedesc']['hdfs'] = ServiceDesc(self.config['gridservice-hdfs'])
  101. mrDesc = self.config['servicedesc']['mapred'] = ServiceDesc(self.config['gridservice-mapred'])
  102. # API : serviceObj = service(desc, workDirs, reqNodes, version)
  103. self.hdfs = Hdfs(hdfsDesc, [], 0, 17)
  104. self.hdfsExternal = HdfsExternal(hdfsDesc, [], 17)
  105. self.mr = MapReduce(mrDesc, [],1, 17)
  106. self.mrExternal = MapReduceExternal(mrDesc, [], 17)
  107. self.log = logging.getLogger()
  108. pass
  109. # All testMethods have to have their names start with 'test'
  110. def testBothInternal(self):
  111. self.serviceDict = {}
  112. self.serviceDict[self.hdfs.getName()] = self.hdfs
  113. self.serviceDict[self.mr.getName()] = self.mr
  114. self.rpcSet = _LogMasterSources(self.serviceDict, self.config, None, self.log, None)
  115. cmdList = self.rpcSet.getCommand('localhost')
  116. self.assertEquals(cmdList.__len__(), 2)
  117. self.assertEquals(cmdList[0].dict['argv'][0], 'namenode')
  118. self.assertEquals(cmdList[1].dict['argv'][0], 'namenode')
  119. pass
  120. def tearDown(self):
  121. pass
  122. class RingmasterRPCsTestSuite(BaseTestSuite):
  123. def __init__(self):
  124. # suite setup
  125. BaseTestSuite.__init__(self, __name__, excludes)
  126. pass
  127. def cleanUp(self):
  128. # suite tearDown
  129. pass
  130. def RunRingmasterRPCsTests():
  131. # modulename_suite
  132. suite = RingmasterRPCsTestSuite()
  133. testResult = suite.runTests()
  134. suite.cleanUp()
  135. return testResult
  136. if __name__ == "__main__":
  137. RunRingmasterRPCsTests()