diff --git a/src/wormhole/journal.py b/src/wormhole/journal.py index 61d1694..f7bf0f3 100644 --- a/src/wormhole/journal.py +++ b/src/wormhole/journal.py @@ -29,6 +29,8 @@ class Journal(object): @implementer(IJournal) class ImmediateJournal(object): + def __init__(self): + pass def queue_outbound(self, fn, *args, **kwargs): fn(*args, **kwargs) @contextlib.contextmanager diff --git a/src/wormhole/test/test_journal.py b/src/wormhole/test/test_journal.py new file mode 100644 index 0000000..96b9319 --- /dev/null +++ b/src/wormhole/test/test_journal.py @@ -0,0 +1,28 @@ +from __future__ import print_function, absolute_import, unicode_literals +from twisted.trial import unittest +from .. import journal +from .._interfaces import IJournal + +class Journal(unittest.TestCase): + def test_journal(self): + events = [] + j = journal.Journal(lambda: events.append("checkpoint")) + self.assert_(IJournal.providedBy(j)) + + with j.process(): + j.queue_outbound(events.append, "message1") + j.queue_outbound(events.append, "message2") + self.assertEqual(events, []) + self.assertEqual(events, ["checkpoint", "message1", "message2"]) + + def test_immediate(self): + events = [] + j = journal.ImmediateJournal() + self.assert_(IJournal.providedBy(j)) + + with j.process(): + j.queue_outbound(events.append, "message1") + self.assertEqual(events, ["message1"]) + j.queue_outbound(events.append, "message2") + self.assertEqual(events, ["message1", "message2"]) + self.assertEqual(events, ["message1", "message2"])