예제 #1
0
 def test_testInterface_smokeSuccess(self):
    "testInterface - returns true for a _minimal match_ on the interface of the component."
    # Test assumes component defaults to having inboxes: "inbox" and "control" and "outboxes": "outbox" and "signal"
    self.failUnless(testInterface(component(), (["inbox","control"],["outbox","signal"])), "Failed with all boxes required.")
    self.failUnless(testInterface(component(), ([],[])), "Failed with no boxes required.")
    self.failUnless(testInterface(component(), (["inbox"],[])), "Failed with no boxes required.")
    self.failUnless(testInterface(component(), ([],["outbox"])), "Failed with no boxes required.")
예제 #2
0
    def setUp(self):
        self.src = component()
        self.dst = component()
        self.dst2 = TestComponent()
        self.controller = component()
        self.split = Splitter()
        self.runner = self.split.main()
        self.linkin = linkage(self.src, self.split)
        self.linkcont = linkage(self.controller,
                                self.split,
                                sinkbox="configuration")
        self.links = [self.linkin, self.linkcont]
        #      self.linkout1 = linkage(self.split,self.dst)
        #      self.linkout2 = linkage(self.split,self.dst2, sourcebox="out2")

        #
        # -- NEW STUFF ------
        #
        Axon.Scheduler.scheduler.run = Axon.Scheduler.scheduler()
        self.execute = Axon.Scheduler.scheduler.run.main()

        self.S = Splitter().activate()
        self.D = component().activate()
        self.D2 = TestComponent().activate()
        self.W = component().activate()
        self.W.link((self.W, "outbox"), (self.S, "configuration"))
예제 #3
0
 def setUp(self):
     self.testerA = component()
     self.testerB = component()
     self.Comparator = Comparator()
     self.Comparator.activate()
     self.pm = postman()
     #pipewidth = 1 implies 2 items in the linkage.  One in outbox and one in sourcebox.  Need to change this code if these semantics change.
     self.pm.registerlinkage(
         linkage(source=self.testerA,
                 sink=self.Comparator,
                 sourcebox="outbox",
                 sinkbox="inA"))
     self.pm.registerlinkage(
         linkage(source=self.testerB,
                 sink=self.Comparator,
                 sourcebox="outbox",
                 sinkbox="inB"))
     self.pm.registerlinkage(
         linkage(source=self.testerA,
                 sink=self.Comparator,
                 sourcebox="signal",
                 sinkbox="control"))
     self.pm.registerlinkage(
         linkage(source=self.Comparator,
                 sink=self.testerA,
                 sourcebox="outbox",
                 sinkbox="inbox"))
     self.pm.registerlinkage(
         linkage(source=self.Comparator,
                 sink=self.testerA,
                 sourcebox="signal",
                 sinkbox="control"))
예제 #4
0
    def test_unactivatedGraphlineHasNoChildren(self):
        """Instantiating a graphline, components specified as named arguments, eg. A=component() and B=component() will not be children of the graphline before it is activated and run"""
        self.setup_initialise(A=component(), B=component(), linkages={})

        gChildren = self.graphline.childComponents()
        for c in self.children.values():
            self.assert_(not (c in gChildren))
예제 #5
0
 def test_unactivatedGraphlineHasNoChildren(self):
     """Instantiating a graphline, components specified as named arguments, eg. A=component() and B=component() will not be children of the graphline before it is activated and run"""
     self.setup_initialise(A=component(), B=component(), linkages={})
     
     gChildren = self.graphline.childComponents()
     for c in self.children.values():
         self.assert_(not(c in gChildren))
예제 #6
0
    def test_graphlineHasChildren(self):
        """Instantiating a graphline, components specified as named arguments, eg. A=component() and B=component() become children of the graphline once activated and run."""
        self.setup_initialise(A=component(), B=component(), linkages={})
        self.setup_activate()

        self.runFor(cycles=1)

        gChildren = self.graphline.childComponents()
        for c in self.children.values():
            self.assert_(c in gChildren)
