Exemplo n.º 1
0
    def test_get_queue_stats_claimed(self, claimed):
        """Get stats on a queue."""
        result = self.client.put(self.queue_url)
        self.addCleanup(self.client.delete, self.queue_url)
        self.assertEqual(result.status_code, 201)

        # Post Messages to the test queue
        doc = helpers.create_message_body(messagecount=self.limits.max_messages_per_claim)

        message_url = self.queue_url + "/messages"
        result = self.client.post(message_url, data=doc)
        self.assertEqual(result.status_code, 201)

        if claimed > 0:
            claim_url = self.queue_url + "/claims?limit=" + str(claimed)
            doc = {"ttl": 300, "grace": 300}
            result = self.client.post(claim_url, data=doc)
            self.assertEqual(result.status_code, 201)

        # Get stats on the queue.
        stats_url = self.queue_url + "/stats"
        result = self.client.get(stats_url)
        self.assertEqual(result.status_code, 200)

        self.assertQueueStats(result.json(), claimed)
Exemplo n.º 2
0
    def test_message_bulk_insert(self):
        """Bulk Insert Messages into the Queue."""
        message_count = self.limits.message_paging_uplimit
        doc = helpers.create_message_body(messagecount=message_count)

        result = self.client.post(data=doc)
        self.assertEqual(result.status_code, 201)

        # GET on posted messages
        location = result.headers['location']
        url = self.cfg.marconi.url + location
        result = self.client.get(url)
        self.assertEqual(result.status_code, 200)

        # Verify that the response json schema matches the expected schema
        expected_schema = self.response.get_schema('message_get_many')
        self.assertSchema(result.json(), expected_schema)

        # Compare message metadata
        result_body = [result.json()[i]['body']
                       for i in range(len(result.json()))]
        result_body.sort()

        posted_metadata = [doc[i]['body']
                           for i in range(message_count)]
        posted_metadata.sort()

        self.assertEqual(result_body, posted_metadata)
Exemplo n.º 3
0
    def test_message_bulk_insert(self):
        """Bulk Insert Messages into the Queue."""
        message_count = self.limits.max_messages_per_page
        doc = helpers.create_message_body(messagecount=message_count)

        result = self.client.post(data=doc)
        self.assertEqual(result.status_code, 201)

        # GET on posted messages
        location = result.headers['location']
        url = self.cfg.marconi.url + location
        result = self.client.get(url)
        self.assertEqual(result.status_code, 200)

        self.skipTest('Bug #1273335 - Get set of messages returns wrong hrefs '
                      '(happens randomly)')

        # Verify that the response json schema matches the expected schema
        self.assertSchema(result.json(), 'message_get_many')

        # Compare message metadata
        result_body = [result.json()[i]['body']
                       for i in range(len(result.json()))]
        result_body.sort()

        posted_metadata = [doc[i]['body']
                           for i in range(message_count)]
        posted_metadata.sort()

        self.assertEqual(result_body, posted_metadata)
Exemplo n.º 4
0
    def test_get_queue_stats_claimed(self, claimed):
        """Get stats on a queue."""
        result = self.client.put(self.queue_url)
        self.addCleanup(self.client.delete, self.queue_url)
        self.assertEqual(result.status_code, 201)

        # Post Messages to the test queue
        doc = helpers.create_message_body(
            messagecount=self.limits.max_messages_per_claim)

        message_url = self.queue_url + '/messages'
        result = self.client.post(message_url, data=doc)
        self.assertEqual(result.status_code, 201)

        if claimed > 0:
            claim_url = self.queue_url + '/claims?limit=' + str(claimed)
            doc = {'ttl': 300, 'grace': 300}
            result = self.client.post(claim_url, data=doc)
            self.assertEqual(result.status_code, 201)

        # Get stats on the queue.
        stats_url = self.queue_url + '/stats'
        result = self.client.get(stats_url)
        self.assertEqual(result.status_code, 200)

        self.assertQueueStats(result.json(), claimed)
