Exemplo n.º 1
0
    def test_ActivityOnAnyWriterResultsInMessageOnThatWritersService(self):
        "main - Activity on a selectable results in a message appearing in the service provided to the selector for that selectable"

        MOCKSELECTORMODULE = MockSelect(results=[ ([],["LOOKINGFORTHIS"],[]), 
                                                  ([],["THENFORTHIS"],[]), 
                                                  ([],["ANDTHENFORTHIS"],[]) ])
        SELECTORMODULE.select = MOCKSELECTORMODULE
        S = Selector()
        S.activate()
        for i in xrange(100): S.next()
        D = Axon.Component.component()
        E = Axon.Component.component()
        F = Axon.Component.component()
        dummyservice1 = (D, "inbox")
        S._deliver(newWriter(S,( dummyservice1, "LOOKINGFORTHIS") ),"notify")
        dummyservice2 = (E, "inbox")
        S._deliver(newWriter(S,( dummyservice2, "THENFORTHIS") ),"notify")
        dummyservice3 = (F, "inbox")
        S._deliver(newWriter(S,( dummyservice3, "ANDTHENFORTHIS") ),"notify")

        for i in xrange(100):
            S.next();
            try:
               S.postoffice.next()
            except:
               pass
        selectable = D.recv("inbox")
        self.assertEqual(selectable,"LOOKINGFORTHIS")#, "The value returned should be the selectable we originally asked for")
        selectable = E.recv("inbox")
        self.assertEqual(selectable,"THENFORTHIS")#, "The value returned should be the selectable we originally asked for")
        selectable = F.recv("inbox")
        self.assertEqual(selectable,"ANDTHENFORTHIS")#, "The value returned should be the selectable we originally asked for")
Exemplo n.º 2
0
   def handleNewConnection(self):
      """\
      Handle notifications from the selector service of new connection requests.

      Accepts and sets up new connections, wiring them up and passing them on via
      the "protocolHandlerSignal" outbox.
      """
      if self.dataReady("newconnection"):
         data = self.recv("newconnection")
         # If we recieve information on data ready, for a server it means we have a new connection
         # to handle
         try:
            newsock, CSA = self.createConnectedSocket(self.listener)
         except socket.error, e:
            (errorno,errmsg) = e
            if errorno != errno.EAGAIN:
               if errorno != errno.EWOULDBLOCK:
                  raise e
         else:
             pass

             self.send(_ki.newCSA(self, CSA), "protocolHandlerSignal")
             self.send(newReader(CSA, ((CSA, "ReadReady"), newsock)), "_selectorSignal")            
             self.send(newWriter(CSA, ((CSA, "SendReady"), newsock)), "_selectorSignal")            
             self.addChildren(CSA)
             self.link((CSA, "CreatorFeedback"),(self,"_feedbackFromCSA"))
             return CSA
Exemplo n.º 3
0
    def handleNewConnection(self):
        """\
      Handle notifications from the selector service of new connection requests.

      Accepts and sets up new connections, wiring them up and passing them on via
      the "protocolHandlerSignal" outbox.
      """
        if self.dataReady("newconnection"):
            data = self.recv("newconnection")
            # If we recieve information on data ready, for a server it means we have a new connection
            # to handle
            try:
                newsock, CSA = self.createConnectedSocket(self.listener)
            except socket.error, e:
                (errorno, errmsg) = e
                if errorno != errno.EAGAIN:
                    if errorno != errno.EWOULDBLOCK:
                        raise e
            else:
                pass

                self.send(_ki.newCSA(self, CSA), "protocolHandlerSignal")
                self.send(newReader(CSA, ((CSA, "ReadReady"), newsock)),
                          "_selectorSignal")
                self.send(newWriter(CSA, ((CSA, "SendReady"), newsock)),
                          "_selectorSignal")
                self.addChildren(CSA)
                self.link((CSA, "CreatorFeedback"), (self, "_feedbackFromCSA"))
                return CSA
Exemplo n.º 4
0
    def test_ActivityOnAnyWriterResultsInMessageOnThatWritersService(self):
        "main - Activity on a selectable results in a message appearing in the service provided to the selector for that selectable"

        MOCKSELECTORMODULE = MockSelect(
            results=[([], ["LOOKINGFORTHIS"],
                      []), ([], ["THENFORTHIS"],
                            []), ([], ["ANDTHENFORTHIS"], [])])
        SELECTORMODULE.select = MOCKSELECTORMODULE
        S = Selector()
        S.activate()
        for i in xrange(100):
            S.next()
        D = Axon.Component.component()
        E = Axon.Component.component()
        F = Axon.Component.component()
        dummyservice1 = (D, "inbox")
        S._deliver(newWriter(S, (dummyservice1, "LOOKINGFORTHIS")), "notify")
        dummyservice2 = (E, "inbox")
        S._deliver(newWriter(S, (dummyservice2, "THENFORTHIS")), "notify")
        dummyservice3 = (F, "inbox")
        S._deliver(newWriter(S, (dummyservice3, "ANDTHENFORTHIS")), "notify")

        for i in xrange(100):
            S.next()
            try:
                S.postoffice.next()
            except:
                pass
        selectable = D.recv("inbox")
        self.assertEqual(
            selectable, "LOOKINGFORTHIS"
        )  #, "The value returned should be the selectable we originally asked for")
        selectable = E.recv("inbox")
        self.assertEqual(
            selectable, "THENFORTHIS"
        )  #, "The value returned should be the selectable we originally asked for")
        selectable = F.recv("inbox")
        self.assertEqual(
            selectable, "ANDTHENFORTHIS"
        )  #, "The value returned should be the selectable we originally asked for")
