Exemplo n.º 1
0
 def _testSchedule(self, scheduler):
     t1 = TestEvent(store=scheduler.store)
     scheduler.schedule(t1, Time.fromPOSIXTimestamp(0))
     self.failIf(self.calls,
                 "Should not have had any calls: %r" % (self.calls,))
     self.assertIdentical(
         scheduler._getNextEvent(Time.fromPOSIXTimestamp(1)).runnable, t1)
Exemplo n.º 2
0
 def _scheduleRunner(self, now, offset):
     scheduledAt = Time.fromPOSIXTimestamp(now + offset)
     rescheduleFor = Time.fromPOSIXTimestamp(now + offset + 10)
     runnable = ScheduleCallingItem(store=self.substore,
                                    rescheduleFor=rescheduleFor)
     self.subscheduler.schedule(runnable, scheduledAt)
     return runnable
Exemplo n.º 3
0
    def testScheduleWithLaterTimedEvents(self):
        """
        Like L{testSchedule}, but use a SubScheduler which has pre-existing
        TimedEvents which are beyond the new runnable's scheduled time (to
        trigger the reschedule-using code-path in
        _SubSchedulerParentHook._schedule).
        """
        now = self.clock.seconds()
        when = Time.fromPOSIXTimestamp(now + 30)
        null = NullRunnable(store=self.substore)
        self.subscheduler.schedule(null, when)
        runnable = self._scheduleRunner(now, 10)

        self.clock.advance(11)

        self.assertEqual(list(self.subscheduler.scheduledTimes(runnable)),
                         [Time.fromPOSIXTimestamp(now + 20)])

        self.assertEqual(list(self.subscheduler.scheduledTimes(null)),
                         [Time.fromPOSIXTimestamp(now + 30)])

        hook = self.store.findUnique(
            _SubSchedulerParentHook,
            _SubSchedulerParentHook.loginAccount == self.substoreItem)

        self.assertEqual(list(self.scheduler.scheduledTimes(hook)),
                         [Time.fromPOSIXTimestamp(20)])
Exemplo n.º 4
0
    def testScheduleWithEarlierTimedEvents(self):
        """
        Like L{testSchedule}, but use a SubScheduler which has pre-existing
        TimedEvents which are before the new runnable's scheduled time.
        """
        now = self.clock.seconds()
        when = Time.fromPOSIXTimestamp(now + 15)
        null = NullRunnable(store=self.substore)
        self.subscheduler.schedule(null, when)
        runnable = self._scheduleRunner(now, 10)

        self.clock.advance(11)

        self.assertEqual(
            list(self.subscheduler.scheduledTimes(runnable)),
            [Time.fromPOSIXTimestamp(now + 20)])

        self.assertEqual(
            list(self.subscheduler.scheduledTimes(null)),
            [Time.fromPOSIXTimestamp(now + 15)])

        hook = self.store.findUnique(
            _SubSchedulerParentHook,
            _SubSchedulerParentHook.subStore == self.substoreItem)

        self.assertEqual(
            list(self.scheduler.scheduledTimes(hook)),
            [Time.fromPOSIXTimestamp(now + 15)])
Exemplo n.º 5
0
    def setUp(self):
        self.clock = Clock()

        self.dbdir = filepath.FilePath(self.mktemp())
        self.store = Store(self.dbdir)
        self.substoreItem = SubStore.createNew(self.store, ['sub'])
        self.substore = self.substoreItem.open()

        self.scheduler = IScheduler(self.store)
        self.subscheduler = IScheduler(self.substore)

        self.scheduler.callLater = self.clock.callLater
        self.scheduler.now = lambda: Time.fromPOSIXTimestamp(self.clock.seconds())
        self.subscheduler.now = lambda: Time.fromPOSIXTimestamp(self.clock.seconds())

        IService(self.store).startService()
Exemplo n.º 6
0
    def _setUpMsg(self):
        """
        Install an innocuous incoming message in a newly-created store

        @rtype: L{xquotient.exmess.Message}
        """
        s = self._setUpStore()

        m = Message.createIncoming(s, _Part(store=s), u'test://test')
        m.subject = u'the subject'
        m.sender = u'sender@host'
        m.senderDisplay = u'Sender'
        m.recipient = u'recipient@host'
        m.sentWhen = Time.fromPOSIXTimestamp(0)
        m.receivedWhen = Time.fromPOSIXTimestamp(1)
        m.classifyClean()
        return m