Exemplo n.º 5
0
    def test_get_message(self, params):
        """Get Messages."""

        expected_msg_count = params.get('limit', 10)

        # Test Setup
        doc = helpers.create_message_body(
            messagecount=self.limits.max_messages_per_page)
        result = self.client.post(data=doc)
        self.assertEqual(result.status_code, 201)

        url = ''
        params['echo'] = True

        # Follow the hrefs & perform GET, till the end of messages i.e. http
        # 204
        while result.status_code in [201, 200]:
            result = self.client.get(url, params=params)
            self.assertIn(result.status_code, [200, 204])

            if result.status_code == 200:
                actual_msg_count = len(result.json()['messages'])
                self.assertMessageCount(actual_msg_count, expected_msg_count)

                href = result.json()['links'][0]['href']
                url = self.cfg.marconi.url + href

        self.assertEqual(result.status_code, 204)
Exemplo n.º 6
0
    def test_get_message(self, params):
        """Get Messages."""

        # Note(abettadapur): This will now return 200s and [].
        # Needs to be addressed when feature patch goes in
        self.skipTest("Not supported")
        expected_msg_count = params.get('limit',
                                        self.limits.max_messages_per_page)

        # Test Setup
        doc = helpers.create_message_body(
            messagecount=self.limits.max_messages_per_page)

        result = self.client.post(data=doc)
        self.assertEqual(result.status_code, 201)

        url = ''
        params['echo'] = True

        # Follow the hrefs & perform GET, till the end of messages i.e. http
        # 204
        while result.status_code in [201, 200]:
            result = self.client.get(url, params=params)
            self.assertIn(result.status_code, [200, 204])

            if result.status_code == 200:
                actual_msg_count = len(result.json()['messages'])
                self.assertMessageCount(actual_msg_count, expected_msg_count)

                href = result.json()['links'][0]['href']
                url = self.cfg.marconi.url + href

        self.assertEqual(result.status_code, 204)
Exemplo n.º 7
0
    def test_get_message(self, params):
        """Get Messages."""

        expected_msg_count = params.get('limit', 10)

        # Test Setup
        doc = helpers.create_message_body(messagecount=
                                          self.limits.message_paging_uplimit)
        result = self.client.post(data=doc)
        self.assertEqual(result.status_code, 201)

        url = ''
        params['echo'] = True

        #Follow the hrefs & perform GET, till the end of messages i.e. http 204
        while result.status_code in [201, 200]:
            result = self.client.get(url, params=params)
            self.assertIn(result.status_code, [200, 204])

            if result.status_code == 200:
                actual_msg_count = len(result.json()['messages'])
                self.assertMessageCount(actual_msg_count, expected_msg_count)

                href = result.json()['links'][0]['href']
                url = self.cfg.marconi.url + href

        self.assertEqual(result.status_code, 204)
Exemplo n.º 8
0
    def test_get_message(self, params):
        """Get Messages."""

        # Note(abettadapur): This will now return 200s and [].
        # Needs to be addressed when feature patch goes in
        self.skipTest("Not supported")
        expected_msg_count = params.get('limit',
                                        self.limits.max_messages_per_page)

        # Test Setup
        doc = helpers.create_message_body(
            messagecount=self.limits.max_messages_per_page)

        result = self.client.post(data=doc)
        self.assertEqual(result.status_code, 201)

        url = ''
        params['echo'] = True

        # Follow the hrefs & perform GET, till the end of messages i.e. http
        # 204
        while result.status_code in [201, 200]:
            result = self.client.get(url, params=params)
            self.assertIn(result.status_code, [200, 204])

            if result.status_code == 200:
                actual_msg_count = len(result.json()['messages'])
                self.assertMessageCount(actual_msg_count, expected_msg_count)

                href = result.json()['links'][0]['href']
                url = self.cfg.marconi.url + href

        self.assertEqual(result.status_code, 204)
