-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathwire_primitives.rs
More file actions
78 lines (72 loc) Β· 2.85 KB
/
Copy pathwire_primitives.rs
File metadata and controls
78 lines (72 loc) Β· 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2023 The RocketMQ Rust Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use rocketmq_model::common::hasher::string_hasher::JavaStringHasher;
use rocketmq_model::common::key_builder::KeyBuilder;
use rocketmq_model::common::sys_flag::message_sys_flag::MessageSysFlag;
use rocketmq_model::common::sys_flag::topic_sys_flag;
use rocketmq_protocol::version::RocketMqVersion;
#[test]
fn java_hash_golden_covers_utf16_and_wrapping() {
assert_eq!(JavaStringHasher::hash_str(""), 0);
assert_eq!(JavaStringHasher::hash_str("hello"), 99_162_322);
assert_eq!(JavaStringHasher::hash_str("π"), 1_772_899);
assert_eq!(JavaStringHasher::hash_str(&"a".repeat(1000)), 904_019_584);
}
#[test]
fn pop_retry_and_polling_keys_match_frozen_grammar() {
assert_eq!(
KeyBuilder::build_pop_retry_topic_v1("orders", "group-a"),
"%RETRY%group-a_orders"
);
assert_eq!(
KeyBuilder::build_pop_retry_topic_v2("orders", "group-a"),
"%RETRY%group-a+orders"
);
assert_eq!(
KeyBuilder::build_polling_key("orders", "group-a", -1),
"orders@group-a@-1"
);
assert_eq!(
KeyBuilder::parse_normal_topic("%RETRY%group-a+orders", "group-a"),
"orders"
);
}
#[test]
fn sys_flag_and_version_ordinals_remain_wire_compatible() {
let flag = MessageSysFlag::COMPRESSED_FLAG | MessageSysFlag::TRANSACTION_COMMIT_TYPE;
assert!(MessageSysFlag::check(flag, MessageSysFlag::COMPRESSED_FLAG));
assert_eq!(
MessageSysFlag::get_transaction_value(flag),
MessageSysFlag::TRANSACTION_COMMIT_TYPE
);
assert!(topic_sys_flag::has_unit_flag(topic_sys_flag::build_sys_flag(
true, false
)));
assert_eq!(RocketMqVersion::V3_0_0_SNAPSHOT.ordinal(), 0);
assert_eq!(RocketMqVersion::V5_3_1_SNAPSHOT.name(), "V5_3_1_SNAPSHOT");
}
#[test]
fn protocol_version_is_an_exact_model_reexport_without_a_reverse_dependency() {
fn protocol(value: rocketmq_protocol::version::RocketMqVersion) -> rocketmq_protocol::version::RocketMqVersion {
value
}
fn model(value: rocketmq_model::version::RocketMqVersion) -> rocketmq_model::version::RocketMqVersion {
value
}
let value = rocketmq_protocol::version::RocketMqVersion::V5_3_1_SNAPSHOT;
assert_eq!(
model(protocol(value)).ordinal(),
rocketmq_model::version::CURRENT_VERSION.ordinal()
);
}