Skip to main content

Creating SharedLock adapters

Implementing your custom ISharedLockAdapter​

In order to create an adapter you need to implement the ISharedLockAdapter contract.

Testing your custom ISharedLockAdapter​

We provide a complete test suite to test your shared-lock adapter implementation. Simply use the sharedLockAdapterTestSuite function:

The suite provides preconfigured Vitest test cases with common edge case coverage and standardized shared-lock adapter contract conformance testing.

Usage example:

./samples/shared-lock-adapter-test-suite.ts
import { beforeEach, describe, expect, test } from "vitest";
import { sharedLockAdapterTestSuite } from "eridu-tech/shared-lock/test-utilities";
import { MemorySharedLockAdapter } from "eridu-tech/shared-lock/memory-shared-lock-adapter";

describe("class: MySharedLockAdapter", () => {
sharedLockAdapterTestSuite({
createAdapter: () => new MemorySharedLockAdapter(),
test,
beforeEach,
expect,
describe,
});
});

Implementing your custom ISharedLockFactory class​

In some cases, you may need to implement a custom SharedLockFactory class to optimize performance for your specific technology stack. You can then directly implement the ISharedLockFactory contract.

Testing your custom ISharedLockFactory class​

We provide a complete test suite to verify your custom event-bus class implementation. Simply use the sharedLockProviderTestSuite function:

The suite provides preconfigured Vitest test cases with common edge case coverage and standardized shared-lock factory contract conformance testing.

Usage example:

./samples/shared-lock-factory-test-suite.ts
import { beforeEach, describe, expect, test } from "vitest";
import { sharedLockFactoryTestSuite } from "eridu-tech/shared-lock/test-utilities";
import { SharedLockFactory } from "eridu-tech/shared-lock";
import { MemorySharedLockAdapter } from "eridu-tech/shared-lock/memory-shared-lock-adapter";
import { Serde } from "eridu-tech/serde";
import { SuperJsonSerdeAdapter } from "eridu-tech/serde/super-json-serde-adapter";

describe("class: SharedLockFactory", () => {
sharedLockFactoryTestSuite({
createSharedLockFactory: () => ({
sharedLockFactory: new SharedLockFactory({
adapter: new MemorySharedLockAdapter(),
}),
serde: new Serde(new SuperJsonSerdeAdapter()),
}),
test,
beforeEach,
expect,
describe,
});
});

Further information​

For further information refer to eridu-tech/shared-lock API docs.