Merge pull request #1058 from nathanielmanistaatgoogle/python-refactoring

Use distinct enums for distinct ticket types
pull/1061/head
Masood Malekghassemi 10 years ago
commit 758a0c252e
  1. 63
      src/python/src/grpc/_adapter/_links_test.py
  2. 12
      src/python/src/grpc/_adapter/_lonely_rear_link_test.py
  3. 28
      src/python/src/grpc/_adapter/fore.py
  4. 28
      src/python/src/grpc/_adapter/rear.py
  5. 31
      src/python/src/grpc/framework/base/packets/_reception.py
  6. 64
      src/python/src/grpc/framework/base/packets/_transmission.py
  7. 57
      src/python/src/grpc/framework/base/packets/packets.py

@ -60,9 +60,11 @@ class RoundTripTest(unittest.TestCase):
test_fore_link = _test_links.ForeLink(None, None)
def rear_action(front_to_back_ticket, fore_link):
if front_to_back_ticket.kind in (
tickets.Kind.COMPLETION, tickets.Kind.ENTIRE):
tickets.FrontToBackPacket.Kind.COMPLETION,
tickets.FrontToBackPacket.Kind.ENTIRE):
back_to_front_ticket = tickets.BackToFrontPacket(
front_to_back_ticket.operation_id, 0, tickets.Kind.COMPLETION, None)
front_to_back_ticket.operation_id, 0,
tickets.BackToFrontPacket.Kind.COMPLETION, None)
fore_link.accept_back_to_front_ticket(back_to_front_ticket)
test_rear_link = _test_links.RearLink(rear_action, None)
@ -81,20 +83,24 @@ class RoundTripTest(unittest.TestCase):
rear_link.start()
front_to_back_ticket = tickets.FrontToBackPacket(
test_operation_id, 0, tickets.Kind.ENTIRE, test_method,
interfaces.ServicedSubscription.Kind.FULL, None, None, _TIMEOUT)
test_operation_id, 0, tickets.FrontToBackPacket.Kind.ENTIRE,
test_method, interfaces.ServicedSubscription.Kind.FULL, None, None,
_TIMEOUT)
rear_link.accept_front_to_back_ticket(front_to_back_ticket)
with test_fore_link.condition:
while (not test_fore_link.tickets or
test_fore_link.tickets[-1].kind is tickets.Kind.CONTINUATION):
test_fore_link.tickets[-1].kind is
tickets.BackToFrontPacket.Kind.CONTINUATION):
test_fore_link.condition.wait()
rear_link.stop()
fore_link.stop()
with test_fore_link.condition:
self.assertIs(test_fore_link.tickets[-1].kind, tickets.Kind.COMPLETION)
self.assertIs(
test_fore_link.tickets[-1].kind,
tickets.BackToFrontPacket.Kind.COMPLETION)
def testEntireRoundTrip(self):
test_operation_id = object()
@ -109,11 +115,15 @@ class RoundTripTest(unittest.TestCase):
else:
payload = test_back_to_front_datum
terminal = front_to_back_ticket.kind in (
tickets.Kind.COMPLETION, tickets.Kind.ENTIRE)
tickets.FrontToBackPacket.Kind.COMPLETION,
tickets.FrontToBackPacket.Kind.ENTIRE)
if payload is not None or terminal:
if terminal:
kind = tickets.BackToFrontPacket.Kind.COMPLETION
else:
kind = tickets.BackToFrontPacket.Kind.CONTINUATION
back_to_front_ticket = tickets.BackToFrontPacket(
front_to_back_ticket.operation_id, rear_sequence_number[0],
tickets.Kind.COMPLETION if terminal else tickets.Kind.CONTINUATION,
front_to_back_ticket.operation_id, rear_sequence_number[0], kind,
payload)
rear_sequence_number[0] += 1
fore_link.accept_back_to_front_ticket(back_to_front_ticket)
@ -135,14 +145,15 @@ class RoundTripTest(unittest.TestCase):
rear_link.start()
front_to_back_ticket = tickets.FrontToBackPacket(
test_operation_id, 0, tickets.Kind.ENTIRE, test_method,
interfaces.ServicedSubscription.Kind.FULL, None,
test_operation_id, 0, tickets.FrontToBackPacket.Kind.ENTIRE,
test_method, interfaces.ServicedSubscription.Kind.FULL, None,
test_front_to_back_datum, _TIMEOUT)
rear_link.accept_front_to_back_ticket(front_to_back_ticket)
with test_fore_link.condition:
while (not test_fore_link.tickets or
test_fore_link.tickets[-1].kind is not tickets.Kind.COMPLETION):
test_fore_link.tickets[-1].kind is not
tickets.BackToFrontPacket.Kind.COMPLETION):
test_fore_link.condition.wait()
rear_link.stop()
@ -172,11 +183,15 @@ class RoundTripTest(unittest.TestCase):
else:
response = None
terminal = front_to_back_ticket.kind in (
tickets.Kind.COMPLETION, tickets.Kind.ENTIRE)
tickets.FrontToBackPacket.Kind.COMPLETION,
tickets.FrontToBackPacket.Kind.ENTIRE)
if response is not None or terminal:
if terminal:
kind = tickets.BackToFrontPacket.Kind.COMPLETION
else:
kind = tickets.BackToFrontPacket.Kind.CONTINUATION
back_to_front_ticket = tickets.BackToFrontPacket(
front_to_back_ticket.operation_id, rear_sequence_number[0],
tickets.Kind.COMPLETION if terminal else tickets.Kind.CONTINUATION,
front_to_back_ticket.operation_id, rear_sequence_number[0], kind,
response)
rear_sequence_number[0] += 1
fore_link.accept_back_to_front_ticket(back_to_front_ticket)
@ -199,25 +214,29 @@ class RoundTripTest(unittest.TestCase):
rear_link.start()
commencement_ticket = tickets.FrontToBackPacket(
test_operation_id, 0, tickets.Kind.COMMENCEMENT, test_method,
interfaces.ServicedSubscription.Kind.FULL, None, None, _TIMEOUT)
test_operation_id, 0, tickets.FrontToBackPacket.Kind.COMMENCEMENT,
test_method, interfaces.ServicedSubscription.Kind.FULL, None, None,
_TIMEOUT)
fore_sequence_number = 1
rear_link.accept_front_to_back_ticket(commencement_ticket)
for request in scenario.requests():
continuation_ticket = tickets.FrontToBackPacket(
test_operation_id, fore_sequence_number, tickets.Kind.CONTINUATION,
None, None, None, request, None)
test_operation_id, fore_sequence_number,
tickets.FrontToBackPacket.Kind.CONTINUATION, None, None, None,
request, None)
fore_sequence_number += 1
rear_link.accept_front_to_back_ticket(continuation_ticket)
completion_ticket = tickets.FrontToBackPacket(
test_operation_id, fore_sequence_number, tickets.Kind.COMPLETION, None,
None, None, None, None)
test_operation_id, fore_sequence_number,
tickets.FrontToBackPacket.Kind.COMPLETION, None, None, None, None,
None)
fore_sequence_number += 1
rear_link.accept_front_to_back_ticket(completion_ticket)
with test_fore_link.condition:
while (not test_fore_link.tickets or
test_fore_link.tickets[-1].kind is not tickets.Kind.COMPLETION):
test_fore_link.tickets[-1].kind is not
tickets.BackToFrontPacket.Kind.COMPLETION):
test_fore_link.condition.wait()
rear_link.stop()