Exemplo n.º 7
0
    def testSchedule(self):
        """
        Test the schedule method, as invoked from the run method of an item
        being run by the subscheduler.
        """
        now = self.clock.seconds()
        runnable = self._scheduleRunner(now, 10)

        self.clock.advance(11)

        self.assertEqual(list(self.subscheduler.scheduledTimes(runnable)),
                         [Time.fromPOSIXTimestamp(now + 20)])

        hook = self.store.findUnique(
            _SubSchedulerParentHook,
            _SubSchedulerParentHook.loginAccount == self.substoreItem)

        self.assertEqual(list(self.scheduler.scheduledTimes(hook)),
                         [Time.fromPOSIXTimestamp(now + 20)])
Exemplo n.º 8
0
    def test_now(self):
        """
        The user store's L{IScheduler} powerup's C{now} method returns whatever
        the site store's L{IScheduler} powerup's C{now} method returns.
        """
        # I don't want the stubbed now method.
        del self.scheduler.now

        self.clock.advance(17)
        self.assertEquals(self.scheduler.now(),
                          Time.fromPOSIXTimestamp(self.clock.seconds()))
Exemplo n.º 9
0
    def test_now(self):
        """
        The user store's L{IScheduler} powerup's C{now} method returns whatever
        the site store's L{IScheduler} powerup's C{now} method returns.
        """
        # I don't want the stubbed now method.
        del self.scheduler.now

        self.clock.advance(17)
        self.assertEquals(
            self.scheduler.now(),
            Time.fromPOSIXTimestamp(self.clock.seconds()))
Exemplo n.º 10
0
    def testSchedule(self):
        """
        Test the schedule method, as invoked from the run method of an item
        being run by the subscheduler.
        """
        now = self.clock.seconds()
        runnable = self._scheduleRunner(now, 10)

        self.clock.advance(11)

        self.assertEqual(
            list(self.subscheduler.scheduledTimes(runnable)),
            [Time.fromPOSIXTimestamp(now + 20)])

        hook = self.store.findUnique(
            _SubSchedulerParentHook,
            _SubSchedulerParentHook.subStore == self.substoreItem)

        self.assertEqual(
            list(self.scheduler.scheduledTimes(hook)),
            [Time.fromPOSIXTimestamp(now + 20)])
Exemplo n.º 11
0
 def test_blurbTimestampColumn(self):
     """
     Verify the L{xmantissa.ixmantissa.IColumn} implementation of
     L{hyperbola_view._BlurbTimestampColumn}.
     """
     col = hyperbola_view._BlurbTimestampColumn()
     self.assertEqual(col.attributeID, 'dateCreated')
     self.assertEqual(col.getType(), 'timestamp')
     self.blogPostItem.dateCreated = Time.fromPOSIXTimestamp(345)
     value = col.extractValue(None, self.blogPostItem)
     self.assertEqual(value, 345)
     self.assertIdentical(col.sortAttribute(), hyperblurb.Blurb.dateCreated)
     comparable = col.toComparableValue(345)
     self.assertEqual(comparable, self.blogPostItem.dateCreated)
Exemplo n.º 12
0
    def testMultipleEventsPerTick(self):
        """
        Test running several runnables in a single tick of the subscheduler.
        """
        now = self.clock.seconds()
        runnables = [
            self._scheduleRunner(now, 10),
            self._scheduleRunner(now, 11),
            self._scheduleRunner(now, 12)
        ]

        self.clock.advance(13)

        for n, runnable in enumerate(runnables):
            self.assertEqual(list(self.subscheduler.scheduledTimes(runnable)),
                             [Time.fromPOSIXTimestamp(now + n + 20)])

        hook = self.store.findUnique(
            _SubSchedulerParentHook,
            _SubSchedulerParentHook.loginAccount == self.substoreItem)

        self.assertEqual(list(self.scheduler.scheduledTimes(hook)),
                         [Time.fromPOSIXTimestamp(now + 20)])