예제 #7
0
 def test_graphlineHasChildren(self):
     """Instantiating a graphline, components specified as named arguments, eg. A=component() and B=component() become children of the graphline once activated and run."""
     self.setup_initialise(A=component(), B=component(), linkages={})
     self.setup_activate()
     
     self.runFor(cycles=1)
     
     gChildren = self.graphline.childComponents()
     for c in self.children.values():
         self.assert_(c in gChildren)
예제 #8
0
 def setUp(self):
     self.testerA = component()
     self.testerB = component()
     self.Comparator = Comparator()
     self.Comparator.activate()
     self.pm = postman()
     #pipewidth = 1 implies 2 items in the linkage.  One in outbox and one in sourcebox.  Need to change this code if these semantics change.
     self.pm.registerlinkage(linkage(source = self.testerA, sink = self.Comparator, sourcebox = "outbox", sinkbox = "inA"))
     self.pm.registerlinkage(linkage(source = self.testerB, sink = self.Comparator, sourcebox = "outbox", sinkbox = "inB"))
     self.pm.registerlinkage(linkage(source = self.testerA, sink = self.Comparator, sourcebox = "signal", sinkbox = "control"))
     self.pm.registerlinkage(linkage(source = self.Comparator, sink = self.testerA, sourcebox = "outbox", sinkbox = "inbox"))
     self.pm.registerlinkage(linkage(source = self.Comparator, sink = self.testerA, sourcebox = "signal", sinkbox = "control"))
예제 #9
0
 def test_BoxAlreadyLinkedToDestinationException(self):
     p=postoffice()
     c1=component()
     c2=component()
     c3=component()
     l1 = p.link( (c1,"outbox"), (c2,"inbox") )
     try:
         l2 = p.link( (c1,"outbox"), (c3,"inbox") )
         self.fail("Should have raised BoxAreadyLinkedException when link was made from already linked c1-outbox")
     except BoxAlreadyLinkedToDestination:
         pass
     p.unlink(thelinkage=l1)
     l2 = p.link( (c1,"outbox"), (c3,"inbox") )
예제 #10
0
    def test_removeOutboxes_default(self):
        """mainBody - addsink|removesink->configuration - Tests addition and removal
      of sinks using the default box arguments.  Adds a array of sinks, removes
      the odd items and then checks that messages are delivered to the even
      sinks and not the odd ones."""
        boxes = 10
        boxlist = {}
        for x in xrange(boxes):
            C = component().activate()
            boxlist[x] = C
            self.W.send(addsink(C), "outbox")

        self.runCycles()

        for x in xrange(1, boxes, 2):
            C = boxlist[x]
            self.W.send(removesink(C), "outbox")

        self.runCycles()

        for i in xrange(20):
            self.S._deliver(i, "inbox")
            self.runCycles()

            for j in xrange(0, boxes, 2):
                self.failUnless(boxlist[j].dataReady("inbox"))
                self.failUnless(boxlist[j].recv("inbox") == i)

            for j in xrange(1, boxes, 2):
                self.failIf(boxlist[j].dataReady("inbox"))
예제 #11
0
 def test_addSinkInboxes_passthrough(self):
     """mainBody - addsink->configurations - Adds a whole set of sinks and checks
   they all receive expected messages.  Complicated by setting the sink to
   passthrough and to be to an inbox."""
     boxes = 10
     boxlist = []
     for x in xrange(boxes):
         c = component()
         boxlist.append(c)
         self.links.append(
             linkage(source=c,
                     sourcebox="outbox",
                     sink=c,
                     sinkbox="control"))
         self.controller.send(addsink(c, "outbox", 2))
         self.deliverhelper()
         runrepeat(self.runner)
     for i in xrange(20):
         self.src.send(i)
         self.deliverhelper()
         runrepeat(self.runner)
         self.deliverhelper()
         self.deliverhelper()
         for comp in boxlist:
             self.failUnless(comp.dataReady("control"))
             self.failUnless(comp.recv("control") == i)