@ -76,22 +76,26 @@ class LonelyRearLinkTest(unittest.TestCase):
with fore_link.condition:
while True:
if (fore_link.tickets and
fore_link.tickets[-1].kind is not packets.Kind.CONTINUATION):
fore_link.tickets[-1].kind is not
packets.BackToFrontPacket.Kind.CONTINUATION):
break
fore_link.condition.wait()
rear_link.stop()
with fore_link.condition:
self.assertIsNot(fore_link.tickets[-1].kind, packets.Kind.COMPLETION)
self.assertIsNot(
fore_link.tickets[-1].kind,
packets.BackToFrontPacket.Kind.COMPLETION)
@unittest.skip('TODO(nathaniel): This seems to have broken in the last few weeks; fix it.')
def testLonelyClientCommencementPacket(self):
self._perform_lonely_client_test_with_ticket_kind(
packets.Kind.COMMENCEMENT)
packets.FrontToBackPacket.Kind.COMMENCEMENT)
def testLonelyClientEntirePacket(self):
self._perform_lonely_client_test_with_ticket_kind(packets.Kind.ENTIRE)
self._perform_lonely_client_test_with_ticket_kind(
packets.FrontToBackPacket.Kind.ENTIRE)
if __name__ == '__main__':

@ -128,7 +128,7 @@ class ForeLink(ticket_interfaces.ForeLink, activated.Activated):
self._response_serializers[method])
ticket = tickets.FrontToBackPacket(
call, 0, tickets.Kind.COMMENCEMENT, method,
call, 0, tickets.FrontToBackPacket.Kind.COMMENCEMENT, method,
interfaces.ServicedSubscription.Kind.FULL, None, None,
service_acceptance.deadline - time.time())
self._rear_link.accept_front_to_back_ticket(ticket)
@ -146,13 +146,13 @@ class ForeLink(ticket_interfaces.ForeLink, activated.Activated):
rpc_state.sequence_number += 1
if event.bytes is None:
ticket = tickets.FrontToBackPacket(
call, sequence_number, tickets.Kind.COMPLETION, None, None, None,
None, None)
call, sequence_number, tickets.FrontToBackPacket.Kind.COMPLETION,
None, None, None, None, None)
else:
call.read(call)
ticket = tickets.FrontToBackPacket(
call, sequence_number, tickets.Kind.CONTINUATION, None, None, None,
rpc_state.deserializer(event.bytes), None)
call, sequence_number, tickets.FrontToBackPacket.Kind.CONTINUATION,
None, None, None, rpc_state.deserializer(event.bytes), None)
self._rear_link.accept_front_to_back_ticket(ticket)
@ -181,7 +181,8 @@ class ForeLink(ticket_interfaces.ForeLink, activated.Activated):
sequence_number = rpc_state.sequence_number
rpc_state.sequence_number += 1
ticket = tickets.FrontToBackPacket(
call, sequence_number, tickets.Kind.TRANSMISSION_FAILURE, None, None,
call, sequence_number,
tickets.FrontToBackPacket.Kind.TRANSMISSION_FAILURE, None, None,
None, None, None)
self._rear_link.accept_front_to_back_ticket(ticket)
@ -200,16 +201,17 @@ class ForeLink(ticket_interfaces.ForeLink, activated.Activated):
rpc_state.sequence_number += 1
if code is _low.Code.CANCELLED:
ticket = tickets.FrontToBackPacket(
call, sequence_number, tickets.Kind.CANCELLATION, None, None, None,
None, None)
call, sequence_number, tickets.FrontToBackPacket.Kind.CANCELLATION,
None, None, None, None, None)
elif code is _low.Code.EXPIRED:
ticket = tickets.FrontToBackPacket(
call, sequence_number, tickets.Kind.EXPIRATION, None, None, None,
None, None)
call, sequence_number, tickets.FrontToBackPacket.Kind.EXPIRATION,
None, None, None, None, None)
else:
# TODO(nathaniel): Better mapping of codes to ticket-categories
ticket = tickets.FrontToBackPacket(
call, sequence_number, tickets.Kind.TRANSMISSION_FAILURE, None, None,
call, sequence_number,
tickets.FrontToBackPacket.Kind.TRANSMISSION_FAILURE, None, None,
None, None, None)
self._rear_link.accept_front_to_back_ticket(ticket)
@ -351,9 +353,9 @@ class ForeLink(ticket_interfaces.ForeLink, activated.Activated):
if self._server is None:
return
if ticket.kind is tickets.Kind.CONTINUATION:
if ticket.kind is tickets.BackToFrontPacket.Kind.CONTINUATION:
self._continue(ticket.operation_id, ticket.payload)
elif ticket.kind is tickets.Kind.COMPLETION:
elif ticket.kind is tickets.BackToFrontPacket.Kind.COMPLETION:
self._complete(ticket.operation_id, ticket.payload)
else:
self._cancel(ticket.operation_id)

