From 4cdf49b5f8aa9dc4baa15742e179c9e8b8325a09 Mon Sep 17 00:00:00 2001 From: Igal Shilman Date: Thu, 14 Mar 2024 00:13:13 +0100 Subject: [PATCH] Adjust the typescript e2e tests after API refactor (#280) This commit adjusts the e2e tests following the removal of objectApi and serviceApi types. --- .../node-services/src/awakeable_holder.ts | 9 +++------ services/node-services/src/cancel_test.ts | 14 +++++++------- services/node-services/src/counter.ts | 12 +++++++----- services/node-services/src/event_handler.ts | 8 +++++--- services/node-services/src/list.ts | 4 ++-- services/node-services/src/map.ts | 4 ++-- services/node-services/src/non_determinism.ts | 19 ++++++++++--------- services/node-services/src/proxy_counter.ts | 7 ++++--- 8 files changed, 40 insertions(+), 37 deletions(-) diff --git a/services/node-services/src/awakeable_holder.ts b/services/node-services/src/awakeable_holder.ts index 9dceb08f..3a99d6a7 100644 --- a/services/node-services/src/awakeable_holder.ts +++ b/services/node-services/src/awakeable_holder.ts @@ -18,10 +18,10 @@ type Ctx = restate.ObjectContext; REGISTRY.add({ fqdn: AwakeableHolderServiceFQN, - binder: (e) => e.object(AwakeableHolderServiceFQN, service), + binder: (e) => e.object(service), }); -const service = restate.object({ +const service = restate.object(AwakeableHolderServiceFQN, { async hold(ctx: restate.ObjectContext, id: string) { ctx.set(ID_KEY, id); }, @@ -41,7 +41,4 @@ const service = restate.object({ }, }); -export const awakeableHolderApi = restate.objectApi( - AwakeableHolderServiceFQN, - service -); +export type awakeableHolderApi = typeof service; diff --git a/services/node-services/src/cancel_test.ts b/services/node-services/src/cancel_test.ts index 8f1cd2aa..d97abad8 100644 --- a/services/node-services/src/cancel_test.ts +++ b/services/node-services/src/cancel_test.ts @@ -13,15 +13,16 @@ import { REGISTRY } from "./services"; export const CancelTestServiceFQN = "CancelTestRunner"; export const BlockingServiceFQN = "CancelTestBlockingService"; +const AwakeableHolder: awakeableHolderApi = { path: "AwakeableHolder"}; REGISTRY.add({ fqdn: CancelTestServiceFQN, - binder: (e) => e.object(CancelTestServiceFQN, canceService), + binder: (e) => e.object(canceService), }); REGISTRY.add({ fqdn: BlockingServiceFQN, - binder: (e) => e.object(BlockingServiceFQN, blockingService), + binder: (e) => e.object(blockingService), }); enum BlockingOperation { @@ -30,7 +31,7 @@ enum BlockingOperation { AWAKEABLE = "AWAKEABLE", } -const canceService = restate.object({ +const canceService = restate.object(CancelTestServiceFQN, { async verifyTest(ctx: restate.ObjectContext): Promise { const isCanceled = (await ctx.get("canceled")) ?? false; return isCanceled; @@ -52,11 +53,11 @@ const canceService = restate.object({ }, }); -const blockingService = restate.object({ +const blockingService = restate.object(BlockingServiceFQN, { async block(ctx: restate.ObjectContext, request: BlockingOperation) { const { id, promise } = ctx.awakeable(); // DO NOT await the next CALL otherwise the test deadlocks. - ctx.object(awakeableHolderApi, "cancel").hold(id); + ctx.object(AwakeableHolder, "cancel").hold(id); await promise; switch (request) { @@ -77,8 +78,7 @@ const blockingService = restate.object({ } }, - async isUnlocked() {}, }); -const api = restate.objectApi(BlockingServiceFQN, blockingService); +const api: typeof blockingService = { path : "CancelTestBlockingService" }; diff --git a/services/node-services/src/counter.ts b/services/node-services/src/counter.ts index 551ac33e..a8e051c5 100644 --- a/services/node-services/src/counter.ts +++ b/services/node-services/src/counter.ts @@ -9,7 +9,7 @@ import * as restate from "@restatedev/restate-sdk"; import { REGISTRY } from "./services"; -import { awakeableHolderApi } from "./awakeable_holder"; +import type { awakeableHolderApi } from "./awakeable_holder"; const COUNTER_KEY = "counter"; @@ -17,10 +17,12 @@ export const CounterServiceFQN = "Counter"; REGISTRY.add({ fqdn: CounterServiceFQN, - binder: (e) => e.object(CounterServiceFQN, service), + binder: (e) => e.object(service), }); -const service = restate.object({ +const AwakeableHolder: awakeableHolderApi = { path: "AwakeableHolder" }; + +const service = restate.object(CounterServiceFQN, { async reset(ctx: restate.ObjectContext) { ctx.clear(COUNTER_KEY); }, @@ -56,7 +58,7 @@ const service = restate.object({ // Wait for the sync with the test runner const { id, promise } = ctx.awakeable(); - ctx.objectSend(awakeableHolderApi, ctx.key()).hold(id); + ctx.objectSend(AwakeableHolder, ctx.key()).hold(id); await promise; // Now start looping @@ -74,4 +76,4 @@ const service = restate.object({ }, }); -export const counterApi = restate.objectApi(CounterServiceFQN, service); +export type counterApi = typeof service; diff --git a/services/node-services/src/event_handler.ts b/services/node-services/src/event_handler.ts index 531f4620..f6deb3f6 100644 --- a/services/node-services/src/event_handler.ts +++ b/services/node-services/src/event_handler.ts @@ -13,13 +13,15 @@ import { counterApi } from "./counter"; const EventHandlerFQN = "EventHandler"; +const CounterApi: counterApi = { path: "Counter" }; + REGISTRY.add({ fqdn: EventHandlerFQN, - binder: (e) => e.object(EventHandlerFQN, service), + binder: (e) => e.object(service), }); -const service = restate.object({ +const service = restate.object(EventHandlerFQN, { async handle(ctx: restate.ObjectContext, value: number) { - ctx.objectSend(counterApi, ctx.key()).add(value); + ctx.objectSend(CounterApi, ctx.key()).add(value); }, }); diff --git a/services/node-services/src/list.ts b/services/node-services/src/list.ts index 6caf7727..2440c25c 100644 --- a/services/node-services/src/list.ts +++ b/services/node-services/src/list.ts @@ -16,10 +16,10 @@ const ListServiceFQN = "ListObject"; REGISTRY.add({ fqdn: ListServiceFQN, - binder: (e) => e.object(ListServiceFQN, service), + binder: (e) => e.object(service), }); -const service = restate.object({ +const service = restate.object(ListServiceFQN, { async append(ctx: restate.ObjectContext, request: string): Promise { const list = (await ctx.get(LIST_KEY)) ?? []; list.push(request); diff --git a/services/node-services/src/map.ts b/services/node-services/src/map.ts index f9737779..7aa4ad05 100644 --- a/services/node-services/src/map.ts +++ b/services/node-services/src/map.ts @@ -13,10 +13,10 @@ export const MapServiceFQN = "MapObject"; REGISTRY.add({ fqdn: MapServiceFQN, - binder: (e) => e.object(MapServiceFQN, service), + binder: (e) => e.object(service), }); -const service = restate.object({ +const service = restate.object(MapServiceFQN, { async clearAll(ctx: restate.ObjectContext): Promise { const keys = await ctx.stateKeys(); ctx.clearAll(); diff --git a/services/node-services/src/non_determinism.ts b/services/node-services/src/non_determinism.ts index 41c0474c..56f38dee 100644 --- a/services/node-services/src/non_determinism.ts +++ b/services/node-services/src/non_determinism.ts @@ -14,9 +14,11 @@ import { REGISTRY } from "./services"; export const NonDeterministicServiceFQN = "NonDeterministic"; +const Counter: counterApi = { path: "Counter" }; + REGISTRY.add({ fqdn: NonDeterministicServiceFQN, - binder: (e) => e.object(NonDeterministicServiceFQN, service), + binder: (e) => e.object(service), }); const invocationCounts = new Map(); @@ -28,33 +30,33 @@ function doLeftAction(ctx: restate.ObjectContext): boolean { } function incrementCounter(ctx: restate.ObjectContext) { - ctx.objectSend(counterApi, ctx.key()).add(1); + ctx.objectSend(Counter, ctx.key()).add(1); } -const service = restate.object({ +const service = restate.object(NonDeterministicServiceFQN, { async leftSleepRightCall(ctx: restate.ObjectContext) { if (doLeftAction(ctx)) { await ctx.sleep(100); } else { - await ctx.object(counterApi, "abc").get(); + await ctx.object(Counter, "abc").get(); } incrementCounter(ctx); }, async callDifferentMethod(ctx: restate.ObjectContext) { if (doLeftAction(ctx)) { - await ctx.object(counterApi, "abc").get(); + await ctx.object(Counter, "abc").get(); } else { - await ctx.object(counterApi, "abc").reset(); + await ctx.object(Counter, "abc").reset(); } incrementCounter(ctx); }, async backgroundInvokeWithDifferentTargets(ctx: restate.ObjectContext) { if (doLeftAction(ctx)) { - ctx.objectSend(counterApi, "abc").get(); + ctx.objectSend(Counter, "abc").get(); } else { - ctx.objectSend(counterApi, "abc").reset(); + ctx.objectSend(Counter, "abc").reset(); } await ctx.sleep(100); incrementCounter(ctx); @@ -76,4 +78,3 @@ const service = restate.object({ incrementCounter(ctx); }, }); - diff --git a/services/node-services/src/proxy_counter.ts b/services/node-services/src/proxy_counter.ts index e274d90a..0989d9e9 100644 --- a/services/node-services/src/proxy_counter.ts +++ b/services/node-services/src/proxy_counter.ts @@ -12,18 +12,19 @@ import { REGISTRY } from "./services"; import { counterApi } from "./counter"; const ProxyCounterServiceFQN = "ProxyCounter"; +const Counter: counterApi = { path: "Counter" }; REGISTRY.add({ fqdn: ProxyCounterServiceFQN, - binder: (e) => e.service(ProxyCounterServiceFQN, service), + binder: (e) => e.service(service), }); -const service = restate.service({ +const service = restate.service(ProxyCounterServiceFQN, { async addInBackground( ctx: restate.Context, request: { counterName: string; value: number } ) { ctx.console.log("addInBackground " + JSON.stringify(request)); - ctx.objectSend(counterApi, request.counterName).add(request.value); + ctx.objectSend(Counter, request.counterName).add(request.value); }, });