source: proiecte/HadoopJUnit/hadoop-0.20.1/contrib/hod/testing/testHodRing.py @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 4.2 KB
Line 
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
9#     http://www.apache.org/licenses/LICENSE-2.0
10
11#Unless required by applicable law or agreed to in writing, software
12#distributed under the License is distributed on an "AS IS" BASIS,
13#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#See the License for the specific language governing permissions and
15#limitations under the License.
16import unittest, os, sys, re, threading, time
17
18myDirectory = os.path.realpath(sys.argv[0])
19rootDirectory   = re.sub("/testing/.*", "", myDirectory)
20
21sys.path.append(rootDirectory)
22
23from testing.lib import BaseTestSuite
24
25excludes = []
26
27import tempfile, getpass, logging
28from xml.dom import minidom
29
30from hodlib.Hod.hadoop import hadoopConfig
31from hodlib.HodRing.hodRing import CommandDesc, HadoopCommand
32
33# All test-case classes should have the naming convention test_.*
34class test_HadoopCommand(unittest.TestCase):
35  def setUp(self):
36    self.rootDir = '/tmp/hod-%s' % getpass.getuser()
37    self.id = 0
38    self.desc = None
39    self.tempDir = os.path.join(self.rootDir,'test_HadoopCommand_tempDir')
40    self.pkgDir = os.path.join(self.rootDir,'test_HadoopCommand_pkgDir')
41    self.log = logging.getLogger() # TODO Use MockLogger
42    self.javaHome = '/usr/java/bin/'
43    self.mrSysDir = '/user/' + getpass.getuser() + '/mapredsystem'
44   
45    self.attrs = {}
46    self.finalAttrs = {
47                        'fs.default.name': 'nohost.apache.com:56366',
48                        'mapred.child.java.opts' : '-Xmx1024m',
49                        'mapred.compress.map.output' : 'false',
50                      }
51    self.attrs = {
52                    'mapred.userlog.limit' : '200',
53                    'mapred.userlog.retain.hours' : '10',
54                    'mapred.reduce.parallel.copies' : '20',
55                 }
56    self.desc = CommandDesc(
57                              {
58                                'name' : 'dummyHadoop',
59                                'program' : 'bin/hadoop',
60                                'pkgdirs' : self.pkgDir,
61                                'final-attrs' : self.finalAttrs,
62                                'attrs' : self.attrs,
63                              }, self.log
64                            )
65    # TODO
66    #   4th arg to HadoopCommand 'tardir' is not used at all. Instead pkgdir is
67    #   specified through HadoopCommand.run(pkgdir). This could be changed so
68    #   that pkgdir is specified at the time of object creation.
69    # END OF TODO
70    self.hadoopCommand = HadoopCommand(self.id, self.desc, self.tempDir,
71                          self.pkgDir, self.log, self.javaHome,
72                          self.mrSysDir, restart=True)
73    self.hadoopSite = os.path.join( self.hadoopCommand.confdir,
74                                    'hadoop-site.xml')
75    pass
76
77  def test_createHadoopSiteXml(self):
78    self.hadoopCommand._createHadoopSiteXml()
79    xmldoc = minidom.parse(self.hadoopSite)
80    xmldoc = xmldoc.childNodes[0] # leave out xml spec
81    properties = xmldoc.childNodes # children of tag configuration
82    keyvals = {}
83    for prop in properties:
84      if not isinstance(prop,minidom.Comment):
85        #      ---------- tag -------------------- -value elem-- data --
86        name = prop.getElementsByTagName('name')[0].childNodes[0].data
87        value = prop.getElementsByTagName('value')[0].childNodes[0].data
88        keyvals[name] = value
89
90    # fs.default.name should start with hdfs://
91    assert(keyvals['fs.default.name'].startswith('hdfs://'))
92
93    # TODO other tests
94    pass
95   
96  def tearDown(self):
97    pass
98
99class HodRingTestSuite(BaseTestSuite):
100  def __init__(self):
101    # suite setup
102    BaseTestSuite.__init__(self, __name__, excludes)
103    pass
104 
105  def cleanUp(self):
106    # suite tearDown
107    pass
108
109def RunHodRingTests():
110  # modulename_suite
111  suite = HodRingTestSuite()
112  testResult = suite.runTests()
113  suite.cleanUp()
114  return testResult
115
116if __name__ == "__main__":
117  RunHodRingTests()
Note: See TracBrowser for help on using the repository browser.