Skip to content

Commit

Permalink
Merge branch 'dapr:main' into fix-e2e-common-server-test
Browse files Browse the repository at this point in the history
  • Loading branch information
MregXN authored Nov 29, 2023
2 parents a00594c + 46c83d9 commit 05194da
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
7 changes: 7 additions & 0 deletions src/actors/ActorId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export default class ActorId {
private readonly id: string;

constructor(id: string) {
if (!id) {
throw new Error("ActorId cannot be empty");

Check warning on line 21 in src/actors/ActorId.ts

View check run for this annotation

Codecov / codecov/patch

src/actors/ActorId.ts#L21

Added line #L21 was not covered by tests
}
this.id = id;
}

Expand All @@ -28,6 +31,10 @@ export default class ActorId {
return this.id;
}

getURLSafeId() {
return encodeURIComponent(this.id);

Check warning on line 35 in src/actors/ActorId.ts

View check run for this annotation

Codecov / codecov/patch

src/actors/ActorId.ts#L35

Added line #L35 was not covered by tests
}

toString() {
return this.id;
}
Expand Down
20 changes: 10 additions & 10 deletions src/actors/client/ActorClient/ActorClientHTTP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class ActorClientHTTP implements IClientActor {
}

async invoke(actorType: string, actorId: ActorId, methodName: string, body?: any): Promise<object> {
const result = await this.client.execute(`/actors/${actorType}/${actorId.getId()}/method/${methodName}`, {
const result = await this.client.execute(`/actors/${actorType}/${actorId.getURLSafeId()}/method/${methodName}`, {

Check warning on line 31 in src/actors/client/ActorClient/ActorClientHTTP.ts

View check run for this annotation

Codecov / codecov/patch

src/actors/client/ActorClient/ActorClientHTTP.ts#L31

Added line #L31 was not covered by tests
method: "POST", // we always use POST calls for Invoking (ref: https://github.com/dapr/js-sdk/pull/137#discussion_r772636068)
body,
});
Expand All @@ -37,7 +37,7 @@ export default class ActorClientHTTP implements IClientActor {
}

async stateTransaction(actorType: string, actorId: ActorId, operations: OperationType[]): Promise<void> {
await this.client.execute(`/actors/${actorType}/${actorId.getId()}/state`, {
await this.client.execute(`/actors/${actorType}/${actorId.getURLSafeId()}/state`, {

Check warning on line 40 in src/actors/client/ActorClient/ActorClientHTTP.ts

View check run for this annotation

Codecov / codecov/patch

src/actors/client/ActorClient/ActorClientHTTP.ts#L40

Added line #L40 was not covered by tests
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -47,7 +47,7 @@ export default class ActorClientHTTP implements IClientActor {
}

async stateGet(actorType: string, actorId: ActorId, key: string): Promise<KeyValueType | string> {
const result = await this.client.execute(`/actors/${actorType}/${actorId.getId()}/state/${key}`);
const result = await this.client.execute(`/actors/${actorType}/${actorId.getURLSafeId()}/state/${key}`);

Check warning on line 50 in src/actors/client/ActorClient/ActorClientHTTP.ts

View check run for this annotation

Codecov / codecov/patch

src/actors/client/ActorClient/ActorClientHTTP.ts#L50

Added line #L50 was not covered by tests
return result as any;
}

Expand All @@ -57,7 +57,7 @@ export default class ActorClientHTTP implements IClientActor {
name: string,
reminder: ActorReminderType,
): Promise<void> {
await this.client.execute(`/actors/${actorType}/${actorId.getId()}/reminders/${name}`, {
await this.client.execute(`/actors/${actorType}/${actorId.getURLSafeId()}/reminders/${name}`, {

Check warning on line 60 in src/actors/client/ActorClient/ActorClientHTTP.ts

View check run for this annotation

Codecov / codecov/patch

src/actors/client/ActorClient/ActorClientHTTP.ts#L60

Added line #L60 was not covered by tests
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -72,18 +72,18 @@ export default class ActorClientHTTP implements IClientActor {
}

async reminderGet(actorType: string, actorId: ActorId, name: string): Promise<object> {
const result = await this.client.execute(`/actors/${actorType}/${actorId.getId()}/reminders/${name}`);
const result = await this.client.execute(`/actors/${actorType}/${actorId.getURLSafeId()}/reminders/${name}`);

Check warning on line 75 in src/actors/client/ActorClient/ActorClientHTTP.ts

View check run for this annotation

Codecov / codecov/patch

src/actors/client/ActorClient/ActorClientHTTP.ts#L75

Added line #L75 was not covered by tests
return result as object;
}

async unregisterActorReminder(actorType: string, actorId: ActorId, name: string): Promise<void> {
await this.client.execute(`/actors/${actorType}/${actorId.getId()}/reminders/${name}`, {
await this.client.execute(`/actors/${actorType}/${actorId.getURLSafeId()}/reminders/${name}`, {

Check warning on line 80 in src/actors/client/ActorClient/ActorClientHTTP.ts

View check run for this annotation

Codecov / codecov/patch

src/actors/client/ActorClient/ActorClientHTTP.ts#L80

Added line #L80 was not covered by tests
method: "DELETE",
});
}

async registerActorTimer(actorType: string, actorId: ActorId, name: string, timer: ActorTimerType): Promise<void> {
await this.client.execute(`/actors/${actorType}/${actorId.getId()}/timers/${name}`, {
await this.client.execute(`/actors/${actorType}/${actorId.getURLSafeId()}/timers/${name}`, {

Check warning on line 86 in src/actors/client/ActorClient/ActorClientHTTP.ts

View check run for this annotation

Codecov / codecov/patch

src/actors/client/ActorClient/ActorClientHTTP.ts#L86

Added line #L86 was not covered by tests
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -99,13 +99,13 @@ export default class ActorClientHTTP implements IClientActor {
}

async unregisterActorTimer(actorType: string, actorId: ActorId, name: string): Promise<void> {
await this.client.execute(`/actors/${actorType}/${actorId.getId()}/timers/${name}`, {
await this.client.execute(`/actors/${actorType}/${actorId.getURLSafeId()}/timers/${name}`, {

Check warning on line 102 in src/actors/client/ActorClient/ActorClientHTTP.ts

View check run for this annotation

Codecov / codecov/patch

src/actors/client/ActorClient/ActorClientHTTP.ts#L102

Added line #L102 was not covered by tests
method: "DELETE",
});
}

async deactivate(actorType: string, actorId: string): Promise<void> {
await this.client.execute(`/actors/${actorType}/${actorId}`, {
async deactivate(actorType: string, actorId: ActorId): Promise<void> {
await this.client.execute(`/actors/${actorType}/${actorId.getURLSafeId()}`, {

Check warning on line 108 in src/actors/client/ActorClient/ActorClientHTTP.ts

View check run for this annotation

Codecov / codecov/patch

src/actors/client/ActorClient/ActorClientHTTP.ts#L108

Added line #L108 was not covered by tests
method: "DELETE",
});
}
Expand Down
28 changes: 26 additions & 2 deletions test/e2e/http/actors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe("http/actors", () => {

const config = JSON.parse(await res.text());

expect(config.entities.length).toBe(9);
expect(config.entities.length).toBe(11);
expect(config.actorIdleTimeout).toBe("1h");
expect(config.actorScanInterval).toBe("30s");
expect(config.drainOngoingCallTimeout).toBe("1m");
Expand All @@ -123,6 +123,26 @@ describe("http/actors", () => {
});
});

describe("actorId", () => {
it("should be able to create an actorId", () => {
const actorId = ActorId.createRandomId();
expect(actorId.getId()).toBeDefined();
expect(actorId.getURLSafeId()).toBeDefined();
expect(actorId.toString()).toBeDefined();
});

it("should not be able to create an actorId with an empty string", () => {
expect(() => new ActorId("")).toThrowError("ActorId cannot be empty");
});

it("should be able to create an actorId with url unsafe characters like '/'", () => {
const actorId = new ActorId("test/actor");
expect(actorId.getURLSafeId()).toEqual("test%2Factor");
expect(actorId.getId()).toEqual("test/actor");
expect(actorId.toString()).toEqual("test/actor");
});
});

describe("actorProxy", () => {
it("should be able to create an actor object through the proxy", async () => {
const builder = new ActorProxyBuilder<DemoActorCounterInterface>(DemoActorCounterImpl, client);
Expand Down Expand Up @@ -179,15 +199,19 @@ describe("http/actors", () => {
it("should register actors correctly", async () => {
const actors = await server.actor.getRegisteredActors();

expect(actors.length).toEqual(9);
expect(actors.length).toEqual(11);

expect(actors).toContain(DemoActorCounterImpl.name);
expect(actors).toContain(DemoActorSayImpl.name);
expect(actors).toContain(DemoActorReminderImpl.name);
expect(actors).toContain(DemoActorReminder2Impl.name);
expect(actors).toContain(DemoActorReminderOnceImpl.name);
expect(actors).toContain(DemoActorTimerImpl.name);
expect(actors).toContain(DemoActorTimerOnceImpl.name);
expect(actors).toContain(DemoActorActivateImpl.name);
expect(actors).toContain(DemoActorTimerTtlImpl.name);
expect(actors).toContain(DemoActorReminderTtlImpl.name);
expect(actors).toContain(DemoActorDeleteStateImpl.name);
});

it("should be able to invoke an actor through a text message", async () => {
Expand Down

0 comments on commit 05194da

Please sign in to comment.