Exemplo n.º 9
0
    def test_message_bulk_insert(self):
        """Bulk Insert Messages into the Queue."""
        message_count = self.limits.max_messages_per_page
        doc = helpers.create_message_body(messagecount=message_count)

        result = self.client.post(data=doc)
        self.assertEqual(result.status_code, 201)

        # GET on posted messages
        location = result.headers['location']
        url = self.cfg.marconi.url + location
        result = self.client.get(url)
        self.assertEqual(result.status_code, 200)

        self.skipTest('Bug #1273335 - Get set of messages returns wrong hrefs '
                      '(happens randomly)')

        # Verify that the response json schema matches the expected schema
        self.assertSchema(result.json(), 'message_get_many')

        # Compare message metadata
        result_body = [
            result.json()[i]['body'] for i in range(len(result.json()))
        ]
        result_body.sort()

        posted_metadata = [doc[i]['body'] for i in range(message_count)]
        posted_metadata.sort()

        self.assertEqual(result_body, posted_metadata)
Exemplo n.º 10
0
    def test_get_message(self, params):
        """Get Messages."""

        expected_msg_count = params.get("limit", 10)

        # Test Setup
        doc = helpers.create_message_body(messagecount=self.limits.max_messages_per_page)

        result = self.client.post(data=doc)
        self.assertEqual(result.status_code, 201)

        url = ""
        params["echo"] = True

        # Follow the hrefs & perform GET, till the end of messages i.e. http
        # 204
        while result.status_code in [201, 200]:
            result = self.client.get(url, params=params)
            self.assertIn(result.status_code, [200, 204])

            if result.status_code == 200:
                actual_msg_count = len(result.json()["messages"])
                self.assertMessageCount(actual_msg_count, expected_msg_count)

                self.assertSchema(result.json(), "message_list")

                href = result.json()["links"][0]["href"]
                url = self.cfg.marconi.url + href

        self.assertEqual(result.status_code, 204)
Exemplo n.º 11
0
    def test_message_bulk_insert_60(self):
        """Insert more than max allowed messages.

        Marconi allows  a maximum of 50 message per POST.
        """
        doc = helpers.create_message_body(messagecount=60)

        result = self.client.post(data=doc)
        self.assertEqual(result.status_code, 400)
Exemplo n.º 12
0
    def test_message_bad_header_single_insert(self):
        """Insert Single Message into the Queue.

        This should fail because of the lack of a Client-ID header
        """

        self.skipTest("Not supported")
        del self.client.headers["Client-ID"]
        doc = helpers.create_message_body(messagecount=1)

        result = self.client.post(data=doc)
        self.assertEqual(result.status_code, 400)
Exemplo n.º 13
0
    def test_message_bad_header_single_insert(self):
        """Insert Single Message into the Queue.

        This should fail because of the lack of a Client-ID header
        """

        self.skipTest("Not supported")
        del self.client.headers["Client-ID"]
        doc = helpers.create_message_body(messagecount=1)

        result = self.client.post(data=doc)
        self.assertEqual(result.status_code, 400)
Exemplo n.º 14
0
    def test_message_partial_get(self):
        """Get Messages will be partially successful."""
        doc = helpers.create_message_body(messagecount=3)
        result = self.client.post(data=doc)

        self.assertEqual(result.status_code, 201)

        # Get posted message and a nonexisting message
        location = result.headers['Location']
        url = self.cfg.marconi.url + location
        url += ',nonexisting'
        result = self.client.get(url)
        self.assertEqual(result.status_code, 200)
Exemplo n.º 15
0
    def test_message_partial_get(self):
        """Get Messages will be partially successful."""
        doc = helpers.create_message_body(messagecount=3)
        result = self.client.post(data=doc)

        self.assertEqual(result.status_code, 201)

        # Get posted message and a nonexisting message
        location = result.headers['Location']
        url = self.cfg.marconi.url + location
        url += ',nonexisting'
        result = self.client.get(url)
        self.assertEqual(result.status_code, 200)
