Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
format!("{}uprotocol/v1/uuid.proto", UPROTOCOL_BASE_URI),
// [impl->req~uri-data-model-proto~1]
format!("{}uprotocol/v1/uri.proto", UPROTOCOL_BASE_URI),
// [impl->req~uattributes-data-model-impl~1]
// [impl->req~uattributes-data-model-proto~1]
format!("{}uprotocol/v1/uattributes.proto", UPROTOCOL_BASE_URI),
format!("{}uprotocol/v1/ucode.proto", UPROTOCOL_BASE_URI),
// [impl->req~umessage-data-model-impl~1]
// [impl->req~umessage-data-model-proto~1]
format!("{}uprotocol/v1/umessage.proto", UPROTOCOL_BASE_URI),
// [impl->req~ustatus-data-model-impl~1]
// [impl->req~ustatus-data-model-proto~1]
Expand Down
4 changes: 2 additions & 2 deletions src/communication/default_notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

// [impl->req~up-language-comm-api-default-impl~1]
// [impl->dsn~communication-layer-impl-default~1]

use std::sync::Arc;

Expand Down Expand Up @@ -100,7 +100,7 @@ impl Notifier for SimpleNotifier {
#[cfg(test)]
mod tests {

// [utest->req~up-language-comm-api-default-impl~1]
// [utest->dsn~communication-layer-impl-default~1]

use super::*;

Expand Down
4 changes: 2 additions & 2 deletions src/communication/default_pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

// [impl->req~up-language-comm-api-default-impl~1]
// [impl->dsn~communication-layer-impl-default~1]

use std::{
collections::{hash_map::Entry, HashMap},
Expand Down Expand Up @@ -446,7 +446,7 @@ impl Subscriber for InMemorySubscriber {
#[cfg(test)]
mod tests {

// [utest->req~up-language-comm-api-default-impl~1]
// [utest->dsn~communication-layer-impl-default~1]

use super::*;

Expand Down
4 changes: 2 additions & 2 deletions src/communication/in_memory_rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

// [impl->req~up-language-comm-api-default-impl~1]
// [impl->dsn~communication-layer-impl-default~1]

use std::collections::hash_map::Entry;
use std::collections::HashMap;
Expand Down Expand Up @@ -288,7 +288,7 @@ impl RpcClient for InMemoryRpcClient {
#[cfg(test)]
mod tests {

// [utest->req~up-language-comm-api-default-impl~1]
// [utest->dsn~communication-layer-impl-default~1]

use super::*;

Expand Down
4 changes: 2 additions & 2 deletions src/communication/in_memory_rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

// [impl->req~up-language-comm-api-default-impl~1]
// [impl->dsn~communication-layer-impl-default~1]

use std::collections::hash_map::Entry;
use std::collections::HashMap;
Expand Down Expand Up @@ -285,7 +285,7 @@ impl RpcServer for InMemoryRpcServer {
#[cfg(test)]
mod tests {

// [utest->req~up-language-comm-api-default-impl~1]
// [utest->dsn~communication-layer-impl-default~1]

use super::*;

Expand Down
4 changes: 2 additions & 2 deletions src/communication/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{UListener, UStatus, UUri};
use super::{CallOptions, UPayload};

/// An error indicating a problem with sending a notification to another uEntity.
// [impl->req~up-language-comm-api~1]
// [impl->dsn~communication-layer-api-declaration~1]
#[derive(Debug)]
pub enum NotificationError {
/// Indicates that the given message cannot be sent because it is not a [valid Notification message](crate::NotificationValidator).
Expand All @@ -48,7 +48,7 @@ impl Error for NotificationError {}
///
/// Please refer to the
/// [Communication Layer API Specifications](https://github.com/eclipse-uprotocol/up-spec/blob/main/up-l2/api.adoc).
// [impl->req~up-language-comm-api~1]
// [impl->dsn~communication-layer-api-declaration~1]
#[cfg_attr(any(test, feature = "test-util"), mockall::automock)]
#[async_trait]
pub trait Notifier: Send + Sync {
Expand Down
8 changes: 4 additions & 4 deletions src/communication/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{UListener, UStatus, UUri};
use super::{CallOptions, UPayload};

/// An error indicating a problem with publishing a message to a topic.
// [impl->req~up-language-comm-api~1]
// [impl->dsn~communication-layer-api-declaration~1]
#[derive(Debug)]
pub enum PubSubError {
/// Indicates that the given message cannot be sent because it is not a [valid Publish message](crate::PublishValidator).
Expand All @@ -49,7 +49,7 @@ impl Error for PubSubError {}
///
/// Please refer to the
/// [Communication Layer API Specifications](https://github.com/eclipse-uprotocol/up-spec/blob/main/up-l2/api.adoc).
// [impl->req~up-language-comm-api~1]
// [impl->dsn~communication-layer-api-declaration~1]
#[async_trait]
pub trait Publisher: Send + Sync {
/// Publishes a message to a topic.
Expand All @@ -71,7 +71,7 @@ pub trait Publisher: Send + Sync {
) -> Result<(), PubSubError>;
}

// [impl->req~up-language-comm-api~1]
// [impl->dsn~communication-layer-api-declaration~1]
#[cfg_attr(any(test, feature = "test-util"), mockall::automock)]
pub trait SubscriptionChangeHandler: Send + Sync {
/// Invoked for each update to the subscription status for a given topic.
Expand All @@ -89,7 +89,7 @@ pub trait SubscriptionChangeHandler: Send + Sync {
///
/// Please refer to the
/// [Communication Layer API Specifications](https://github.com/eclipse-uprotocol/up-spec/blob/main/up-l2/api.adoc).
// [impl->req~up-language-comm-api~1]
// [impl->dsn~communication-layer-api-declaration~1]
#[async_trait]
pub trait Subscriber: Send + Sync {
/// Registers a handler to invoke for messages that have been published to a given topic.
Expand Down
8 changes: 4 additions & 4 deletions src/communication/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{UAttributes, UCode, UStatus, UUri};
use super::{CallOptions, UPayload};

/// An error indicating a problem with invoking a (remote) service operation.
// [impl->req~up-language-comm-api~1]
// [impl->dsn~communication-layer-api-declaration~1]
#[derive(Clone, Error, Debug)]
pub enum ServiceInvocationError {
/// Indicates that the calling uE requested to add/create something that already exists.
Expand Down Expand Up @@ -136,7 +136,7 @@ impl From<ServiceInvocationError> for UStatus {
/// Please refer to the
/// [Communication Layer API specification](https://github.com/eclipse-uprotocol/up-spec/blob/main/up-l2/api.adoc)
/// for details.
// [impl->req~up-language-comm-api~1]
// [impl->dsn~communication-layer-api-declaration~1]
#[cfg_attr(any(test, feature = "test-util"), mockall::automock)]
#[async_trait]
pub trait RpcClient: Send + Sync {
Expand Down Expand Up @@ -210,7 +210,7 @@ impl dyn RpcClient {

/// A handler for processing incoming RPC requests.
///
// [impl->req~up-language-comm-api~1]
// [impl->dsn~communication-layer-api-declaration~1]
#[cfg_attr(any(test, feature = "test-util"), mockall::automock)]
#[async_trait]
pub trait RequestHandler: Send + Sync {
Expand Down Expand Up @@ -246,7 +246,7 @@ pub trait RequestHandler: Send + Sync {
/// Please refer to the
/// [Communication Layer API specification](https://github.com/eclipse-uprotocol/up-spec/blob/main/up-l2/api.adoc)
/// for details.
// [impl->req~up-language-comm-api~1]
// [impl->dsn~communication-layer-api-declaration~1]
#[async_trait]
pub trait RpcServer {
/// Registers an endpoint for RPC requests.
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ mod cloudevents;
#[cfg(feature = "cloudevents")]
pub use cloudevents::{CloudEvent, CONTENT_TYPE_CLOUDEVENTS_PROTOBUF};

// [impl->dsn~communication-layer-api-namespace~1]
#[cfg(feature = "communication")]
pub mod communication;

Expand Down
11 changes: 2 additions & 9 deletions src/uattributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub use upriority::*;
pub use crate::up_core_api::uattributes::*;
use crate::UUID;

const UPRIORITY_DEFAULT: UPriority = UPriority::UPRIORITY_CS1;
pub(crate) const UPRIORITY_DEFAULT: UPriority = UPriority::UPRIORITY_CS1;

#[derive(Debug)]
pub enum UAttributesError {
Expand Down Expand Up @@ -62,9 +62,8 @@ impl UAttributes {
/// Checks if a given priority class is the default priority class.
///
/// Messages that do not have a priority class set explicity, are assigned to
/// the default prioritiy class.
/// the default priority class.
pub(crate) fn is_default_priority(prio: UPriority) -> bool {
// [impl->dsn~up-attributes-priority~1]
prio == UPRIORITY_DEFAULT
}

Expand Down Expand Up @@ -146,11 +145,9 @@ impl UAttributes {
pub fn check_expired(&self) -> Result<(), UAttributesError> {
let ttl = match self.ttl {
Some(t) if t > 0 => u64::from(t),
// [impl->dsn~up-attributes-ttl~1]
_ => return Ok(()),
};

// [impl->dsn~up-attributes-ttl-timeout~1]
if let Some(creation_time) = self.id.as_ref().and_then(UUID::get_time) {
let delta = match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
Ok(duration) => {
Expand Down Expand Up @@ -195,15 +192,11 @@ mod tests {
}

#[test_case(None, None, false; "for message without ID nor TTL")]
// [utest->dsn~up-attributes-ttl~1]
#[test_case(None, Some(0), false; "for message without ID with TTL 0")]
#[test_case(None, Some(500), false; "for message without ID with TTL")]
#[test_case(Some(build_n_ms_in_past(1000)), None, false; "for message with ID without TTL")]
// [utest->dsn~up-attributes-ttl~1]
#[test_case(Some(build_n_ms_in_past(1000)), Some(0), false; "for message with ID and TTL 0")]
// [utest->dsn~up-attributes-ttl-timeout~1]
#[test_case(Some(build_n_ms_in_past(1000)), Some(500), true; "for message with ID and expired TTL")]
// [utest->dsn~up-attributes-ttl-timeout~1]
#[test_case(Some(build_n_ms_in_past(1000)), Some(2000), false; "for message with ID and non-expired TTL")]
fn test_is_expired(id: Option<UUID>, ttl: Option<u32>, should_be_expired: bool) {
let attributes = UAttributes {
Expand Down
3 changes: 1 addition & 2 deletions src/umessage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,9 @@ impl UMessage {
self.attributes
.as_ref()
.and_then(|attribs| attribs.priority.enum_value().ok())
// [impl->dsn~up-attributes-priority~1]
.map(|prio| {
if prio == UPriority::UPRIORITY_UNSPECIFIED {
UPriority::UPRIORITY_CS1
crate::uattributes::UPRIORITY_DEFAULT
} else {
prio
}
Expand Down
Loading