@inlineCallbacks
    def test_get(self):
        channel = self.channel
        yield channel.queue_declare(queue="test-get", exclusive=True)

        #publish some messages (no_ack=True) with persistent messaging
        for i in range(1, 11):
            msg=Content("Message %d" % i)
            msg["delivery mode"] = 2
            channel.basic_publish(routing_key="test-get",content=msg )

        #use basic_get to read back the messages, and check that we get an empty at the end
        for i in range(1, 11):
            reply = yield channel.basic_get(no_ack=True)
            self.assertEqual(reply.method.klass.name, "basic")
            self.assertEqual(reply.method.name, "get-ok")
            self.assertEqual("Message %d" % i, reply.content.body)

        reply = yield channel.basic_get(no_ack=True)
        self.assertEqual(reply.method.klass.name, "basic")
        self.assertEqual(reply.method.name, "get-empty")


        #publish some messages (no_ack=True) transient messaging
        for i in range(11, 21):
            channel.basic_publish(routing_key="test-get", content=Content("Message %d" % i))

        #use basic_get to read back the messages, and check that we get an empty at the end
        for i in range(11, 21):
            reply = yield channel.basic_get(no_ack=True)
            self.assertEqual(reply.method.klass.name, "basic")
            self.assertEqual(reply.method.name, "get-ok")
            self.assertEqual("Message %d" % i, reply.content.body)

        reply = yield channel.basic_get(no_ack=True)
        self.assertEqual(reply.method.klass.name, "basic")
        self.assertEqual(reply.method.name, "get-empty")

        #repeat for no_ack=False

        #publish some messages (no_ack=False) with persistent messaging
        for i in range(21, 31):
            msg=Content("Message %d" % i)
            msg["delivery mode"] = 2
            channel.basic_publish(routing_key="test-get",content=msg )

        #use basic_get to read back the messages, and check that we get an empty at the end
        for i in range(21, 31):
            reply = yield channel.basic_get(no_ack=False)
            self.assertEqual(reply.method.klass.name, "basic")
            self.assertEqual(reply.method.name, "get-ok")
            self.assertEqual("Message %d" % i, reply.content.body)

        reply = yield channel.basic_get(no_ack=True)
        self.assertEqual(reply.method.klass.name, "basic")
        self.assertEqual(reply.method.name, "get-empty")

        #public some messages (no_ack=False) with transient messaging
        for i in range(31, 41):
            channel.basic_publish(routing_key="test-get", content=Content("Message %d" % i))

        for i in range(31, 41):
            reply = yield channel.basic_get(no_ack=False)
            self.assertEqual(reply.method.klass.name, "basic")
            self.assertEqual(reply.method.name, "get-ok")
            self.assertEqual("Message %d" % i, reply.content.body)
            if(i == 33):
                channel.basic_ack(delivery_tag=reply.delivery_tag, multiple=True)
            if(i in [35, 37, 39]):
                channel.basic_ack(delivery_tag=reply.delivery_tag)

        reply = yield channel.basic_get(no_ack=True)
        self.assertEqual(reply.method.klass.name, "basic")
        self.assertEqual(reply.method.name, "get-empty")

        #recover(requeue=True)
        yield channel.basic_recover(requeue=True)

        #get the unacked messages again (34, 36, 38, 40)
        for i in [34, 36, 38, 40]:
            reply = yield channel.basic_get(no_ack=False)
            self.assertEqual(reply.method.klass.name, "basic")
            self.assertEqual(reply.method.name, "get-ok")
            self.assertEqual("Message %d" % i, reply.content.body)
            channel.basic_ack(delivery_tag=reply.delivery_tag)

        reply = yield channel.basic_get(no_ack=True)
        self.assertEqual(reply.method.klass.name, "basic")
        self.assertEqual(reply.method.name, "get-empty")

        yield channel.basic_recover(requeue=True)

        reply = yield channel.basic_get(no_ack=True)
        self.assertEqual(reply.method.klass.name, "basic")
        self.assertEqual(reply.method.name, "get-empty")
Test basic_get method
dataset/ETHPy150Open tweetdeck/txAMQP/src/txamqp/test/test_basic.py/BasicTests.test_get