예제 #12
0
   def test_removeOutboxes_default(self):
      """mainBody - addsink|removesink->configuration - Tests addition and removal
      of sinks using the default box arguments.  Adds a array of sinks, removes
      the odd items and then checks that messages are delivered to the even
      sinks and not the odd ones."""
      boxes = 10
      boxlist = {}
      for x in xrange(boxes): 
            C = component().activate()
            boxlist[x] = C
            self.W.send(addsink(C), "outbox")

      self.runCycles()

      for x in xrange(1,boxes,2):
            C = boxlist[x]
            self.W.send(removesink(C), "outbox")

      self.runCycles()

      for i in xrange(20):
         self.S._deliver(i, "inbox")
         self.runCycles()

         for j in xrange(0,boxes,2):
            self.failUnless(boxlist[j].dataReady("inbox"))
            self.failUnless(boxlist[j].recv("inbox") == i)
            
         for j in xrange(1,boxes,2):
             self.failIf(boxlist[j].dataReady("inbox"))
예제 #13
0
 def setUp(self):
     self.tester = component()
     self.trcomp = TestResult()
     self.trcomp.activate()
     self.pm = postman()
     self.pm.activate()
     self.tester.activate()
     #pipewidth = 1 implies 2 items in the linkage.  One in outbox and one in sourcebox.  Need to change this code if these semantics change.
     self.pm.registerlinkage(linkage(source = self.tester, sink = self.trcomp, sourcebox = "outbox", sinkbox = "inbox"))
     self.pm.registerlinkage(linkage(source = self.tester, sink = self.trcomp, sourcebox = "signal", sinkbox = "control"))
예제 #14
0
 def test_testInterface_failmodes(self):
    "In production mode failed tests will return false.  Otherwise they will throw an exception that is likely to stop the system."
    if production:
        self.failIf(testInterface(component(), (["fred"],[])), "Does not return false for failed test.")
        self.failIf(testInterface(component(), (["inbox","control","fred"],["outbox","signal"])), "Does not return false for failed test.")
        self.failIf(testInterface(component(), ([],["fred"])), "Does not return false for failed test.")
        self.failIf(testInterface(component(), (["inbox","control"],["outbox","signal","fred"])), "Does not return false for failed test.")
    else:
        self.failUnlessRaises(invalidComponentInterface, testInterface, component(), (["fred"],[]))
        self.failUnlessRaises(invalidComponentInterface, testInterface, component(), ([],["fred"]))
        self.failUnlessRaises(invalidComponentInterface, testInterface, component(), (["inbox","control","fred"],[]))
        self.failUnlessRaises(invalidComponentInterface, testInterface, component(), (["inbox","control"],["outbox","signal","fred"]))
        c = component()
        exceptioncount=0
        try:
            testInterface(c,(["fred"],[]))
        except Exception:
            e = sys.exc_info()[1]
            self.failUnless(isinstance(e, invalidComponentInterface))
            self.failUnless(e.args == ("inboxes", c, (["fred"],[])), "Exception not as expected.")
            exceptioncount=exceptioncount+1
        try:
            testInterface(c,([],["fred"]))
        except Exception:
            e = sys.exc_info()[1]
            self.failUnless(isinstance(e, invalidComponentInterface))
            self.failUnless(e.args == ("outboxes", c, ([],["fred"])), "Exception not as expected.")
            exceptioncount=exceptioncount+1
        try:
            testInterface(c,(["inbox","control","fred"],[]))
        except Exception:
            e = sys.exc_info()[1]
            self.failUnless(isinstance(e, invalidComponentInterface))
            self.failUnless(e.args == ("inboxes", c, (["inbox","control","fred"],[])), "Exception not as expected.")
            exceptioncount=exceptioncount+1
        try:
            testInterface(c,(["inbox","control"],["outbox","signal","fred"]))
        except Exception:
            e = sys.exc_info()[1]
            self.failUnless(isinstance(e, invalidComponentInterface))
            self.failUnless(e.args == ("outboxes", c, (["inbox","control"],["outbox","signal","fred"])), "Exception not as expected.")
            exceptioncount=exceptioncount+1
        self.failUnless(exceptioncount == 4, "Expected exception wasn't thrown!!!")
예제 #15
0
   def setUp(self):
      self.src = component()
      self.dst = component()
      self.dst2 = TestComponent()
      self.controller = component()
      self.split = Splitter()
      self.runner = self.split.main()
      self.linkin = linkage(self.src,self.split)
      self.linkcont = linkage(self.controller, self.split, sinkbox="configuration")
      self.links = [self.linkin, self.linkcont]
