From b6285c607f4d3db69246240e909cf6812f5d037c Mon Sep 17 00:00:00 2001 From: Jack Kleeman Date: Fri, 6 Dec 2024 14:42:36 +0000 Subject: [PATCH 1/3] Support headers in service to service call/send --- src/lib.rs | 19 +++++++++++++++++++ src/tests/async_result.rs | 1 + src/tests/calls.rs | 2 ++ src/tests/failures.rs | 1 + src/vm/mod.rs | 10 ++++++++++ src/vm/transitions/journal.rs | 10 +--------- 6 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a6df126..b94de83 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,6 +31,24 @@ pub struct Header { pub value: Cow<'static, str>, } +impl From for Header { + fn from(header: service_protocol::messages::Header) -> Self { + Self { + key: Cow::Owned(header.key), + value: Cow::Owned(header.value), + } + } +} + +impl From
for service_protocol::messages::Header { + fn from(header: Header) -> Self { + Self { + key: header.key.into(), + value: header.value.into(), + } + } +} + #[derive(Debug)] pub struct ResponseHead { pub status_code: u16, @@ -123,6 +141,7 @@ pub struct Target { pub handler: String, pub key: Option, pub idempotency_key: Option, + pub headers: Vec
, } #[derive(Debug, Hash, Clone, Copy, Eq, PartialEq)] diff --git a/src/tests/async_result.rs b/src/tests/async_result.rs index e0fafeb..97b634d 100644 --- a/src/tests/async_result.rs +++ b/src/tests/async_result.rs @@ -11,6 +11,7 @@ fn greeter_target() -> Target { handler: "greeter".to_string(), key: None, idempotency_key: None, + headers: Vec::new(), } } diff --git a/src/tests/calls.rs b/src/tests/calls.rs index d43b713..f062f7a 100644 --- a/src/tests/calls.rs +++ b/src/tests/calls.rs @@ -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(), ) @@ -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, diff --git a/src/tests/failures.rs b/src/tests/failures.rs index f0b4608..2ca12d4 100644 --- a/src/tests/failures.rs +++ b/src/tests/failures.rs @@ -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, diff --git a/src/vm/mod.rs b/src/vm/mod.rs index a8bd3c7..1ed251a 100644 --- a/src/vm/mod.rs +++ b/src/vm/mod.rs @@ -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) + .collect(), parameter: input, ..Default::default() }, @@ -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| { diff --git a/src/vm/transitions/journal.rs b/src/vm/transitions/journal.rs index 9af29fe..60864c9 100644 --- a/src/vm/transitions/journal.rs +++ b/src/vm/transitions/journal.rs @@ -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, @@ -121,14 +120,7 @@ impl TransitionAndReturn 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, }, )) From 8ef46cf4c51b404d17f392022e373011a9fb24ce Mon Sep 17 00:00:00 2001 From: Jack Kleeman Date: Fri, 6 Dec 2024 14:48:45 +0000 Subject: [PATCH 2/3] Fix failing lint --- src/tests/state.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tests/state.rs b/src/tests/state.rs index ee28a4b..bdca3fe 100644 --- a/src/tests/state.rs +++ b/src/tests/state.rs @@ -5,7 +5,6 @@ use assert2::let_assert; use bytes::Bytes; /// Normal state - fn get_state_handler(vm: &mut CoreVM) { vm.sys_input().unwrap(); @@ -349,7 +348,6 @@ mod only_lazy_state { } /// Eager state - mod eager { use super::*; From da7f00a53b363bb164952217879bedf84a44d534 Mon Sep 17 00:00:00 2001 From: Jack Kleeman Date: Mon, 9 Dec 2024 09:10:37 +0000 Subject: [PATCH 3/3] Move header conversions into service protocol crate --- src/lib.rs | 18 ------------------ src/service_protocol/messages.rs | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b94de83..db7b421 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,24 +31,6 @@ pub struct Header { pub value: Cow<'static, str>, } -impl From for Header { - fn from(header: service_protocol::messages::Header) -> Self { - Self { - key: Cow::Owned(header.key), - value: Cow::Owned(header.value), - } - } -} - -impl From
for service_protocol::messages::Header { - fn from(header: Header) -> Self { - Self { - key: header.key.into(), - value: header.value.into(), - } - } -} - #[derive(Debug)] pub struct ResponseHead { pub status_code: u16, diff --git a/src/service_protocol/messages.rs b/src/service_protocol/messages.rs index 72bd0ce..3ce2464 100644 --- a/src/service_protocol/messages.rs +++ b/src/service_protocol/messages.rs @@ -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::{ @@ -455,6 +457,24 @@ impl From for crate::TerminalFailure { } } +impl From
for crate::Header { + fn from(header: Header) -> Self { + Self { + key: Cow::Owned(header.key), + value: Cow::Owned(header.value), + } + } +} + +impl From for Header { + fn from(header: crate::Header) -> Self { + Self { + key: header.key.into(), + value: header.value.into(), + } + } +} + // --- Completion parsing #[derive(Debug)]