Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guarantee uE implementors always get the correct UUID when calling UUIDBuilder::build() by using internally held singleton #74

465 changes: 459 additions & 6 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ bytes = { version = "1.5" }
chrono = { version = "0.4.32" } chrono = { version = "0.4.32" }
cloudevents-sdk = { version = "0.7", optional = true } cloudevents-sdk = { version = "0.7", optional = true }
mediatype = "0.19" mediatype = "0.19"
once_cell = { version = "1.19" }
protobuf = { version = "3.3" } protobuf = { version = "3.3" }
rand = { version = "0.8" } rand = { version = "0.8" }
regex = { version = "1.10" } regex = { version = "1.10" }
Expand All @@ -58,4 +59,6 @@ protoc-bin-vendored = { version = "3.0" }
reqwest = { version = "0.12", features = ["blocking"] } reqwest = { version = "0.12", features = ["blocking"] }


[dev-dependencies] [dev-dependencies]
async-std = { version = "1.12.0", features = ["attributes"] }
futures = { version = "0.3.30" }
test-case = { version = "3.3" } test-case = { version = "3.3" }
2 changes: 1 addition & 1 deletion src/cloudevents.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ mod tests {
.into(), .into(),
..Default::default() ..Default::default()
}; };
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let payload = UPayload { let payload = UPayload {
data: Some(crate::up_core_api::upayload::upayload::Data::Value( data: Some(crate::up_core_api::upayload::upayload::Data::Value(
Any::default().value, Any::default().value,
Expand Down
36 changes: 18 additions & 18 deletions src/cloudevents/cloudeventvalidator.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ mod tests {


#[test] #[test]
fn validate_cloud_event_version_when_valid() { fn validate_cloud_event_version_when_valid() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let builder = build_base_cloud_event_builder_for_test() let builder = build_base_cloud_event_builder_for_test()
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_cloudevent_type()) .ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_cloudevent_type())
.id(uuid); .id(uuid);
Expand Down Expand Up @@ -726,7 +726,7 @@ mod tests {


#[test] #[test]
fn validate_cloud_event_id_when_valid() { fn validate_cloud_event_id_when_valid() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let builder = build_base_cloud_event_builder_for_test() let builder = build_base_cloud_event_builder_for_test()
.ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_cloudevent_type()) .ty(UMessageType::UMESSAGE_TYPE_PUBLISH.to_cloudevent_type())
.id(uuid); .id(uuid);
Expand Down Expand Up @@ -765,7 +765,7 @@ mod tests {


#[test] #[test]
fn test_publish_type_cloudevent_is_valid_when_everything_is_valid_local() { fn test_publish_type_cloudevent_is_valid_when_everything_is_valid_local() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let event = build_base_cloud_event_builder_for_test() let event = build_base_cloud_event_builder_for_test()
.id(uuid) .id(uuid)
.source("/body.access/1/door.front_left#Door".to_string()) .source("/body.access/1/door.front_left#Door".to_string())
Expand All @@ -784,7 +784,7 @@ mod tests {


#[test] #[test]
fn test_publish_type_cloudevent_is_valid_when_everything_is_valid_remote() { fn test_publish_type_cloudevent_is_valid_when_everything_is_valid_remote() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let uri = "//VCU.myvin/body.access/1/door.front_left#Door"; let uri = "//VCU.myvin/body.access/1/door.front_left#Door";
let event = build_base_cloud_event_builder_for_test() let event = build_base_cloud_event_builder_for_test()
.id(uuid) .id(uuid)
Expand All @@ -804,7 +804,7 @@ mod tests {


#[test] #[test]
fn test_publish_type_cloudevent_is_valid_when_everything_is_valid_remote_with_a_sink() { fn test_publish_type_cloudevent_is_valid_when_everything_is_valid_remote_with_a_sink() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let uri = "//VCU.myvin/body.access/1/door.front_left#Door"; let uri = "//VCU.myvin/body.access/1/door.front_left#Door";
let sink = "//bo.cloud/petapp"; let sink = "//bo.cloud/petapp";
let event = build_base_cloud_event_builder_for_test() let event = build_base_cloud_event_builder_for_test()
Expand All @@ -822,7 +822,7 @@ mod tests {


#[test] #[test]
fn test_publish_type_cloudevent_is_not_valid_when_remote_with_invalid_sink() { fn test_publish_type_cloudevent_is_not_valid_when_remote_with_invalid_sink() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let uri = "//VCU.myvin/body.access/1/door.front_left#Door"; let uri = "//VCU.myvin/body.access/1/door.front_left#Door";
let sink = "//bo.cloud"; let sink = "//bo.cloud";
let event = build_base_cloud_event_builder_for_test() let event = build_base_cloud_event_builder_for_test()
Expand All @@ -841,7 +841,7 @@ mod tests {


#[test] #[test]
fn test_publish_type_cloudevent_is_not_valid_when_source_is_empty() { fn test_publish_type_cloudevent_is_not_valid_when_source_is_empty() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let event = build_base_cloud_event_builder_for_test() let event = build_base_cloud_event_builder_for_test()
.id(uuid) .id(uuid)
.source("/".to_string()) .source("/".to_string())
Expand Down Expand Up @@ -891,7 +891,7 @@ mod tests {


#[test] #[test]
fn test_notification_type_cloudevent_is_valid_when_everything_is_valid() { fn test_notification_type_cloudevent_is_valid_when_everything_is_valid() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let uri = "/body.access/1/door.front_left#Door"; let uri = "/body.access/1/door.front_left#Door";
let sink = "//bo.cloud/petapp"; let sink = "//bo.cloud/petapp";
let event = build_base_cloud_event_builder_for_test() let event = build_base_cloud_event_builder_for_test()
Expand All @@ -909,7 +909,7 @@ mod tests {


#[test] #[test]
fn test_notification_type_cloudevent_is_not_valid_missing_sink() { fn test_notification_type_cloudevent_is_not_valid_missing_sink() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let uri = UUri::from_str("/body.access/1/door.front_left#Door").unwrap(); let uri = UUri::from_str("/body.access/1/door.front_left#Door").unwrap();
let event = build_base_cloud_event_builder_for_test() let event = build_base_cloud_event_builder_for_test()
.id(uuid) .id(uuid)
Expand All @@ -926,7 +926,7 @@ mod tests {


#[test] #[test]
fn test_notification_type_cloudevent_is_not_valid_invalid_sink() { fn test_notification_type_cloudevent_is_not_valid_invalid_sink() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let uri = UUri::from_str("/body.access/1/door.front_left#Door").unwrap(); let uri = UUri::from_str("/body.access/1/door.front_left#Door").unwrap();
let sink = UUri::from_str("//bo.cloud").unwrap(); let sink = UUri::from_str("//bo.cloud").unwrap();
let event = build_base_cloud_event_builder_for_test() let event = build_base_cloud_event_builder_for_test()
Expand All @@ -945,7 +945,7 @@ mod tests {


#[test] #[test]
fn test_request_type_cloudevent_is_valid_when_everything_is_valid() { fn test_request_type_cloudevent_is_valid_when_everything_is_valid() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let source = "//bo.cloud/petapp//rpc.response"; let source = "//bo.cloud/petapp//rpc.response";
let sink = "//VCU.myvin/body.access/1/rpc.UpdateDoor"; let sink = "//VCU.myvin/body.access/1/rpc.UpdateDoor";
let event = build_base_cloud_event_builder_for_test() let event = build_base_cloud_event_builder_for_test()
Expand All @@ -964,7 +964,7 @@ mod tests {


#[test] #[test]
fn test_request_type_cloudevent_is_not_valid_invalid_source() { fn test_request_type_cloudevent_is_not_valid_invalid_source() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let source = "//bo.cloud/petapp//dog"; let source = "//bo.cloud/petapp//dog";
let sink = "//VCU.myvin/body.access/1/rpc.UpdateDoor"; let sink = "//VCU.myvin/body.access/1/rpc.UpdateDoor";
let event = build_base_cloud_event_builder_for_test() let event = build_base_cloud_event_builder_for_test()
Expand All @@ -983,7 +983,7 @@ mod tests {


#[test] #[test]
fn test_request_type_cloudevent_is_not_valid_missing_sink() { fn test_request_type_cloudevent_is_not_valid_missing_sink() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let source = "//bo.cloud/petapp//rpc.response"; let source = "//bo.cloud/petapp//rpc.response";
let event = build_base_cloud_event_builder_for_test() let event = build_base_cloud_event_builder_for_test()
.id(uuid) .id(uuid)
Expand All @@ -1004,7 +1004,7 @@ mod tests {


#[test] #[test]
fn test_request_type_cloudevent_is_not_valid_invalid_sink_not_rpc_command() { fn test_request_type_cloudevent_is_not_valid_invalid_sink_not_rpc_command() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let source = "//bo.cloud/petapp//rpc.response"; let source = "//bo.cloud/petapp//rpc.response";
let sink = "//VCU.myvin/body.access/1/UpdateDoor"; let sink = "//VCU.myvin/body.access/1/UpdateDoor";
let event = build_base_cloud_event_builder_for_test() let event = build_base_cloud_event_builder_for_test()
Expand All @@ -1023,7 +1023,7 @@ mod tests {


#[test] #[test]
fn test_response_type_cloudevent_is_valid_when_everything_is_valid() { fn test_response_type_cloudevent_is_valid_when_everything_is_valid() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let source = "//VCU.myvin/body.access/1/rpc.UpdateDoor"; let source = "//VCU.myvin/body.access/1/rpc.UpdateDoor";
let sink = "//bo.cloud/petapp//rpc.response"; let sink = "//bo.cloud/petapp//rpc.response";
let event = build_base_cloud_event_builder_for_test() let event = build_base_cloud_event_builder_for_test()
Expand All @@ -1042,7 +1042,7 @@ mod tests {


#[test] #[test]
fn test_response_type_cloudevent_is_not_valid_invalid_source() { fn test_response_type_cloudevent_is_not_valid_invalid_source() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let source = "//VCU.myvin/body.access/1/UpdateDoor"; let source = "//VCU.myvin/body.access/1/UpdateDoor";
let sink = "//bo.cloud/petapp//rpc.response"; let sink = "//bo.cloud/petapp//rpc.response";
let event = build_base_cloud_event_builder_for_test() let event = build_base_cloud_event_builder_for_test()
Expand All @@ -1061,7 +1061,7 @@ mod tests {


#[test] #[test]
fn test_response_type_cloudevent_is_not_valid_missing_sink_and_invalid_source() { fn test_response_type_cloudevent_is_not_valid_missing_sink_and_invalid_source() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let source = "//VCU.myvin/body.access/1/UpdateDoor"; let source = "//VCU.myvin/body.access/1/UpdateDoor";
let event = build_base_cloud_event_builder_for_test() let event = build_base_cloud_event_builder_for_test()
.id(uuid) .id(uuid)
Expand All @@ -1078,7 +1078,7 @@ mod tests {


#[test] #[test]
fn test_response_type_cloudevent_is_not_valid_invalid_source_not_rpc_command() { fn test_response_type_cloudevent_is_not_valid_invalid_source_not_rpc_command() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let source = "//bo.cloud/petapp/1/dog"; let source = "//bo.cloud/petapp/1/dog";
let sink = "//VCU.myvin/body.access/1/UpdateDoor"; let sink = "//VCU.myvin/body.access/1/UpdateDoor";
let event = build_base_cloud_event_builder_for_test() let event = build_base_cloud_event_builder_for_test()
Expand Down
2 changes: 1 addition & 1 deletion src/cloudevents/ucloudeventbuilder.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl UCloudEventBuilder {
/// Creates the string representation of a `UUIDv8` as defined by /// Creates the string representation of a `UUIDv8` as defined by
/// [RFC 4122](https://www.rfc-editor.org/rfc/rfc4122.html#section-3) /// [RFC 4122](https://www.rfc-editor.org/rfc/rfc4122.html#section-3)
fn create_cloudevent_id() -> String { fn create_cloudevent_id() -> String {
UUIDBuilder::new().build().to_hyphenated_string() UUIDBuilder::build().to_hyphenated_string()
} }


/// Creates a `CloudEvent` for an event for the use case of an RPC Request message. /// Creates a `CloudEvent` for an event for the use case of an RPC Request message.
Expand Down
10 changes: 5 additions & 5 deletions src/cloudevents/ucloudeventutils.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ mod tests {


#[test] #[test]
fn test_extract_creation_timestamp_from_cloud_event_uuidv8_id_when_uuidv8_id_is_valid() { fn test_extract_creation_timestamp_from_cloud_event_uuidv8_id_when_uuidv8_id_is_valid() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let builder = build_base_cloud_event_for_test(); let builder = build_base_cloud_event_for_test();
let cloud_event = builder.id(uuid).build().unwrap(); let cloud_event = builder.id(uuid).build().unwrap();


Expand Down Expand Up @@ -894,7 +894,7 @@ mod tests {


#[test] #[test]
fn test_cloudevent_is_not_expired_when_ttl_is_minus_one() { fn test_cloudevent_is_not_expired_when_ttl_is_minus_one() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let builder = build_base_cloud_event_for_test() let builder = build_base_cloud_event_for_test()
.extension("ttl", -1) .extension("ttl", -1)
.id(uuid); .id(uuid);
Expand All @@ -905,7 +905,7 @@ mod tests {


#[test] #[test]
fn test_cloudevent_is_not_expired_when_ttl_is_large_number_mili() { fn test_cloudevent_is_not_expired_when_ttl_is_large_number_mili() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let builder = build_base_cloud_event_for_test() let builder = build_base_cloud_event_for_test()
.extension("ttl", i64::MAX) .extension("ttl", i64::MAX)
.id(uuid); .id(uuid);
Expand All @@ -919,7 +919,7 @@ mod tests {
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;


let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let builder = build_base_cloud_event_for_test() let builder = build_base_cloud_event_for_test()
.extension("ttl", 1) .extension("ttl", 1)
.id(uuid); .id(uuid);
Expand All @@ -932,7 +932,7 @@ mod tests {


#[test] #[test]
fn test_cloudevent_has_a_v8_uuid() { fn test_cloudevent_has_a_v8_uuid() {
let uuid = UUIDBuilder::new().build(); let uuid = UUIDBuilder::build();
let builder = build_base_cloud_event_for_test().id(uuid); let builder = build_base_cloud_event_for_test().id(uuid);
let cloud_event = builder.build().unwrap(); let cloud_event = builder.build().unwrap();


Expand Down
5 changes: 2 additions & 3 deletions src/uattributes.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ impl UAttributes {
/// ///
/// ```rust /// ```rust
/// use up_rust::{CallOptions, UAttributes, UMessageType, UPriority, UUIDBuilder, UUri}; /// use up_rust::{CallOptions, UAttributes, UMessageType, UPriority, UUIDBuilder, UUri};
///
/// # fn main() -> Result<(), Box<dyn std::error::Error>> { /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let uuid_builder = UUIDBuilder::new(); /// let message_id = UUIDBuilder::build();
/// let message_id = uuid_builder.build();
/// let method_to_invoke = UUri::try_from("my-vehicle/cabin/1/rpc.doors")?; /// let method_to_invoke = UUri::try_from("my-vehicle/cabin/1/rpc.doors")?;
/// let reply_to_address = UUri::try_from("my-cloud/dashboard/1/rpc.response")?; /// let reply_to_address = UUri::try_from("my-cloud/dashboard/1/rpc.response")?;
/// let options = CallOptions { /// let options = CallOptions {
Expand Down
Loading