Exemplo n.º 1
0
  def testCancellation(self):
    """Tests cancelling a long-lived operation."""
    test_consumer = stream_testing.TestConsumer()
    subscription = util.full_serviced_subscription(
        EasyServicedIngestor(test_consumer))

    operation = self.front.operate(
        ASYNCHRONOUS_ECHO, None, False, SMALL_TIMEOUT, subscription,
        'test trace ID')
    operation.cancel()

    util.wait_for_idle(self.front)
    self.assertEqual(
        1, self.front.operation_stats()[interfaces.Outcome.CANCELLED])
    util.wait_for_idle(self.back)
    self.assertListEqual([], test_consumer.calls)

    # Assuming nothing really pathological (such as pauses on the order of
    # SMALL_TIMEOUT interfering with this test) there are a two different ways
    # the back could have experienced execution up to this point:
    # (1) Both tickets are still either in the front waiting to be transmitted
    # or are somewhere on the link between the front and the back. The back has
    # no idea that this test is even happening. Calling wait_for_idle on it
    # would do no good because in this case the back is idle and the call would
    # return with the tickets bound for it still in the front or on the link.
    back_operation_stats = self.back.operation_stats()
    first_back_possibility = EMPTY_OUTCOME_DICT
    # (2) Both tickets arrived within SMALL_TIMEOUT of one another at the back.
    # The back started processing based on the first ticket and then stopped
    # upon receiving the cancellation ticket.
    second_back_possibility = dict(EMPTY_OUTCOME_DICT)
    second_back_possibility[interfaces.Outcome.CANCELLED] = 1
    self.assertIn(
        back_operation_stats, (first_back_possibility, second_back_possibility))
Exemplo n.º 2
0
    def testBidirectionalStreamingEcho(self):
        """Tests sending multiple tickets each way."""
        test_payload_template = 'test_payload: %03d'
        test_payloads = [
            test_payload_template % i for i in range(STREAM_LENGTH)
        ]
        test_consumer = stream_testing.TestConsumer()
        subscription = util.full_serviced_subscription(
            EasyServicedIngestor(test_consumer))

        operation = self.front.operate(SYNCHRONOUS_ECHO, None, False,
                                       SMALL_TIMEOUT, subscription,
                                       'test trace ID')

        for test_payload in test_payloads:
            operation.consumer.consume(test_payload)
        operation.consumer.terminate()

        util.wait_for_idle(self.front)
        util.wait_for_idle(self.back)
        self.assertEqual(
            1,
            self.front.operation_stats()[interfaces.Outcome.COMPLETED])
        self.assertEqual(
            1,
            self.back.operation_stats()[interfaces.Outcome.COMPLETED])
        self.assertListEqual(test_payloads, test_consumer.values())
Exemplo n.º 3
0
  def testEntireEcho(self):
    """Tests a very simple one-ticket-each-way round-trip."""
    test_payload = 'test payload'
    test_consumer = stream_testing.TestConsumer()
    subscription = util.full_serviced_subscription(
        EasyServicedIngestor(test_consumer))

    self.front.operate(
        ASYNCHRONOUS_ECHO, test_payload, True, SMALL_TIMEOUT, subscription,
        'test trace ID')

    util.wait_for_idle(self.front)
    util.wait_for_idle(self.back)
    self.assertEqual(
        1, self.front.operation_stats()[interfaces.Outcome.COMPLETED])
    self.assertEqual(
        1, self.back.operation_stats()[interfaces.Outcome.COMPLETED])
    self.assertListEqual([(test_payload, True)], test_consumer.calls)
Exemplo n.º 4
0
  def testBidirectionalStreamingEcho(self):
    """Tests sending multiple tickets each way."""
    test_payload_template = 'test_payload: %03d'
    test_payloads = [test_payload_template % i for i in range(STREAM_LENGTH)]
    test_consumer = stream_testing.TestConsumer()
    subscription = util.full_serviced_subscription(
        EasyServicedIngestor(test_consumer))

    operation = self.front.operate(
        SYNCHRONOUS_ECHO, None, False, SMALL_TIMEOUT, subscription,
        'test trace ID')

    for test_payload in test_payloads:
      operation.consumer.consume(test_payload)
    operation.consumer.terminate()

    util.wait_for_idle(self.front)
    util.wait_for_idle(self.back)
    self.assertEqual(
        1, self.front.operation_stats()[interfaces.Outcome.COMPLETED])
    self.assertEqual(
        1, self.back.operation_stats()[interfaces.Outcome.COMPLETED])
    self.assertListEqual(test_payloads, test_consumer.values())
Exemplo n.º 5
0
def _stream_event_subscription(result_consumer, abortion_callback):
    return base_util.full_serviced_subscription(
        _EventServicedIngestor(result_consumer, abortion_callback))
Exemplo n.º 6
0
def _unary_event_subscription(completion_callback, abortion_callback):
    return base_util.full_serviced_subscription(
        _EventServicedIngestor(_control.UnaryConsumer(completion_callback),
                               abortion_callback))
Exemplo n.º 7
0
def _rendezvous_subscription(rendezvous):
    return base_util.full_serviced_subscription(
        _RendezvousServicedIngestor(rendezvous))
Exemplo n.º 8
0
def _stream_event_subscription(result_consumer, abortion_callback):
  return base_util.full_serviced_subscription(
      _EventServicedIngestor(result_consumer, abortion_callback))
Exemplo n.º 9
0
def _unary_event_subscription(completion_callback, abortion_callback):
  return base_util.full_serviced_subscription(
      _EventServicedIngestor(
          _control.UnaryConsumer(completion_callback), abortion_callback))
Exemplo n.º 10
0
def _rendezvous_subscription(rendezvous):
  return base_util.full_serviced_subscription(
      _RendezvousServicedIngestor(rendezvous))