def test_batch_submit_with_wait(self):
        """Verifies finisher works properly when waiting for commit.

        Queries the default mock block store which will have no block with
        the id 'new' until added by a separate thread.

        Expects to find:
            - less than 8 seconds to have passed (i.e. did not wait for timeout)
            - a response status of OK
            - a status of COMMITTED at key 'b-new' in batch_statuses
        """
        self._tracker.notify_batch_pending(make_mock_batch('new'))
        start_time = time()
        def delayed_add():
            sleep(1)
            self._store.add_block('new')
        Thread(target=delayed_add).start()

        response = self.make_request(
            batches=[make_mock_batch('new')],
            wait_for_commit=True,
            timeout=10)

        self.assertGreater(8, time() - start_time)
        self.assertEqual(self.status.OK, response.status)
        self.assertEqual(response.batch_statuses[0].batch_id, 'b-new')
        self.assertEqual(response.batch_statuses[0].status, BatchStatus.COMMITTED)
Esempio n. 2
0
    def test_batch_submit_with_wait(self):
        """Verifies finisher works properly when waiting for commit.

        Queries the default mock block store which will have no block with
        the id 'new' until added by a separate thread.

        Expects to find:
            - less than 8 seconds to have passed (i.e. did not wait for timeout)
            - a response status of OK
            - a status of COMMITTED at key 'b-new' in batch_statuses
        """
        self._tracker.notify_batch_pending(make_mock_batch('new'))
        start_time = time()

        def delayed_add():
            sleep(1)
            self._store.add_block('new')
            self._tracker.chain_update(None, [])

        Thread(target=delayed_add).start()

        response = self.make_request(batches=[make_mock_batch('new')],
                                     wait_for_commit=True,
                                     timeout=10)

        self.assertGreater(8, time() - start_time)
        self.assertEqual(self.status.OK, response.status)
        self.assertEqual(response.batch_statuses[0].batch_id, 'b-new')
        self.assertEqual(response.batch_statuses[0].status,
                         BatchStatus.COMMITTED)
Esempio n. 3
0
    def test_batch_statuses_with_wait(self):
        """Verifies requests for status that wait for commit work properly.

        Queries the default mock block store which will have no block with
        the id 'aaa...e' until added by a separate thread.

        Expects to find:
            - less than 8 seconds to have passed (i.e. did not wait for
            timeout)
            - a response status of OK
            - a status of COMMITTED at key 'aaa...e' in batch_statuses
        """
        self._tracker.notify_batch_pending(make_mock_batch('e'))
        start_time = time()

        def delayed_add():
            sleep(1)
            self._store.add_block('e')
            self._tracker.chain_update(None, [])

        Thread(target=delayed_add).start()

        response = self.make_request(batch_ids=['a' * 127 + 'e'],
                                     wait=True,
                                     timeout=10)

        self.assertGreater(8, time() - start_time)
        self.assertEqual(self.status.OK, response.status)
        self.assertEqual(response.batch_statuses[0].status,
                         ClientBatchStatus.COMMITTED)
    def test_batch_statuses_with_wait(self):
        """Verifies requests for status that wait for commit work properly.

        Queries the default mock block store which will have no block with
        the id 'aaa...e' until added by a separate thread.

        Expects to find:
            - less than 8 seconds to have passed (i.e. did not wait for
            timeout)
            - a response status of OK
            - a status of COMMITTED at key 'aaa...e' in batch_statuses
        """
        self._tracker.notify_batch_pending(make_mock_batch('e'))
        start_time = time()

        def delayed_add():
            sleep(1)
            self._store.add_block('e')
            self._tracker.chain_update(None, [])

        Thread(target=delayed_add).start()

        response = self.make_request(
            batch_ids=['a' * 127 + 'e'],
            wait=True,
            timeout=10)

        self.assertGreater(8, time() - start_time)
        self.assertEqual(self.status.OK, response.status)
        self.assertEqual(response.batch_statuses[0].status,
                         ClientBatchStatus.COMMITTED)
