-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86a228b
commit d7357af
Showing
7 changed files
with
180 additions
and
17 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
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,103 @@ | ||
/* | ||
* Copyright (c) 2023 - Restate Software, Inc., Restate GmbH | ||
* | ||
* This file is part of the Restate SDK for Node.js/TypeScript, | ||
* which is released under the MIT license. | ||
* | ||
* You can find a copy of the license in file LICENSE in the root | ||
* directory of this repository or package, or at | ||
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE | ||
*/ | ||
|
||
import { describe, expect } from "@jest/globals"; | ||
import * as restate from "../src/public_api"; | ||
import { TestDriver } from "./testdriver"; | ||
import { | ||
completionMessage, | ||
END_MESSAGE, | ||
getStateKeysMessage, | ||
greetRequest, | ||
greetResponse, | ||
inputMessage, | ||
keyVal, | ||
outputMessage, | ||
startMessage, | ||
suspensionMessage, | ||
} from "./protoutils"; | ||
import { TestGreeter, TestResponse } from "../src/generated/proto/test"; | ||
import { GetStateKeysEntryMessage_StateKeys } from "../src/generated/proto/protocol"; | ||
|
||
const INPUT_MESSAGE = inputMessage(greetRequest("")); | ||
|
||
function stateKeys(...keys: Array<string>): GetStateKeysEntryMessage_StateKeys { | ||
return { | ||
keys: keys.map((b) => Buffer.from(b)), | ||
}; | ||
} | ||
|
||
class ListKeys implements TestGreeter { | ||
async greet(): Promise<TestResponse> { | ||
const ctx = restate.useContext(this); | ||
|
||
return { | ||
greeting: (await ctx.stateKeys()).join(","), | ||
}; | ||
} | ||
} | ||
|
||
describe("ListKeys", () => { | ||
it("with partial state suspends", async () => { | ||
const result = await new TestDriver(new ListKeys(), [ | ||
startMessage(1, true, [keyVal("A", "1")]), | ||
INPUT_MESSAGE, | ||
]).run(); | ||
|
||
expect(result).toStrictEqual([ | ||
getStateKeysMessage(), | ||
suspensionMessage([1]), | ||
]); | ||
}); | ||
|
||
it("with partial state", async () => { | ||
const result = await new TestDriver(new ListKeys(), [ | ||
startMessage(1, true, [keyVal("A", "1")]), | ||
INPUT_MESSAGE, | ||
completionMessage( | ||
1, | ||
GetStateKeysEntryMessage_StateKeys.encode(stateKeys("B", "C")).finish() | ||
), | ||
]).run(); | ||
|
||
expect(result).toStrictEqual([ | ||
getStateKeysMessage(), | ||
outputMessage(greetResponse("B,C")), | ||
END_MESSAGE, | ||
]); | ||
}); | ||
|
||
it("with complete state", async () => { | ||
const result = await new TestDriver(new ListKeys(), [ | ||
startMessage(1, false, [keyVal("A", "1")]), | ||
INPUT_MESSAGE, | ||
]).run(); | ||
|
||
expect(result).toStrictEqual([ | ||
getStateKeysMessage(["A"]), | ||
outputMessage(greetResponse("A")), | ||
END_MESSAGE, | ||
]); | ||
}); | ||
|
||
it("replay", async () => { | ||
const result = await new TestDriver(new ListKeys(), [ | ||
startMessage(1, true, [keyVal("A", "1")]), | ||
INPUT_MESSAGE, | ||
getStateKeysMessage(["A", "B", "C"]), | ||
]).run(); | ||
|
||
expect(result).toStrictEqual([ | ||
outputMessage(greetResponse("A,B,C")), | ||
END_MESSAGE, | ||
]); | ||
}); | ||
}); |