def test_rndstr(self): """ test generator.rndstr() """ print("checking string creation") for index in range(1000): string = generator.rndstr(index) self.assert_(len(string) == index, "size not expected") print("...string creation ok")
def generate_str(): """ Example which shows how to generate strings of given length. """ print("generating string") length = 1024 string = generator.rndstr(length) assert(len(string) == length) print("...string generation OK!")
def test_full_chain(self): """ Test kombu full chain. """ print("checking kombu full chain") try: import kombu except ImportError: print("kombu is not available, skipping it") return mq1_path = self.path + "/mq1" mq2_path = self.path + "/mq2" mq1 = DQS(path=mq1_path) count = 10 dest = "/queue/test%s" % (rndstr(10), ) bodies = list() for i in range(count): body = "hello world %s" % (i, ) bodies.append(body) msg = Message(body=body) msg.header = {"destination": dest} mq1.add_message(msg) self.assertEqual(count, mq1.count()) cmd1 = "python bin/amqpclt --incoming-queue path=%s" \ " --outgoing-broker-uri %s " \ " --outgoing-broker-module kombu " \ " --outgoing-broker-auth plain,name=guest,pass=guest" \ " --remove --loglevel debug" \ % (mq1_path, self.broker) (ret, out, err) = proc.timed_process(cmd1.split()) self.assertEqual(0, ret, "out: %s\nerr: %s" % (out, err)) cmd2 = "python bin/amqpclt --incoming-broker-uri %s" \ " --incoming-broker-module kombu" \ " --incoming-broker-auth plain,name=guest,pass=guest" \ " --subscribe destination=%s" \ " --outgoing-queue path=%s --count %d --reliable " \ "--loglevel debug" \ % (self.broker, dest, mq2_path, count) (ret, out, err) = proc.timed_process(cmd2.split()) self.assertEqual(0, ret, "out: %s\nerr: %s" % (out, err)) mq2 = DQS(path=mq2_path) for i in mq2: if mq2.lock(i): bodies.remove(mq2.get_message(i).body) self.assertEqual(count, mq2.count()) self.assertEqual(0, len(bodies)) self.assertEqual(0, mq1.count()) print("checking kombu fullchain OK")
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Copyright (C) 2013 CERN """ from messaging.message import Message import messaging.generator as generator import messaging.queue as queue import os import shutil PATH = "%s/%s" % (os.getcwd(), generator.rndstr(10)) def dirq_normal(): """ Example that shows how to use a normal dirq """ print("dirq normal") # 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 normal queue option = {"type": "DQN", "path": "%s/%s" % (PATH, "normal")} dirq = queue.new(option)