@ -154,7 +154,7 @@ class RearLink(ticket_interfaces.RearLink, activated.Activated):
rpc_state.active = False
ticket = tickets.BackToFrontPacket(
operation_id, rpc_state.common.sequence_number,
tickets.Kind.TRANSMISSION_FAILURE, None)
tickets.BackToFrontPacket.Kind.TRANSMISSION_FAILURE, None)
rpc_state.common.sequence_number += 1
self._fore_link.accept_back_to_front_ticket(ticket)
@ -165,7 +165,8 @@ class RearLink(ticket_interfaces.RearLink, activated.Activated):
ticket = tickets.BackToFrontPacket(
operation_id, rpc_state.common.sequence_number,
tickets.Kind.CONTINUATION, rpc_state.common.deserializer(event.bytes))
tickets.BackToFrontPacket.Kind.CONTINUATION,
rpc_state.common.deserializer(event.bytes))
rpc_state.common.sequence_number += 1
self._fore_link.accept_back_to_front_ticket(ticket)
@ -175,7 +176,7 @@ class RearLink(ticket_interfaces.RearLink, activated.Activated):
rpc_state.active = False
ticket = tickets.BackToFrontPacket(
operation_id, rpc_state.common.sequence_number,
tickets.Kind.TRANSMISSION_FAILURE, None)
tickets.BackToFrontPacket.Kind.TRANSMISSION_FAILURE, None)
rpc_state.common.sequence_number += 1
self._fore_link.accept_back_to_front_ticket(ticket)
@ -188,17 +189,16 @@ class RearLink(ticket_interfaces.RearLink, activated.Activated):
"""Handle termination of an RPC."""
# TODO(nathaniel): Cover all statuses.
if event.status.code is _low.Code.OK:
category = tickets.Kind.COMPLETION
kind = tickets.BackToFrontPacket.Kind.COMPLETION
elif event.status.code is _low.Code.CANCELLED:
# TODO(issue 752): Use a CANCELLATION ticket kind here.
category = tickets.Kind.SERVICER_FAILURE
kind = tickets.BackToFrontPacket.Kind.SERVICER_FAILURE
elif event.status.code is _low.Code.EXPIRED:
category = tickets.Kind.EXPIRATION
kind = tickets.BackToFrontPacket.Kind.EXPIRATION
else:
category = tickets.Kind.TRANSMISSION_FAILURE
kind = tickets.BackToFrontPacket.Kind.TRANSMISSION_FAILURE
ticket = tickets.BackToFrontPacket(
operation_id, rpc_state.common.sequence_number, category,
None)
operation_id, rpc_state.common.sequence_number, kind, None)
rpc_state.common.sequence_number += 1
self._fore_link.accept_back_to_front_ticket(ticket)
@ -372,17 +372,17 @@ class RearLink(ticket_interfaces.RearLink, activated.Activated):
if self._completion_queue is None:
return
if ticket.kind is tickets.Kind.COMMENCEMENT:
if ticket.kind is tickets.FrontToBackPacket.Kind.COMMENCEMENT:
self._commence(
ticket.operation_id, ticket.name, ticket.payload, ticket.timeout)
elif ticket.kind is tickets.Kind.CONTINUATION:
elif ticket.kind is tickets.FrontToBackPacket.Kind.CONTINUATION:
self._continue(ticket.operation_id, ticket.payload)
elif ticket.kind is tickets.Kind.COMPLETION:
elif ticket.kind is tickets.FrontToBackPacket.Kind.COMPLETION:
self._complete(ticket.operation_id, ticket.payload)
elif ticket.kind is tickets.Kind.ENTIRE:
elif ticket.kind is tickets.FrontToBackPacket.Kind.ENTIRE:
self._entire(
ticket.operation_id, ticket.name, ticket.payload, ticket.timeout)
elif ticket.kind is tickets.Kind.CANCELLATION:
elif ticket.kind is tickets.FrontToBackPacket.Kind.CANCELLATION:
self._cancel(ticket.operation_id)
else:
# NOTE(nathaniel): All other categories are treated as cancellation.

