use bytes::Bytes;
use rocketmq_protocol::protocol::header::empty_header::EmptyHeader;
use rocketmq_protocol::protocol::remoting_command_defaults::initialize_remoting_command_defaults;
use rocketmq_protocol::protocol::remoting_command_defaults::RemotingCommandDefaults;
use rocketmq_protocol::protocol::remoting_command_defaults::RemotingCommandFactory;
use rocketmq_protocol::protocol::SerializeType;
use rocketmq_protocol::RemotingCommand;
#[test]
fn business_factories_share_immutable_application_defaults() {
let defaults = RemotingCommandDefaults::new(4242, SerializeType::ROCKETMQ);
initialize_remoting_command_defaults(defaults).expect("application defaults should initialize");
let explicit_factory = RemotingCommandFactory::new(defaults);
let commands = [
RemotingCommand::new_request(10, Bytes::from_static(b"body")),
RemotingCommand::create_request_command(11, EmptyHeader {}),
RemotingCommand::create_remoting_command(12),
RemotingCommand::create_success_response_command(),
RemotingCommand::create_response_command_with_code(1),
RemotingCommand::create_response_command_with_code_and_header(1, EmptyHeader {}),
RemotingCommand::create_response_command_with_code_remark(1, "error"),
RemotingCommand::create_success_response_command_with_header(EmptyHeader {}),
RemotingCommand::create_java_default_error_response_command(),
RemotingCommand::create_java_default_error_response_command_with_header(EmptyHeader {}),
explicit_factory.create_request_command(13, EmptyHeader {}),
explicit_factory.create_success_response_command(),
explicit_factory.create_java_default_error_response_command(),
];
for command in commands {
assert_eq!(command.version(), 4242);
assert_eq!(command.serialize_type(), SerializeType::ROCKETMQ);
}
let neutral = RemotingCommand::default();
assert_eq!(neutral.version(), 0);
assert_eq!(neutral.serialize_type(), SerializeType::JSON);
}