浏览代码

HADOOP-2783. Fixes a problem to do with import in hod/hodlib/Common/xmlrpc.py. Contributed by Vinod Kumar Vavilapalli.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@639215 13f79535-47bb-0310-9956-ffa450edef68
Devaraj Das 17 年之前
父节点
当前提交
a6024dcb5e
共有 4 个文件被更改,包括 31 次插入19 次删除
  1. 4 1
      CHANGES.txt
  2. 1 1
      src/contrib/hod/hodlib/Common/xmlrpc.py
  3. 0 1
      src/contrib/hod/testing/main.py
  4. 26 16
      src/contrib/hod/testing/testXmlrpc.py

+ 4 - 1
CHANGES.txt

@@ -118,7 +118,7 @@ Trunk (unreleased changes)
     requests or server slowdown. (Hairong Kuang via dhruba)
 
     HADOOP-2848. [HOD]hod -o list and deallocate works even after deleting
-    the cluster directory. (Vinod Kumar Vavilapalli via ddas)
+    the cluster directory. (Hemanth Yamijala via ddas)
 
   OPTIMIZATIONS
 
@@ -301,6 +301,9 @@ Trunk (unreleased changes)
     HADOOP-3036. Fix findbugs warnings in UpgradeUtilities. (Konstantin
     Shvachko via cdouglas)
 
+    HADOOP-2783. Fixes a problem to do with import in 
+    hod/hodlib/Common/xmlrpc.py. (Vinod Kumar Vavilapalli via ddas) 
+
 Release 0.16.2 - Unreleased
 
   BUG FIXES

+ 1 - 1
src/contrib/hod/hodlib/Common/xmlrpc.py

@@ -14,7 +14,7 @@
 #See the License for the specific language governing permissions and
 #limitations under the License.
 import xmlrpclib, time, random, signal
-from hodlib.Common.util import hodInterrupt
+from hodlib.Common.util import hodInterrupt, HodInterruptException
 
 class hodXRClient(xmlrpclib.ServerProxy):
     def __init__(self, uri, transport=None, encoding=None, verbose=0,

+ 0 - 1
src/contrib/hod/testing/main.py

@@ -26,7 +26,6 @@ from testing.lib import printSeparator, printLine
 moduleList = []
 allList = []
 excludes = [
-            'Xmlrpc'
            ]
 
 # Build a module list by scanning through all files in testingDir

+ 26 - 16
src/contrib/hod/testing/testXmlrpc.py

@@ -22,47 +22,55 @@ sys.path.append(rootDirectory)
 
 from hodlib.Common.xmlrpc import hodXRClient
 from hodlib.Common.socketServers import hodXMLRPCServer
+from hodlib.GridServices.service import ServiceUtil
+from hodlib.Common.util import hodInterrupt, HodInterruptException
 
 from testing.lib import BaseTestSuite
 
 excludes = []
 
+global serverPort
+serverPort = None
+
 class test_HodXRClient(unittest.TestCase):
   def setUp(self):
     pass
 
   # All testMethods have to have their names start with 'test'
   def testSuccess(self):
-    client = hodXRClient('http://localhost:5555', retryRequests=False)
+    global serverPort
+    client = hodXRClient('http://localhost:' + str(serverPort), retryRequests=False)
     self.assertEqual(client.testing(), True)
     pass
     
   def testFailure(self):
-    client = hodXRClient('http://localhost:5555', retryRequests=False)
-    # client.noMethod()
+    """HOD should raise Exception when unregistered rpc is called"""
+    global serverPort
+    client = hodXRClient('http://localhost:' + str(serverPort), retryRequests=False)
     self.assertRaises(Exception, client.noMethod)
     pass
 
   def testTimeout(self):
     """HOD should raise Exception when rpc call times out"""
-    client = hodXRClient('http://localhost:567823', retryRequests=False)
-    # client.noMethod()
+    # Give client some random nonexistent url
+    serverPort = ServiceUtil.getUniqRandomPort(h='localhost',low=40000,high=50000)
+    client = hodXRClient('http://localhost:' + str(serverPort), retryRequests=False)
     self.assertRaises(Exception, client.testing)
     pass
 
   def testInterrupt(self):
     """ HOD should raise HodInterruptException when interrupted"""
-    from hodlib.Common.util import hodInterrupt, HodInterruptException
-
-    def interrupt():
-      client = hodXRClient('http://localhost:59087')
-      thread = threading.Thread(name='testinterrupt', target=client.testing)
-      thread.start()
-      time.sleep(1)
-      hodInterrupt.setFlag()
-      thread.join()
 
-    self.assertRaises(HodInterruptException, interrupt)
+    def interrupt(testClass):
+      testClass.assertRaises(HodInterruptException, client.testing)
+      
+    serverPort = ServiceUtil.getUniqRandomPort(h='localhost',low=40000,high=50000)
+    client = hodXRClient('http://localhost:' + str(serverPort))
+    myThread = threading.Thread(name='testinterrupt', target=interrupt,args=(self,))
+    # Set the global interrupt
+    hodInterrupt.setFlag()
+    myThread.start()
+    myThread.join()
     pass
 
   def tearDown(self):
@@ -76,7 +84,9 @@ class XmlrpcTestSuite(BaseTestSuite):
     def rpcCall():
       return True
     
-    self.server = hodXMLRPCServer('localhost', ['5555'])
+    global serverPort
+    serverPort = ServiceUtil.getUniqRandomPort(h='localhost',low=40000,high=50000)
+    self.server = hodXMLRPCServer('localhost', [serverPort])
     self.server.register_function(rpcCall, 'testing')
     self.thread = threading.Thread(name="server", 
                                    target=self.server._serve_forever)