@ -35,6 +35,11 @@ from grpc.framework.base import interfaces as base_interfaces
from grpc.framework.base.packets import _interfaces
from grpc.framework.base.packets import packets
_INITIAL_FRONT_TO_BACK_PACKET_KINDS = (
packets.FrontToBackPacket.Kind.COMMENCEMENT,
packets.FrontToBackPacket.Kind.ENTIRE,
)
class _Receiver(object):
"""Common specification of different packet-handling behavior."""
@ -151,15 +156,15 @@ class _BackReceiver(_Receiver):
A base_interfaces.Outcome value describing operation abortion if the
packet is abortive or None if the packet is not abortive.
"""
if packet.kind is packets.Kind.CANCELLATION:
if packet.kind is packets.FrontToBackPacket.Kind.CANCELLATION:
return base_interfaces.Outcome.CANCELLED
elif packet.kind is packets.Kind.EXPIRATION:
elif packet.kind is packets.FrontToBackPacket.Kind.EXPIRATION:
return base_interfaces.Outcome.EXPIRED
elif packet.kind is packets.Kind.SERVICED_FAILURE:
elif packet.kind is packets.FrontToBackPacket.Kind.SERVICED_FAILURE:
return base_interfaces.Outcome.SERVICED_FAILURE
elif packet.kind is packets.Kind.RECEPTION_FAILURE:
elif packet.kind is packets.FrontToBackPacket.Kind.RECEPTION_FAILURE:
return base_interfaces.Outcome.SERVICED_FAILURE
elif (packet.kind in (packets.Kind.COMMENCEMENT, packets.Kind.ENTIRE) and
elif (packet.kind in _INITIAL_FRONT_TO_BACK_PACKET_KINDS and
self._first_packet_seen):
return base_interfaces.Outcome.RECEPTION_FAILURE
elif self._last_packet_seen:
@ -179,14 +184,14 @@ class _BackReceiver(_Receiver):
if packet.timeout is not None:
self._expiration_manager.change_timeout(packet.timeout)
if packet.kind is packets.Kind.COMMENCEMENT:
if packet.kind is packets.FrontToBackPacket.Kind.COMMENCEMENT:
self._first_packet_seen = True
self._ingestion_manager.start(packet.name)
if packet.payload is not None:
self._ingestion_manager.consume(packet.payload)
elif packet.kind is packets.Kind.CONTINUATION:
elif packet.kind is packets.FrontToBackPacket.Kind.CONTINUATION:
self._ingestion_manager.consume(packet.payload)
elif packet.kind is packets.Kind.COMPLETION:
elif packet.kind is packets.FrontToBackPacket.Kind.COMPLETION:
self._last_packet_seen = True
if packet.payload is None:
self._ingestion_manager.terminate()
@ -239,11 +244,11 @@ class _FrontReceiver(_Receiver):
A base_interfaces.Outcome value describing operation abortion if the
packet is abortive or None if the packet is not abortive.
"""
if packet.kind is packets.Kind.EXPIRATION:
if packet.kind is packets.BackToFrontPacket.Kind.EXPIRATION:
return base_interfaces.Outcome.EXPIRED
elif packet.kind is packets.Kind.SERVICER_FAILURE:
elif packet.kind is packets.BackToFrontPacket.Kind.SERVICER_FAILURE:
return base_interfaces.Outcome.SERVICER_FAILURE
elif packet.kind is packets.Kind.RECEPTION_FAILURE:
elif packet.kind is packets.BackToFrontPacket.Kind.RECEPTION_FAILURE:
return base_interfaces.Outcome.SERVICER_FAILURE
elif self._last_packet_seen:
return base_interfaces.Outcome.RECEPTION_FAILURE
@ -259,9 +264,9 @@ class _FrontReceiver(_Receiver):
def receive(self, packet):
"""See _Receiver.receive for specification."""
if packet.kind is packets.Kind.CONTINUATION:
if packet.kind is packets.BackToFrontPacket.Kind.CONTINUATION:
self._ingestion_manager.consume(packet.payload)
elif packet.kind is packets.Kind.COMPLETION:
elif packet.kind is packets.BackToFrontPacket.Kind.COMPLETION:
self._last_packet_seen = True
if packet.payload is None:
self._ingestion_manager.terminate()

