@ohos-ports/core 1.0.113-beta.0 → 1.16.33-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +13 -0
- package/README.md +3 -0
- package/lib/api/node.js +176 -0
- package/lib/api/team.js +1889 -0
- package/lib/blocklet/downloader/blocklet-downloader.js +246 -0
- package/lib/blocklet/downloader/bundle-downloader.js +316 -0
- package/lib/blocklet/downloader/constants.js +3 -0
- package/lib/blocklet/downloader/resolve-download.js +187 -0
- package/lib/blocklet/extras.js +177 -0
- package/lib/blocklet/hooks.js +89 -0
- package/lib/blocklet/manager/base.js +49 -0
- package/lib/blocklet/manager/config-synchronizer.js +128 -0
- package/lib/blocklet/manager/disk.js +5170 -0
- package/lib/blocklet/manager/engine.js +124 -0
- package/lib/blocklet/manager/helper/install-application-from-backup.js +285 -0
- package/lib/blocklet/manager/helper/install-application-from-dev.js +72 -0
- package/lib/blocklet/manager/helper/install-application-from-general.js +209 -0
- package/lib/blocklet/manager/helper/install-component-from-dev.js +128 -0
- package/lib/blocklet/manager/helper/install-component-from-upload.js +197 -0
- package/lib/blocklet/manager/helper/install-component-from-url.js +214 -0
- package/lib/blocklet/manager/helper/migrate-application-to-struct-v2.js +557 -0
- package/lib/blocklet/manager/helper/rollback-cache.js +41 -0
- package/lib/blocklet/manager/helper/upgrade-components.js +179 -0
- package/lib/blocklet/manager/pm2-events.js +50 -0
- package/lib/blocklet/migration-dist/migration.cjs +38605 -0
- package/lib/blocklet/migration-dist/run-script.cjs +29 -0
- package/lib/blocklet/migration.js +145 -0
- package/lib/blocklet/project/connect-by-studio.js +91 -0
- package/lib/blocklet/project/connect-to-store.js +64 -0
- package/lib/blocklet/project/create-pack-release.js +293 -0
- package/lib/blocklet/project/disconnect-from-store.js +13 -0
- package/lib/blocklet/project/get-is-multiple-tenant.js +8 -0
- package/lib/blocklet/project/index.js +545 -0
- package/lib/blocklet/project/logo.png +0 -0
- package/lib/blocklet/project/publish-to-store.js +108 -0
- package/lib/blocklet/project/util.js +194 -0
- package/lib/blocklet/security/access-policy.js +131 -0
- package/lib/blocklet/security/index.js +309 -0
- package/lib/blocklet/security/response-header-policy.js +178 -0
- package/lib/blocklet/security/security-rule.js +127 -0
- package/lib/blocklet/security/utils.js +35 -0
- package/lib/blocklet/security/validator.js +40 -0
- package/lib/blocklet/storage/backup/base.js +149 -0
- package/lib/blocklet/storage/backup/blocklet-extras.js +110 -0
- package/lib/blocklet/storage/backup/blocklet.js +159 -0
- package/lib/blocklet/storage/backup/blocklets.js +109 -0
- package/lib/blocklet/storage/backup/data.js +35 -0
- package/lib/blocklet/storage/backup/disk.js +131 -0
- package/lib/blocklet/storage/backup/logs.js +24 -0
- package/lib/blocklet/storage/backup/routing-rule.js +47 -0
- package/lib/blocklet/storage/backup/spaces.js +345 -0
- package/lib/blocklet/storage/restore/base.js +74 -0
- package/lib/blocklet/storage/restore/blocklet-extras.js +89 -0
- package/lib/blocklet/storage/restore/blocklet.js +56 -0
- package/lib/blocklet/storage/restore/blocklets.js +43 -0
- package/lib/blocklet/storage/restore/disk.js +104 -0
- package/lib/blocklet/storage/restore/logs.js +21 -0
- package/lib/blocklet/storage/restore/spaces.js +174 -0
- package/lib/blocklet/storage/utils/disk.js +178 -0
- package/lib/blocklet/storage/utils/hash.js +53 -0
- package/lib/blocklet/storage/utils/zip.js +43 -0
- package/lib/cert.js +221 -0
- package/lib/crons/check-new-version.js +68 -0
- package/lib/crons/monitor-disk-usage.js +46 -0
- package/lib/crons/rotate-pm2-logs/index.js +41 -0
- package/lib/crons/rotate-pm2-logs/script.js +56 -0
- package/lib/event/auto-backup-handler.js +48 -0
- package/lib/event/index.js +520 -0
- package/lib/index.js +768 -364
- package/lib/locales/ar.js +18 -0
- package/lib/locales/de.js +21 -0
- package/lib/locales/en.js +19 -0
- package/lib/locales/es.js +21 -0
- package/lib/locales/fr.js +21 -0
- package/lib/locales/hi.js +18 -0
- package/lib/locales/i18n.db +0 -0
- package/lib/locales/id.js +20 -0
- package/lib/locales/index.js +54 -0
- package/lib/locales/ja.js +19 -0
- package/lib/locales/ko.js +18 -0
- package/lib/locales/pt.js +20 -0
- package/lib/locales/ru.js +21 -0
- package/lib/locales/th.js +18 -0
- package/lib/locales/vi.js +18 -0
- package/lib/locales/zh-tw.js +17 -0
- package/lib/locales/zh.js +17 -0
- package/lib/migrations/1.0.21-update-config.js +34 -0
- package/lib/migrations/1.0.22-max-memory.js +40 -0
- package/lib/migrations/1.0.25.js +36 -0
- package/lib/migrations/1.0.32-update-config.js +30 -0
- package/lib/migrations/1.0.33-blocklets.js +33 -0
- package/lib/migrations/1.0.36-snapshot.js +10 -0
- package/lib/migrations/1.1.10-team.js +26 -0
- package/lib/migrations/1.1.9-snapshot.js +7 -0
- package/lib/migrations/1.16.11-component-status.js +22 -0
- package/lib/migrations/1.16.33-blocklet-security-rule.js +17 -0
- package/lib/migrations/1.16.6-chain-info.js +78 -0
- package/lib/migrations/1.16.8-component-title.js +66 -0
- package/lib/migrations/1.2.11-blocklet-registry.js +10 -0
- package/lib/migrations/1.2.2-blocklet-registry.js +10 -0
- package/lib/migrations/1.3.1-disk-alert-threshold.js +10 -0
- package/lib/migrations/1.4.5-access-key.js +18 -0
- package/lib/migrations/1.5.0-site.js +34 -0
- package/lib/migrations/1.5.15-site.js +184 -0
- package/lib/migrations/1.5.20-registry.js +15 -0
- package/lib/migrations/1.6.17-blocklet-children.js +48 -0
- package/lib/migrations/1.6.21-rename-ip-echo-domain.js +35 -0
- package/lib/migrations/1.6.4-security.js +59 -0
- package/lib/migrations/1.6.5-security.js +60 -0
- package/lib/migrations/1.6.9-update-node-info-and-certificate.js +39 -0
- package/lib/migrations/1.7.1-blocklet-setup.js +18 -0
- package/lib/migrations/1.7.12-blocklet-meta.js +51 -0
- package/lib/migrations/1.7.15-blocklet-bundle-source.js +42 -0
- package/lib/migrations/1.7.20-blocklet-component.js +41 -0
- package/lib/migrations/1.8.33-blocklet-mem-limit.js +20 -0
- package/lib/migrations/README.md +71 -0
- package/lib/migrations/index.js +215 -0
- package/lib/monitor/blocklet-runtime-monitor.js +204 -0
- package/lib/monitor/get-history-list.js +37 -0
- package/lib/monitor/node-monit-sender.js +99 -0
- package/lib/monitor/node-runtime-monitor.js +205 -0
- package/lib/processes/updater.js +186 -0
- package/lib/router/helper.js +1653 -0
- package/lib/router/index.js +341 -0
- package/lib/router/manager.js +806 -0
- package/lib/states/README.md +38 -0
- package/lib/states/access-key.js +124 -0
- package/lib/states/access-policy.js +29 -0
- package/lib/states/audit-log.js +734 -0
- package/lib/states/backup.js +165 -0
- package/lib/states/base.js +25 -0
- package/lib/states/blocklet-extras.js +257 -0
- package/lib/states/blocklet.js +755 -0
- package/lib/states/cache.js +23 -0
- package/lib/states/connect-account.js +8 -0
- package/lib/states/index.js +76 -0
- package/lib/states/job.js +8 -0
- package/lib/states/migration.js +34 -0
- package/lib/states/node.js +324 -0
- package/lib/states/notification.js +81 -0
- package/lib/states/passport.js +8 -0
- package/lib/states/project.js +119 -0
- package/lib/states/release.js +50 -0
- package/lib/states/response-header-policy.js +30 -0
- package/lib/states/routing-snapshot.js +146 -0
- package/lib/states/runtime-insight.js +25 -0
- package/lib/states/security-rule.js +30 -0
- package/lib/states/session.js +53 -0
- package/lib/states/site.js +102 -0
- package/lib/states/tag.js +8 -0
- package/lib/states/traffic-insight.js +25 -0
- package/lib/states/user-session.js +8 -0
- package/lib/states/user.js +717 -0
- package/lib/states/verify-code.js +152 -0
- package/lib/states/webhook.js +66 -0
- package/lib/team/manager.js +508 -0
- package/lib/util/blocklet.js +2182 -0
- package/lib/util/cache.js +63 -0
- package/lib/util/chain.js +29 -0
- package/lib/util/default-node-config.js +46 -0
- package/lib/util/docker/blocklet-custom-dockerfile.js +92 -0
- package/lib/util/docker/check-docker-has-image.js +23 -0
- package/lib/util/docker/check-docker-installed.js +32 -0
- package/lib/util/docker/check-docker-run-history.js +18 -0
- package/lib/util/docker/check-need-run-docker.js +32 -0
- package/lib/util/docker/create-docker-image.js +65 -0
- package/lib/util/docker/debian-dockerfile.js +50 -0
- package/lib/util/docker/docker-container-prune.js +75 -0
- package/lib/util/docker/docker-exec-chown.js +39 -0
- package/lib/util/docker/docker-exec.js +68 -0
- package/lib/util/docker/docker-remove-by-name.js +20 -0
- package/lib/util/docker/get-docker-runtime-info.js +39 -0
- package/lib/util/docker/parse-docker-name.js +10 -0
- package/lib/util/docker/parse-docker-options-from-pm2.js +295 -0
- package/lib/util/docker/shard-network.js +10 -0
- package/lib/util/domain-status.js +118 -0
- package/lib/util/get-accessible-external-node-ip.js +92 -0
- package/lib/util/get-dynamic-components.js +47 -0
- package/lib/util/get-meta-from-url.js +30 -0
- package/lib/util/get-migration-scripts.js +36 -0
- package/lib/util/get-safe-env.js +12 -0
- package/lib/util/index.js +522 -0
- package/lib/util/install-external-dependencies.js +67 -0
- package/lib/util/ip.js +53 -0
- package/lib/util/launcher.js +475 -0
- package/lib/util/log.js +431 -0
- package/lib/util/maintain.js +178 -0
- package/lib/util/promise-debounce.js +29 -0
- package/lib/util/promise-once.js +14 -0
- package/lib/util/promise-spawn.js +93 -0
- package/lib/util/queue.js +44 -0
- package/lib/util/ready.js +89 -0
- package/lib/util/request.js +10 -0
- package/lib/util/requirement.js +61 -0
- package/lib/util/reset-node.js +166 -0
- package/lib/util/rotator.js +194 -0
- package/lib/util/router.js +122 -0
- package/lib/util/rpc.js +78 -0
- package/lib/util/spaces.js +102 -0
- package/lib/util/store.js +184 -0
- package/lib/util/sysinfo.js +46 -0
- package/lib/util/ua.js +54 -0
- package/lib/validators/backup.js +34 -0
- package/lib/validators/blocklet-extra.js +18 -0
- package/lib/validators/node.js +73 -0
- package/lib/validators/permission.js +38 -0
- package/lib/validators/project.js +39 -0
- package/lib/validators/role.js +64 -0
- package/lib/validators/router.js +192 -0
- package/lib/validators/space-gateway.js +33 -0
- package/lib/validators/trusted-factory.js +28 -0
- package/lib/validators/trusted-passport.js +32 -0
- package/lib/validators/user.js +62 -0
- package/lib/validators/util.js +92 -0
- package/lib/validators/webhook.js +42 -0
- package/lib/webhook/index.js +216 -0
- package/lib/webhook/reduce-queue.js +12 -0
- package/lib/webhook/sender/api/index.js +67 -0
- package/lib/webhook/sender/base.js +11 -0
- package/lib/webhook/sender/index.js +44 -0
- package/lib/webhook/sender/slack/index.js +167 -0
- package/lib/webhook/sender/wallet/index.js +62 -0
- package/package.json +107 -34
- package/examples/BatchClient.js +0 -61
- package/examples/compressor/example.js +0 -7
- package/examples/jsonrpcserver/rpcmethod.js +0 -21
- package/examples/jsonrpcserver/rpcrequest.js +0 -20
- package/examples/jsonrpcserver/rpctest.js +0 -6
- package/examples/loader-pipes/test-mc.js +0 -52
- package/examples/loader-pipes/test.js +0 -51
- package/examples/mc-test.js +0 -44
- package/examples/redisdebug.js +0 -80
- package/lib/cache/CFMemcache.js +0 -57
- package/lib/cache/CacheLoader.js +0 -217
- package/lib/cache/Memcache.js +0 -406
- package/lib/class/Class.js +0 -54
- package/lib/client/MemcacheAdapter.js +0 -139
- package/lib/client/Memcached.js +0 -142
- package/lib/client/MemcachedSocket.js +0 -570
- package/lib/client/MySQLPool.js +0 -153
- package/lib/client/PGPool.js +0 -296
- package/lib/client/Redis.js +0 -787
- package/lib/client/S3.js +0 -103
- package/lib/client/S3Client.js +0 -392
- package/lib/client/pg/CursorQueryWorker.js +0 -160
- package/lib/client/rabbitmq/RbmqChannel.js +0 -61
- package/lib/client/rabbitmq/RbmqConfig.js +0 -144
- package/lib/client/rabbitmq/RbmqConnection.js +0 -259
- package/lib/client/rabbitmq/RbmqExchange.js +0 -112
- package/lib/client/rabbitmq/RbmqIncomingMessage.js +0 -53
- package/lib/client/rabbitmq/RbmqMessage.js +0 -120
- package/lib/client/rabbitmq/RbmqOutcomingMessage.js +0 -47
- package/lib/client/rabbitmq/RbmqQueue.js +0 -87
- package/lib/client/rabbitmq/index.js +0 -8
- package/lib/common/Assertions.js +0 -184
- package/lib/common/Merge.js +0 -32
- package/lib/common/Net.js +0 -56
- package/lib/common/Process.js +0 -20
- package/lib/common/Random.js +0 -53
- package/lib/common/Sort.js +0 -19
- package/lib/common/Types.js +0 -163
- package/lib/credentials/CredentialsProvider.js +0 -45
- package/lib/credentials/Manager.js +0 -101
- package/lib/crypto/Crypto.js +0 -66
- package/lib/data/BinaryData.js +0 -363
- package/lib/data/Compressor.js +0 -83
- package/lib/data/FormData.js +0 -144
- package/lib/data/Mime.js +0 -45
- package/lib/event/ErrorEvent.js +0 -71
- package/lib/event/Event.js +0 -20
- package/lib/event/EventDispatcher.js +0 -157
- package/lib/http/ConnectionPool.js +0 -82
- package/lib/http/ExpressServer.js +0 -19
- package/lib/http/Headers.js +0 -165
- package/lib/http/Loader.js +0 -584
- package/lib/http/Message.js +0 -189
- package/lib/http/Request.js +0 -848
- package/lib/http/RequestProcessor.js +0 -150
- package/lib/http/Response.js +0 -850
- package/lib/http/Server.js +0 -267
- package/lib/http/Socket.js +0 -157
- package/lib/http/Url.js +0 -2
- package/lib/jsonrpc/JsonRpcAbstract.js +0 -109
- package/lib/jsonrpc/JsonRpcBatchRequest.js +0 -54
- package/lib/jsonrpc/JsonRpcBatchResponse.js +0 -73
- package/lib/jsonrpc/JsonRpcError.js +0 -191
- package/lib/jsonrpc/JsonRpcMethod.js +0 -67
- package/lib/jsonrpc/JsonRpcRequest.js +0 -224
- package/lib/jsonrpc/JsonRpcRequestProcessor.js +0 -366
- package/lib/jsonrpc/JsonRpcResponse.js +0 -175
- package/lib/jsonrpc/JsonRpcServer.js +0 -81
- package/lib/logger/EmptyLogger.js +0 -15
- package/lib/logger/LoggerFactory.js +0 -20
- package/lib/logger/WildFireLogger.js +0 -267
- package/lib/pattern/Pool.js +0 -187
- package/lib/pattern/decorator/AbstractDecorator.js +0 -49
- package/lib/pattern/decorator/DecoratorChain.js +0 -285
- package/lib/util/DeviceDetector.js +0 -153
- package/lib/yaml/YAML.js +0 -46
- package/patterns.conf +0 -6
- package/tests/cache/CacheLoaderSpec.js +0 -7
- package/tests/class/ClassSpec.js +0 -106
- package/tests/client/MemcachedSocketSpec.js +0 -1228
- package/tests/client/MemcachedSpec.js +0 -77
- package/tests/client/MySQLPoolSpec.js +0 -231
- package/tests/client/PGPoolSpec.js +0 -479
- package/tests/client/RedisSpec.js +0 -471
- package/tests/client/S3ClientSpec.js +0 -26
- package/tests/client/S3Spec.js +0 -129
- package/tests/client/rabbitmq/RbmqConnectionSpec.js +0 -71
- package/tests/common/AssertionsSpec.js +0 -278
- package/tests/common/NetSpec.js +0 -6
- package/tests/common/RandomSpec.js +0 -35
- package/tests/common/TypesSpec.js +0 -7
- package/tests/credentials/CredentialsProviderSpec.js +0 -46
- package/tests/crypto/CryptoSpec.js +0 -33
- package/tests/data/BinaryDataSpec.js +0 -50
- package/tests/data/CompressorSpec.js +0 -7
- package/tests/data/FormDataSpec.js +0 -7
- package/tests/data/MimeSpec.js +0 -7
- package/tests/event/ErrorEventSpec.js +0 -20
- package/tests/event/EventDispatcherSpec.js +0 -319
- package/tests/event/EventSpec.js +0 -17
- package/tests/http/ConnectionPoolSpec.js +0 -7
- package/tests/http/HeadersSpec.js +0 -79
- package/tests/http/LoaderSpec.js +0 -43
- package/tests/http/MessageSpec.js +0 -251
- package/tests/http/RequestProcessorSpec.js +0 -124
- package/tests/http/RequestSpec.js +0 -651
- package/tests/http/ResponseSpec.js +0 -491
- package/tests/http/ServerSpec.js +0 -7
- package/tests/http/SocketSpec.js +0 -7
- package/tests/http/UrlSpec.js +0 -14
- package/tests/jsonrpc/JsonRpcAbstractSpec.js +0 -20
- package/tests/jsonrpc/JsonRpcBatchRequestSpec.js +0 -31
- package/tests/jsonrpc/JsonRpcBatchResponseSpec.js +0 -38
- package/tests/jsonrpc/JsonRpcErrorSpec.js +0 -58
- package/tests/jsonrpc/JsonRpcMethodSpec.js +0 -7
- package/tests/jsonrpc/JsonRpcRequestProcessorSpec.js +0 -271
- package/tests/jsonrpc/JsonRpcRequestSpec.js +0 -70
- package/tests/jsonrpc/JsonRpcResponseSpec.js +0 -63
- package/tests/jsonrpc/JsonRpcServerSpec.js +0 -42
- package/tests/pattern/PoolSpec.js +0 -180
- package/tests/pattern/decorator/AbstractDecoratorSpec.js +0 -7
- package/tests/pattern/decorator/DecoratorChainSpec.js +0 -7
- package/tests/yaml/YAMLSpec.js +0 -132
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
var JsonRpcMethod = require('../../lib/jsonrpc/JsonRpcMethod.js').JsonRpcMethod;
|
|
2
|
-
var JsonRpcRequest = require('../../lib/jsonrpc/JsonRpcRequest.js').JsonRpcRequest;
|
|
3
|
-
var RequestProcessor = require('../../lib/http/RequestProcessor.js').RequestProcessor;
|
|
4
|
-
var Response = require('../../lib/http/Response.js').Response;
|
|
5
|
-
var Request = require('../../lib/http/Request.js').Request;
|
|
6
|
-
var Event = require('../../lib/event/Event.js').Event;
|
|
7
|
-
describe('JsonRpcRequestProcessor', function () {
|
|
8
|
-
var JsonRpcRequestProcessor;
|
|
9
|
-
var Testmethod,
|
|
10
|
-
request,
|
|
11
|
-
response,
|
|
12
|
-
server,
|
|
13
|
-
processor;
|
|
14
|
-
it('require', function () {
|
|
15
|
-
var test;
|
|
16
|
-
expect(function () {
|
|
17
|
-
test = require('../../lib/jsonrpc/JsonRpcRequestProcessor.js').JsonRpcRequestProcessor;
|
|
18
|
-
}).not.toThrow();
|
|
19
|
-
expect(test).toBeTruthy();
|
|
20
|
-
});
|
|
21
|
-
beforeEach(function () {
|
|
22
|
-
JsonRpcRequestProcessor = require('../../lib/jsonrpc/JsonRpcRequestProcessor.js').JsonRpcRequestProcessor;
|
|
23
|
-
var requestProcessor = spyOn(RequestProcessor.prototype, 'process').andCallFake( function (req, resp) {
|
|
24
|
-
}
|
|
25
|
-
);
|
|
26
|
-
Testmethod = function (request, response, server) {
|
|
27
|
-
JsonRpcMethod.call(this, request, response, server);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
Testmethod.prototype = Object.create(JsonRpcMethod.prototype);
|
|
31
|
-
Testmethod.prototype.execute = function (params) {
|
|
32
|
-
var result = {
|
|
33
|
-
test: 'OK',
|
|
34
|
-
time: new Date(),
|
|
35
|
-
rand: Math.random(),
|
|
36
|
-
params: params
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
var retEvent = new Event(JsonRpcMethod.Event.OK, result);
|
|
40
|
-
this.dispatchEvent(retEvent);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
server = {
|
|
44
|
-
getMethod: jasmine.createSpy()
|
|
45
|
-
};
|
|
46
|
-
server.getMethod.andCallFake(function (methodname) {
|
|
47
|
-
return Testmethod;
|
|
48
|
-
});
|
|
49
|
-
request = new Request();
|
|
50
|
-
spyOn(request, 'getMethod').andCallFake(function() { return'POST';});
|
|
51
|
-
spyOn(request, 'getPath').andCallFake(function () {return '/';});
|
|
52
|
-
spyOn(request, 'getHttpVersion').andCallFake(function () {
|
|
53
|
-
return '1.0';
|
|
54
|
-
});
|
|
55
|
-
spyOn(request, 'getClientAddress').andCallFake(function () { return '';});
|
|
56
|
-
spyOn(request, 'getClientPort').andCallFake(function () { return "0";});
|
|
57
|
-
response = new Response();
|
|
58
|
-
spyOn(response, 'addEventListener').andCallFake(function() {});
|
|
59
|
-
spyOn(response, 'setStatusCode').andCallFake(function() {});
|
|
60
|
-
spyOn(response, 'setHeaders').andCallFake(function() {});
|
|
61
|
-
spyOn(response, 'setBody').andCallFake(function() {});
|
|
62
|
-
spyOn(response, 'send').andCallFake(function() {});
|
|
63
|
-
|
|
64
|
-
spyOn(process, 'nextTick').andCallFake(function (cb) {cb();});
|
|
65
|
-
|
|
66
|
-
processor = new JsonRpcRequestProcessor(server);
|
|
67
|
-
spyOn(processor, '_handleError').andCallThrough();
|
|
68
|
-
spyOn(processor, '_success').andCallThrough();
|
|
69
|
-
spyOn(processor, '_throwError').andCallThrough();
|
|
70
|
-
|
|
71
|
-
});
|
|
72
|
-
describe('one Request', function () {
|
|
73
|
-
beforeEach(function () {
|
|
74
|
-
spyOn(request, 'getBody').andCallFake(function () {
|
|
75
|
-
var request_body = {
|
|
76
|
-
toBuffer: function () {
|
|
77
|
-
var string = { toString:function () {
|
|
78
|
-
var stringjson = (new JsonRpcRequest({'id': '1', 'method': 'get', 'params': 'test_ok'})).toString();
|
|
79
|
-
return stringjson;
|
|
80
|
-
// '\"params\": {}}';
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
return string;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
return request_body;
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
it(' succes', function () {
|
|
90
|
-
processor.process(request, response);
|
|
91
|
-
expect(response.setStatusCode).toHaveBeenCalled();
|
|
92
|
-
expect(response.setStatusCode.calls[0].args[0]).toEqual(200);
|
|
93
|
-
expect(response.setBody.calls[0].args[0]).toBeDefined();
|
|
94
|
-
expect(response.send).toHaveBeenCalled();
|
|
95
|
-
expect(process.nextTick).toHaveBeenCalled();
|
|
96
|
-
expect(processor._success).toHaveBeenCalled();
|
|
97
|
-
expect(processor._handleError).not.toHaveBeenCalled();
|
|
98
|
-
expect(processor._throwError).not.toHaveBeenCalled();
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it(' error', function () {
|
|
102
|
-
|
|
103
|
-
Testmethod.prototype.execute = function (params) {
|
|
104
|
-
var result = {
|
|
105
|
-
test: 'OK',
|
|
106
|
-
time: new Date(),
|
|
107
|
-
rand: Math.random(),
|
|
108
|
-
params: params
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
var retEvent = new Event(JsonRpcMethod.Event.ERROR, result);
|
|
112
|
-
this.dispatchEvent(retEvent);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
processor.process(request, response);
|
|
116
|
-
expect(response.setStatusCode).toHaveBeenCalled();
|
|
117
|
-
expect(response.setBody.calls[0].args[0]).toBeDefined();
|
|
118
|
-
expect(response.send).toHaveBeenCalled();
|
|
119
|
-
expect(process.nextTick).toHaveBeenCalled();
|
|
120
|
-
expect(processor._success).not.toHaveBeenCalled();
|
|
121
|
-
expect(processor._handleError).toHaveBeenCalled();
|
|
122
|
-
expect(processor._throwError).toHaveBeenCalled();
|
|
123
|
-
});
|
|
124
|
-
it('error method not found', function () {
|
|
125
|
-
server.getMethod.andCallFake(function (methodname) {
|
|
126
|
-
return null;
|
|
127
|
-
});
|
|
128
|
-
processor.process(request, response);
|
|
129
|
-
expect(response.setStatusCode).toHaveBeenCalled();
|
|
130
|
-
expect(response.setBody.calls[0].args[0]).toBeDefined();
|
|
131
|
-
expect(response.send).toHaveBeenCalled();
|
|
132
|
-
expect(process.nextTick).toHaveBeenCalled();
|
|
133
|
-
expect(processor._throwError.calls[0].args[0]).toEqual(JsonRpcRequestProcessor.Errors.METHOD_NOT_FOUND);
|
|
134
|
-
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
describe('batch Request', function () {
|
|
138
|
-
beforeEach(function () {
|
|
139
|
-
spyOn(request, 'getBody').andCallFake(function () {
|
|
140
|
-
var request_body = {
|
|
141
|
-
toBuffer: function () {
|
|
142
|
-
var string = { toString:function () {
|
|
143
|
-
// return '{\"jsonrpc\": \"2.0\",'+
|
|
144
|
-
// '\"id\": \"example\",'+
|
|
145
|
-
// '\"method\": \"get\",'+
|
|
146
|
-
var stringjson = (new JsonRpcRequest({'id': '1', 'method': 'get', 'params': 'test_ok'})).toString();
|
|
147
|
-
return '[' + stringjson +','+ stringjson+ ']';
|
|
148
|
-
// '\"params\": {}}';
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
return string;
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
return request_body;
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
it('succes', function () {
|
|
158
|
-
processor.process(request, response);
|
|
159
|
-
expect(response.setStatusCode).toHaveBeenCalled();
|
|
160
|
-
expect(response.setBody.calls[0].args[0]).toBeDefined();
|
|
161
|
-
expect(response.send).toHaveBeenCalled();
|
|
162
|
-
expect(process.nextTick).toHaveBeenCalled();
|
|
163
|
-
expect(processor._success).toHaveBeenCalled();
|
|
164
|
-
expect(processor._success.calls.length).toEqual(2);
|
|
165
|
-
expect(processor._handleError).not.toHaveBeenCalled();
|
|
166
|
-
expect(processor._throwError).not.toHaveBeenCalled();
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it('error', function () {
|
|
170
|
-
|
|
171
|
-
Testmethod.prototype.execute = function (params) {
|
|
172
|
-
var result = {
|
|
173
|
-
test: 'OK',
|
|
174
|
-
time: new Date(),
|
|
175
|
-
rand: Math.random(),
|
|
176
|
-
params: params
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
var retEvent = new Event(JsonRpcMethod.Event.ERROR, result);
|
|
180
|
-
this.dispatchEvent(retEvent);
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
processor.process(request, response);
|
|
184
|
-
expect(response.setStatusCode).toHaveBeenCalled();
|
|
185
|
-
expect(response.setBody.calls[0].args[0]).toBeDefined();
|
|
186
|
-
expect(response.send).toHaveBeenCalled();
|
|
187
|
-
expect(process.nextTick).toHaveBeenCalled();
|
|
188
|
-
expect(processor._success).not.toHaveBeenCalled();
|
|
189
|
-
expect(processor._handleError.calls.length).toEqual(2);
|
|
190
|
-
expect(processor._throwError).toHaveBeenCalled();
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('invalid request', function () {
|
|
195
|
-
spyOn(request, 'getBody').andCallFake(function () {
|
|
196
|
-
var request_body = {
|
|
197
|
-
toBuffer: function () {
|
|
198
|
-
var string = { toString:function () {
|
|
199
|
-
var stringjson = '{\"id\":\"1\",\"methaod\":\"get\",\"params\":\"test_ok\"}';
|
|
200
|
-
|
|
201
|
-
var stringjson2 = (new JsonRpcRequest({'id': '1', 'method': 'get', 'params': 'test_ok'})).toString();
|
|
202
|
-
return '[' + stringjson +','+ stringjson2+ ']';
|
|
203
|
-
|
|
204
|
-
// '\"params\": {}}';
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
return string;
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
return request_body;
|
|
211
|
-
});
|
|
212
|
-
Testmethod.prototype.execute = function (params) {
|
|
213
|
-
var result = {
|
|
214
|
-
test: 'OK',
|
|
215
|
-
time: new Date(),
|
|
216
|
-
rand: Math.random(),
|
|
217
|
-
params: params
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
var retEvent = new Event(JsonRpcMethod.Event.OK, result);
|
|
221
|
-
this.dispatchEvent(retEvent);
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
processor.process(request, response);
|
|
225
|
-
expect(response.setStatusCode).toHaveBeenCalled();
|
|
226
|
-
expect(response.setBody.calls[0].args[0]).toBeDefined();
|
|
227
|
-
expect(response.send).toHaveBeenCalled();
|
|
228
|
-
expect(process.nextTick).toHaveBeenCalled();
|
|
229
|
-
expect(processor._success.calls.length).toEqual(1);
|
|
230
|
-
expect(processor._throwError).toHaveBeenCalled();
|
|
231
|
-
expect(processor._throwError.calls[0].args[0]).toEqual(JsonRpcRequestProcessor.Errors.INVALID_REQUEST);
|
|
232
|
-
});
|
|
233
|
-
it('parse error', function () {
|
|
234
|
-
spyOn(request, 'getBody').andCallFake(function () {
|
|
235
|
-
var request_body = {
|
|
236
|
-
toBuffer: function () {
|
|
237
|
-
var string = { toString:function () {
|
|
238
|
-
var stringjson = '{\"id\":\"1\",\"methaod\":\"get\",\"params\":\"test_ok\"}';
|
|
239
|
-
|
|
240
|
-
var stringjson2 = (new JsonRpcRequest({'id': '1', 'method': 'get', 'params': 'test_ok'})).toString();
|
|
241
|
-
return '[' + stringjson + stringjson2+ ']';
|
|
242
|
-
|
|
243
|
-
// '\"params\": {}}';
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
return string;
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
return request_body;
|
|
250
|
-
});
|
|
251
|
-
Testmethod.prototype.execute = function (params) {
|
|
252
|
-
var result = {
|
|
253
|
-
test: 'OK',
|
|
254
|
-
time: new Date(),
|
|
255
|
-
rand: Math.random(),
|
|
256
|
-
params: params
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
var retEvent = new Event(JsonRpcMethod.Event.OK, result);
|
|
260
|
-
this.dispatchEvent(retEvent);
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
processor.process(request, response);
|
|
264
|
-
expect(response.setStatusCode).toHaveBeenCalled();
|
|
265
|
-
expect(response.send).toHaveBeenCalled();
|
|
266
|
-
expect(process.nextTick).toHaveBeenCalled();
|
|
267
|
-
expect(processor._success.calls.length).toEqual(0);
|
|
268
|
-
expect(processor._throwError).toHaveBeenCalled();
|
|
269
|
-
expect(processor._throwError.calls[0].args[0]).toEqual(JsonRpcRequestProcessor.Errors.PARSE_ERROR);
|
|
270
|
-
});
|
|
271
|
-
});
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
describe('JsonRpcRequest', function () {
|
|
2
|
-
var JsonRpcRequest;
|
|
3
|
-
it('require', function () {
|
|
4
|
-
expect(function () {
|
|
5
|
-
JsonRpcRequest = require('../../lib/jsonrpc/JsonRpcRequest.js').JsonRpcRequest;
|
|
6
|
-
}).not.toThrow();
|
|
7
|
-
expect(JsonRpcRequest).toBeTruthy();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('check constructor', function () {
|
|
11
|
-
expect(function () {
|
|
12
|
-
new JsonRpcRequest(1);
|
|
13
|
-
}).not.toThrow("Id should be a string");
|
|
14
|
-
|
|
15
|
-
expect(function () {
|
|
16
|
-
new JsonRpcRequest('1', 2);
|
|
17
|
-
}).toThrow("Method should be a string");
|
|
18
|
-
|
|
19
|
-
expect(function () {
|
|
20
|
-
new JsonRpcRequest();
|
|
21
|
-
}).not.toThrow();
|
|
22
|
-
|
|
23
|
-
expect(function () {
|
|
24
|
-
new JsonRpcRequest('1', '2', '3');
|
|
25
|
-
}).not.toThrow();
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('check setters/getters', function () {
|
|
32
|
-
var req = new JsonRpcRequest();
|
|
33
|
-
|
|
34
|
-
expect(function () {
|
|
35
|
-
req.setVersion(1);
|
|
36
|
-
}).toThrow("Version should be a string");
|
|
37
|
-
|
|
38
|
-
req.setVersion('2.0');
|
|
39
|
-
expect(req.getVersion()).toEqual('2.0');
|
|
40
|
-
|
|
41
|
-
req.setId('2');
|
|
42
|
-
expect(req.getId()).toEqual('2');
|
|
43
|
-
|
|
44
|
-
req.setMethod('3');
|
|
45
|
-
expect(req.getMethod()).toEqual('3');
|
|
46
|
-
|
|
47
|
-
expect(function () {
|
|
48
|
-
req.setParam(1, 2);
|
|
49
|
-
}).toThrow("Key should be a string");
|
|
50
|
-
req.setParam('1', 2);
|
|
51
|
-
expect(req.getParam('1')).toEqual(2);
|
|
52
|
-
expect(req.getParam('2')).toEqual(null);
|
|
53
|
-
|
|
54
|
-
expect(req.toJson()).toEqual({
|
|
55
|
-
'jsonrpc' : '2.0',
|
|
56
|
-
'id' : '2',
|
|
57
|
-
'method' : '3',
|
|
58
|
-
'params' : {
|
|
59
|
-
'1' : 2
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
expect(req.toString()).toEqual(JSON.stringify(req.toJson()));
|
|
64
|
-
|
|
65
|
-
req.setParams('4');
|
|
66
|
-
expect(req.getParams()).toEqual('4');
|
|
67
|
-
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
})
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
describe('JsonRpcResponse', function () {
|
|
2
|
-
var JsonRpcResponse;
|
|
3
|
-
it('require', function () {
|
|
4
|
-
JsonRpcResponse = require('../../lib/jsonrpc/JsonRpcResponse.js').JsonRpcResponse;
|
|
5
|
-
expect(JsonRpcResponse).toBeTruthy();
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
it('check constructor', function () {
|
|
9
|
-
expect(function () {
|
|
10
|
-
new JsonRpcResponse(1);
|
|
11
|
-
}).toThrow("Id should be a String");
|
|
12
|
-
|
|
13
|
-
expect(function () {
|
|
14
|
-
new JsonRpcResponse('1');
|
|
15
|
-
}).toThrow();
|
|
16
|
-
|
|
17
|
-
expect(function () {
|
|
18
|
-
new JsonRpcResponse('1',2);
|
|
19
|
-
}).not.toThrow();
|
|
20
|
-
|
|
21
|
-
expect(function () {
|
|
22
|
-
new JsonRpcResponse('1',2, {code:-1, message:'New msg', data: 'new data'});
|
|
23
|
-
}).not.toThrow();
|
|
24
|
-
|
|
25
|
-
expect(function () {
|
|
26
|
-
new JsonRpcResponse('1',2, {code:'-10', message:'New msg', data: 'new data'});
|
|
27
|
-
}).toThrow();
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe('check methods', function () {
|
|
32
|
-
var JsonRpcResponse= null;
|
|
33
|
-
beforeEach(function () {
|
|
34
|
-
JsonRpcResponse = require('../../lib/jsonrpc/JsonRpcResponse.js').JsonRpcResponse;
|
|
35
|
-
this.jsonRpcResponse = new JsonRpcResponse();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('setId should set 1', function () {
|
|
39
|
-
this.jsonRpcResponse.setId('1');
|
|
40
|
-
expect(this.jsonRpcResponse.getId()).toEqual('1');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('setResult should set 2', function () {
|
|
44
|
-
this.jsonRpcResponse.setResult(2);
|
|
45
|
-
expect(this.jsonRpcResponse.getResult()).toEqual(2);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('setError should set code:-1, message: New msg , data: new data' , function () {
|
|
49
|
-
this.jsonRpcResponse.setError(-1, 'New msg', 'new data');
|
|
50
|
-
expect(this.jsonRpcResponse.getError().toJson()).toEqual(this.jsonRpcResponse.toJson()['error']);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
afterEach(function () {
|
|
54
|
-
this.jsonRpcResponse = new JsonRpcResponse('1', 2);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('check isError is false', function () {
|
|
58
|
-
expect(this.jsonRpcResponse.isError()).toBe(false);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
})
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
describe('JsonRpcServer', function () {
|
|
2
|
-
var JsonRpcServer;
|
|
3
|
-
it('require', function () {
|
|
4
|
-
JsonRpcServer = require('../../lib/jsonrpc/JsonRpcServer.js').JsonRpcServer;
|
|
5
|
-
expect(JsonRpcServer).toBeTruthy();
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
describe('check methods', function (){
|
|
9
|
-
var JsonRpcServer = null;
|
|
10
|
-
var result = null;
|
|
11
|
-
beforeEach(function(){
|
|
12
|
-
JsonRpcServer = require('../../lib/jsonrpc/JsonRpcServer.js').JsonRpcServer;
|
|
13
|
-
this.jsonRpcServer = new JsonRpcServer();
|
|
14
|
-
this.jsonRpcServer.addMethod('getTest', 'test');
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('check when add new method', function() {
|
|
18
|
-
expect(this.jsonRpcServer.addMethod('getttTest', 'test')).toEqual(true);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('check when exist method', function() {
|
|
22
|
-
expect(this.jsonRpcServer.addMethod('getTest', 'test')).toEqual(false);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('check when get exist method', function() {
|
|
26
|
-
expect(this.jsonRpcServer.getMethod('getTest')).toEqual('test');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('check when get not exist method', function() {
|
|
30
|
-
expect(this.jsonRpcServer.getMethod('setTest')).toEqual(false);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('check when delete exist method', function() {
|
|
34
|
-
expect(this.jsonRpcServer.removeMethod('getTest')).toEqual(true);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('check when delete not exist method', function() {
|
|
38
|
-
expect(this.jsonRpcServer.removeMethod('setTest')).toEqual(false);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
});
|
|
42
|
-
});
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
describe('Pool', function () {
|
|
2
|
-
var Pool;
|
|
3
|
-
describe('require', function () {
|
|
4
|
-
it('should not throw exception', function () {
|
|
5
|
-
expect(function () {
|
|
6
|
-
Pool = require('../../lib/pattern/Pool.js').Pool;
|
|
7
|
-
}).not.toThrow();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('should be truthy', function () {
|
|
11
|
-
expect(Pool).toBeTruthy();
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
describe('constructor', function () {
|
|
16
|
-
beforeEach(function () {
|
|
17
|
-
this.pool = new Pool();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should not have spare objects', function () {
|
|
21
|
-
expect(this.pool.getSpareLength()).toEqual(0);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('should not have waiting callbacks', function () {
|
|
25
|
-
expect(this.pool.getWaitingLength()).toEqual(0);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe('adding object', function () {
|
|
30
|
-
beforeEach(function () {
|
|
31
|
-
this.pool = new Pool();
|
|
32
|
-
this.fakeObj = 'a';
|
|
33
|
-
this.pool.add(this.fakeObj);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should have one spare object', function () {
|
|
37
|
-
expect(this.pool.getSpareLength()).toEqual(1);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should not have waiting callbacks', function () {
|
|
41
|
-
expect(this.pool.getWaitingLength()).toEqual(0);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe('get object', function () {
|
|
46
|
-
beforeEach(function () {
|
|
47
|
-
this.pool = new Pool();
|
|
48
|
-
this.callbackMock = jasmine.createSpy();
|
|
49
|
-
this.fakeObj = 'a';
|
|
50
|
-
this.pool.add(this.fakeObj);
|
|
51
|
-
this.pool.get(this.callbackMock);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should call mock callback', function () {
|
|
55
|
-
expect(this.callbackMock).toHaveBeenCalledWith(this.fakeObj);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should not have spare objects', function () {
|
|
59
|
-
expect(this.pool.getSpareLength()).toEqual(0);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('get and release object', function () {
|
|
64
|
-
beforeEach(function () {
|
|
65
|
-
var that = this;
|
|
66
|
-
this.pool = new Pool();
|
|
67
|
-
this.callbackMock = function (client) {
|
|
68
|
-
that.pool.release(client);
|
|
69
|
-
};
|
|
70
|
-
this.fakeObj = 'a';
|
|
71
|
-
this.pool.add(this.fakeObj);
|
|
72
|
-
this.pool.get(this.callbackMock);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('should not have waiting callback', function () {
|
|
76
|
-
expect(this.pool.getWaitingLength()).toEqual(0);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('should have spare objects', function () {
|
|
80
|
-
expect(this.pool.getSpareLength()).toEqual(1);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
describe('add object', function () {
|
|
85
|
-
beforeEach(function () {
|
|
86
|
-
this.pool = new Pool;
|
|
87
|
-
this.pool.add('a');
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('should have one spare object', function () {
|
|
91
|
-
expect(this.pool.getSpareLength()).toEqual(1);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe('mark known objects for deletion', function () {
|
|
97
|
-
beforeEach(function () {
|
|
98
|
-
this.pool = new Pool();
|
|
99
|
-
this.fakeObj1 = 'a';
|
|
100
|
-
this.fakeObj2 = 'b';
|
|
101
|
-
this.pool.add(this.fakeObj1);
|
|
102
|
-
this.pool.markForDeletion();
|
|
103
|
-
this.pool.add(this.fakeObj2);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('should have one spare element', function () {
|
|
107
|
-
expect(this.pool.getSpareLength()).toEqual(1);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('should not have waiting callbacks', function () {
|
|
111
|
-
expect(this.pool.getWaitingLength()).toEqual(0);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should returns fakeObj2', function () {
|
|
115
|
-
var that = this;
|
|
116
|
-
this.pool.get(function () {
|
|
117
|
-
expect(arguments[0]).toEqual(that.fakeObj2);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
describe('queued stats', function () {
|
|
124
|
-
beforeEach(function () {
|
|
125
|
-
this.pool = new Pool();
|
|
126
|
-
this.cb = jasmine.createSpy();
|
|
127
|
-
this.pool.get(this.cb.bind(this));
|
|
128
|
-
this.queued1 = this.pool.getQueued();
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('should not execute fake callback', function () {
|
|
132
|
-
expect(this.cb).not.toHaveBeenCalled();
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('should returns one request queued', function () {
|
|
136
|
-
expect(this.queued1).toEqual(1);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
describe('queued callbacks overflow with disabled queuing', function () {
|
|
142
|
-
beforeEach(function () {
|
|
143
|
-
this.pool = new Pool();
|
|
144
|
-
this.pool.setMaxQueued(0);
|
|
145
|
-
this.cb = jasmine.createSpy();
|
|
146
|
-
this.pool.get(this.cb);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('should execute fake callback', function () {
|
|
150
|
-
expect(this.cb).toHaveBeenCalled();
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('should execute fake callback with error', function () {
|
|
154
|
-
expect(this.cb.mostRecentCall.args[0]).toEqual(Pool.ERROR.MAX_QUEUED_REACHED);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
describe('queued callbacks overflow with one cb allowed for queuing', function () {
|
|
159
|
-
beforeEach(function () {
|
|
160
|
-
this.pool = new Pool();
|
|
161
|
-
this.pool.setMaxQueued(1);
|
|
162
|
-
this.cb1 = jasmine.createSpy();
|
|
163
|
-
this.cb2 = jasmine.createSpy();
|
|
164
|
-
this.pool.get(this.cb1);
|
|
165
|
-
this.pool.get(this.cb2);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('should not execute first fake callback (queued)', function () {
|
|
169
|
-
expect(this.cb1).not.toHaveBeenCalled();
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('should not execute second fake callback', function () {
|
|
173
|
-
expect(this.cb2).toHaveBeenCalled();
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('should execute second fake callback with error', function () {
|
|
177
|
-
expect(this.cb2.mostRecentCall.args[0]).toEqual(Pool.ERROR.MAX_QUEUED_REACHED);
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
});
|