-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented the lock tests for the 'ResourceTester'
- Loading branch information
1 parent
6097857
commit cb90c9f
Showing
12 changed files
with
113 additions
and
81 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,6 +1,2 @@ | ||
import { ResourceTesterTestCallback } from './Types'; | ||
export declare function getLocks(callback: ResourceTesterTestCallback): void; | ||
export declare function setLock(callback: ResourceTesterTestCallback): void; | ||
export declare function removeLock(callback: ResourceTesterTestCallback): void; | ||
export declare function getAvailableLocks(callback: ResourceTesterTestCallback): void; | ||
export declare function getLock(callback: ResourceTesterTestCallback): void; | ||
export declare function lock(callback: ResourceTesterTestCallback): void; |
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 |
---|---|---|
@@ -1,34 +1,56 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function getLocks(callback) { | ||
var LockScope_1 = require("../../lock/LockScope"); | ||
var LockKind_1 = require("../../lock/LockKind"); | ||
var LockType_1 = require("../../lock/LockType"); | ||
var Lock_1 = require("../../lock/Lock"); | ||
function lock(callback) { | ||
var _this = this; | ||
callback = this.multiple(callback, 1); | ||
if (!this.options.canLock) { | ||
callback = this.multiple(callback, 5); | ||
var lock_1 = new Lock_1.Lock(new LockKind_1.LockKind(LockScope_1.LockScope.Exclusive, LockType_1.LockType.Write), '123', null); | ||
this.producer(false, function (r1) { return r1.getLock('123', function (e) { return callback(e, !e, 'getLock must return an error', false); }); }); | ||
this.producer(false, function (r1) { return r1.setLock(lock_1, function (e) { return callback(e, !e, 'setLock must return an error', false); }); }); | ||
this.producer(false, function (r1) { return r1.getAvailableLocks(function (e, kinds) { return callback(e, !e, 'getAvailableLocks must return an error', false); }); }); | ||
this.producer(false, function (r1) { return r1.getLocks(function (e, locks) { return callback(e, !e, 'getLocks must return an error', false); }); }); | ||
this.producer(false, function (r1) { return r1.removeLock('123', function (e, removed) { return callback(e, !e, 'removeLock must return an error', false); }); }); | ||
return; | ||
} | ||
callback = this.multiple(callback, 2); | ||
var lock1 = new Lock_1.Lock(new LockKind_1.LockKind(LockScope_1.LockScope.Exclusive, LockType_1.LockType.Write), '123', null); | ||
this.producer(false, function (r1) { | ||
r1.getLocks(function (e, locks) { | ||
callback(e, !e, 'getLocks error', _this.options.canGetLocks, function () { | ||
callback(null, !!locks && !!locks.prototype[Symbol.iterator], 'getLocks returns an invalid value : must be an iterable', _this.options.canWrite); | ||
r1.setLock(lock1, function (e) { | ||
callback(e, !e, 'setLock error', undefined, function () { | ||
r1.getLock(lock1.uuid, function (e, lock) { | ||
callback(e, !e, 'getLock error - cannot find the lock', undefined, function () { | ||
callback(null, lock && lock.isSame && lock.isSame(lock1), 'The lock returned by getLock is not the one stored previously by setLock', undefined, function () { | ||
r1.getLocks(function (e, locks) { | ||
callback(e, !e, 'getLocks error', undefined, function () { | ||
callback(null, locks && locks.length === 1 && locks[0].isSame && locks[0].isSame(lock1), 'The lock added is not listed in the result of getLocks', undefined, function () { | ||
r1.removeLock(lock1.uuid, function (e, removed) { | ||
callback(e, !e && removed, 'removeLock error', undefined, function () { | ||
r1.getLocks(function (e, locks) { | ||
callback(e, !e, 'getLocks error', undefined, function () { | ||
callback(null, locks && locks.length === 0, 'The lock has not really been removed'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
this.producer(false, function (r1) { | ||
r1.getAvailableLocks(function (e, locks) { | ||
callback(e, !e, 'getAvailableLocks error', _this.options.canLock, function () { | ||
callback(null, !!locks && !!locks.constructor.prototype[Symbol.iterator], 'getAvailableLocks returns an invalid value : must be an iterable', _this.options.canLock); | ||
}); | ||
}); | ||
}); | ||
} | ||
exports.getLocks = getLocks; | ||
function setLock(callback) { | ||
callback = this.multiple(callback, 1); | ||
callback(null, true, ''); | ||
} | ||
exports.setLock = setLock; | ||
function removeLock(callback) { | ||
callback = this.multiple(callback, 1); | ||
callback(null, true, ''); | ||
} | ||
exports.removeLock = removeLock; | ||
function getAvailableLocks(callback) { | ||
callback = this.multiple(callback, 1); | ||
callback(null, true, ''); | ||
} | ||
exports.getAvailableLocks = getAvailableLocks; | ||
function getLock(callback) { | ||
callback = this.multiple(callback, 1); | ||
callback(null, true, ''); | ||
} | ||
exports.getLock = getLock; | ||
exports.lock = lock; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,64 @@ | ||
import { ResourceTesterTestCallback } from './Types' | ||
import { IResource } from '../../IResource' | ||
import { LockScope } from '../../lock/LockScope' | ||
import { LockKind } from '../../lock/LockKind' | ||
import { LockType } from '../../lock/LockType' | ||
import { Lock } from '../../lock/Lock' | ||
|
||
// ****************************** Locks ****************************** // | ||
export function getLocks(callback : ResourceTesterTestCallback) | ||
export function lock(callback : ResourceTesterTestCallback) | ||
{ | ||
callback = this.multiple(callback, 1); | ||
if(!this.options.canLock) | ||
{ | ||
callback = this.multiple(callback, 5); | ||
|
||
const lock = new Lock(new LockKind(LockScope.Exclusive, LockType.Write), '123', null); | ||
|
||
this.producer(false, (r1 : IResource) => r1.getLock('123', (e) => callback(e, !e, 'getLock must return an error', false))); | ||
this.producer(false, (r1 : IResource) => r1.setLock(lock, (e) => callback(e, !e, 'setLock must return an error', false))); | ||
this.producer(false, (r1 : IResource) => r1.getAvailableLocks((e, kinds) => callback(e, !e, 'getAvailableLocks must return an error', false))); | ||
this.producer(false, (r1 : IResource) => r1.getLocks((e, locks) => callback(e, !e, 'getLocks must return an error', false))); | ||
this.producer(false, (r1 : IResource) => r1.removeLock('123', (e, removed) => callback(e, !e, 'removeLock must return an error', false))); | ||
return; | ||
} | ||
|
||
callback = this.multiple(callback, 2); | ||
|
||
const lock1 = new Lock(new LockKind(LockScope.Exclusive, LockType.Write), '123', null); | ||
|
||
this.producer(false, (r1 : IResource) => { | ||
r1.setLock(lock1, (e) => { | ||
callback(e, !e, 'setLock error', undefined, () => { | ||
r1.getLock(lock1.uuid, (e, lock) => { | ||
callback(e, !e, 'getLock error - cannot find the lock', undefined, () => { | ||
callback(null, lock && lock.isSame && lock.isSame(lock1), 'The lock returned by getLock is not the one stored previously by setLock', undefined, () => { | ||
r1.getLocks((e, locks) => { | ||
callback(e, !e, 'getLocks error', undefined, () => { | ||
callback(null, locks && locks.length === 1 && locks[0].isSame && locks[0].isSame(lock1), 'The lock added is not listed in the result of getLocks', undefined, () => { | ||
r1.removeLock(lock1.uuid, (e, removed) => { | ||
callback(e, !e && removed, 'removeLock error', undefined, () => { | ||
r1.getLocks((e, locks) => { | ||
callback(e, !e, 'getLocks error', undefined, () => { | ||
callback(null, locks && locks.length === 0, 'The lock has not really been removed'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}) | ||
}); | ||
}) | ||
}) | ||
|
||
this.producer(false, (r1) => { | ||
r1.getLocks((e, locks) => { | ||
callback(e, !e, 'getLocks error', this.options.canGetLocks, () => { | ||
callback(null, !!locks && !!(locks as any).prototype[Symbol.iterator], 'getLocks returns an invalid value : must be an iterable', this.options.canWrite) | ||
r1.getAvailableLocks((e, locks) => { | ||
callback(e, !e, 'getAvailableLocks error', this.options.canLock, () => { | ||
callback(null, !!locks && !!(locks as any).constructor.prototype[Symbol.iterator], 'getAvailableLocks returns an invalid value : must be an iterable', this.options.canLock) | ||
}); | ||
}) | ||
}) | ||
} | ||
export function setLock(callback : ResourceTesterTestCallback) | ||
{ | ||
callback = this.multiple(callback, 1); | ||
callback(null, true, ''); | ||
} | ||
export function removeLock(callback : ResourceTesterTestCallback) | ||
{ | ||
callback = this.multiple(callback, 1); | ||
callback(null, true, ''); | ||
} | ||
export function getAvailableLocks(callback : ResourceTesterTestCallback) | ||
{ | ||
callback = this.multiple(callback, 1); | ||
callback(null, true, ''); | ||
} | ||
export function getLock(callback : ResourceTesterTestCallback) | ||
{ | ||
callback = this.multiple(callback, 1); | ||
callback(null, true, ''); | ||
} |
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
Empty file.
Empty file.
Empty file.
Empty file.