@ -47,15 +47,33 @@ _BACK_TO_FRONT_NO_TRANSMISSION_OUTCOMES = (
interfaces.Outcome.SERVICED_FAILURE,
)
_ABORTION_OUTCOME_TO_PACKET_KIND = {
interfaces.Outcome.CANCELLED: packets.Kind.CANCELLATION,
interfaces.Outcome.EXPIRED: packets.Kind.EXPIRATION,
interfaces.Outcome.RECEPTION_FAILURE: packets.Kind.RECEPTION_FAILURE,
interfaces.Outcome.TRANSMISSION_FAILURE: packets.Kind.TRANSMISSION_FAILURE,
interfaces.Outcome.SERVICED_FAILURE: packets.Kind.SERVICED_FAILURE,
interfaces.Outcome.SERVICER_FAILURE: packets.Kind.SERVICER_FAILURE,
_ABORTION_OUTCOME_TO_FRONT_TO_BACK_PACKET_KIND = {
interfaces.Outcome.CANCELLED:
packets.FrontToBackPacket.Kind.CANCELLATION,
interfaces.Outcome.EXPIRED:
packets.FrontToBackPacket.Kind.EXPIRATION,
interfaces.Outcome.RECEPTION_FAILURE:
packets.FrontToBackPacket.Kind.RECEPTION_FAILURE,
interfaces.Outcome.TRANSMISSION_FAILURE:
packets.FrontToBackPacket.Kind.TRANSMISSION_FAILURE,
interfaces.Outcome.SERVICED_FAILURE:
packets.FrontToBackPacket.Kind.SERVICED_FAILURE,
interfaces.Outcome.SERVICER_FAILURE:
packets.FrontToBackPacket.Kind.SERVICER_FAILURE,
}
_ABORTION_OUTCOME_TO_BACK_TO_FRONT_PACKET_KIND = {
interfaces.Outcome.EXPIRED:
packets.BackToFrontPacket.Kind.EXPIRATION,
interfaces.Outcome.RECEPTION_FAILURE:
packets.BackToFrontPacket.Kind.RECEPTION_FAILURE,
interfaces.Outcome.TRANSMISSION_FAILURE:
packets.BackToFrontPacket.Kind.TRANSMISSION_FAILURE,
interfaces.Outcome.SERVICED_FAILURE:
packets.BackToFrontPacket.Kind.SERVICED_FAILURE,
interfaces.Outcome.SERVICER_FAILURE:
packets.BackToFrontPacket.Kind.SERVICER_FAILURE,
}
class _Packetizer(object):
@ -120,24 +138,28 @@ class _FrontPacketizer(_Packetizer):
def packetize(self, operation_id, sequence_number, payload, complete):
"""See _Packetizer.packetize for specification."""
if sequence_number:
if complete:
kind = packets.FrontToBackPacket.Kind.COMPLETION
else:
kind = packets.FrontToBackPacket.Kind.CONTINUATION
return packets.FrontToBackPacket(
operation_id, sequence_number,
packets.Kind.COMPLETION if complete else packets.Kind.CONTINUATION,
self._name, self._subscription_kind, self._trace_id, payload,
self._timeout)
operation_id, sequence_number, kind, self._name,
self._subscription_kind, self._trace_id, payload, self._timeout)
else:
if complete:
kind = packets.FrontToBackPacket.Kind.ENTIRE
else:
kind = packets.FrontToBackPacket.Kind.COMMENCEMENT
return packets.FrontToBackPacket(
operation_id, 0,
packets.Kind.ENTIRE if complete else packets.Kind.COMMENCEMENT,
self._name, self._subscription_kind, self._trace_id, payload,
self._timeout)
operation_id, 0, kind, self._name, self._subscription_kind,
self._trace_id, payload, self._timeout)
def packetize_abortion(self, operation_id, sequence_number, outcome):
"""See _Packetizer.packetize_abortion for specification."""
if outcome in _FRONT_TO_BACK_NO_TRANSMISSION_OUTCOMES:
return None
else:
kind = _ABORTION_OUTCOME_TO_PACKET_KIND[outcome]
kind = _ABORTION_OUTCOME_TO_FRONT_TO_BACK_PACKET_KIND[outcome]
return packets.FrontToBackPacket(
operation_id, sequence_number, kind, None, None, None, None, None)
@ -147,17 +169,19 @@ class _BackPacketizer(_Packetizer):
def packetize(self, operation_id, sequence_number, payload, complete):
"""See _Packetizer.packetize for specification."""
if complete:
kind = packets.BackToFrontPacket.Kind.COMPLETION
else:
kind = packets.BackToFrontPacket.Kind.CONTINUATION
return packets.BackToFrontPacket(
operation_id, sequence_number,
packets.Kind.COMPLETION if complete else packets.Kind.CONTINUATION,
payload)
operation_id, sequence_number, kind, payload)
def packetize_abortion(self, operation_id, sequence_number, outcome):
"""See _Packetizer.packetize_abortion for specification."""
if outcome in _BACK_TO_FRONT_NO_TRANSMISSION_OUTCOMES:
return None
else:
kind = _ABORTION_OUTCOME_TO_PACKET_KIND[outcome]
kind = _ABORTION_OUTCOME_TO_BACK_TO_FRONT_PACKET_KIND[outcome]
return packets.BackToFrontPacket(
operation_id, sequence_number, kind, None)