Exemplo n.º 16
0
    def test_message_partial_delete(self):
        """Delete Messages will be partially successful."""
        doc = helpers.create_message_body(messagecount=3)
        result = self.client.post(data=doc)

        self.assertEqual(result.status_code, 201)

        # Delete posted message
        location = result.headers["Location"]
        url = self.cfg.marconi.url + location
        url += ",nonexisting"
        result = self.client.delete(url)
        self.assertEqual(result.status_code, 204)
Exemplo n.º 17
0
    def test_message_bulk_delete(self):
        """Bulk Delete Messages."""
        doc = helpers.create_message_body(messagecount=10)
        result = self.client.post(data=doc)

        self.assertEqual(result.status_code, 201)

        # Delete posted messages
        location = result.headers['Location']
        url = self.cfg.marconi.url + location

        result = self.client.delete(url)
        self.assertEqual(result.status_code, 204)

        result = self.client.get(url)
        self.assertEqual(result.status_code, 204)
Exemplo n.º 18
0
    def test_message_bulk_delete(self):
        """Bulk Delete Messages."""
        doc = helpers.create_message_body(messagecount=10)
        result = self.client.post(data=doc)

        self.assertEqual(result.status_code, 201)

        # Delete posted messages
        location = result.headers['Location']
        url = self.cfg.marconi.url + location

        result = self.client.delete(url)
        self.assertEqual(result.status_code, 204)

        result = self.client.get(url)
        self.assertEqual(result.status_code, 404)
Exemplo n.º 19
0
    def test_message_delete(self):
        """Delete Message."""
        # Test Setup
        doc = helpers.create_message_body(messagecount=1)
        result = self.client.post(data=doc)
        self.assertEqual(result.status_code, 201)

        # Delete posted message
        href = result.json()['resources'][0]
        url = self.cfg.marconi.url + href

        result = self.client.delete(url)
        self.assertEqual(result.status_code, 204)

        result = self.client.get(url)
        self.assertEqual(result.status_code, 404)
Exemplo n.º 20
0
    def test_message_delete(self):
        """Delete Message."""
        # Test Setup
        doc = helpers.create_message_body(messagecount=1)
        result = self.client.post(data=doc)
        self.assertEqual(result.status_code, 201)

        # Delete posted message
        href = result.json()['resources'][0]
        url = self.cfg.marconi.url + href

        result = self.client.delete(url)
        self.assertEqual(result.status_code, 204)

        result = self.client.get(url)
        self.assertEqual(result.status_code, 404)
Exemplo n.º 21
0
    def test_message_single_insert(self):
        """Insert Single Message into the Queue.

        This test also verifies that claimed messages are
        retuned (or not) depending on the include_claimed flag.
        """
        doc = helpers.create_message_body(messagecount=1)

        result = self.client.post(data=doc)
        self.assertEqual(result.status_code, 201)

        response_headers = set(result.headers.keys())
        self.assertIsSubset(self.headers_response_with_body, response_headers)

        # GET on posted message
        href = result.json()['resources'][0]
        url = self.cfg.marconi.url + href

        result = self.client.get(url)
        self.assertEqual(result.status_code, 200)

        # Compare message metadata
        result_body = result.json()['body']
        posted_metadata = doc[0]['body']
        self.assertEqual(result_body, posted_metadata)

        # Post a claim & verify the include_claimed flag.
        url = self.queue_url + '/claims'
        doc = {"ttl": 300, "grace": 100}
        result = self.client.post(url, data=doc)
        self.assertEqual(result.status_code, 201)

        params = {'include_claimed': True,
                  'echo': True}
        result = self.client.get(params=params)
        self.assertEqual(result.status_code, 200)

        response_message_body = result.json()["messages"][0]["body"]
        self.assertEqual(response_message_body, posted_metadata)

        # By default, include_claimed = false
        result = self.client.get(self.message_url)
        self.assertEqual(result.status_code, 204)
