Example #1
0
 def test_computed_graph_function_invocation_returns_its_argument(self):
     event = threading.Event()
     interface = self.connect()
     webObjects = SubscribableWebObjects.WebObjectFactory(interface, maxObjectIds=10)
     testCGLocation = webObjects.TestCGLocation({'definition': 0})
     eventHandler = EventHandler(event)
     inputArg = "test argument"
     testCGLocation.testFunction(inputArg, eventHandler)
     event.wait()
     self.assertSuccessResponse(eventHandler)
     response = eventHandler.responses['Success'][0]
     self.assertTrue(response == inputArg)
     interface.close()
Example #2
0
def connect(url):
    """Connects to a Ufora cluster listening on the url and port provided by 'url'

    Returns:
        An executor object responsibe for submitting python code to the cluster for 
        execution returning RemotePythonObjects that can be used to download the 
        results from the server.
    """
    socketIoInterface = SocketIoJsonInterface.SocketIoJsonInterface(
        url, '/subscribableWebObjects')
    socketIoInterface.connect()

    webObjectFactory = SubscribableWebObjects.WebObjectFactory(
        socketIoInterface)
    return Executor.Executor(
        Connection(webObjectFactory, createObjectConverter(webObjectFactory)))
Example #3
0
    def test_ComputedGraphLocation(self):
        event = threading.Event()

        interface = self.connect()

        webObjects = SubscribableWebObjects.WebObjectFactory(interface, maxObjectIds=10)
        testCGLocation = webObjects.TestCGLocation({'definition': 0})

        eventHandler = EventHandler(event)
        testCGLocation.get_testCgLocation(eventHandler)
        event.wait()

        self.assertSuccessResponse(eventHandler)
        response = eventHandler.responses['Success'][0]
        self.assertIsInstance(response, SubscribableWebObjects.TestCGLocation)

        interface.close()
    def test_volumeTest(self):
        interface = self.connect()
        webObjects = SubscribableWebObjects.WebObjectFactory(interface,
                                                             maxObjectIds=50)
        initialTimesCleared = webObjects.sessionState.timesCleared

        totalToTry = 11000
        maxToSubmitAtOnce = 1000
        totalSubmitted = [0]
        totalReceived = [0]

        allDone = threading.Event()

        def receivedAll():
            return totalReceived[0] == totalToTry

        def canSubmit():
            return (totalSubmitted[0] < totalToTry and
                    totalSubmitted[0] - totalReceived[0] < maxToSubmitAtOnce)

        def submitOne():
            #if totalSubmitted[0] % 100 == 0:
            #print "submitting definition:", totalSubmitted[0]
            def onLocation(location):
                def onDefinition(d):
                    totalReceived[0] += 1
                    #if totalReceived[0] % 100 == 0:
                    #print "total received:", totalReceived[0]
                    if receivedAll():
                        allDone.set()
                    elif canSubmit():
                        submitOne()

                location.get_definition(EventHandler(onSuccess=onDefinition))

            loc = webObjects.TestCGLocation({'definition': totalSubmitted[0]})
            loc.get_testCgLocation(EventHandler(onSuccess=onLocation))
            totalSubmitted[0] += 1

        while canSubmit():
            submitOne()

        allDone.wait()
        self.assertGreater(webObjects.sessionState.timesCleared,
                           initialTimesCleared)
Example #5
0
    def test_failure_callback(self):
        event = threading.Event()

        interface = self.connect()
        webObjects = SubscribableWebObjects.WebObjectFactory(interface, maxObjectIds=10)
        testCGLocation = webObjects.TestCGLocation({'this_should_fail': 0})
        eventHandler = EventHandler(event)
        testCGLocation.get_testCgLocation(eventHandler)
        event.wait()

        self.assertEqual(len(eventHandler.responses['Success']), 0)
        self.assertEqual(len(eventHandler.responses['Failure']), 1)
        self.assertEqual(len(eventHandler.responses['Changed']), 0)
        failure = eventHandler.responses['Failure'][0]
        self.assertIn('responseType', failure)
        self.assertEqual(failure['responseType'], 'Exception')

        interface.close()
Example #6
0
        def threadProc(ix, iterations):
            for i in xrange(iterations):
                event = threading.Event()

                interface = self.connect()

                webObjects = SubscribableWebObjects.WebObjectFactory(interface, maxObjectIds=10)
                testCGLocation = webObjects.TestCGLocation({'definition': ix*iterations + i})

                eventHandler = EventHandler(event)
                testCGLocation.get_testCgLocation(eventHandler)
                event.wait()

                for eventType in ['Failure', 'Changed']:
                    if len(eventHandler.responses[eventType]) > 0:
                        threadResults[ix] = eventHandler.responses[eventType]
                        break

                if threadResults[ix] is None:
                    threadResults[ix] = eventHandler.responses['Success'][0]

                interface.close()
Example #7
0
def connectGivenSocketIo(socketIoInterface):
    import pyfora.SubscribableWebObjects as SubscribableWebObjects
    webObjectFactory = SubscribableWebObjects.WebObjectFactory(
        socketIoInterface)
    return Executor.Executor(
        Connection(webObjectFactory, createObjectConverter(webObjectFactory)))