Exemplo n.º 13
0
 def setMetadata(self, meta):
     """
     Set the topic in the database
     """
     self.channelItem.topic = unicode(meta['topic'])
     self.channelItem.topicAuthor = unicode(meta['topic_author'])
     self.channelItem.topicTime = Time.fromPOSIXTimestamp(meta['topic_date'])
     sets = []
     for p in self.users.itervalues():
         d = defer.maybeDeferred(p.groupMetaUpdate, self, meta)
         d.addErrback(self._ebUserCall, p=p)
         sets.append(d)
     defer.DeferredList(sets).addCallback(self._cbUserCall)
     return defer.succeed(None)
Exemplo n.º 14
0
 def setMetadata(self, meta):
     """
     Set the topic in the database
     """
     self.channelItem.topic = unicode(meta['topic'])
     self.channelItem.topicAuthor = unicode(meta['topic_author'])
     self.channelItem.topicTime = Time.fromPOSIXTimestamp(
         meta['topic_date'])
     sets = []
     for p in self.users.itervalues():
         d = defer.maybeDeferred(p.groupMetaUpdate, self, meta)
         d.addErrback(self._ebUserCall, p=p)
         sets.append(d)
     defer.DeferredList(sets).addCallback(self._cbUserCall)
     return defer.succeed(None)
Exemplo n.º 15
0
    def testMultipleEventsPerTick(self):
        """
        Test running several runnables in a single tick of the subscheduler.
        """
        now = self.clock.seconds()
        runnables = [
            self._scheduleRunner(now, 10),
            self._scheduleRunner(now, 11),
            self._scheduleRunner(now, 12)]

        self.clock.advance(13)

        for n, runnable in enumerate(runnables):
            self.assertEqual(
                list(self.subscheduler.scheduledTimes(runnable)),
                [Time.fromPOSIXTimestamp(now + n + 20)])

        hook = self.store.findUnique(
            _SubSchedulerParentHook,
            _SubSchedulerParentHook.subStore == self.substoreItem)

        self.assertEqual(
            list(self.scheduler.scheduledTimes(hook)),
            [Time.fromPOSIXTimestamp(now + 20)])
Exemplo n.º 16
0
    def _makeMessages(self):
        """
        Make 3 incoming messages

        @rtype: C{list} of L{xquotient.exmess.Message}
        """
        msgs = []
        for (subject, timestamp) in ((u'3', 67), (u'1', 43), (u'2', 55)):
            msgs.append(
                testMessageFactory(
                    store=self.store,
                    read=False,
                    spam=False,
                    subject=subject,
                    receivedWhen=Time.fromPOSIXTimestamp(timestamp)))
        return msgs
Exemplo n.º 17
0
    def _makeMessages(self):
        """
        Make 3 incoming messages

        @rtype: C{list} of L{xquotient.exmess.Message}
        """
        msgs = []
        for (subject, timestamp) in ((u'3', 67), (u'1', 43), (u'2', 55)):
            msgs.append(
                testMessageFactory(
                    store=self.store,
                    read=False,
                    spam=False,
                    subject=subject,
                    receivedWhen=Time.fromPOSIXTimestamp(timestamp)))
        return msgs
Exemplo n.º 18
0
 def now(self):
     return Time.fromPOSIXTimestamp(self.clock.seconds())
Exemplo n.º 19
0
 def fxn():
     for x in xrange(itemCount):
         yield (x * 2, u"Number %d" % (x, ),
                Time.fromPOSIXTimestamp(now - x), colors[x % 2])
Exemplo n.º 20
0
 def readTimestamp(self):
     return Time.fromPOSIXTimestamp(float(self.readline()))
Exemplo n.º 21
0
 def outfilter(self, dbval, oself):
     if dbval is None:
         return None
     return Time.fromPOSIXTimestamp(dbval / MICRO)
Exemplo n.º 22
0
 def toComparableValue(self, value):
     """
     Convert a float from the client back into a timestamp.
     """
     return Time.fromPOSIXTimestamp(value)
Exemplo n.º 23
0
 def registerAddress(self, physicalURL, expiryTime):
     self.physicalURL = physicalURL.toString()
     self.expiryTime = Time.fromPOSIXTimestamp(time.time() + expiryTime)
     return [(physicalURL, self.expiryTime)]