Exemplo n.º 22
0
    def test_message_single_insert(self):
        """Insert Single Message into the Queue.

        This test also verifies that claimed messages are
        retuned (or not) depending on the include_claimed flag.
        """
        doc = helpers.create_message_body(messagecount=1)

        result = self.client.post(data=doc)
        self.assertEqual(result.status_code, 201)

        response_headers = set(result.headers.keys())
        self.assertIsSubset(self.headers_response_with_body, response_headers)

        # GET on posted message
        href = result.json()['resources'][0]
        url = self.cfg.marconi.url + href

        result = self.client.get(url)
        self.assertEqual(result.status_code, 200)

        # Compare message metadata
        result_body = result.json()['body']
        posted_metadata = doc[0]['body']
        self.assertEqual(result_body, posted_metadata)

        # Post a claim & verify the include_claimed flag.
        url = self.queue_url + '/claims'
        doc = {"ttl": 300, "grace": 100}
        result = self.client.post(url, data=doc)
        self.assertEqual(result.status_code, 201)

        params = {'include_claimed': True,
                  'echo': True}
        result = self.client.get(params=params)
        self.assertEqual(result.status_code, 200)

        response_message_body = result.json()["messages"][0]["body"]
        self.assertEqual(response_message_body, posted_metadata)

        # By default, include_claimed = false
        result = self.client.get(self.message_url)
        self.assertEqual(result.status_code, 204)
Exemplo n.º 23
0
    def test_messages_pop_invalid(self, limit):
        """Pop messages from a queue."""
        doc = helpers.create_message_body(
            messagecount=self.limits.max_messages_per_page)
        result = self.client.post(data=doc)

        self.assertEqual(result.status_code, 201)

        # Pop messages
        url = self.message_url + '?pop=' + str(limit)

        result = self.client.delete(url)
        self.assertEqual(result.status_code, 400)

        params = {'echo': True}
        result = self.client.get(self.message_url, params=params)
        self.assertEqual(result.status_code, 200)

        messages = result.json()['messages']
        self.assertNotEqual(messages, [])
Exemplo n.º 24
0
    def setUp(self):
        super(TestClaims, self).setUp()

        self.queue = uuid.uuid1()
        self.queue_url = ("{url}/{version}/queues/{queue}".format(
            url=self.cfg.marconi.url,
            version=self.cfg.marconi.version,
            queue=self.queue))

        self.client.put(self.queue_url)

        self.claim_url = self.queue_url + '/claims'
        self.client.set_base_url(self.claim_url)

        #Post Messages
        url = self.queue_url + '/messages'
        doc = helpers.create_message_body(
            messagecount=self.limits.message_paging_uplimit)
        for i in range(25):
            self.client.post(url, data=doc)
Exemplo n.º 25
0
    def test_messages_pop_invalid(self, limit):
        """Pop messages from a queue."""
        doc = helpers.create_message_body(
            messagecount=self.limits.max_messages_per_page)
        result = self.client.post(data=doc)

        self.assertEqual(result.status_code, 201)

        # Pop messages
        url = self.message_url + '?pop=' + str(limit)

        result = self.client.delete(url)
        self.assertEqual(result.status_code, 400)

        params = {'echo': True}
        result = self.client.get(self.message_url, params=params)
        self.assertEqual(result.status_code, 200)

        messages = result.json()['messages']
        self.assertNotEqual(messages, [])
Exemplo n.º 26
0
    def setUp(self):
        super(TestClaims, self).setUp()

        self.queue = uuid.uuid1()
        self.queue_url = ("{url}/{version}/queues/{queue}".format(
                          url=self.cfg.marconi.url,
                          version=self.cfg.marconi.version,
                          queue=self.queue))

        self.client.put(self.queue_url)

        self.claim_url = self.queue_url + '/claims'
        self.client.set_base_url(self.claim_url)

        #Post Messages
        url = self.queue_url + '/messages'
        doc = helpers.create_message_body(messagecount=
                                          self.limits.message_paging_uplimit)
        for i in range(25):
            self.client.post(url, data=doc)