#      self.linkout1 = linkage(self.split,self.dst)
#      self.linkout2 = linkage(self.split,self.dst2, sourcebox="out2")

      #
      # -- NEW STUFF ------
      #
      Axon.Scheduler.scheduler.run = Axon.Scheduler.scheduler()
      self.execute = Axon.Scheduler.scheduler.run.main()

      self.S = Splitter().activate()
      self.D = component().activate()
      self.D2 = TestComponent().activate()
      self.W = component().activate()
      self.W.link( (self.W, "outbox"), (self.S, "configuration") )
예제 #16
0
 def __test_addOutboxes_createsink(self):  # SMELL - internal diagnostic
    """createsink - Called repeatedly.  Adds a whole set of sinks and checks
    they all receive expected messages."""
    boxes = 10
    boxlist = []
    for x in xrange(boxes):
       c=component()
       boxlist.append(c)
       self.split.createsink(c)
    for i in xrange(20):
       self.src.send(i)
       self.deliverhelper()
       runrepeat(self.runner)
       self.deliverhelper()
       for comp in boxlist:
          self.failUnless(comp.dataReady())
          self.failUnless(comp.recv() == i)
예제 #17
0
 def __test_addOutboxes_createsink(self):  # SMELL - internal diagnostic
     """createsink - Called repeatedly.  Adds a whole set of sinks and checks
   they all receive expected messages."""
     boxes = 10
     boxlist = []
     for x in xrange(boxes):
         c = component()
         boxlist.append(c)
         self.split.createsink(c)
     for i in xrange(20):
         self.src.send(i)
         self.deliverhelper()
         runrepeat(self.runner)
         self.deliverhelper()
         for comp in boxlist:
             self.failUnless(comp.dataReady())
             self.failUnless(comp.recv() == i)
 def setUp(self):
     self.tester = component()
     self.trcomp = TestResult()
     self.trcomp.activate()
     self.pm = postman()
     self.pm.activate()
     self.tester.activate()
     #pipewidth = 1 implies 2 items in the linkage.  One in outbox and one in sourcebox.  Need to change this code if these semantics change.
     self.pm.registerlinkage(
         linkage(source=self.tester,
                 sink=self.trcomp,
                 sourcebox="outbox",
                 sinkbox="inbox"))
     self.pm.registerlinkage(
         linkage(source=self.tester,
                 sink=self.trcomp,
                 sourcebox="signal",
                 sinkbox="control"))
예제 #19
0
 def test_addOutboxes(self):
     """mainBody - addsink->configurations - Adds a whole set of sinks and checks
   they all receive expected messages."""
     boxes = 10
     boxlist = []
     for x in xrange(boxes):
         c = component()
         boxlist.append(c)
         self.controller.send(addsink(c))
         self.deliverhelper()
         runrepeat(self.runner)
     for i in xrange(20):
         self.src.send(i)
         self.deliverhelper()
         runrepeat(self.runner)
         self.deliverhelper()
         for comp in boxlist:
             self.failUnless(comp.dataReady())
             self.failUnless(comp.recv() == i)
예제 #20
0
 def test_addOutboxes(self):
    """mainBody - addsink->configurations - Adds a whole set of sinks and checks
    they all receive expected messages."""
    boxes = 10
    boxlist = []
    for x in xrange(boxes):
       c=component()
       boxlist.append(c)
       self.controller.send(addsink(c))
       self.deliverhelper()
       runrepeat(self.runner)
    for i in xrange(20):
       self.src.send(i)
       self.deliverhelper()
       runrepeat(self.runner)
       self.deliverhelper()
       for comp in boxlist:
          self.failUnless(comp.dataReady())
          self.failUnless(comp.recv() == i)
