1
+ import datetime
2
+
3
+ from google .protobuf .json_format import MessageToDict
4
+
1
5
from ydb ._grpc .grpcwrapper .ydb_topic import OffsetsRange
6
+ from .ydb_topic import AlterTopicRequest
7
+ from .ydb_topic_public_types import (
8
+ AlterTopicRequestParams ,
9
+ PublicAlterConsumer ,
10
+ PublicConsumer ,
11
+ PublicCodec ,
12
+ )
2
13
3
14
4
15
def test_offsets_range_intersected ():
@@ -17,3 +28,59 @@ def test_offsets_range_intersected():
17
28
]:
18
29
assert OffsetsRange (test [0 ], test [1 ]).is_intersected_with (OffsetsRange (test [2 ], test [3 ]))
19
30
assert OffsetsRange (test [2 ], test [3 ]).is_intersected_with (OffsetsRange (test [0 ], test [1 ]))
31
+
32
+
33
+ def test_alter_topic_request_from_public_to_proto ():
34
+ # Specify all fields with all possible input ways
35
+ params = {
36
+ "path" : "topic_name" ,
37
+ "add_consumers" : [
38
+ "new_consumer_1" ,
39
+ PublicConsumer ("new_consumer_2" ),
40
+ ],
41
+ "alter_consumers" : [
42
+ "old_consumer_1" ,
43
+ PublicAlterConsumer ("old_consumer_2" ),
44
+ ],
45
+ "drop_consumers" : ["redundant_consumer" ],
46
+ "set_retention_period" : datetime .timedelta (weeks = 4 ),
47
+ "set_retention_storage_mb" : 4 ,
48
+ "set_supported_codecs" : [1 , PublicCodec (2 )],
49
+ "set_partition_write_burst_bytes" : 8 ,
50
+ "set_partition_write_speed_bytes_per_second" : 15 ,
51
+ "alter_attributes" : {"key" : "value" },
52
+ "set_metering_mode" : 1 ,
53
+ "set_min_active_partitions" : 2 ,
54
+ "set_partition_count_limit" : 4 ,
55
+ }
56
+
57
+ params_public = AlterTopicRequestParams (** params )
58
+ request = AlterTopicRequest .from_public (params_public )
59
+ request_proto = request .to_proto ()
60
+
61
+ msg_dict = MessageToDict (request_proto , preserving_proto_field_name = True )
62
+
63
+ assert msg_dict ["path" ] == params ["path" ]
64
+ assert len (msg_dict ["add_consumers" ]) == len (params ["add_consumers" ])
65
+ assert len (msg_dict ["alter_consumers" ]) == len (params ["alter_consumers" ])
66
+ assert len (msg_dict ["drop_consumers" ]) == len (params ["drop_consumers" ])
67
+ assert msg_dict ["alter_attributes" ] == params ["alter_attributes" ]
68
+
69
+ assert (
70
+ int (msg_dict ["alter_partitioning_settings" ]["set_min_active_partitions" ]) == params ["set_min_active_partitions" ]
71
+ )
72
+ assert (
73
+ int (msg_dict ["alter_partitioning_settings" ]["set_partition_count_limit" ]) == params ["set_partition_count_limit" ]
74
+ )
75
+
76
+ assert int (msg_dict ["set_partition_write_burst_bytes" ]) == params ["set_partition_write_burst_bytes" ]
77
+ assert (
78
+ int (msg_dict ["set_partition_write_speed_bytes_per_second" ])
79
+ == params ["set_partition_write_speed_bytes_per_second" ]
80
+ )
81
+ assert msg_dict ["set_retention_period" ] == str (int (params ["set_retention_period" ].total_seconds ())) + "s"
82
+ assert int (msg_dict ["set_retention_storage_mb" ]) == params ["set_retention_storage_mb" ]
83
+
84
+ assert msg_dict ["set_metering_mode" ] == "METERING_MODE_RESERVED_CAPACITY"
85
+
86
+ assert msg_dict ["set_supported_codecs" ]["codecs" ] == params ["set_supported_codecs" ]
0 commit comments