Exemplo n.º 27
0
    def test_messages_delete_pop_and_id(self):
        """Delete messages with pop & id params in the request."""
        doc = helpers.create_message_body(messagecount=1)
        result = self.client.post(data=doc)

        self.assertEqual(result.status_code, 201)
        location = result.headers['Location']

        # Pop messages
        url = self.cfg.marconi.url + location + '&pop=1'

        result = self.client.delete(url)
        self.assertEqual(result.status_code, 400)

        params = {'echo': True}

        result = self.client.get(self.message_url, params=params)
        self.assertEqual(result.status_code, 200)

        messages = result.json()['messages']
        self.assertNotEqual(messages, [])
Exemplo n.º 28
0
    def test_messages_delete_pop_and_id(self):
        """Delete messages with pop & id params in the request."""
        doc = helpers.create_message_body(
            messagecount=1)
        result = self.client.post(data=doc)

        self.assertEqual(result.status_code, 201)
        location = result.headers['Location']

        # Pop messages
        url = self.cfg.marconi.url + location + '&pop=1'

        result = self.client.delete(url)
        self.assertEqual(result.status_code, 400)

        params = {'echo': True}

        result = self.client.get(self.message_url, params=params)
        self.assertEqual(result.status_code, 200)

        messages = result.json()['messages']
        self.assertNotEqual(messages, [])
Exemplo n.º 29
0
    def test_messages_pop_one(self):
        """Pop single messages from a queue."""
        doc = helpers.create_message_body(
            messagecount=self.limits.max_messages_per_page)
        result = self.client.post(data=doc)

        self.assertEqual(result.status_code, 201)

        # Pop Single Message
        url = self.message_url + '?pop=1'

        result = self.client.delete(url)
        self.assertEqual(result.status_code, 200)

        # Get messages from the queue & verify message count
        params = {'echo': True, 'limit': self.limits.max_messages_per_page}

        result = self.client.get(self.message_url, params=params)
        self.assertEqual(result.status_code, 200)

        expected_msg_count = self.limits.max_messages_per_page - 1
        actual_msg_count = len(result.json()['messages'])
        self.assertEqual(expected_msg_count, actual_msg_count)
Exemplo n.º 30
0
    def test_messages_pop_one(self):
        """Pop single messages from a queue."""
        doc = helpers.create_message_body(
            messagecount=self.limits.max_messages_per_page)
        result = self.client.post(data=doc)

        self.assertEqual(result.status_code, 201)

        # Pop Single Message
        url = self.message_url + '?pop=1'

        result = self.client.delete(url)
        self.assertEqual(result.status_code, 200)

        # Get messages from the queue & verify message count
        params = {'echo': True, 'limit': self.limits.max_messages_per_page}

        result = self.client.get(self.message_url, params=params)
        self.assertEqual(result.status_code, 200)

        expected_msg_count = self.limits.max_messages_per_page - 1
        actual_msg_count = len(result.json()['messages'])
        self.assertEqual(expected_msg_count, actual_msg_count)
Exemplo n.º 31
0
    def setUp(self):
        super(TestClaims, self).setUp()

        self.headers = helpers.create_marconi_headers(self.cfg)
        self.client.headers = self.headers

        self.queue = uuid.uuid1()
        self.queue_url = ("{url}/{version}/queues/{queue}".format(
                          url=self.cfg.marconi.url,
                          version="v1.1",
                          queue=self.queue))

        self.client.put(self.queue_url)

        self.claim_url = self.queue_url + '/claims'
        self.client.set_base_url(self.claim_url)

        # Post Messages
        url = self.queue_url + '/messages'
        doc = helpers.create_message_body(
            messagecount=self.limits.max_messages_per_page)

        for i in range(10):
            self.client.post(url, data=doc)