Esempio n. 5
0
    def test_batch_submit_bad_request(self):
        """Verifies finisher breaks properly when sent a bad request.

        Expects to find:
            - a response status of INTERNAL_ERROR
        """
        response = self.make_bad_request(batches=[make_mock_batch('new')])

        self.assertEqual(self.status.INTERNAL_ERROR, response.status)
    def test_batch_submit_bad_request(self):
        """Verifies finisher breaks properly when sent a bad request.

        Expects to find:
            - a response status of INTERNAL_ERROR
        """
        response = self.make_bad_request(batches=[make_mock_batch('new')])

        self.assertEqual(self.status.INTERNAL_ERROR, response.status)
Esempio n. 7
0
    def test_batch_submit_without_wait(self):
        """Verifies finisher simply returns OK when not set to wait.

        Expects to find:
            - a response status of OK
            - no batch_statuses
        """
        response = self.make_request(batches=[make_mock_batch('new')])

        self.assertEqual(self.status.OK, response.status)
    def test_batch_submit_without_wait(self):
        """Verifies finisher simply returns OK when not set to wait.

        Expects to find:
            - a response status of OK
            - no batch_statusus
        """
        response = self.make_request(batches=[make_mock_batch('new')])

        self.assertEqual(self.status.OK, response.status)
        self.assertFalse(response.batch_statuses)
    def test_batch_submit_without_wait(self):
        """Verifies finisher simply returns OK when not set to wait.

        Expects to find:
            - a response status of OK
            - no batch_statuses
        """
        response = self._handle(
            client_batch_submit_pb2.ClientBatchSubmitRequest(
                batches=[make_mock_batch('new')]))

        self.assertEqual(self.status.OK, response.status)
    def test_batch_submit_bad_request(self):
        """Verifies preprocessor breaks properly when sent a bad request.

        Expects to find:
            - a response status of INTERNAL_ERROR
        """

        request = client_batch_submit_pb2.ClientBatchSubmitRequest(
            batches=[make_mock_batch('new')]).SerializeToString()[0:-1]

        result = handlers.client_batch_submit_request_preprocessor(request)

        self.assertEqual(
            client_batch_submit_pb2.ClientBatchSubmitResponse.INTERNAL_ERROR,
            result.message_out.status)
    def test_batch_submit_bad_request(self):
        """Verifies preprocessor breaks properly when sent a bad request.

        Expects to find:
            - a response status of INTERNAL_ERROR
        """

        request = client_batch_submit_pb2.ClientBatchSubmitRequest(
            batches=[make_mock_batch('new')]
        ).SerializeToString()[0:-1]

        result = handlers.client_batch_submit_request_preprocessor(request)

        self.assertEqual(
            client_batch_submit_pb2.ClientBatchSubmitResponse.INTERNAL_ERROR,
            result.message_out.status)
def test_batch_statuses_with_wait(benchmark):
    """Verifies requests for status that wait for commit work properly.

    Queries the default mock block store which will have no block with
    the id 'aaa...e' until added by a separate thread.

    Expects to find:
        - less than 8 seconds to have passed (i.e. did not wait for
        timeout)
        - a response status of OK
        - a status of COMMITTED at key 'aaa...e' in batch_statuses
    """
    clientHanlerTestCase._tracker.notify_batch_pending(make_mock_batch('e'))
    start_time = time()

    def delayed_add():
        sleep(1)
        clientHanlerTestCase._store.add_block('e')
        clientHanlerTestCase._tracker.chain_update(None, [])

    Thread(target=delayed_add).start()

    # if there are more than 2 functions called, we can define a closure function then benchmark it
    # response = clientHanlerTestCase.make_request(
    #     batch_ids=['a' * 127 + 'e'],
    #     wait=True,
    #     timeout=10)

    response = benchmark.pedantic(clientHanlerTestCase.make_request,
                                  setup=setUp2,
                                  rounds=10,
                                  kwargs={
                                      'batch_ids': ['a' * 127 + 'e'],
                                      'wait': True,
                                      'timeout': 10
                                  })

    assert 8 > time() - start_time
    assert clientHanlerTestCase.status.OK == response.status
    assert response.batch_statuses[0].status == ClientBatchStatus.UNKNOWN
 def batch_submit():
     setUp()
     batch_submit = client_batch_submit_pb2.ClientBatchSubmitRequest(
         batches=[make_mock_batch('new')])
     return clientHanlerTestCase._handle(batch_submit)