Example #1
0
def test_continuation():
    "test Continuation, Continue, Join and finalization"
    Continue((Watch('begin'), Watch('one'), Join(
        (Watch('two'), Watch('three'))), Watch('joined'),
              finalization.Branch((
                  Watch('end'),
                  Watch('branched'),
              ))))
    async_loop.dispatch()
def test_cycle ():
        "test a finalizations' cycle collection"
        one = Watch ('one')
        two = Watch ('two')
        three = Watch ('three')
        four = Watch ('four')
        finalization.continuation ([one, two, three, four])
        four.cycle = three
        del one, two, three, four
        async_loop.dispatch ()
        gc.collect ()
        loginfo.log ('garbage: %r' % gc.garbage)
        for cycled in gc.garbage:
                cycled.finalization = None
        async_loop.dispatch ()
Example #3
0
def test_cycle():
    "test a finalizations' cycle collection"
    one = Watch('one')
    two = Watch('two')
    three = Watch('three')
    four = Watch('four')
    finalization.continuation([one, two, three, four])
    four.cycle = three
    del one, two, three, four
    async_loop.dispatch()
    gc.collect()
    loginfo.log('garbage: %r' % gc.garbage)
    for cycled in gc.garbage:
        cycled.finalization = None
    async_loop.dispatch()
def test_continuation ():
        "test Continuation, Continue, Join and finalization"
        Continue ((
                Watch ('begin'),
                Watch ('one'),
                Join ((
                        Watch ('two'), 
                        Watch ('three')
                        )),
                Watch ('joined'),
                finalization.Branch ((
                        Watch ('end'), 
                        Watch ('branched'),
                        ))
                ))
        async_loop.dispatch ()
Example #5
0
def test_managed():
    test_connections(connections, hosts)
    async_loop.dispatch()
    finalization.collect()
    test_cache(cache, hosts)
    async_loop.dispatch()
    finalization.collect()
    test_pool(pool)
    async_loop.dispatch()
    finalization.collect()
def test_managed ():
        test_connections (connections, hosts)
        async_loop.dispatch ()
        finalization.collect ()
        test_cache (cache, hosts)
        async_loop.dispatch ()
        finalization.collect ()
        test_pool (pool)
        async_loop.dispatch ()
        finalization.collect ()
Example #7
0
# test unmanaged client dispatcher


def test_unmanaged():
    loginfo.log('test_unmanaged')
    for host in ('999.999.999.999', '127.0.0.2', '127.0.0.1'):
        dispatcher = async_chat.Dispatcher()
        if async_client.connect(dispatcher, (host, 80), 3):
            dispatcher.async_chat_push('GET /prompt.xml HTTP/1.1\r\n'
                                       'Host: %s\r\n'
                                       '\r\n' % host)


test_unmanaged()
async_loop.dispatch()
finalization.collect()

# test managed client dispatcher


def push(dispatcher, host):
    if not dispatcher.closing:
        dispatcher.async_chat_push(
            'GET /prompt.xml?PRESTo=async&prompt=xdir(reactor)'
            ' HTTP/1.1\r\n'
            'Host: %s\r\n'
            'Connection: keep-alive\r\n'
            '\r\n' % host)

from time import sleep
from threading import Thread
from allegra.select_trigger import Select_trigger
        
class Foobar (Thread, Select_trigger):
    def __init__ (self, interval):
        self.interval = interval
        Select_trigger.__init__ (self)
        Thread.__init__ (self)
        self.start ()
        
    def run (self):
        self.select_trigger ((
            self.log, ("start", "debug")
            ))
        sleep (self.interval)
        self.select_trigger ((
            self.log, ("stop", "debug")
            ))
            
from allegra.async_loop import dispatch
[Foobar (x) for x in range (3)]
dispatch ()
def test_watch ():
        Watch ('A').finalization = Watch ('B')
        async_loop.dispatch ()
t_instanciated = time.clock ()
http = http_client.Connections ()
for i in range (C):
        pipeline = http (host, port)
        for j in range (R):
                if method == 'GET':
                        http_client.GET (pipeline, urlpath) (collect)
                elif method == 'POST':
                        http_client.POST (
                                pipeline, urlpath, 
                                producer.Simple (body)
                                ) (collect)
        del pipeline
t_instanciated = time.clock () - t_instanciated
t_completed = time.clock ()
async_loop.dispatch ()
t_completed = time.clock () - t_completed
loginfo.log (
        'Completed in %f seconds, '
        'at the average rate of %f seconds per requests, '
        'or %f requests per seconds. '
        'Note that it took %f seconds to instanciate '
        'the %d client channels and %d requests.' % (
                t_completed, t_completed/(C*R), (C*R)/t_completed, 
                t_instanciated, C, R
                ), 'info'
        )
#
# Note:
#
# Network latency is usually so high that the DNS response will
Example #11
0
def test_watch():
    Watch('A').finalization = Watch('B')
    async_loop.dispatch()
Example #12
0
from allegra.thread_loop import Thread_loop

foobar = Thread_loop()

from time import sleep

from allegra.async_loop import dispatch
from time import sleep

for i in range(4):
    foobar.thread_loop_queue((sleep, (i, )))
foobar.thread_loop_queue(None)
foobar.start()
del foobar
dispatch()

# Thread_loop inheritor


class Foobar(Thread_loop):
    def sleep(self, interval):
        sleep(interval)
        self.select_trigger_log("sleeped %s s" % interval)


foobar = Foobar()
for i in range(4):
    foobar.thread_loop_queue((foobar.sleep, (i, )))
foobar.thread_loop_queue(None)
foobar.start()