RoundRobinWorkerChoiceStrategy
} = require('../../../lib/pools/selection-strategies/round-robin-worker-choice-strategy')
const {
- LessRecentlyUsedWorkerChoiceStrategy
-} = require('../../../lib/pools/selection-strategies/less-recently-used-worker-choice-strategy')
+ LessUsedWorkerChoiceStrategy
+} = require('../../../lib/pools/selection-strategies/less-used-worker-choice-strategy')
+const {
+ LessBusyWorkerChoiceStrategy
+} = require('../../../lib/pools/selection-strategies/less-busy-worker-choice-strategy')
const {
FairShareWorkerChoiceStrategy
} = require('../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy')
const WorkerChoiceStrategyStub = sinon.createStubInstance(
RoundRobinWorkerChoiceStrategy,
{
- choose: sinon.stub().returns('worker')
+ choose: sinon.stub().returns(0)
}
)
workerChoiceStrategyContext.workerChoiceStrategy = WorkerChoiceStrategyStub
- const chosenWorker = workerChoiceStrategyContext.execute()
+ const chosenWorkerKey = workerChoiceStrategyContext.execute()
expect(
workerChoiceStrategyContext.getWorkerChoiceStrategy().choose.calledOnce
).toBe(true)
- expect(chosenWorker).toBe('worker')
+ expect(chosenWorkerKey).toBe(0)
})
it('Verify that execute() return the worker chosen by the strategy with dynamic pool', () => {
const WorkerChoiceStrategyStub = sinon.createStubInstance(
RoundRobinWorkerChoiceStrategy,
{
- choose: sinon.stub().returns('worker')
+ choose: sinon.stub().returns(0)
}
)
workerChoiceStrategyContext.workerChoiceStrategy = WorkerChoiceStrategyStub
- const chosenWorker = workerChoiceStrategyContext.execute()
+ const chosenWorkerKey = workerChoiceStrategyContext.execute()
expect(
workerChoiceStrategyContext.getWorkerChoiceStrategy().choose.calledOnce
).toBe(true)
- expect(chosenWorker).toBe('worker')
+ expect(chosenWorkerKey).toBe(0)
})
it('Verify that setWorkerChoiceStrategy() works with ROUND_ROBIN and fixed pool', () => {
).toBeInstanceOf(RoundRobinWorkerChoiceStrategy)
})
- it('Verify that setWorkerChoiceStrategy() works with LESS_RECENTLY_USED and fixed pool', () => {
+ it('Verify that setWorkerChoiceStrategy() works with LESS_USED and fixed pool', () => {
+ const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
+ fixedPool
+ )
+ workerChoiceStrategyContext.setWorkerChoiceStrategy(
+ WorkerChoiceStrategies.LESS_USED
+ )
+ expect(
+ workerChoiceStrategyContext.getWorkerChoiceStrategy()
+ ).toBeInstanceOf(LessUsedWorkerChoiceStrategy)
+ })
+
+ it('Verify that setWorkerChoiceStrategy() works with LESS_USED and dynamic pool', () => {
+ const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
+ dynamicPool
+ )
+ workerChoiceStrategyContext.setWorkerChoiceStrategy(
+ WorkerChoiceStrategies.LESS_USED
+ )
+ expect(
+ workerChoiceStrategyContext.getWorkerChoiceStrategy()
+ ).toBeInstanceOf(DynamicPoolWorkerChoiceStrategy)
+ expect(
+ workerChoiceStrategyContext.getWorkerChoiceStrategy().workerChoiceStrategy
+ ).toBeInstanceOf(LessUsedWorkerChoiceStrategy)
+ })
+
+ it('Verify that setWorkerChoiceStrategy() works with LESS_BUSY and fixed pool', () => {
const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
fixedPool
)
workerChoiceStrategyContext.setWorkerChoiceStrategy(
- WorkerChoiceStrategies.LESS_RECENTLY_USED
+ WorkerChoiceStrategies.LESS_BUSY
)
expect(
workerChoiceStrategyContext.getWorkerChoiceStrategy()
- ).toBeInstanceOf(LessRecentlyUsedWorkerChoiceStrategy)
+ ).toBeInstanceOf(LessBusyWorkerChoiceStrategy)
})
- it('Verify that setWorkerChoiceStrategy() works with LESS_RECENTLY_USED and dynamic pool', () => {
+ it('Verify that setWorkerChoiceStrategy() works with LESS_BUSY and dynamic pool', () => {
const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
dynamicPool
)
workerChoiceStrategyContext.setWorkerChoiceStrategy(
- WorkerChoiceStrategies.LESS_RECENTLY_USED
+ WorkerChoiceStrategies.LESS_BUSY
)
expect(
workerChoiceStrategyContext.getWorkerChoiceStrategy()
).toBeInstanceOf(DynamicPoolWorkerChoiceStrategy)
expect(
workerChoiceStrategyContext.getWorkerChoiceStrategy().workerChoiceStrategy
- ).toBeInstanceOf(LessRecentlyUsedWorkerChoiceStrategy)
+ ).toBeInstanceOf(LessBusyWorkerChoiceStrategy)
})
it('Verify that setWorkerChoiceStrategy() works with FAIR_SHARE and fixed pool', () => {