-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
139 additions
and
87 deletions.
There are no files selected for viewing
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) | ||
* Weyoss <weyoss@protonmail.com> | ||
* https://github.com/weyoss | ||
* | ||
* This source code is licensed under the MIT license found in the LICENSE file | ||
* in the root directory of this source tree. | ||
*/ | ||
|
||
import { expect, test } from '@jest/globals'; | ||
import bluebird from 'bluebird'; | ||
import { | ||
EQueueDeliveryModel, | ||
EQueueType, | ||
Namespace, | ||
NamespaceNotFoundError, | ||
Queue, | ||
} from '../../../src/lib/index.js'; | ||
|
||
test('Namespace', async () => { | ||
const queue = bluebird.promisifyAll(new Queue()); | ||
await queue.saveAsync( | ||
'myqueue', | ||
EQueueType.FIFO_QUEUE, | ||
EQueueDeliveryModel.POINT_TO_POINT, | ||
); | ||
|
||
const namespace = bluebird.promisifyAll(new Namespace()); | ||
const nsList = await namespace.getNamespacesAsync(); | ||
expect(nsList).toEqual(['testing']); | ||
|
||
const nsQueues = await namespace.getNamespaceQueuesAsync('testing'); | ||
expect(nsQueues).toEqual([{ ns: 'testing', name: 'myqueue' }]); | ||
|
||
await namespace.deleteAsync('testing'); | ||
const nsList1 = await namespace.getNamespacesAsync(); | ||
expect(nsList1).toEqual([]); | ||
|
||
await expect(namespace.getNamespaceQueuesAsync('testing')).rejects.toThrow( | ||
NamespaceNotFoundError, | ||
); | ||
|
||
await queue.shutdownAsync(); | ||
await namespace.shutdownAsync(); | ||
}); |
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,44 @@ | ||
/* | ||
* Copyright (c) | ||
* Weyoss <weyoss@protonmail.com> | ||
* https://github.com/weyoss | ||
* | ||
* This source code is licensed under the MIT license found in the LICENSE file | ||
* in the root directory of this source tree. | ||
*/ | ||
|
||
import { expect, test } from '@jest/globals'; | ||
import bluebird from 'bluebird'; | ||
import { | ||
Consumer, | ||
ConsumerGroupIdNotSupportedError, | ||
EQueueDeliveryModel, | ||
EQueueType, | ||
IQueueParams, | ||
} from '../../../src/lib/index.js'; | ||
import { getQueue } from '../../common/queue.js'; | ||
|
||
test('ConsumerGroupIdNotSupportedError', async () => { | ||
const queue1: IQueueParams = { | ||
name: 'test-queue', | ||
ns: 'ns1', | ||
}; | ||
|
||
const queue = await getQueue(); | ||
await queue.saveAsync( | ||
queue1, | ||
EQueueType.PRIORITY_QUEUE, | ||
EQueueDeliveryModel.POINT_TO_POINT, | ||
); | ||
|
||
const consumer1 = bluebird.promisifyAll(new Consumer()); | ||
await consumer1.consumeAsync( | ||
{ queue: queue1, groupId: 'my-group-1' }, | ||
(msg, cb) => cb(), | ||
); | ||
|
||
await expect(consumer1.runAsync()).rejects.toThrow( | ||
ConsumerGroupIdNotSupportedError, | ||
); | ||
await consumer1.shutdownAsync(); | ||
}); |
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,50 @@ | ||
/* | ||
* Copyright (c) | ||
* Weyoss <weyoss@protonmail.com> | ||
* https://github.com/weyoss | ||
* | ||
* This source code is licensed under the MIT license found in the LICENSE file | ||
* in the root directory of this source tree. | ||
*/ | ||
|
||
import { expect, test } from '@jest/globals'; | ||
import bluebird from 'bluebird'; | ||
import { RedisKeysError } from '../../../src/common/redis-keys/redis-keys.error.js'; | ||
import { | ||
Consumer, | ||
ConsumerGroups, | ||
EQueueDeliveryModel, | ||
EQueueType, | ||
IQueueParams, | ||
} from '../../../src/lib/index.js'; | ||
import { getQueue } from '../../common/queue.js'; | ||
|
||
test('Consumer group ID validation', async () => { | ||
const queue1: IQueueParams = { | ||
name: 'test-queue', | ||
ns: 'ns1', | ||
}; | ||
|
||
const queue = await getQueue(); | ||
await queue.saveAsync( | ||
queue1, | ||
EQueueType.PRIORITY_QUEUE, | ||
EQueueDeliveryModel.PUB_SUB, | ||
); | ||
|
||
const consumer1 = bluebird.promisifyAll(new Consumer()); | ||
await expect( | ||
consumer1.consumeAsync( | ||
{ queue: queue1, groupId: 'my-group-1!' }, | ||
(msg, cb) => cb(), | ||
), | ||
).rejects.toThrow(RedisKeysError); | ||
|
||
const consumerGroups = bluebird.promisifyAll(new ConsumerGroups()); | ||
await expect( | ||
consumerGroups.saveConsumerGroupAsync(queue1, 'my-group-1!'), | ||
).rejects.toThrow(RedisKeysError); | ||
|
||
await consumerGroups.shutdownAsync(); | ||
await consumer1.shutdownAsync(); | ||
}); |