-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove optimisticConcurrencyValue (#1414)
Add rush change Add local provider concurrency
- Loading branch information
1 parent
3215284
commit b06f34f
Showing
14 changed files
with
309 additions
and
27 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
common/changes/@boostercloud/framework-core/local_concurrency_2023-06-06-14-44.json
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,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@boostercloud/framework-core", | ||
"comment": "Add Local Provider concurrency", | ||
"type": "minor" | ||
} | ||
], | ||
"packageName": "@boostercloud/framework-core" | ||
} |
99 changes: 99 additions & 0 deletions
99
...ation-tests/integration/provider-unaware/end-to-end/read-model-concurrency.integration.ts
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,99 @@ | ||
import { ApolloClient, gql, NormalizedCacheObject } from '@apollo/client' | ||
import { random } from 'faker' | ||
import { expect } from '../../helper/expect' | ||
import { applicationUnderTest } from './setup' | ||
import 'mocha' | ||
import { ReadModelInterface, UUID } from '@boostercloud/framework-types' | ||
import { waitForIt } from '../../helper/sleep' | ||
|
||
describe('Concurrency end-to-end tests', () => { | ||
let client: ApolloClient<NormalizedCacheObject> | ||
|
||
before(async () => { | ||
client = applicationUnderTest.graphql.client() | ||
}) | ||
|
||
context('ReadModels', () => { | ||
describe('With one projection', () => { | ||
it('insert and update generate one ReadModel with version 2', async () => { | ||
const entityId: UUID = random.uuid() | ||
|
||
const insertedReadModel = await addConcurrency(client, entityId, 1, 'ConcurrencyReadModel') | ||
expect(insertedReadModel.id).to.be.eq(entityId) | ||
expect(insertedReadModel.boosterMetadata?.version).to.be.eq(1) | ||
|
||
const updatedReadModel = await addConcurrency(client, entityId, 2, 'ConcurrencyReadModel') | ||
expect(updatedReadModel.id).to.be.eq(entityId) | ||
expect(updatedReadModel.boosterMetadata?.version).to.be.eq(2) | ||
}) | ||
}) | ||
|
||
describe('With two projections for the same ReadModel', () => { | ||
if (process.env.TESTED_PROVIDER === 'AWS') { | ||
console.log('AWS Provider is not working properly when inserting a ReadModel with two projections') // TODO: Fix AWS Provider | ||
return | ||
} | ||
it('insert and update generate one ReadModel with version 4', async () => { | ||
const entityId: UUID = random.uuid() | ||
|
||
const insertedReadModel = await addConcurrency(client, entityId, 2, 'OtherConcurrencyReadModel') | ||
expect(insertedReadModel.id).to.be.eq(entityId) | ||
expect(insertedReadModel.otherId).to.be.eq(entityId) | ||
expect(insertedReadModel.boosterMetadata?.version).to.be.eq(2) | ||
|
||
const updatedReadModel = await addConcurrency(client, entityId, 4, 'OtherConcurrencyReadModel') | ||
expect(updatedReadModel.id).to.be.eq(entityId) | ||
expect(updatedReadModel.otherId).to.be.eq(entityId) | ||
expect(updatedReadModel.boosterMetadata?.version).to.be.eq(4) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
async function addConcurrency( | ||
client: ApolloClient<NormalizedCacheObject>, | ||
entityId: UUID, | ||
expectedVersion: number, | ||
readModelName: string | ||
): Promise<ReadModelInterface> { | ||
await client.mutate({ | ||
variables: { | ||
id: entityId, | ||
otherId: entityId, | ||
}, | ||
mutation: gql` | ||
mutation AddConcurrency($id: ID!, $otherId: ID!) { | ||
AddConcurrency(input: { id: $id, otherId: $otherId }) | ||
} | ||
`, | ||
}) | ||
|
||
const mutateResult = await waitForIt( | ||
() => { | ||
return client.mutate({ | ||
variables: { | ||
id: entityId, | ||
readModelName: readModelName, | ||
}, | ||
mutation: gql` | ||
mutation GetConcurrency($id: ID!, $readModelName: String!) { | ||
GetConcurrency(input: { id: $id, readModelName: $readModelName }) | ||
} | ||
`, | ||
}) | ||
}, | ||
(result) => | ||
result?.data?.GetConcurrency && | ||
result?.data?.GetConcurrency.length > 0 && | ||
result?.data?.GetConcurrency[0] && | ||
(result?.data?.GetConcurrency as Array<ReadModelInterface>).find( | ||
(value: ReadModelInterface) => value.boosterMetadata?.version === expectedVersion | ||
) !== undefined | ||
) | ||
|
||
const concurrency = (mutateResult?.data?.GetConcurrency as Array<ReadModelInterface>).find( | ||
(value: ReadModelInterface) => value.boosterMetadata?.version === expectedVersion | ||
)! | ||
expect(concurrency.id).to.be.eq(entityId) | ||
return concurrency | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/framework-integration-tests/src/commands/add-concurrency.ts
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,19 @@ | ||
import { Command } from '@boostercloud/framework-core' | ||
import { Register, UUID } from '@boostercloud/framework-types' | ||
import { ConcurrencyPersisted } from '../events/concurrency-persisted' | ||
|
||
export interface ProjectionDetails { | ||
methodName: string | ||
joinKey: keyof AddConcurrency | ||
} | ||
|
||
@Command({ | ||
authorize: 'all', | ||
}) | ||
export class AddConcurrency { | ||
public constructor(readonly id: UUID, readonly otherId: UUID) {} | ||
|
||
public static async handle(command: AddConcurrency, register: Register): Promise<void> { | ||
register.events(new ConcurrencyPersisted(command.id, command.otherId)) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/framework-integration-tests/src/commands/get-concurrency.ts
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,17 @@ | ||
import { Booster, Command } from '@boostercloud/framework-core' | ||
import { ReadModelInterface, ReadOnlyNonEmptyArray, Register, UUID } from '@boostercloud/framework-types' | ||
|
||
@Command({ | ||
authorize: 'all', | ||
}) | ||
export class GetConcurrency { | ||
public constructor(readonly id: UUID, readonly readModelName: string) {} | ||
|
||
public static async handle( | ||
command: GetConcurrency, | ||
register: Register | ||
): Promise<ReadOnlyNonEmptyArray<ReadModelInterface>> { | ||
const config = Booster.config | ||
return await config.provider.readModels.fetch(config, command.readModelName, command.id) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/framework-integration-tests/src/entities/concurrency.ts
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,19 @@ | ||
import { Entity, Reduces } from '@boostercloud/framework-core' | ||
import { UUID } from '@boostercloud/framework-types' | ||
import { ConcurrencyPersisted } from '../events/concurrency-persisted' | ||
|
||
@Entity({ | ||
authorizeReadEvents: 'all', | ||
}) | ||
export class Concurrency { | ||
public constructor(readonly id: UUID, readonly otherId: UUID) {} | ||
|
||
public getId() { | ||
return this.id | ||
} | ||
|
||
@Reduces(ConcurrencyPersisted) | ||
public static persisted(event: ConcurrencyPersisted, currentConcurrency: Concurrency): Concurrency { | ||
return new Concurrency(event.id, event.otherId) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/framework-integration-tests/src/events/concurrency-persisted.ts
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,11 @@ | ||
import { Event } from '@boostercloud/framework-core' | ||
import { UUID } from '@boostercloud/framework-types' | ||
|
||
@Event | ||
export class ConcurrencyPersisted { | ||
public constructor(readonly id: UUID, readonly otherId: UUID) {} | ||
|
||
public entityID(): UUID { | ||
return this.id | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/framework-integration-tests/src/read-models/concurrency-read-model.ts
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,18 @@ | ||
import { Projects, ReadModel } from '@boostercloud/framework-core' | ||
import { ProjectionResult, UUID } from '@boostercloud/framework-types' | ||
import { Concurrency } from '../entities/concurrency' | ||
|
||
@ReadModel({ | ||
authorize: 'all', | ||
}) | ||
export class ConcurrencyReadModel { | ||
public constructor(readonly id: UUID) {} | ||
|
||
@Projects(Concurrency, 'id') | ||
public static persisted( | ||
concurrency: Concurrency, | ||
concurrencyReadModel?: ConcurrencyReadModel | ||
): ProjectionResult<ConcurrencyReadModel> { | ||
return new ConcurrencyReadModel(concurrency.id) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/framework-integration-tests/src/read-models/other-concurrency-read-model.ts
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,26 @@ | ||
import { Projects, ReadModel } from '@boostercloud/framework-core' | ||
import { ProjectionResult, UUID } from '@boostercloud/framework-types' | ||
import { Concurrency } from '../entities/concurrency' | ||
|
||
@ReadModel({ | ||
authorize: 'all', | ||
}) | ||
export class OtherConcurrencyReadModel { | ||
public constructor(readonly id: UUID, readonly otherId: UUID) {} | ||
|
||
@Projects(Concurrency, 'id') | ||
public static persisted( | ||
concurrency: Concurrency, | ||
concurrencyReadModel?: OtherConcurrencyReadModel | ||
): ProjectionResult<OtherConcurrencyReadModel> { | ||
return new OtherConcurrencyReadModel(concurrency.id, concurrency.otherId) | ||
} | ||
|
||
@Projects(Concurrency, 'otherId') | ||
public static persistedByOtherId( | ||
concurrency: Concurrency, | ||
concurrencyReadModel?: OtherConcurrencyReadModel | ||
): ProjectionResult<OtherConcurrencyReadModel> { | ||
return new OtherConcurrencyReadModel(concurrency.otherId, concurrency.otherId) | ||
} | ||
} |
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
Oops, something went wrong.