Exemplo n.º 24
0
 def _scheduleRunner(self, now, offset):
     scheduledAt = Time.fromPOSIXTimestamp(now + offset)
     rescheduleFor = Time.fromPOSIXTimestamp(now + offset + 10)
     runnable = ScheduleCallingItem(store=self.substore, rescheduleFor=rescheduleFor)
     self.subscheduler.schedule(runnable, scheduledAt)
     return runnable
Exemplo n.º 25
0
 def fxn():
     for x in xrange(itemCount):
         yield (x * 2,
                u"Number %d" % (x,),
                Time.fromPOSIXTimestamp(now - x),
                colors[x % 2])
Exemplo n.º 26
0
"""
Generate a stub for the tests for the upgrade from schema version 2 to 3 of the
Person item.
"""

from epsilon.extime import Time

from axiom.test.historic.stubloader import saveStub

from xmantissa.people import Organizer, Person

NAME = u'Test User'
CREATED = Time.fromPOSIXTimestamp(1234567890)

def createDatabase(store):
    """
    Make a L{Person} in the given store.
    """
    organizer = Organizer(store=store)
    person = Person(
        store=store,
        organizer=organizer,
        name=NAME)
    person.created = CREATED


if __name__ == '__main__':
    saveStub(createDatabase, 13344)
Exemplo n.º 27
0
from epsilon.extime import Time

from xquotient.exmess import Message
from xquotient.mimestorage import Part

attrs = dict(
    sender=u"*****@*****.**",
    subject=u"This is a spam",
    recipient=u"*****@*****.**",
    senderDisplay=u"Spammer",
    spam=True,
    archived=False,
    trash=True,
    outgoing=False,
    draft=False,
    trained=True,
    read=True,
    attachments=23,
    sentWhen=Time.fromPOSIXTimestamp(123),
    receivedWhen=Time.fromPOSIXTimestamp(456),
)


def createDatabase(s):
    Message(store=s, impl=Part(store=s), **attrs)


if __name__ == "__main__":
    saveStub(createDatabase, 7105)
Exemplo n.º 28
0
 def invoke(self, data):
     value = data[self.param.name]
     if value is not None:
         value = Time.fromPOSIXTimestamp(value / 1000)
     self.param.value = value
Exemplo n.º 29
0
def main(cursor):
    # All the ticket data in the database
    tickets = tracstats.tickets(cursor)

    # For the purposes of means, anything that is open gets a "close" time of
    # right now.
    now = Time().asNaiveDatetime()

    # A mapping from ticket id to a two-tuple of open, closed times.  If a
    # ticket is closed multiple times, the closed time associated with it is
    # the final close time.  If the ticket is open, the closed time is None.
    ticketInfos = {}
    for id, tkt in tickets.iteritems():
        ticketInfos[id] = (tkt['time'], now)

    # Find all the latest close times for all the tickets
    for change in tracstats.changes(
            cursor,
            Time.fromPOSIXTimestamp(0).asNaiveDatetime(), now):
        id = change['ticket']
        open, close = ticketInfos[id]
        if isOpeningChange(change):
            ticketInfos[id] = (open, now)
        elif isClosingChange(change):
            ticketInfos[id] = (open, change['time'])

    # Create an ordering of ticket open and close times
    events = []
    for ticketId, (open, close) in ticketInfos.iteritems():
        if close is None:
            print 'Skipping', ticketId
            continue
        events.append((open, ticketId, 'open'))
        events.append((close, ticketId, 'close'))
    events.sort()

    # A mapping of tickets which are open at the point in the events which to
    # which processing has advanced.  Keys are ticket ids, values are times
    # when they opened.
    openTickets = {}

    # Data points for the output graph.  First element of each two-tuple is a
    # time, second element is mean ticket age at that time.
    output = []

    for (when, ticket, change) in events:
        if openTickets:
            output.append(
                (when,
                 sum([when - v
                      for v in openTickets.itervalues()], timedelta(0)) /
                 len(openTickets)))
        if change == 'open':
            # A new ticket is now open.
            openTickets[ticket] = when
        elif change == 'closed':
            # An old open ticket is now closed.
            del openTickets[ticket]

    def toInt(delta):
        return delta.days * (60 * 60 * 24) + delta.seconds

    return tracstats.TimeSeries("mean ticket age",
                                [(when, toInt(mean))
                                 for (when, mean) in output])