예제 #21
0
 def test_addSinkInboxes_passthrough(self):
    """mainBody - addsink->configurations - Adds a whole set of sinks and checks
    they all receive expected messages.  Complicated by setting the sink to
    passthrough and to be to an inbox."""
    boxes = 10
    boxlist = []
    for x in xrange(boxes):
       c=component()
       boxlist.append(c)
       self.links.append(linkage(source=c, sourcebox="outbox", sink=c, sinkbox="control"))
       self.controller.send(addsink(c,"outbox",2))
       self.deliverhelper()
       runrepeat(self.runner)
    for i in xrange(20):
       self.src.send(i)
       self.deliverhelper()
       runrepeat(self.runner)
       self.deliverhelper()
       self.deliverhelper()
       for comp in boxlist:
          self.failUnless(comp.dataReady("control"))
          self.failUnless(comp.recv("control") == i)
예제 #22
0
    def main(self):
        """Main loop."""

        while not self.finished():
            while not self.dataReady("inbox"):
                self.pause()
                yield 1
            data = self.recv("inbox")

            log("[PS] data: ", data,lvl=debug)

            direction = hit = False


            for condition, pipegen in self.routes:
                if condition(data):
                    hit = True
                    direction = pipegen

            if not hit:
                if self.defaultpipe:
                    log("[PS] No hit, running through defaultpipe.",lvl=debug)
                    direction = self.defaultpipe

            if direction:
                log("[PS] Generating pipe", lvl=debug)

                pipe = direction()
                #component(pipe).initialiseComponent()

                log("[PS] Generating boxes.",lvl=debug)

                self.addOutbox(pipe.name)
                self.addOutbox(pipe.name + "signal")
                self.addInbox(pipe.name + "control")
                self.addInbox(pipe.name + "inbox")

                log("[PS] Generating links.",lvl=debug)

                thetolink = self.link((self, pipe.name), (pipe, "inbox"))
                thefromlink = self.link((pipe, "outbox"), (self, pipe.name + "inbox"))
                thetosignal = self.link((self, pipe.name + "signal"), (pipe, "control"))
                thefromsignal = self.link((pipe, "signal"), (self, pipe.name + "control"))

                log("[PS] Transmitting data to pipe:", data, lvl=debug)

                self.send(data, pipe.name)
                pipe.activate()
                self.send(producerFinished, pipe.name + "signal")

                def clearLinks():
                    #log("[PS] Unlinking..")

                    self.unlink(pipe, thetolink)
                    self.unlink(pipe, thefromlink)
                    self.unlink(pipe, thetosignal)
                    self.unlink(pipe, thefromsignal)

                begin = time.time()
                #component(pipe)._callOnCloseDown.append(clearLinks)
                #while (not component(pipe)._isStopped()) and (time.time() < begin + 5):
                #    yield 1

                while (not self.dataReady(pipe.name + "inbox")) and (time.time() < begin + 1):
                    yield 1

                if self.dataReady(pipe.name + "inbox"):
                    self.send(self.recv(pipe.name + "inbox"), "outbox")
                else:
                    log("[PS] WARNING: Pipe didn't respond in time: ", pipe.name, pipe, lvl=warn)

                #log("[PS] Pipe sent signal:", self.recv(pipe.name+"control")
                #)
                clearLinks()
                component(pipe).closeDownComponent()
                self.deleteOutbox(pipe.name)
                self.deleteOutbox(pipe.name + "signal")
                self.deleteInbox(pipe.name + "control")
                self.deleteInbox(pipe.name + "inbox")

                log("[PS] Done.",lvl=debug)

            else:
                log("[PS] No match, no default",lvl=warn)
예제 #23
0
 def test_graphlineNoLinkagesArg(self):
     """Instantiating with components as named arguments, but specifying no linkages argument results in a ValueError exception"""
     self.failUnlessRaises(ValueError, Graphline, A=component(), B=component())
예제 #24
0
 def test_graphlineEmptyLinkagesArg(self):
     """Instantiating with components as named arguments, and specifying an empty linkages argument succeeds"""
     Graphline(A=component(), B=component(), linkages={})
예제 #25
0
 def test_graphlineNoLinkagesArg(self):
     """Instantiating with components as named arguments, but specifying no linkages argument results in a ValueError exception"""
     self.failUnlessRaises(ValueError,
                           Graphline,
                           A=component(),
                           B=component())
예제 #26
0
 def test_graphlineEmptyLinkagesArg(self):
     """Instantiating with components as named arguments, and specifying an empty linkages argument succeeds"""
     Graphline(A=component(), B=component(), linkages={})