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

Support headers in service to service call/send #23

Merged
merged 3 commits into from
Dec 9, 2024
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
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ pub struct Target {
pub handler: String,
pub key: Option<String>,
pub idempotency_key: Option<String>,
pub headers: Vec<Header>,
}

#[derive(Debug, Hash, Clone, Copy, Eq, PartialEq)]
Expand Down
20 changes: 20 additions & 0 deletions src/service_protocol/messages.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::borrow::Cow;

use crate::service_protocol::messages::get_state_keys_entry_message::StateKeys;
use crate::service_protocol::{MessageHeader, MessageType};
use crate::vm::errors::{
Expand Down Expand Up @@ -455,6 +457,24 @@ impl From<Failure> for crate::TerminalFailure {
}
}

impl From<Header> for crate::Header {
fn from(header: Header) -> Self {
Self {
key: Cow::Owned(header.key),
value: Cow::Owned(header.value),
}
}
}

impl From<crate::Header> for Header {
fn from(header: crate::Header) -> Self {
Self {
key: header.key.into(),
value: header.value.into(),
}
}
}

// --- Completion parsing

#[derive(Debug)]
Expand Down
1 change: 1 addition & 0 deletions src/tests/async_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fn greeter_target() -> Target {
handler: "greeter".to_string(),
key: None,
idempotency_key: None,
headers: Vec::new(),
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/tests/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fn call_then_get_invocation_id_then_cancel_invocation() {
handler: "MyHandler".to_string(),
key: None,
idempotency_key: None,
headers: Vec::new(),
},
Bytes::new(),
)
Expand Down Expand Up @@ -113,6 +114,7 @@ fn send_then_get_invocation_id_then_cancel_invocation() {
handler: "MyHandler".to_string(),
key: None,
idempotency_key: None,
headers: Vec::new(),
},
Bytes::new(),
None,
Expand Down
1 change: 1 addition & 0 deletions src/tests/failures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ fn one_way_call_entry_mismatch() {
handler: "greet".to_owned(),
key: Some("my-key".to_owned()),
idempotency_key: None,
headers: Vec::new(),
},
Bytes::from_static(b"456"),
None,
Expand Down
2 changes: 0 additions & 2 deletions src/tests/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use assert2::let_assert;
use bytes::Bytes;

/// Normal state

fn get_state_handler(vm: &mut CoreVM) {
vm.sys_input().unwrap();

Expand Down Expand Up @@ -349,7 +348,6 @@ mod only_lazy_state {
}

/// Eager state

mod eager {
use super::*;

Expand Down
10 changes: 10 additions & 0 deletions src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,11 @@ impl super::VM for CoreVM {
handler_name: target.handler,
key: target.key.unwrap_or_default(),
idempotency_key: target.idempotency_key,
headers: target
.headers
.into_iter()
.map(crate::service_protocol::messages::Header::from)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can do simply Into::into

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree, but stylistically i much prefer seeing what type its becoming

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for what Jack said. Into::into is really not helping for readability.

.collect(),
parameter: input,
..Default::default()
},
Expand Down Expand Up @@ -491,6 +496,11 @@ impl super::VM for CoreVM {
handler_name: target.handler,
key: target.key.unwrap_or_default(),
idempotency_key: target.idempotency_key,
headers: target
.headers
.into_iter()
.map(crate::service_protocol::messages::Header::from)
.collect(),
parameter: input,
invoke_time: delay
.map(|d| {
Expand Down
10 changes: 1 addition & 9 deletions src/vm/transitions/journal.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::retries::NextRetry;
use crate::service_protocol::messages;
use crate::service_protocol::messages::{
run_entry_message, CompletableEntryMessage, EntryMessage, EntryMessageHeaderEq,
InputEntryMessage, RestateMessage, RunEntryMessage, WriteableRestateMessage,
Expand Down Expand Up @@ -121,14 +120,7 @@ impl TransitionAndReturn<Context, SysInput> for State {
invocation_id: start_info.debug_id.clone(),
random_seed: compute_random_seed(&start_info.id),
key: start_info.key.clone(),
headers: msg
.headers
.into_iter()
.map(|messages::Header { key, value }| Header {
key: key.into(),
value: value.into(),
})
.collect(),
headers: msg.headers.into_iter().map(Header::from).collect(),
input: msg.value,
},
))
Expand Down