Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 41cbb7e

Browse files
committed
define claim/cancel message types
1 parent 6a2b3e8 commit 41cbb7e

File tree

4 files changed

+115
-7
lines changed

4 files changed

+115
-7
lines changed

tchannel/messages/__init__.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,32 @@
2020

2121
from __future__ import absolute_import
2222

23-
from .types import Types
24-
from .error import ErrorMessage, ErrorCode, error_rw
25-
from .common import Tracing, ChecksumType
2623
from .call_request import CallRequestMessage, call_req_rw
24+
from .call_request_continue import call_req_c_rw
2725
from .call_response import CallResponseMessage, call_res_rw
26+
from .call_response_continue import call_res_c_rw
27+
from .cancel import CancelMessage, cancel_rw
28+
from .claim import ClaimMessage, claim_rw
29+
from .common import Tracing, ChecksumType
30+
from .error import ErrorMessage, ErrorCode, error_rw
2831
from .init_request import InitRequestMessage, init_req_rw
2932
from .init_response import InitResponseMessage, init_res_rw
3033
from .ping_request import PingRequestMessage, ping_req_rw
3134
from .ping_response import PingResponseMessage, ping_res_rw
32-
from .call_request_continue import call_req_c_rw
33-
from .call_response_continue import call_res_c_rw
35+
from .types import Types
3436

3537
RW = {
3638
Types.CALL_REQ: call_req_rw,
39+
Types.CALL_REQ_CONTINUE: call_req_c_rw,
3740
Types.CALL_RES: call_res_rw,
41+
Types.CALL_RES_CONTINUE: call_res_c_rw,
42+
Types.CANCEL: cancel_rw,
43+
Types.CLAIM: claim_rw,
3844
Types.ERROR: error_rw,
3945
Types.INIT_REQ: init_req_rw,
4046
Types.INIT_RES: init_res_rw,
4147
Types.PING_REQ: ping_req_rw,
4248
Types.PING_RES: ping_res_rw,
43-
Types.CALL_REQ_CONTINUE: call_req_c_rw,
44-
Types.CALL_RES_CONTINUE: call_res_c_rw,
4549
}
4650

4751
__all__ = [
@@ -51,6 +55,8 @@
5155
"CallRequestContinueMessage",
5256
"CallResponseMessage",
5357
"CallResponseContinueMessage",
58+
"CancelMessage",
59+
"ClaimMessage",
5460
"ErrorMessage",
5561
"ErrorCode",
5662
"InitRequestMessage",

tchannel/messages/cancel.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright (c) 2015 Uber Technologies, Inc.
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in
11+
# all copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
# THE SOFTWARE.
20+
21+
from __future__ import absolute_import
22+
23+
from . import common
24+
from .. import rw
25+
from ..glossary import DEFAULT_TTL
26+
from .base import BaseMessage
27+
28+
29+
class CancelMessage(BaseMessage):
30+
__slots__ = BaseMessage.__slots__ + (
31+
'ttl',
32+
'tracing',
33+
'why',
34+
)
35+
36+
def __init__(self, ttl=DEFAULT_TTL, tracing=None, why=None, id=0):
37+
super(CancelMessage, self).__init__(id)
38+
self.ttl = ttl
39+
self.tracing = tracing or common.Tracing(0, 0, 0, 0)
40+
self.why = why or ''
41+
42+
43+
cancel_rw = rw.instance(
44+
CancelMessage,
45+
('ttl', rw.number(4)), # ttl:4
46+
('tracing', common.tracing_rw), # tracing:24
47+
('why', rw.len_prefixed_string(rw.number(2))), # why:2
48+
)

tchannel/messages/claim.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright (c) 2015 Uber Technologies, Inc.
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in
11+
# all copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
# THE SOFTWARE.
20+
21+
from __future__ import absolute_import
22+
23+
from . import common
24+
from .. import rw
25+
from ..glossary import DEFAULT_TTL
26+
from .base import BaseMessage
27+
28+
29+
class ClaimMessage(BaseMessage):
30+
__slots__ = BaseMessage.__slots__ + (
31+
'ttl',
32+
'tracing',
33+
)
34+
35+
def __init__(self, ttl=DEFAULT_TTL, tracing=None, id=0):
36+
super(ClaimMessage, self).__init__(id)
37+
self.ttl = ttl
38+
self.tracing = tracing or common.Tracing(0, 0, 0, 0)
39+
40+
41+
claim_rw = rw.instance(
42+
ClaimMessage,
43+
('ttl', rw.number(4)), # ttl:4
44+
('tracing', common.tracing_rw), # tracing:24
45+
)

tests/test_messages.py

+9
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ def test_valid_ping_request():
152152
'checksum': (messages.ChecksumType.crc32, 1),
153153
'args': None,
154154
}),
155+
(messages.ClaimMessage, messages.claim_rw, {
156+
'ttl': 4,
157+
'tracing': messages.Tracing(0, 0, 0, 1),
158+
}),
159+
(messages.CancelMessage, messages.cancel_rw, {
160+
'ttl': 4,
161+
'tracing': messages.Tracing(0, 0, 0, 1),
162+
'why': 'foo',
163+
}),
155164
])
156165
def test_roundtrip_message(message_class, message_rw, attrs):
157166
"""Verify all message types serialize and deserialize properly."""

0 commit comments

Comments
 (0)