-
Notifications
You must be signed in to change notification settings - Fork 3
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
Move verification tests into this repo #123
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@restatedev:registry=https://npm.pkg.github.com/ | ||
//npm.pkg.github.com/:_authToken=${GH_PACKAGE_READ_ACCESS_TOKEN} |
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,31 +1,30 @@ | ||
FROM node:18 AS build | ||
ARG NPM_TOKEN | ||
ARG GH_PACKAGE_READ_ACCESS_TOKEN | ||
|
||
WORKDIR /usr/src/app | ||
COPY . . | ||
|
||
RUN echo "//npm.pkg.github.com/:_authToken=$NPM_TOKEN\n" >> .npmrc && \ | ||
echo "@restatedev:registry=https://npm.pkg.github.com/" >> .npmrc && \ | ||
npm ci && \ | ||
npm run build && \ | ||
rm -f .npmrc | ||
RUN npm ci | ||
RUN npm run build | ||
|
||
FROM node:18 as prod | ||
ARG NPM_TOKEN | ||
ARG GH_PACKAGE_READ_ACCESS_TOKEN | ||
WORKDIR /usr/src/app | ||
|
||
# Install app dependencies | ||
COPY package*.json *.tgz ./ | ||
RUN echo "//npm.pkg.github.com/:_authToken=$NPM_TOKEN\n" >> .npmrc && \ | ||
echo "@restatedev:registry=https://npm.pkg.github.com/" >> .npmrc && \ | ||
npm ci --production && \ | ||
rm -f .npmrc | ||
COPY package*.json *.tgz .npmrc ./ | ||
RUN npm ci --production | ||
|
||
COPY --from=build /usr/src/app/dist /usr/src/app/dist | ||
|
||
FROM node:18 | ||
|
||
# Use a new stage so that the build-arg GH_PACKAGE_READ_ACCESS_TOKEN isn't leaked into the final image history | ||
COPY --from=prod /usr/src/app/ /usr/src/app/ | ||
Comment on lines
+22
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for fixing this! |
||
|
||
# Install Tini | ||
RUN apt-get update && apt-get -y install tini | ||
|
||
EXPOSE 8080 | ||
ENTRYPOINT ["tini", "--"] | ||
CMD ["node", "/usr/src/app/dist/app.js"] | ||
CMD ["node", "/usr/src/app/dist/app.js"] |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,189 @@ | ||
import { RestateContext, useContext } from "@restatedev/restate-sdk"; | ||
import { | ||
BackgroundCallRequest, | ||
CallRequest, | ||
ClearRequest, | ||
Command_AsyncCall, | ||
Command_AsyncCallAwait, | ||
Command_BackgroundCall, | ||
Command_IncrementState, | ||
Command_Sleep, | ||
Command_SyncCall, | ||
CommandInterpreter, | ||
CommandInterpreterClientImpl, | ||
Commands, | ||
Empty, | ||
Key, | ||
protobufPackage, | ||
TestParams, | ||
VerificationRequest, | ||
VerificationResult, | ||
} from "./generated/interpreter"; | ||
|
||
export const CommandInterpreterServiceFQN = | ||
protobufPackage + ".CommandInterpreter"; | ||
|
||
export class CommandInterpreterService implements CommandInterpreter { | ||
async call(request: CallRequest): Promise<Empty> { | ||
return this.eitherCall(request.key, request.commands); | ||
} | ||
|
||
async backgroundCall(request: BackgroundCallRequest): Promise<Empty> { | ||
return this.eitherCall(request.key, request.commands); | ||
} | ||
|
||
async eitherCall( | ||
key: Key | undefined, | ||
commands: Commands | undefined | ||
): Promise<Empty> { | ||
if (!commands?.command) { | ||
throw new Error("CallRequest with no commands"); | ||
} | ||
if (!key) { | ||
throw new Error("CallRequest with no key"); | ||
} | ||
if (!key.params) { | ||
throw new Error("CallRequest with no test parameters"); | ||
} | ||
const ctx = useContext(this); | ||
const client = new CommandInterpreterClientImpl(ctx); | ||
const pending_calls = new Map<number, Promise<Empty>>(); | ||
|
||
for (const c of commands.command) { | ||
switch (true) { | ||
case c.increment !== undefined: | ||
await this._increment(ctx, c.increment as Command_IncrementState); | ||
break; | ||
case c.syncCall !== undefined: | ||
await this._syncCall( | ||
ctx, | ||
client, | ||
key.params, | ||
c.syncCall as Command_SyncCall | ||
); | ||
break; | ||
case c.asyncCall !== undefined: | ||
this._asyncCall( | ||
ctx, | ||
client, | ||
pending_calls, | ||
key.params, | ||
c.asyncCall as Command_AsyncCall | ||
); | ||
break; | ||
case c.asyncCallAwait !== undefined: | ||
await this._asyncCallAwait( | ||
ctx, | ||
pending_calls, | ||
c.asyncCallAwait as Command_AsyncCallAwait | ||
); | ||
break; | ||
case c.backgroundCall !== undefined: | ||
await this._backgroundCall( | ||
ctx, | ||
client, | ||
key.params, | ||
c.backgroundCall as Command_BackgroundCall | ||
); | ||
break; | ||
case c.sleep !== undefined: | ||
await this._sleep(ctx, c.sleep as Command_Sleep); | ||
break; | ||
default: | ||
// should be unreachable | ||
throw new Error("Empty Command in CallRequest"); | ||
} | ||
} | ||
|
||
return Empty.create({}); | ||
} | ||
|
||
async _increment( | ||
ctx: RestateContext, | ||
request: Command_IncrementState | ||
): Promise<void> { | ||
const counter = (await ctx.get<number>("counter")) || 0; | ||
return ctx.set("counter", counter + 1); | ||
} | ||
|
||
async _syncCall( | ||
ctx: RestateContext, | ||
client: CommandInterpreterClientImpl, | ||
params: TestParams, | ||
request: Command_SyncCall | ||
): Promise<void> { | ||
await client.call( | ||
CallRequest.create({ | ||
key: { params, target: request.target }, | ||
commands: request.commands, | ||
}) | ||
); | ||
} | ||
|
||
_asyncCall( | ||
ctx: RestateContext, | ||
client: CommandInterpreterClientImpl, | ||
pending_calls: Map<number, Promise<Empty>>, | ||
params: TestParams, | ||
request: Command_AsyncCall | ||
) { | ||
pending_calls.set( | ||
request.callId, | ||
client.call( | ||
CallRequest.create({ | ||
key: { params, target: request.target }, | ||
commands: request.commands, | ||
}) | ||
) | ||
); | ||
} | ||
|
||
async _asyncCallAwait( | ||
ctx: RestateContext, | ||
pending_calls: Map<number, Promise<Empty>>, | ||
request: Command_AsyncCallAwait | ||
): Promise<void> { | ||
const p = pending_calls.get(request.callId); | ||
if (p === undefined) { | ||
throw new Error("Unrecognised CallID in AsyncCallAwait command"); | ||
} | ||
await p; | ||
return; | ||
} | ||
|
||
async _backgroundCall( | ||
ctx: RestateContext, | ||
client: CommandInterpreterClientImpl, | ||
params: TestParams, | ||
request: Command_BackgroundCall | ||
): Promise<void> { | ||
return ctx.oneWayCall(() => | ||
client.backgroundCall( | ||
BackgroundCallRequest.create({ | ||
key: { params, target: request.target }, | ||
commands: request.commands, | ||
}) | ||
) | ||
); | ||
} | ||
|
||
async _sleep(ctx: RestateContext, request: Command_Sleep): Promise<void> { | ||
return ctx.sleep(request.milliseconds); | ||
} | ||
|
||
async verify(request: VerificationRequest): Promise<VerificationResult> { | ||
const ctx = useContext(this); | ||
return VerificationResult.create({ | ||
expected: request.expected, | ||
actual: (await ctx.get<number>("counter")) || 0, | ||
}); | ||
} | ||
|
||
async clear(request: ClearRequest): Promise<Empty> { | ||
const ctx = useContext(this); | ||
|
||
await ctx.clear("counter"); | ||
|
||
return Empty.create({}); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tillrohrmann can you double check this? I don't remember you ever needed this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need this fix in 5.7.0 java-native-access/jna#1238
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's quite an old bug, i wonder which dep is bringing this in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its this thing which is unmaintained https://github.com/JetBrains/intellij-deps-trove4j
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh ok i'll try to see if this goes away when bumping kotlin