diff --git a/lib/resource/std/resourceTester/Locks.d.ts b/lib/resource/std/resourceTester/Locks.d.ts index 8453c90b..daefdda3 100644 --- a/lib/resource/std/resourceTester/Locks.d.ts +++ b/lib/resource/std/resourceTester/Locks.d.ts @@ -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; diff --git a/lib/resource/std/resourceTester/Locks.js b/lib/resource/std/resourceTester/Locks.js index b35a4a82..8d8425ec 100644 --- a/lib/resource/std/resourceTester/Locks.js +++ b/lib/resource/std/resourceTester/Locks.js @@ -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; diff --git a/lib/resource/std/resourceTester/ResourceTester.d.ts b/lib/resource/std/resourceTester/ResourceTester.d.ts index f90ad27d..0c6bcad5 100644 --- a/lib/resource/std/resourceTester/ResourceTester.d.ts +++ b/lib/resource/std/resourceTester/ResourceTester.d.ts @@ -21,11 +21,7 @@ export declare class ResourceTester { protected writeRead: typeof content.writeRead; protected mimeType: typeof content.mimeType; protected size: typeof content.size; - protected getLocks: typeof locks.getLocks; - protected setLock: typeof locks.setLock; - protected removeLock: typeof locks.removeLock; - protected getAvailableLocks: typeof locks.getAvailableLocks; - protected getLock: typeof locks.getLock; + protected lock: typeof locks.lock; protected addChild: typeof children.addChild; protected removeChild: typeof children.removeChild; protected getChildren: typeof children.getChildren; diff --git a/lib/resource/std/resourceTester/ResourceTester.js b/lib/resource/std/resourceTester/ResourceTester.js index ee6bc0c1..6cd71aa8 100644 --- a/lib/resource/std/resourceTester/ResourceTester.js +++ b/lib/resource/std/resourceTester/ResourceTester.js @@ -19,11 +19,11 @@ var DefaultResourceTesterOptions = (function () { this.canBeCreated = true; this.canBeDeleted = true; this.canBeRenamed = true; - this.canGetLocks = true; this.canGetSize = true; this.canBeMoved = true; this.canWrite = true; this.canRead = true; + this.canLock = true; } return DefaultResourceTesterOptions; }()); @@ -38,11 +38,7 @@ var ResourceTester = (function () { this.writeRead = content.writeRead; this.mimeType = content.mimeType; this.size = content.size; - this.getLocks = locks.getLocks; - this.setLock = locks.setLock; - this.removeLock = locks.removeLock; - this.getAvailableLocks = locks.getAvailableLocks; - this.getLock = locks.getLock; + this.lock = locks.lock; this.addChild = children.addChild; this.removeChild = children.removeChild; this.getChildren = children.getChildren; @@ -138,6 +134,7 @@ var ResourceTester = (function () { test('writeRead'); test('mimeType'); test('size'); + test('lock'); test('addChild'); test('removeChild'); test('getChildren'); diff --git a/lib/resource/std/resourceTester/Types.d.ts b/lib/resource/std/resourceTester/Types.d.ts index e49aaaab..368736ab 100644 --- a/lib/resource/std/resourceTester/Types.d.ts +++ b/lib/resource/std/resourceTester/Types.d.ts @@ -10,11 +10,11 @@ export interface ResourceTesterOptions { canBeCreated: boolean; canBeDeleted: boolean; canBeRenamed: boolean; - canGetLocks: boolean; canGetSize: boolean; canBeMoved: boolean; canWrite: boolean; canRead: boolean; + canLock: boolean; } export declare type ResourceTesterTestCallback = (error: Error, isValid: boolean, text: string, optionReverse?: boolean, cbNext?: () => void) => void; export declare type ResourceTesterProducerCallback = (resource: T) => void; diff --git a/src/resource/std/resourceTester/Locks.ts b/src/resource/std/resourceTester/Locks.ts index 3bfbc312..e555c9e4 100644 --- a/src/resource/std/resourceTester/Locks.ts +++ b/src/resource/std/resourceTester/Locks.ts @@ -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, ''); -} diff --git a/src/resource/std/resourceTester/ResourceTester.ts b/src/resource/std/resourceTester/ResourceTester.ts index 8cf79f8b..794f8e14 100644 --- a/src/resource/std/resourceTester/ResourceTester.ts +++ b/src/resource/std/resourceTester/ResourceTester.ts @@ -20,11 +20,11 @@ class DefaultResourceTesterOptions implements ResourceTesterOptions canBeCreated : boolean = true canBeDeleted : boolean = true canBeRenamed : boolean = true - canGetLocks : boolean = true canGetSize : boolean = true canBeMoved : boolean = true canWrite : boolean = true canRead : boolean = true + canLock : boolean = true } export class ResourceTester @@ -135,12 +135,8 @@ export class ResourceTester test('rename'); test('writeRead'); test('mimeType'); - test('size'); /* - test('getLocks'); - test('setLock'); - test('removeLock'); - test('getAvailableLocks'); - test('getLock');*/ + test('size'); + test('lock'); test('addChild'); test('removeChild'); test('getChildren'); @@ -165,11 +161,7 @@ export class ResourceTester protected size = content.size // ****************************** Locks ****************************** // - protected getLocks = locks.getLocks - protected setLock = locks.setLock - protected removeLock = locks.removeLock - protected getAvailableLocks = locks.getAvailableLocks - protected getLock = locks.getLock + protected lock = locks.lock // ****************************** Children ****************************** // protected addChild = children.addChild diff --git a/src/resource/std/resourceTester/Types.ts b/src/resource/std/resourceTester/Types.ts index ec57f378..94f35c2f 100644 --- a/src/resource/std/resourceTester/Types.ts +++ b/src/resource/std/resourceTester/Types.ts @@ -12,11 +12,11 @@ export interface ResourceTesterOptions canBeCreated : boolean canBeDeleted : boolean canBeRenamed : boolean - canGetLocks : boolean canGetSize : boolean canBeMoved : boolean canWrite : boolean canRead : boolean + canLock : boolean } export type ResourceTesterTestCallback = (error : Error, isValid : boolean, text : string, optionReverse ?: boolean, cbNext ?: () => void) => void; diff --git a/test/tests/resourceTesterPhysical/testFile22 b/test/tests/resourceTesterPhysical/testFile22 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterPhysical/testFile23 b/test/tests/resourceTesterPhysical/testFile23 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterVirtualStored/16 b/test/tests/resourceTesterVirtualStored/16 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterVirtualStored/17 b/test/tests/resourceTesterVirtualStored/17 new file mode 100644 index 00000000..e69de29b