Exemplo n.º 30
0
from md5 import md5

from twisted.application import service
from twisted.python import log
from twisted.internet import defer

from axiom import store, substore, item, attributes as A

from zope.interface import Interface, implements

from epsilon.extime import Time

from webby import obscurement
from webby.iwebby import IFileObserver

EPOCH = Time.fromPOSIXTimestamp(0)


class DataService(item.Item, service.Service):
    powerupInterfaces = (service.IService, )
    schemaVersion = 1
    smtpFrom = A.text(doc="The email address used as From: in emails")
    smtpServer = A.text(doc="The SMTP server used for outgoing email")

    parent = A.inmemory()
    running = A.inmemory()

    def startService(self):
        log.msg("Starting service %r" % (self, ))

Exemplo n.º 31
0
 def toComparableValue(self, value):
     """
     Override L{AttributeColumn}'s implementation to return a L{Time} instance.
     """
     return Time.fromPOSIXTimestamp(value)
Exemplo n.º 32
0
from md5 import md5

from twisted.application import service
from twisted.python import log
from twisted.internet import defer

from axiom import store, substore, item, attributes as A

from zope.interface import Interface, implements

from epsilon.extime import Time

from webby import obscurement
from webby.iwebby import IFileObserver

EPOCH = Time.fromPOSIXTimestamp(0)

class DataService(item.Item, service.Service):
    powerupInterfaces = (service.IService,)
    schemaVersion = 1
    smtpFrom = A.text(doc="The email address used as From: in emails")
    smtpServer = A.text(doc="The SMTP server used for outgoing email")

    parent = A.inmemory()
    running = A.inmemory()

    def startService(self):
        log.msg("Starting service %r" % (self, ))

class IArticle(Interface):
    """
Exemplo n.º 33
0
 def registerAddress(self, physicalURL, expiryTime):
     self.physicalURL = physicalURL.toString()
     self.expiryTime = Time.fromPOSIXTimestamp(time.time() + expiryTime)
     return [(physicalURL, self.expiryTime)]
Exemplo n.º 34
0
"""
Generate a stub for the tests for the upgrade from schema version 2 to 3 of the
Person item.
"""

from epsilon.extime import Time

from axiom.test.historic.stubloader import saveStub

from xmantissa.people import Organizer, Person

NAME = u"Test User"
CREATED = Time.fromPOSIXTimestamp(1234567890)


def createDatabase(store):
    """
    Make a L{Person} in the given store.
    """
    organizer = Organizer(store=store)
    person = Person(store=store, organizer=organizer, name=NAME)
    person.created = CREATED


if __name__ == "__main__":
    saveStub(createDatabase, 13344)
Exemplo n.º 35
0
from axiom.test.historic.stubloader import saveStub

from epsilon.extime import Time

from xquotient.exmess import Message
from xquotient.mimestorage import Part

attrs = dict(sender=u'*****@*****.**',
             subject=u'This is a spam',
             recipient=u'*****@*****.**',
             senderDisplay=u'Spammer',
             spam=True,
             archived=False,
             trash=True,
             outgoing=False,
             draft=False,
             trained=True,
             read=True,
             attachments=23,
             sentWhen=Time.fromPOSIXTimestamp(123),
             receivedWhen=Time.fromPOSIXTimestamp(456))

def createDatabase(s):
    Message(store=s,
            impl=Part(store=s),
            **attrs)

if __name__ == '__main__':
    saveStub(createDatabase, 7105)
Exemplo n.º 36
0
 def readTimestamp(self):
     return Time.fromPOSIXTimestamp(float(self.readline()))
Exemplo n.º 37
0
 def invoke(self, data):
     value = data[self.param.name]
     if value is not None:
         value = Time.fromPOSIXTimestamp(value / 1000)
     self.param.value = value
Exemplo n.º 38
0
 def outfilter(self, dbval, oself):
     if dbval is None:
         return None
     return Time.fromPOSIXTimestamp(dbval / MICRO)
Exemplo n.º 39
0
 def toComparableValue(self, value):
     """
     Override L{AttributeColumn}'s implementation to return a L{Time} instance.
     """
     return Time.fromPOSIXTimestamp(value)