testRingmasterRPCs.py
上传用户:quxuerui
上传日期:2018-01-08
资源大小:41811k
文件大小:6k
源码类别:

网格计算

开发平台:

Java

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