Skip to content

Commit

Permalink
Add DummyPrimitives for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHecart committed Feb 26, 2021
1 parent ae8dd2b commit 4748b39
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 74 deletions.
72 changes: 2 additions & 70 deletions zenoh/benches/tables_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,85 +15,17 @@
extern crate criterion;
use async_std::sync::Arc;
use async_std::task;
use async_trait::async_trait;
use criterion::{BenchmarkId, Criterion};
use zenoh::net::protocol::core::{
whatami, CongestionControl, PeerId, QueryConsolidation, QueryTarget, Reliability, ResKey,
SubInfo, SubMode, ZInt,
whatami, CongestionControl, PeerId, Reliability, SubInfo, SubMode,
};
use zenoh::net::protocol::io::RBuf;
use zenoh::net::protocol::proto::{DataInfo, RoutingContext};
use zenoh::net::protocol::session::Primitives;
use zenoh::net::protocol::session::DummyPrimitives;
use zenoh::net::routing::pubsub::*;
use zenoh::net::routing::resource::*;
use zenoh::net::routing::router::Tables;
use zenoh::net::routing::OutSession;

struct DummyPrimitives {}

#[async_trait]
impl Primitives for DummyPrimitives {
async fn decl_resource(&self, _rid: ZInt, _reskey: &ResKey) {}
async fn forget_resource(&self, _rid: ZInt) {}

async fn decl_publisher(&self, _reskey: &ResKey, _routing_context: Option<RoutingContext>) {}
async fn forget_publisher(&self, _reskey: &ResKey, _routing_context: Option<RoutingContext>) {}

async fn decl_subscriber(
&self,
_reskey: &ResKey,
_sub_info: &SubInfo,
_routing_context: Option<RoutingContext>,
) {
}
async fn forget_subscriber(&self, _reskey: &ResKey, _routing_context: Option<RoutingContext>) {}

async fn decl_queryable(&self, _reskey: &ResKey, _routing_context: Option<RoutingContext>) {}
async fn forget_queryable(&self, _reskey: &ResKey, _routing_context: Option<RoutingContext>) {}

async fn send_data(
&self,
_reskey: &ResKey,
_payload: RBuf,
_reliability: Reliability,
_congestion_control: CongestionControl,
_info: Option<DataInfo>,
_routing_context: Option<RoutingContext>,
) {
}
async fn send_query(
&self,
_reskey: &ResKey,
_predicate: &str,
_qid: ZInt,
_target: QueryTarget,
_consolidation: QueryConsolidation,
_routing_context: Option<RoutingContext>,
) {
}
async fn send_reply_data(
&self,
_qid: ZInt,
_source_kind: ZInt,
_replier_id: PeerId,
_reskey: ResKey,
_info: Option<DataInfo>,
_payload: RBuf,
) {
}
async fn send_reply_final(&self, _qid: ZInt) {}
async fn send_pull(
&self,
_is_final: bool,
_reskey: &ResKey,
_pull_id: ZInt,
_max_samples: &Option<ZInt>,
) {
}

async fn send_close(&self) {}
}

fn tables_bench(c: &mut Criterion) {
task::block_on(async {
let mut tables = Tables::new(PeerId::new(0, [0; 16]), whatami::ROUTER, None);
Expand Down
72 changes: 72 additions & 0 deletions zenoh/src/net/protocol/session/primitives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,75 @@ pub trait Primitives {

async fn send_close(&self);
}

#[derive(Default)]
pub struct DummyPrimitives;

impl DummyPrimitives {
pub fn new() -> Self {
Self
}
}

#[async_trait]
impl Primitives for DummyPrimitives {
async fn decl_resource(&self, _rid: ZInt, _reskey: &ResKey) {}
async fn forget_resource(&self, _rid: ZInt) {}

async fn decl_publisher(&self, _reskey: &ResKey, _routing_context: Option<RoutingContext>) {}
async fn forget_publisher(&self, _reskey: &ResKey, _routing_context: Option<RoutingContext>) {}

async fn decl_subscriber(
&self,
_reskey: &ResKey,
_sub_info: &SubInfo,
_routing_context: Option<RoutingContext>,
) {
}
async fn forget_subscriber(&self, _reskey: &ResKey, _routing_context: Option<RoutingContext>) {}

async fn decl_queryable(&self, _reskey: &ResKey, _routing_context: Option<RoutingContext>) {}
async fn forget_queryable(&self, _reskey: &ResKey, _routing_context: Option<RoutingContext>) {}

async fn send_data(
&self,
_reskey: &ResKey,
_payload: RBuf,
_reliability: Reliability,
_congestion_control: CongestionControl,
_info: Option<DataInfo>,
_routing_context: Option<RoutingContext>,
) {
}
async fn send_query(
&self,
_reskey: &ResKey,
_predicate: &str,
_qid: ZInt,
_target: QueryTarget,
_consolidation: QueryConsolidation,
_routing_context: Option<RoutingContext>,
) {
}
async fn send_reply_data(
&self,
_qid: ZInt,
_source_kind: ZInt,
_replier_id: PeerId,
_reskey: ResKey,
_info: Option<DataInfo>,
_payload: RBuf,
) {
}
async fn send_reply_final(&self, _qid: ZInt) {}
async fn send_pull(
&self,
_is_final: bool,
_reskey: &ResKey,
_pull_id: ZInt,
_max_samples: &Option<ZInt>,
) {
}

async fn send_close(&self) {}
}
8 changes: 4 additions & 4 deletions zenoh/tests/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use zenoh::net::protocol::core::{
};
use zenoh::net::protocol::io::RBuf;
use zenoh::net::protocol::proto::{DataInfo, RoutingContext};
use zenoh::net::protocol::session::Primitives;
use zenoh::net::protocol::session::{DummyPrimitives, Primitives};
use zenoh::net::routing::router::*;
use zenoh::net::routing::OutSession;

Expand All @@ -35,7 +35,7 @@ fn base_test() {
whatami::CLIENT,
Some(HLC::default()),
);
let primitives = Arc::new(ClientPrimitives::new());
let primitives = Arc::new(DummyPrimitives::new());
let face = tables
.open_face(
PeerId::new(0, [0; 16]),
Expand Down Expand Up @@ -141,7 +141,7 @@ fn match_test() {
whatami::CLIENT,
Some(HLC::default()),
);
let primitives = Arc::new(ClientPrimitives::new());
let primitives = Arc::new(DummyPrimitives::new());
let face = tables
.open_face(
PeerId::new(0, [0; 16]),
Expand Down Expand Up @@ -186,7 +186,7 @@ fn clean_test() {
Some(HLC::default()),
);

let primitives = Arc::new(ClientPrimitives::new());
let primitives = Arc::new(DummyPrimitives::new());
let face0 = tables
.open_face(
PeerId::new(0, [0; 16]),
Expand Down

0 comments on commit 4748b39

Please sign in to comment.