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:

  • Preconfigured Vitest test cases
  • Common edge case coverage

Usage example:

// filename: MySharedLockAdapter.test.ts

import { beforeEach, describe, expect, test } from "vitest";
import { sharedLockAdapterTestSuite } from "eridu-tech/shared-lock/test-utilities";
import { MemorySharedLockAdapter } from "./MemorySharedLockAdapter.js";

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:

  • Preconfigured Vitest test cases
  • Standardized event-bus behavior validation
  • Common edge case coverage

Usage example:

// filename: MySharedLockFactory.test.ts

import { beforeEach, describe, expect, test } from "vitest";
import { sharedLockProviderTestSuite } from "eridu-tech/shared-lock/test-utilities";
import { MySharedLockFactory } from "./MySharedLockFactory.js";

describe("class: MySharedLockFactory", () => {
sharedLockProviderTestSuite({
createSharedLockFactory: () => new MySharedLockFactory(),
test,
beforeEach,
expect,
describe,
});
});

Further information

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