Exemplo n.º 1
0
 def test_Instantiate_SpecifyBoth(self):
     """You can't specify both chunkrate and chunksize as arguments for __init__()"""
     try:
         r = RateControl(rate=100, chunksize=25, chunkrate=4)
         self.fail("Should have failed")
     except:
         pass
Exemplo n.º 2
0
    def test_Instantiate_SpecifyChunkRate(self):
        """Specifying only rate and chunkrate is okay as arguments for __init__()"""
        r = RateControl(rate=100, chunkrate=8)

        self.assert_(r.chunksize == 12.5,
                     "__init__ RateControl.chunksize calculated correctly")
        self.assert_(r.timestep == 0.125,
                     "__init__ RateControl.timestep is as specified")
Exemplo n.º 3
0
def RateControlledReadFileAdapter(filename, readmode = "bytes", **rateargs):
    """ReadFileAdapter combined with a RateControl component
       Returns a component encapsulating a RateControl and ReadFileAdapter components.
            filename   = filename
            readmode   = "bytes" or "lines"
            **rateargs = named arguments to be passed to RateControl
        """
    return Graphline(RC  = RateControl(**rateargs),
                     RFA = ReadFileAdapter(filename, readmode),
                     linkages = { ("RC",  "outbox")  : ("RFA", "inbox"),
                                  ("RFA", "outbox")  : ("self", "outbox"),
                                  ("RFA", "signal")  : ("RC",  "control"),
                                  ("RC",  "signal")  : ("self", "signal"),
                                  ("self", "control") : ("RFA", "control")
                                }
    )
Exemplo n.º 4
0
def FixedRate_ReadFileAdapter_Carousel(readmode = "bytes", **rateargs):
    """A file reading carousel, that reads at a fixed rate.
       Takes filenames on its inbox
    """
    return Graphline(RC       = RateControl(**rateargs),
                     CAR      = ReusableFileReader(readmode),
                     linkages = { 
                         ("self", "inbox")      : ("CAR", "next"),
                         ("self", "control")    : ("RC", "control"),
                         ("RC", "outbox")       : ("CAR", "inbox"),
                         ("RC", "signal")       : ("CAR", "control"),
                         ("CAR", "outbox")      : ("self", "outbox"),
                         ("CAR", "signal")      : ("self", "signal"),
                         ("CAR", "requestNext") : ("self", "requestNext"),
                         ("self", "next")       : ("CAR", "next")
                     }
    
    )
Exemplo n.º 5
0
 def test_Instantiate_Defaults(self):
     """No arguments is okay for __init__()"""
     r = RateControl()
Exemplo n.º 6
0
    def do_test_EventSequence(self, argDict, tolerance, schedule):
        """Do a timing test for the rate control component.

        argDict = arguments passed to RateControl.__init__()
        tolerance = tolerance of timings for the test (+ or -) this amount acceptable
        schedule = list of events (in chronological order).
                    Each list item is a tuple:
                    (relative_time, action, actionarg)

                    t, action, arg:
                        t, "expect", N   - at time 't' since start of test, expect RateControl to send 'N'
                        t, "freeze", N   - at time 't' freeze (don't call RateControl) for 'N' seconds

        Test will succeed if and only if, all 'expect' events occur (within the timing tolerance specified)
        and no other events occur at other times
        """
        r = RateControl(**argDict)

        r.resetTiming()
        starttime = time.time()

        chunklist = []
        event = 0
        for (reltime, action, arg) in schedule:
            event += 1
            e = "[" + str(event) + "] "

            if action == "expect":
                expectedFound = False
                while not expectedFound and (time.time() <
                                             starttime + reltime + tolerance):
                    if not chunklist:
                        chunklist = list(r.getChunksToSend())

                    if chunklist:
                        chunksize = chunklist[0]
                        chunklist = chunklist[1:]

                        now = time.time() - starttime
                        if now >= reltime - tolerance:
                            self.assert_(
                                chunksize == arg, e +
                                "RateControl emits request for chunksize of " +
                                str(arg) + " (not " + str(chunksize) +
                                ") at time " + str(now) + " in this test")
                            expectedFound = True
                        else:
                            self.fail(
                                e +
                                "RateControl shouldn't emit 'chunksize' of " +
                                str(chunksize) + " at time " + now +
                                " in this test")

                self.assert_(
                    expectedFound,
                    e + "RateControl didn't emit request at time " +
                    str(reltime) + " as required in this test")

            elif action == "freeze":
                while (time.time() < starttime + reltime + tolerance):
                    for chunksize in r.getChunksToSend():
                        now = time.time() - starttime
                        self.fail(
                            e + "RateControl shouldn't emit 'chunksize' of " +
                            str(chunksize) + " at time " + now +
                            " in this test")

                # we've waited until reltime + tolerance (to catch any spurious 'emissions' from RateControl
                # so when we now 'freeze' we must compensate the sleep duration
                time.sleep(arg - tolerance)