def test_Message_chunkDeChunk_remainsintact(self): from Kamaelia.Chassis.Pipeline import Pipeline syncmessage = "XXXXXXXXXXXXXXXXXXXXXXX" File = open("../../Examples/SimpleGraphicalApps/Ticker/Ulysses").read() chunks = [File[y:y + 20] for y in xrange(0, len(File), 20)] chunker = Framing.DataChunker(syncmessage=syncmessage) dechunker = Framing.DataDeChunker(syncmessage=syncmessage) system = Pipeline( chunker, dechunker, ).activate() Dummy = Axon.Component.component() system.link((system, "outbox"), (Dummy, "inbox")) system.link((system, "signal"), (Dummy, "control")) for chunk in chunks: system._deliver(chunk, "inbox") activeScheduler = system.schedulerClass.run.main() for _ in xrange(2000): activeScheduler.next() resultchunks = [] try: while 1: # chunk = system._collect("outbox") chunk = Dummy.recv("inbox") resultchunks.append(chunk) except IndexError: pass # We collect all items in the outbox result = "".join(resultchunks) self.assertEqual(File[:20], result[:20])
def test_makeChunk_oneSync(self): syncmessage = "XXXXXXXXXXXXXXXXXXXXXXX" message = "1234567890qwertyuiopasdfghjklzxcvbnm\n" * 10 message += syncmessage message += "1234567890qwertyuiopasdfghjklzxcvbnm\n" * 10 X = Framing.DataChunker(syncmessage=syncmessage) Dummy = Axon.Component.component() X.link((X, "outbox"), (Dummy, "inbox")) X.link((X, "signal"), (Dummy, "control")) X.activate() X._deliver(message, "inbox") for i in xrange( 20): # More than sufficient cycles (should be lots less!) X.next() # result = X._collect("outbox") result = Dummy.recv("inbox") result_message = result[len(syncmessage):] index = result_message.find(syncmessage) self.assertEqual( -1, index, "Should not be able to find the syncmessage in the chunked version" )
def makeBasicChunk(self, message, syncmessage): X = Framing.DataChunker(syncmessage=syncmessage) Dummy = Axon.Component.component() X.link((X, "outbox"), (Dummy, "inbox")) X.link((X, "signal"), (Dummy, "control")) X.activate() X._deliver(message, "inbox") for i in xrange( 20): # More than sufficient cycles (should be lots less!) X.next() # result = X._collect("outbox") result = Dummy.recv("inbox") return result
def test_makeChunk(self): message = "1234567890qwertyuiopasdfghjklzxcvbnm\n" * 20 syncmessage = "XXXXXXXXXXXXXXXXXXXXXXX" X = Framing.DataChunker(syncmessage=syncmessage) Dummy = Axon.Component.component() X.link((X, "outbox"), (Dummy, "inbox")) X.link((X, "signal"), (Dummy, "control")) X.activate() X._deliver(message, "inbox") for i in xrange( 20): # More than sufficient cycles (should be lots less!) X.next() # result = X._collect("outbox") result = Dummy.recv("inbox") result_start = result[:len(syncmessage)] result_message = result[len(syncmessage):] self.assertEqual(message, result_message) self.assertEqual(syncmessage, result_start)
def test_smokeTest(self): X = Framing.DataChunker() X.activate()