Exemplo n.º 5
0
    def test_RemoveWriter_ResultsInWriterNoLongerBeingSelectedOrWiredIn(self):
        "main - Sending a remove writer message unwires/links a component, and also removes it's selectable from the writers list"
        MOCKSELECTORMODULE = MockSelect(results=[ ([], [], [] )])
        SELECTORMODULE.select = MOCKSELECTORMODULE
        S = Selector()
        S.activate()
        for i in xrange(100): S.next()
        D = Axon.Component.component() 
        dummyservice = (D, "inbox")
        S._deliver(newWriter(S,( dummyservice, "LOOKINGFORTHIS") ),"notify")
        S._deliver(removeWriter(S,"LOOKINGFORTHIS"),"notify")

        for i in xrange(100):
            S.next();
            try:
               S.postoffice.next()
            except:
               pass
        print 
        self.assert_( D.inboxes["inbox"] == [] )
Exemplo n.º 6
0
    def test_RemoveWriter_ResultsInWriterNoLongerBeingSelectedOrWiredIn(self):
        "main - Sending a remove writer message unwires/links a component, and also removes it's selectable from the writers list"
        MOCKSELECTORMODULE = MockSelect(results=[([], [], [])])
        SELECTORMODULE.select = MOCKSELECTORMODULE
        S = Selector()
        S.activate()
        for i in xrange(100):
            S.next()
        D = Axon.Component.component()
        dummyservice = (D, "inbox")
        S._deliver(newWriter(S, (dummyservice, "LOOKINGFORTHIS")), "notify")
        S._deliver(removeWriter(S, "LOOKINGFORTHIS"), "notify")

        for i in xrange(100):
            S.next()
            try:
                S.postoffice.next()
            except:
                pass
        print
        self.assert_(D.inboxes["inbox"] == [])
Exemplo n.º 7
0
    def main(self):
        writeBuffer = []
        shutdownMessage = False

        selectorService, selectorShutdownService, S = Selector.getSelectorServices(self.tracker)
        if S:
            S.activate()
        yield 1
        yield 1
        yield 1
        self.link((self, "selector"), (selectorService))
        #        self.link((self, "selectorsignal"), (selectorShutdownService))

        x = self.openSubprocess()
        self.send(newWriter(self, ((self, "stdinready"), x.stdin)), "selector")
        self.send(newReader(self, ((self, "stderrready"), x.stderr)), "selector")
        self.send(newReader(self, ((self, "stdoutready"), x.stdout)), "selector")

        # Assume all ready
        stdin_ready = 1
        stdout_ready = 1
        stderr_ready = 1

        exit_status = x.poll()  # while x.poll() is None
        success = 0
        while exit_status is None:
            exit_status = x.poll()

            if (not self.anyReady()) and not (stdin_ready + stdout_ready + stderr_ready):
                print self.name, "Mighty Foo", stdin_ready, stdout_ready, stderr_ready, len(self.inboxes["inbox"]), len(
                    writeBuffer
                )
                self.pause()
                yield 1
                continue

            while self.dataReady("inbox"):
                d = self.recv("inbox")
                writeBuffer.append(d)

            if self.dataReady("stdinready"):
                self.recv("stdinready")
                stdin_ready = 1

            if self.dataReady("stdoutready"):
                self.recv("stdoutready")
                stdout_ready = 1

            if self.dataReady("stderrready"):
                self.recv("stderrready")
                stderr_ready = 1

            if len(writeBuffer) > 10000:
                writeBuffer = writeBuffer[-10000:]
            if stdin_ready:
                while len(writeBuffer) > 0:
                    d = writeBuffer[0]
                    #                    d = writeBuffer.pop(0)
                    try:
                        count = os.write(x.stdin.fileno(), d)
                        writeBuffer.pop(0)
                        success += 1
                    except OSError, e:
                        success -= 1
                        print self.name, "Mighty FooBar", len(self.inboxes["inbox"]), len(writeBuffer)
                        # Stdin wasn't ready. Let's send through a newWriter request
                        # Want to wait
                        stdin_ready = 0
                        writeBuffer = writeBuffer[len(writeBuffer) / 2 :]
                        self.send(newWriter(self, ((self, "stdinready"), x.stdin)), "selector")
                        print self.name, "OK, we're waiting....", len(self.inboxes["inbox"]), len(writeBuffer)
                        break  # Break out of this loop
                    except:
                        print self.name, "Unexpected error whilst trying to write to stdin:"
                        print sys.exc_info()[0]
                        break