def test_queue_null(self): """ Test null dirq. """ qtype = "NULL" print("checking %s queue" % qtype) option = {'type': qtype} try: dirq = queue.new(option) except SyntaxError: print(">>>>>>>> Dirq %s not supported in this Python version" % qtype) return False except ImportError: print(">>>>>>>> Dirq %s not installed or not in PYTHONPATH" % qtype) return False msg = self.generator.message() element = dirq.add_message(msg) self.assertEqual(element, "", "add_message should return empty string") try: dirq.get_message(element) raise AssertionError("null queue get_message should " "raise NotImplementedError") except NotImplementedError: pass print("...%s queue ok" % qtype)
def dirq_simple(): """ Example that shows how to use a simple dirq """ print("dirq simple") # creating a couple of messages msg1 = Message(body="hello world".encode("utf-8"), header={"h1": "val1"}) msg2 = Message(body="hello world 2".encode("utf-8"), header={"h2": "val2"}) # creating a simple queue option = {"type": "DQS", "path": "%s/%s" % (PATH, "simple")} dirq = queue.new(option) # adding the two messages element1 = dirq.add_message(msg1) element2 = dirq.add_message(msg2) # getting back the messages and checking they are as expected post_msg2 = None if dirq.lock(element2): post_msg2 = dirq.get_message(element2) assert post_msg2 == msg2 post_msg1 = None if dirq.lock(element1): post_msg1 = dirq.get_message(element1) assert post_msg1 == msg1 print("...dirq simple OK!")
def __test_dq(self, qtype): """ Dirq base test. """ print("checking %s queue" % qtype) option = {"type": qtype, "path": "%s/%s" % (self.path, qtype), } try: dirq = queue.new(option) except SyntaxError: print(">>>>>>>> Dirq %s not supported in this Python version" % qtype) return False except ImportError: print(">>>>>>>> Dirq %s not installed or not in PYTHONPATH" % qtype) return False path = ["test/compliance", ] counter = 0 for folder in path: content = sorted(os.listdir(folder)) for each in content: if not COMPLIANCE_NAME.match(each): continue filer = open("%s/%s" % (folder, each), 'rb') serialized = EMPTY_BYTES.join(filer.readlines()) filer.close() try: msg = message.deserialize(serialized) except MessageError: error = sys.exc_info()[1] if "decoding supported but not installed" in \ "%s" % error: print("skipping compliance test for %s: %s" % (each, error)) else: raise error md5 = re.split('[.-]', each)[0] msg_md5 = msg.md5() self.assertEqual(md5, msg_md5, "deserialization of %s failed:%s\nresult:%s" % (each, msg, msg_md5)) element = dirq.add_message(msg) msg2 = None if dirq.lock(element): msg2 = dirq.get_message(element) dirq.unlock(element) self.assertEqual(msg, msg2, "messages should be equal:\n%s\n###\n%s" % (msg, msg2)) try: msg3 = dirq.dequeue_message(element) self.assertEqual(msg, msg3, "messages should be equal:\n%s\n###\n%s" % (msg, msg3)) except AttributeError: # "dequeue method not supported by this queue type" pass counter += 1 print("...%s queue ok, checked it with %d files" % (qtype, counter))
def start(self): """ Start the outgoing queue module. """ if self._config.get("outgoing-queue-type") is None: self._config["outgoing-queue-type"] = "DQS" self._queue = queue.new(self._config.get("outgoing-queue").copy()) self._path = getattr(self._queue, "path", "") LOGGER.debug("outgoing queue %s %s" % (self._config.get("outgoing-queue-type"), self._path))
def start(self): """ Start the outgoing queue module. """ if self._config.get("outgoing-queue-type") is None: self._config["outgoing-queue-type"] = "DQS" self._queue = queue.new(self._config.get("outgoing-queue").copy()) self._path = getattr(self._queue, "path", "") LOGGER.debug( "outgoing queue %s %s" % (self._config.get("outgoing-queue-type"), self._path))