@ -36,22 +36,6 @@ import enum
from grpc.framework.base import interfaces # pylint: disable=unused-import
@enum.unique
class Kind(enum.Enum):
"""Identifies the overall kind of a ticket."""
COMMENCEMENT = 'commencement'
CONTINUATION = 'continuation'
COMPLETION = 'completion'
ENTIRE = 'entire'
CANCELLATION = 'cancellation'
EXPIRATION = 'expiration'
SERVICER_FAILURE = 'servicer failure'
SERVICED_FAILURE = 'serviced failure'
RECEPTION_FAILURE = 'reception failure'
TRANSMISSION_FAILURE = 'transmission failure'
class FrontToBackPacket(
collections.namedtuple(
'FrontToBackPacket',
@ -66,9 +50,7 @@ class FrontToBackPacket(
packet's place among all the packets sent from front to back for this
particular operation. Must be zero if kind is Kind.COMMENCEMENT or
Kind.ENTIRE. Must be positive for any other kind.
kind: One of Kind.COMMENCEMENT, Kind.CONTINUATION, Kind.COMPLETION,
Kind.ENTIRE, Kind.CANCELLATION, Kind.EXPIRATION, Kind.SERVICED_FAILURE,
Kind.RECEPTION_FAILURE, or Kind.TRANSMISSION_FAILURE.
kind: A Kind value describing the overall kind of ticket.
name: The name of an operation. Must be present if kind is Kind.COMMENCEMENT
or Kind.ENTIRE. Must be None for any other kind.
subscription: An interfaces.ServicedSubscription.Kind value describing the
@ -88,6 +70,21 @@ class FrontToBackPacket(
operations.
"""
@enum.unique
class Kind(enum.Enum):
"""Identifies the overall kind of a FrontToBackPacket."""
COMMENCEMENT = 'commencement'
CONTINUATION = 'continuation'
COMPLETION = 'completion'
ENTIRE = 'entire'
CANCELLATION = 'cancellation'
EXPIRATION = 'expiration'
SERVICER_FAILURE = 'servicer failure'
SERVICED_FAILURE = 'serviced failure'
RECEPTION_FAILURE = 'reception failure'
TRANSMISSION_FAILURE = 'transmission failure'
class BackToFrontPacket(
collections.namedtuple(
@ -101,11 +98,21 @@ class BackToFrontPacket(
sequence_number: A zero-indexed integer sequence number identifying the
packet's place among all the packets sent from back to front for this
particular operation.
kind: One of Kind.CONTINUATION, Kind.COMPLETION, Kind.EXPIRATION,
Kind.SERVICER_FAILURE, Kind.RECEPTION_FAILURE, or
Kind.TRANSMISSION_FAILURE.
kind: A Kind value describing the overall kind of ticket.
payload: A customer payload object. Must be present if kind is
Kind.CONTINUATION. May be None if kind is Kind.COMPLETION. Must be None if
kind is Kind.EXPIRATION, Kind.SERVICER_FAILURE, Kind.RECEPTION_FAILURE, or
Kind.TRANSMISSION_FAILURE.
Kind.CONTINUATION. May be None if kind is Kind.COMPLETION. Must be None
otherwise.
"""
@enum.unique
class Kind(enum.Enum):
"""Identifies the overall kind of a BackToFrontPacket."""
# TODO(issue 752): Add CANCELLATION.
CONTINUATION = 'continuation'
COMPLETION = 'completion'
EXPIRATION = 'expiration'
SERVICER_FAILURE = 'servicer failure'
SERVICED_FAILURE = 'serviced failure'
RECEPTION_FAILURE = 'reception failure'
TRANSMISSION_FAILURE = 'transmission failure'

Loading…
Cancel
Save