-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from restatedev/other-e2e-tests
Other e2e tests
- Loading branch information
Showing
8 changed files
with
217 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,39 @@ | ||
exclusions: | ||
"alwaysSuspending": | ||
- "dev.restate.sdktesting.tests.AwaitTimeout" | ||
- "dev.restate.sdktesting.tests.ServiceToServiceCommunication" | ||
- "dev.restate.sdktesting.tests.SideEffect" | ||
- "dev.restate.sdktesting.tests.Sleep" | ||
- "dev.restate.sdktesting.tests.SleepWithFailures" | ||
- "dev.restate.sdktesting.tests.State" | ||
- "dev.restate.sdktesting.tests.UpgradeWithInFlightInvocation" | ||
- "dev.restate.sdktesting.tests.UpgradeWithNewInvocation" | ||
- "dev.restate.sdktesting.tests.UserErrors" | ||
- "dev.restate.sdktesting.tests.WorkflowAPI" | ||
- "dev.restate.sdktesting.tests.AwaitTimeout" | ||
- "dev.restate.sdktesting.tests.ServiceToServiceCommunication" | ||
- "dev.restate.sdktesting.tests.SideEffect" | ||
- "dev.restate.sdktesting.tests.Sleep" | ||
- "dev.restate.sdktesting.tests.SleepWithFailures" | ||
- "dev.restate.sdktesting.tests.UpgradeWithInFlightInvocation" | ||
- "dev.restate.sdktesting.tests.UpgradeWithNewInvocation" | ||
- "dev.restate.sdktesting.tests.UserErrors" | ||
- "dev.restate.sdktesting.tests.WorkflowAPI" | ||
"default": | ||
- "dev.restate.sdktesting.tests.AwaitTimeout" | ||
- "dev.restate.sdktesting.tests.CallOrdering" | ||
- "dev.restate.sdktesting.tests.CancelInvocation" | ||
- "dev.restate.sdktesting.tests.Ingress" | ||
- "dev.restate.sdktesting.tests.KafkaIngress" | ||
- "dev.restate.sdktesting.tests.KillInvocation" | ||
- "dev.restate.sdktesting.tests.PrivateService" | ||
- "dev.restate.sdktesting.tests.ServiceToServiceCommunication" | ||
- "dev.restate.sdktesting.tests.Sleep" | ||
- "dev.restate.sdktesting.tests.SleepWithFailures" | ||
- "dev.restate.sdktesting.tests.State" | ||
- "dev.restate.sdktesting.tests.UpgradeWithInFlightInvocation" | ||
- "dev.restate.sdktesting.tests.UpgradeWithNewInvocation" | ||
- "dev.restate.sdktesting.tests.UserErrors" | ||
- "dev.restate.sdktesting.tests.WorkflowAPI" | ||
"lazyState": | ||
- "dev.restate.sdktesting.tests.State" | ||
- "dev.restate.sdktesting.tests.AwaitTimeout" | ||
- "dev.restate.sdktesting.tests.CallOrdering" | ||
- "dev.restate.sdktesting.tests.CancelInvocation" | ||
- "dev.restate.sdktesting.tests.Ingress" | ||
- "dev.restate.sdktesting.tests.KillInvocation" | ||
- "dev.restate.sdktesting.tests.ServiceToServiceCommunication" | ||
- "dev.restate.sdktesting.tests.Sleep" | ||
- "dev.restate.sdktesting.tests.SleepWithFailures" | ||
- "dev.restate.sdktesting.tests.UpgradeWithInFlightInvocation" | ||
- "dev.restate.sdktesting.tests.UpgradeWithNewInvocation" | ||
- "dev.restate.sdktesting.tests.UserErrors" | ||
- "dev.restate.sdktesting.tests.WorkflowAPI" | ||
"persistedTimers": | ||
- "dev.restate.sdktesting.tests.ServiceToServiceCommunication" | ||
- "dev.restate.sdktesting.tests.Sleep" | ||
- "dev.restate.sdktesting.tests.Sleep" | ||
"singleThreadSinglePartition": | ||
- "dev.restate.sdktesting.tests.AwaitTimeout" | ||
- "dev.restate.sdktesting.tests.CallOrdering" | ||
- "dev.restate.sdktesting.tests.CancelInvocation" | ||
- "dev.restate.sdktesting.tests.Ingress" | ||
- "dev.restate.sdktesting.tests.KafkaIngress" | ||
- "dev.restate.sdktesting.tests.KillInvocation" | ||
- "dev.restate.sdktesting.tests.PrivateService" | ||
- "dev.restate.sdktesting.tests.ServiceToServiceCommunication" | ||
- "dev.restate.sdktesting.tests.Sleep" | ||
- "dev.restate.sdktesting.tests.SleepWithFailures" | ||
- "dev.restate.sdktesting.tests.State" | ||
- "dev.restate.sdktesting.tests.UpgradeWithInFlightInvocation" | ||
- "dev.restate.sdktesting.tests.UpgradeWithNewInvocation" | ||
- "dev.restate.sdktesting.tests.UserErrors" | ||
- "dev.restate.sdktesting.tests.WorkflowAPI" | ||
- "dev.restate.sdktesting.tests.AwaitTimeout" | ||
- "dev.restate.sdktesting.tests.CallOrdering" | ||
- "dev.restate.sdktesting.tests.CancelInvocation" | ||
- "dev.restate.sdktesting.tests.Ingress" | ||
- "dev.restate.sdktesting.tests.KillInvocation" | ||
- "dev.restate.sdktesting.tests.ServiceToServiceCommunication" | ||
- "dev.restate.sdktesting.tests.Sleep" | ||
- "dev.restate.sdktesting.tests.SleepWithFailures" | ||
- "dev.restate.sdktesting.tests.UpgradeWithInFlightInvocation" | ||
- "dev.restate.sdktesting.tests.UpgradeWithNewInvocation" | ||
- "dev.restate.sdktesting.tests.UserErrors" | ||
- "dev.restate.sdktesting.tests.WorkflowAPI" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use anyhow::anyhow; | ||
use restate_sdk::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub(crate) struct Entry { | ||
key: String, | ||
value: String, | ||
} | ||
|
||
#[restate_sdk::object] | ||
#[name = "MapObject"] | ||
pub(crate) trait MapObject { | ||
#[name = "set"] | ||
async fn set(entry: Json<Entry>) -> HandlerResult<()>; | ||
#[name = "get"] | ||
async fn get(key: String) -> HandlerResult<String>; | ||
#[name = "clearAll"] | ||
async fn clear_all() -> HandlerResult<Json<Vec<Entry>>>; | ||
} | ||
|
||
pub(crate) struct MapObjectImpl; | ||
|
||
impl MapObject for MapObjectImpl { | ||
async fn set( | ||
&self, | ||
ctx: ObjectContext<'_>, | ||
Json(Entry { key, value }): Json<Entry>, | ||
) -> HandlerResult<()> { | ||
ctx.set(&key, value); | ||
Ok(()) | ||
} | ||
|
||
async fn get(&self, ctx: ObjectContext<'_>, key: String) -> HandlerResult<String> { | ||
Ok(ctx.get(&key).await?.unwrap_or_default()) | ||
} | ||
|
||
async fn clear_all(&self, ctx: ObjectContext<'_>) -> HandlerResult<Json<Vec<Entry>>> { | ||
let keys = ctx.get_keys().await?; | ||
|
||
let mut entries = vec![]; | ||
for k in keys { | ||
let value = ctx | ||
.get(&k) | ||
.await? | ||
.ok_or_else(|| HandlerError::from_anyhow(anyhow!("Missing key {k}")))?; | ||
entries.push(Entry { key: k, value }) | ||
} | ||
|
||
ctx.clear_all(); | ||
|
||
Ok(entries.into()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
use futures::future::BoxFuture; | ||
use futures::FutureExt; | ||
use restate_sdk::context::RequestTarget; | ||
use restate_sdk::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
use std::time::Duration; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub(crate) struct ProxyRequest { | ||
service_name: String, | ||
virtual_object_key: Option<String>, | ||
handler_name: String, | ||
message: Vec<u8>, | ||
delay_millis: Option<u64>, | ||
} | ||
|
||
impl ProxyRequest { | ||
fn to_target(&self) -> RequestTarget { | ||
if let Some(key) = &self.virtual_object_key { | ||
RequestTarget::Object { | ||
name: self.service_name.clone(), | ||
key: key.clone(), | ||
handler: self.handler_name.clone(), | ||
} | ||
} else { | ||
RequestTarget::Service { | ||
name: self.service_name.clone(), | ||
handler: self.handler_name.clone(), | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub(crate) struct ManyCallRequest { | ||
proxy_request: ProxyRequest, | ||
one_way_call: bool, | ||
await_at_the_end: bool, | ||
} | ||
|
||
#[restate_sdk::service] | ||
#[name = "Proxy"] | ||
pub(crate) trait Proxy { | ||
#[name = "call"] | ||
async fn call(req: Json<ProxyRequest>) -> HandlerResult<Json<Vec<u8>>>; | ||
#[name = "oneWayCall"] | ||
async fn one_way_call(req: Json<ProxyRequest>) -> HandlerResult<()>; | ||
#[name = "manyCalls"] | ||
async fn many_calls(req: Json<Vec<ManyCallRequest>>) -> HandlerResult<()>; | ||
} | ||
|
||
pub(crate) struct ProxyImpl; | ||
|
||
impl Proxy for ProxyImpl { | ||
async fn call( | ||
&self, | ||
ctx: Context<'_>, | ||
Json(req): Json<ProxyRequest>, | ||
) -> HandlerResult<Json<Vec<u8>>> { | ||
Ok(ctx.call(req.to_target(), req.message).await?) | ||
} | ||
|
||
async fn one_way_call( | ||
&self, | ||
ctx: Context<'_>, | ||
Json(req): Json<ProxyRequest>, | ||
) -> HandlerResult<()> { | ||
ctx.send( | ||
req.to_target(), | ||
req.message, | ||
req.delay_millis.map(Duration::from_millis), | ||
); | ||
Ok(()) | ||
} | ||
|
||
async fn many_calls( | ||
&self, | ||
ctx: Context<'_>, | ||
Json(requests): Json<Vec<ManyCallRequest>>, | ||
) -> HandlerResult<()> { | ||
let mut futures: Vec<BoxFuture<'_, Result<Vec<u8>, TerminalError>>> = vec![]; | ||
|
||
for req in requests { | ||
if req.one_way_call { | ||
ctx.send( | ||
req.proxy_request.to_target(), | ||
req.proxy_request.message, | ||
req.proxy_request.delay_millis.map(Duration::from_millis), | ||
); | ||
} else { | ||
let fut = ctx | ||
.call::<_, Vec<u8>>(req.proxy_request.to_target(), req.proxy_request.message); | ||
if req.await_at_the_end { | ||
futures.push(fut.boxed()) | ||
} | ||
} | ||
} | ||
|
||
for fut in futures { | ||
fut.await?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |