@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.
Files changed (346) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +3 -0
  3. package/lib/api/node.js +176 -0
  4. package/lib/api/team.js +1889 -0
  5. package/lib/blocklet/downloader/blocklet-downloader.js +246 -0
  6. package/lib/blocklet/downloader/bundle-downloader.js +316 -0
  7. package/lib/blocklet/downloader/constants.js +3 -0
  8. package/lib/blocklet/downloader/resolve-download.js +187 -0
  9. package/lib/blocklet/extras.js +177 -0
  10. package/lib/blocklet/hooks.js +89 -0
  11. package/lib/blocklet/manager/base.js +49 -0
  12. package/lib/blocklet/manager/config-synchronizer.js +128 -0
  13. package/lib/blocklet/manager/disk.js +5170 -0
  14. package/lib/blocklet/manager/engine.js +124 -0
  15. package/lib/blocklet/manager/helper/install-application-from-backup.js +285 -0
  16. package/lib/blocklet/manager/helper/install-application-from-dev.js +72 -0
  17. package/lib/blocklet/manager/helper/install-application-from-general.js +209 -0
  18. package/lib/blocklet/manager/helper/install-component-from-dev.js +128 -0
  19. package/lib/blocklet/manager/helper/install-component-from-upload.js +197 -0
  20. package/lib/blocklet/manager/helper/install-component-from-url.js +214 -0
  21. package/lib/blocklet/manager/helper/migrate-application-to-struct-v2.js +557 -0
  22. package/lib/blocklet/manager/helper/rollback-cache.js +41 -0
  23. package/lib/blocklet/manager/helper/upgrade-components.js +179 -0
  24. package/lib/blocklet/manager/pm2-events.js +50 -0
  25. package/lib/blocklet/migration-dist/migration.cjs +38605 -0
  26. package/lib/blocklet/migration-dist/run-script.cjs +29 -0
  27. package/lib/blocklet/migration.js +145 -0
  28. package/lib/blocklet/project/connect-by-studio.js +91 -0
  29. package/lib/blocklet/project/connect-to-store.js +64 -0
  30. package/lib/blocklet/project/create-pack-release.js +293 -0
  31. package/lib/blocklet/project/disconnect-from-store.js +13 -0
  32. package/lib/blocklet/project/get-is-multiple-tenant.js +8 -0
  33. package/lib/blocklet/project/index.js +545 -0
  34. package/lib/blocklet/project/logo.png +0 -0
  35. package/lib/blocklet/project/publish-to-store.js +108 -0
  36. package/lib/blocklet/project/util.js +194 -0
  37. package/lib/blocklet/security/access-policy.js +131 -0
  38. package/lib/blocklet/security/index.js +309 -0
  39. package/lib/blocklet/security/response-header-policy.js +178 -0
  40. package/lib/blocklet/security/security-rule.js +127 -0
  41. package/lib/blocklet/security/utils.js +35 -0
  42. package/lib/blocklet/security/validator.js +40 -0
  43. package/lib/blocklet/storage/backup/base.js +149 -0
  44. package/lib/blocklet/storage/backup/blocklet-extras.js +110 -0
  45. package/lib/blocklet/storage/backup/blocklet.js +159 -0
  46. package/lib/blocklet/storage/backup/blocklets.js +109 -0
  47. package/lib/blocklet/storage/backup/data.js +35 -0
  48. package/lib/blocklet/storage/backup/disk.js +131 -0
  49. package/lib/blocklet/storage/backup/logs.js +24 -0
  50. package/lib/blocklet/storage/backup/routing-rule.js +47 -0
  51. package/lib/blocklet/storage/backup/spaces.js +345 -0
  52. package/lib/blocklet/storage/restore/base.js +74 -0
  53. package/lib/blocklet/storage/restore/blocklet-extras.js +89 -0
  54. package/lib/blocklet/storage/restore/blocklet.js +56 -0
  55. package/lib/blocklet/storage/restore/blocklets.js +43 -0
  56. package/lib/blocklet/storage/restore/disk.js +104 -0
  57. package/lib/blocklet/storage/restore/logs.js +21 -0
  58. package/lib/blocklet/storage/restore/spaces.js +174 -0
  59. package/lib/blocklet/storage/utils/disk.js +178 -0
  60. package/lib/blocklet/storage/utils/hash.js +53 -0
  61. package/lib/blocklet/storage/utils/zip.js +43 -0
  62. package/lib/cert.js +221 -0
  63. package/lib/crons/check-new-version.js +68 -0
  64. package/lib/crons/monitor-disk-usage.js +46 -0
  65. package/lib/crons/rotate-pm2-logs/index.js +41 -0
  66. package/lib/crons/rotate-pm2-logs/script.js +56 -0
  67. package/lib/event/auto-backup-handler.js +48 -0
  68. package/lib/event/index.js +520 -0
  69. package/lib/index.js +768 -364
  70. package/lib/locales/ar.js +18 -0
  71. package/lib/locales/de.js +21 -0
  72. package/lib/locales/en.js +19 -0
  73. package/lib/locales/es.js +21 -0
  74. package/lib/locales/fr.js +21 -0
  75. package/lib/locales/hi.js +18 -0
  76. package/lib/locales/i18n.db +0 -0
  77. package/lib/locales/id.js +20 -0
  78. package/lib/locales/index.js +54 -0
  79. package/lib/locales/ja.js +19 -0
  80. package/lib/locales/ko.js +18 -0
  81. package/lib/locales/pt.js +20 -0
  82. package/lib/locales/ru.js +21 -0
  83. package/lib/locales/th.js +18 -0
  84. package/lib/locales/vi.js +18 -0
  85. package/lib/locales/zh-tw.js +17 -0
  86. package/lib/locales/zh.js +17 -0
  87. package/lib/migrations/1.0.21-update-config.js +34 -0
  88. package/lib/migrations/1.0.22-max-memory.js +40 -0
  89. package/lib/migrations/1.0.25.js +36 -0
  90. package/lib/migrations/1.0.32-update-config.js +30 -0
  91. package/lib/migrations/1.0.33-blocklets.js +33 -0
  92. package/lib/migrations/1.0.36-snapshot.js +10 -0
  93. package/lib/migrations/1.1.10-team.js +26 -0
  94. package/lib/migrations/1.1.9-snapshot.js +7 -0
  95. package/lib/migrations/1.16.11-component-status.js +22 -0
  96. package/lib/migrations/1.16.33-blocklet-security-rule.js +17 -0
  97. package/lib/migrations/1.16.6-chain-info.js +78 -0
  98. package/lib/migrations/1.16.8-component-title.js +66 -0
  99. package/lib/migrations/1.2.11-blocklet-registry.js +10 -0
  100. package/lib/migrations/1.2.2-blocklet-registry.js +10 -0
  101. package/lib/migrations/1.3.1-disk-alert-threshold.js +10 -0
  102. package/lib/migrations/1.4.5-access-key.js +18 -0
  103. package/lib/migrations/1.5.0-site.js +34 -0
  104. package/lib/migrations/1.5.15-site.js +184 -0
  105. package/lib/migrations/1.5.20-registry.js +15 -0
  106. package/lib/migrations/1.6.17-blocklet-children.js +48 -0
  107. package/lib/migrations/1.6.21-rename-ip-echo-domain.js +35 -0
  108. package/lib/migrations/1.6.4-security.js +59 -0
  109. package/lib/migrations/1.6.5-security.js +60 -0
  110. package/lib/migrations/1.6.9-update-node-info-and-certificate.js +39 -0
  111. package/lib/migrations/1.7.1-blocklet-setup.js +18 -0
  112. package/lib/migrations/1.7.12-blocklet-meta.js +51 -0
  113. package/lib/migrations/1.7.15-blocklet-bundle-source.js +42 -0
  114. package/lib/migrations/1.7.20-blocklet-component.js +41 -0
  115. package/lib/migrations/1.8.33-blocklet-mem-limit.js +20 -0
  116. package/lib/migrations/README.md +71 -0
  117. package/lib/migrations/index.js +215 -0
  118. package/lib/monitor/blocklet-runtime-monitor.js +204 -0
  119. package/lib/monitor/get-history-list.js +37 -0
  120. package/lib/monitor/node-monit-sender.js +99 -0
  121. package/lib/monitor/node-runtime-monitor.js +205 -0
  122. package/lib/processes/updater.js +186 -0
  123. package/lib/router/helper.js +1653 -0
  124. package/lib/router/index.js +341 -0
  125. package/lib/router/manager.js +806 -0
  126. package/lib/states/README.md +38 -0
  127. package/lib/states/access-key.js +124 -0
  128. package/lib/states/access-policy.js +29 -0
  129. package/lib/states/audit-log.js +734 -0
  130. package/lib/states/backup.js +165 -0
  131. package/lib/states/base.js +25 -0
  132. package/lib/states/blocklet-extras.js +257 -0
  133. package/lib/states/blocklet.js +755 -0
  134. package/lib/states/cache.js +23 -0
  135. package/lib/states/connect-account.js +8 -0
  136. package/lib/states/index.js +76 -0
  137. package/lib/states/job.js +8 -0
  138. package/lib/states/migration.js +34 -0
  139. package/lib/states/node.js +324 -0
  140. package/lib/states/notification.js +81 -0
  141. package/lib/states/passport.js +8 -0
  142. package/lib/states/project.js +119 -0
  143. package/lib/states/release.js +50 -0
  144. package/lib/states/response-header-policy.js +30 -0
  145. package/lib/states/routing-snapshot.js +146 -0
  146. package/lib/states/runtime-insight.js +25 -0
  147. package/lib/states/security-rule.js +30 -0
  148. package/lib/states/session.js +53 -0
  149. package/lib/states/site.js +102 -0
  150. package/lib/states/tag.js +8 -0
  151. package/lib/states/traffic-insight.js +25 -0
  152. package/lib/states/user-session.js +8 -0
  153. package/lib/states/user.js +717 -0
  154. package/lib/states/verify-code.js +152 -0
  155. package/lib/states/webhook.js +66 -0
  156. package/lib/team/manager.js +508 -0
  157. package/lib/util/blocklet.js +2182 -0
  158. package/lib/util/cache.js +63 -0
  159. package/lib/util/chain.js +29 -0
  160. package/lib/util/default-node-config.js +46 -0
  161. package/lib/util/docker/blocklet-custom-dockerfile.js +92 -0
  162. package/lib/util/docker/check-docker-has-image.js +23 -0
  163. package/lib/util/docker/check-docker-installed.js +32 -0
  164. package/lib/util/docker/check-docker-run-history.js +18 -0
  165. package/lib/util/docker/check-need-run-docker.js +32 -0
  166. package/lib/util/docker/create-docker-image.js +65 -0
  167. package/lib/util/docker/debian-dockerfile.js +50 -0
  168. package/lib/util/docker/docker-container-prune.js +75 -0
  169. package/lib/util/docker/docker-exec-chown.js +39 -0
  170. package/lib/util/docker/docker-exec.js +68 -0
  171. package/lib/util/docker/docker-remove-by-name.js +20 -0
  172. package/lib/util/docker/get-docker-runtime-info.js +39 -0
  173. package/lib/util/docker/parse-docker-name.js +10 -0
  174. package/lib/util/docker/parse-docker-options-from-pm2.js +295 -0
  175. package/lib/util/docker/shard-network.js +10 -0
  176. package/lib/util/domain-status.js +118 -0
  177. package/lib/util/get-accessible-external-node-ip.js +92 -0
  178. package/lib/util/get-dynamic-components.js +47 -0
  179. package/lib/util/get-meta-from-url.js +30 -0
  180. package/lib/util/get-migration-scripts.js +36 -0
  181. package/lib/util/get-safe-env.js +12 -0
  182. package/lib/util/index.js +522 -0
  183. package/lib/util/install-external-dependencies.js +67 -0
  184. package/lib/util/ip.js +53 -0
  185. package/lib/util/launcher.js +475 -0
  186. package/lib/util/log.js +431 -0
  187. package/lib/util/maintain.js +178 -0
  188. package/lib/util/promise-debounce.js +29 -0
  189. package/lib/util/promise-once.js +14 -0
  190. package/lib/util/promise-spawn.js +93 -0
  191. package/lib/util/queue.js +44 -0
  192. package/lib/util/ready.js +89 -0
  193. package/lib/util/request.js +10 -0
  194. package/lib/util/requirement.js +61 -0
  195. package/lib/util/reset-node.js +166 -0
  196. package/lib/util/rotator.js +194 -0
  197. package/lib/util/router.js +122 -0
  198. package/lib/util/rpc.js +78 -0
  199. package/lib/util/spaces.js +102 -0
  200. package/lib/util/store.js +184 -0
  201. package/lib/util/sysinfo.js +46 -0
  202. package/lib/util/ua.js +54 -0
  203. package/lib/validators/backup.js +34 -0
  204. package/lib/validators/blocklet-extra.js +18 -0
  205. package/lib/validators/node.js +73 -0
  206. package/lib/validators/permission.js +38 -0
  207. package/lib/validators/project.js +39 -0
  208. package/lib/validators/role.js +64 -0
  209. package/lib/validators/router.js +192 -0
  210. package/lib/validators/space-gateway.js +33 -0
  211. package/lib/validators/trusted-factory.js +28 -0
  212. package/lib/validators/trusted-passport.js +32 -0
  213. package/lib/validators/user.js +62 -0
  214. package/lib/validators/util.js +92 -0
  215. package/lib/validators/webhook.js +42 -0
  216. package/lib/webhook/index.js +216 -0
  217. package/lib/webhook/reduce-queue.js +12 -0
  218. package/lib/webhook/sender/api/index.js +67 -0
  219. package/lib/webhook/sender/base.js +11 -0
  220. package/lib/webhook/sender/index.js +44 -0
  221. package/lib/webhook/sender/slack/index.js +167 -0
  222. package/lib/webhook/sender/wallet/index.js +62 -0
  223. package/package.json +107 -34
  224. package/examples/BatchClient.js +0 -61
  225. package/examples/compressor/example.js +0 -7
  226. package/examples/jsonrpcserver/rpcmethod.js +0 -21
  227. package/examples/jsonrpcserver/rpcrequest.js +0 -20
  228. package/examples/jsonrpcserver/rpctest.js +0 -6
  229. package/examples/loader-pipes/test-mc.js +0 -52
  230. package/examples/loader-pipes/test.js +0 -51
  231. package/examples/mc-test.js +0 -44
  232. package/examples/redisdebug.js +0 -80
  233. package/lib/cache/CFMemcache.js +0 -57
  234. package/lib/cache/CacheLoader.js +0 -217
  235. package/lib/cache/Memcache.js +0 -406
  236. package/lib/class/Class.js +0 -54
  237. package/lib/client/MemcacheAdapter.js +0 -139
  238. package/lib/client/Memcached.js +0 -142
  239. package/lib/client/MemcachedSocket.js +0 -570
  240. package/lib/client/MySQLPool.js +0 -153
  241. package/lib/client/PGPool.js +0 -296
  242. package/lib/client/Redis.js +0 -787
  243. package/lib/client/S3.js +0 -103
  244. package/lib/client/S3Client.js +0 -392
  245. package/lib/client/pg/CursorQueryWorker.js +0 -160
  246. package/lib/client/rabbitmq/RbmqChannel.js +0 -61
  247. package/lib/client/rabbitmq/RbmqConfig.js +0 -144
  248. package/lib/client/rabbitmq/RbmqConnection.js +0 -259
  249. package/lib/client/rabbitmq/RbmqExchange.js +0 -112
  250. package/lib/client/rabbitmq/RbmqIncomingMessage.js +0 -53
  251. package/lib/client/rabbitmq/RbmqMessage.js +0 -120
  252. package/lib/client/rabbitmq/RbmqOutcomingMessage.js +0 -47
  253. package/lib/client/rabbitmq/RbmqQueue.js +0 -87
  254. package/lib/client/rabbitmq/index.js +0 -8
  255. package/lib/common/Assertions.js +0 -184
  256. package/lib/common/Merge.js +0 -32
  257. package/lib/common/Net.js +0 -56
  258. package/lib/common/Process.js +0 -20
  259. package/lib/common/Random.js +0 -53
  260. package/lib/common/Sort.js +0 -19
  261. package/lib/common/Types.js +0 -163
  262. package/lib/credentials/CredentialsProvider.js +0 -45
  263. package/lib/credentials/Manager.js +0 -101
  264. package/lib/crypto/Crypto.js +0 -66
  265. package/lib/data/BinaryData.js +0 -363
  266. package/lib/data/Compressor.js +0 -83
  267. package/lib/data/FormData.js +0 -144
  268. package/lib/data/Mime.js +0 -45
  269. package/lib/event/ErrorEvent.js +0 -71
  270. package/lib/event/Event.js +0 -20
  271. package/lib/event/EventDispatcher.js +0 -157
  272. package/lib/http/ConnectionPool.js +0 -82
  273. package/lib/http/ExpressServer.js +0 -19
  274. package/lib/http/Headers.js +0 -165
  275. package/lib/http/Loader.js +0 -584
  276. package/lib/http/Message.js +0 -189
  277. package/lib/http/Request.js +0 -848
  278. package/lib/http/RequestProcessor.js +0 -150
  279. package/lib/http/Response.js +0 -850
  280. package/lib/http/Server.js +0 -267
  281. package/lib/http/Socket.js +0 -157
  282. package/lib/http/Url.js +0 -2
  283. package/lib/jsonrpc/JsonRpcAbstract.js +0 -109
  284. package/lib/jsonrpc/JsonRpcBatchRequest.js +0 -54
  285. package/lib/jsonrpc/JsonRpcBatchResponse.js +0 -73
  286. package/lib/jsonrpc/JsonRpcError.js +0 -191
  287. package/lib/jsonrpc/JsonRpcMethod.js +0 -67
  288. package/lib/jsonrpc/JsonRpcRequest.js +0 -224
  289. package/lib/jsonrpc/JsonRpcRequestProcessor.js +0 -366
  290. package/lib/jsonrpc/JsonRpcResponse.js +0 -175
  291. package/lib/jsonrpc/JsonRpcServer.js +0 -81
  292. package/lib/logger/EmptyLogger.js +0 -15
  293. package/lib/logger/LoggerFactory.js +0 -20
  294. package/lib/logger/WildFireLogger.js +0 -267
  295. package/lib/pattern/Pool.js +0 -187
  296. package/lib/pattern/decorator/AbstractDecorator.js +0 -49
  297. package/lib/pattern/decorator/DecoratorChain.js +0 -285
  298. package/lib/util/DeviceDetector.js +0 -153
  299. package/lib/yaml/YAML.js +0 -46
  300. package/patterns.conf +0 -6
  301. package/tests/cache/CacheLoaderSpec.js +0 -7
  302. package/tests/class/ClassSpec.js +0 -106
  303. package/tests/client/MemcachedSocketSpec.js +0 -1228
  304. package/tests/client/MemcachedSpec.js +0 -77
  305. package/tests/client/MySQLPoolSpec.js +0 -231
  306. package/tests/client/PGPoolSpec.js +0 -479
  307. package/tests/client/RedisSpec.js +0 -471
  308. package/tests/client/S3ClientSpec.js +0 -26
  309. package/tests/client/S3Spec.js +0 -129
  310. package/tests/client/rabbitmq/RbmqConnectionSpec.js +0 -71
  311. package/tests/common/AssertionsSpec.js +0 -278
  312. package/tests/common/NetSpec.js +0 -6
  313. package/tests/common/RandomSpec.js +0 -35
  314. package/tests/common/TypesSpec.js +0 -7
  315. package/tests/credentials/CredentialsProviderSpec.js +0 -46
  316. package/tests/crypto/CryptoSpec.js +0 -33
  317. package/tests/data/BinaryDataSpec.js +0 -50
  318. package/tests/data/CompressorSpec.js +0 -7
  319. package/tests/data/FormDataSpec.js +0 -7
  320. package/tests/data/MimeSpec.js +0 -7
  321. package/tests/event/ErrorEventSpec.js +0 -20
  322. package/tests/event/EventDispatcherSpec.js +0 -319
  323. package/tests/event/EventSpec.js +0 -17
  324. package/tests/http/ConnectionPoolSpec.js +0 -7
  325. package/tests/http/HeadersSpec.js +0 -79
  326. package/tests/http/LoaderSpec.js +0 -43
  327. package/tests/http/MessageSpec.js +0 -251
  328. package/tests/http/RequestProcessorSpec.js +0 -124
  329. package/tests/http/RequestSpec.js +0 -651
  330. package/tests/http/ResponseSpec.js +0 -491
  331. package/tests/http/ServerSpec.js +0 -7
  332. package/tests/http/SocketSpec.js +0 -7
  333. package/tests/http/UrlSpec.js +0 -14
  334. package/tests/jsonrpc/JsonRpcAbstractSpec.js +0 -20
  335. package/tests/jsonrpc/JsonRpcBatchRequestSpec.js +0 -31
  336. package/tests/jsonrpc/JsonRpcBatchResponseSpec.js +0 -38
  337. package/tests/jsonrpc/JsonRpcErrorSpec.js +0 -58
  338. package/tests/jsonrpc/JsonRpcMethodSpec.js +0 -7
  339. package/tests/jsonrpc/JsonRpcRequestProcessorSpec.js +0 -271
  340. package/tests/jsonrpc/JsonRpcRequestSpec.js +0 -70
  341. package/tests/jsonrpc/JsonRpcResponseSpec.js +0 -63
  342. package/tests/jsonrpc/JsonRpcServerSpec.js +0 -42
  343. package/tests/pattern/PoolSpec.js +0 -180
  344. package/tests/pattern/decorator/AbstractDecoratorSpec.js +0 -7
  345. package/tests/pattern/decorator/DecoratorChainSpec.js +0 -7
  346. package/tests/yaml/YAMLSpec.js +0 -132
@@ -1,1228 +0,0 @@
1
- var net = require('net'), MemcachedSocket = null;
2
-
3
- var getKey = function (k, i) {
4
- if (i == 1) {
5
- return k;
6
- } else {
7
- return k + "_chunk_" + i;
8
- }
9
- };
10
-
11
- var getHead = function (p) {
12
- return new Buffer(p.join(' ') + "\r\n", "binary");;
13
- };
14
-
15
- var ending = new Buffer("\r\n");
16
-
17
- describe("MemcachedSocket", function () {
18
-
19
- var length,
20
- key,
21
- value,
22
- dataValue,
23
- lifetime,
24
- chunkSize,
25
- socketMock,
26
- readyCallCount,
27
- sck,
28
- progressSpy,
29
- errorSpy,
30
- readySpy,
31
- endSpy;
32
-
33
- beforeEach(function () {
34
- length = 32;
35
- key = "eloszka";
36
- value = "12345678";
37
- dataValue = value + value + value + value;
38
- lifetime = 1234;
39
- chunkSize = 8;
40
- socketMock = {
41
- _connected: true,
42
- cb: null,
43
- a: false,
44
- b: false,
45
- events: {},
46
- write: function (buff, encoding, cb) {
47
- if (cb) {
48
- cb();
49
- }
50
- },
51
- on: function (ev, cb) {
52
- this.events[ev] = cb;
53
- }
54
- },
55
- readyCallCount = 0;
56
-
57
- if (MemcachedSocket) {
58
- sck = new MemcachedSocket;
59
- }
60
-
61
- progressSpy = jasmine.createSpy();
62
- errorSpy = jasmine.createSpy();
63
- readySpy = jasmine.createSpy();
64
- endSpy = jasmine.createSpy();
65
- });
66
-
67
- it("require", function () {
68
- MemcachedSocket = require('../../lib/client/MemcachedSocket.js').MemcachedSocket;
69
-
70
- expect(MemcachedSocket).toBeTruthy();
71
- });
72
-
73
- describe("set", function () {
74
- it("with chunks using static data with reply", function () {
75
- socketMock.write = function (buff, encoding, cb) {
76
- if (buff.toString() == value) {
77
- this.a = true;
78
- }
79
-
80
- if (buff.toString() == ending.toString()) {
81
- this.b = true;
82
- }
83
-
84
- if (this.a && this.b) {
85
- this.a = false;
86
- this.b = false;
87
- this.events.data(new Buffer("STORED\r\n"));
88
- }
89
-
90
- if (cb) {
91
- cb();
92
- }
93
- };
94
-
95
- spyOn(socketMock, 'write').andCallThrough();
96
-
97
- runs(function () {
98
- sck.init(MemcachedSocket.Operation.SET, key, {
99
- lifetime: lifetime,
100
- length: length,
101
- waitForReply: true,
102
- chunkSize: chunkSize,
103
- data: new Buffer(dataValue)
104
- });
105
- sck.addEventListener(MemcachedSocket.Event.READY, readySpy);
106
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
107
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
108
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
109
- sck.setSocket(socketMock);
110
- });
111
-
112
- waitsFor(function () {
113
- return readySpy.callCount;
114
- }, 'eventReady');
115
-
116
- runs(function () {
117
- var calls = socketMock.write.argsForCall,
118
- l = socketMock.write.callCount,
119
- i = 0,
120
- chunk = 0;
121
-
122
- expect(l).toEqual(12);
123
-
124
- for (; i < l; i += 3) {
125
- //naglowek
126
- chunk++;
127
- expect(calls[i][0].toString()).toEqual(getHead([MemcachedSocket.Operation.SET, getKey(key, chunk), 0, lifetime, chunkSize]).toString());
128
- //dane
129
- expect(calls[i + 1][0].toString()).toEqual((new Buffer(value)).toString());
130
- //zakonczenie
131
- expect(calls[i + 2][0].toString()).toEqual(ending.toString());
132
- }
133
- });
134
-
135
- waitsFor(function () {
136
- return endSpy.callCount;
137
- }, 'eventEnd');
138
-
139
- runs(function () {
140
- expect(readySpy.callCount).toEqual(1);
141
-
142
- expect(progressSpy).not.toHaveBeenCalled();
143
- expect(errorSpy).not.toHaveBeenCalled();
144
-
145
- expect(endSpy.callCount).toEqual(1);
146
- expect(endSpy.argsForCall[0][0].data).toBeTruthy();
147
- });
148
- });
149
-
150
- it("with chunks using static data withOUT reply", function () {
151
- spyOn(socketMock, 'write').andCallThrough();
152
-
153
- runs(function () {
154
- sck.init(MemcachedSocket.Operation.SET, key, {
155
- lifetime: lifetime,
156
- length: length,
157
- waitForReply: false,
158
- chunkSize: chunkSize,
159
- data: new Buffer(dataValue)
160
- });
161
- sck.addEventListener(MemcachedSocket.Event.READY, readySpy);
162
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
163
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
164
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
165
- sck.setSocket(socketMock);
166
- });
167
-
168
- waitsFor(function () {
169
- return readySpy.callCount;
170
- }, 'eventReady');
171
-
172
- runs(function () {
173
- var calls = socketMock.write.argsForCall,
174
- l = socketMock.write.callCount,
175
- i = 0,
176
- chunk = 0;
177
-
178
- expect(l).toEqual(12);
179
-
180
- for (; i < l; i += 3) {
181
- //naglowek
182
- chunk++;
183
- expect(calls[i][0].toString()).toEqual(getHead([MemcachedSocket.Operation.SET, getKey(key, chunk), 0, lifetime, chunkSize, 'noreply']).toString());
184
- //dane
185
- expect(calls[i + 1][0].toString()).toEqual((new Buffer(value)).toString());
186
- //zakonczenie
187
- expect(calls[i + 2][0].toString()).toEqual(ending.toString());
188
- }
189
- });
190
-
191
- waitsFor(function () {
192
- return endSpy.callCount;
193
- }, 'eventEnd');
194
-
195
- runs(function () {
196
- expect(readySpy.callCount).toEqual(1);
197
-
198
- expect(progressSpy).not.toHaveBeenCalled();
199
- expect(errorSpy).not.toHaveBeenCalled();
200
-
201
- expect(endSpy.callCount).toEqual(1);
202
- expect(endSpy.argsForCall[0][0].data).toBeTruthy();
203
- });
204
- });
205
-
206
- it("with chunks using streamed data with reply", function () {
207
- socketMock.write = function (buff, encoding, cb) {
208
- if (buff.toString() == value) {
209
- this.a = true;
210
- }
211
-
212
- if (buff.toString() == ending.toString()) {
213
- this.b = true;
214
- }
215
-
216
- if (this.a && this.b) {
217
- this.a = false;
218
- this.b = false;
219
- this.events.data(new Buffer("STORED\r\n"));
220
- }
221
-
222
- if (cb) {
223
- cb();
224
- }
225
- };
226
-
227
- spyOn(socketMock, 'write').andCallThrough();
228
-
229
- runs(function () {
230
- sck.init(MemcachedSocket.Operation.SET, key, {
231
- lifetime: lifetime,
232
- length: length,
233
- waitForReply: true,
234
- chunkSize: chunkSize,
235
- });
236
- sck.addEventListener(MemcachedSocket.Event.READY, function () {
237
- for(var i = 0, l = 4; i < l; i++) {
238
- sck.write(new Buffer(value));
239
- }
240
- readyCallCount++;
241
- });
242
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
243
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
244
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
245
- sck.setSocket(socketMock);
246
- });
247
-
248
- waitsFor(function () {
249
- return readyCallCount;
250
- }, 'eventReady');
251
-
252
- runs(function () {
253
- var calls = socketMock.write.argsForCall,
254
- l = socketMock.write.callCount,
255
- i = 0,
256
- chunk = 0;
257
-
258
- expect(l).toEqual(12);
259
-
260
- for (; i < l; i += 3) {
261
- //naglowek
262
- chunk++;
263
- expect(calls[i][0].toString()).toEqual(getHead([MemcachedSocket.Operation.SET, getKey(key, chunk), 0, lifetime, chunkSize]).toString());
264
- //dane
265
- expect(calls[i + 1][0].toString()).toEqual((new Buffer(value)).toString());
266
- //zakonczenie
267
- expect(calls[i + 2][0].toString()).toEqual(ending.toString());
268
- }
269
- });
270
-
271
- waitsFor(function () {
272
- return endSpy.callCount;
273
- }, 'eventEnd');
274
-
275
- runs(function () {
276
- expect(readyCallCount).toEqual(1);
277
-
278
- expect(progressSpy).not.toHaveBeenCalled();
279
- expect(errorSpy).not.toHaveBeenCalled();
280
-
281
- expect(endSpy.callCount).toEqual(1);
282
- expect(endSpy.argsForCall[0][0].data).toBeTruthy();
283
- });
284
- });
285
-
286
- it("with chunks using streamed data withOUT reply", function () {
287
- spyOn(socketMock, 'write').andCallThrough();
288
-
289
- runs(function () {
290
- sck.init(MemcachedSocket.Operation.SET, key, {
291
- lifetime: lifetime,
292
- length: length,
293
- waitForReply: false,
294
- chunkSize: chunkSize,
295
- });
296
- sck.addEventListener(MemcachedSocket.Event.READY, function () {
297
- for(var i = 0, l = 4; i < l; i++) {
298
- sck.write(new Buffer(value));
299
- }
300
- readyCallCount++;
301
- });
302
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
303
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
304
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
305
- sck.setSocket(socketMock);
306
- });
307
-
308
- waitsFor(function () {
309
- return readyCallCount;
310
- }, 'eventReady');
311
-
312
- runs(function () {
313
- var calls = socketMock.write.argsForCall,
314
- l = socketMock.write.callCount,
315
- i = 0,
316
- chunk = 0;
317
-
318
- expect(l).toEqual(12);
319
-
320
- for (; i < l; i += 3) {
321
- //naglowek
322
- chunk++;
323
- expect(calls[i][0].toString()).toEqual(getHead([MemcachedSocket.Operation.SET, getKey(key, chunk), 0, lifetime, chunkSize, 'noreply']).toString());
324
- //dane
325
- expect(calls[i + 1][0].toString()).toEqual((new Buffer(value)).toString());
326
- //zakonczenie
327
- expect(calls[i + 2][0].toString()).toEqual(ending.toString());
328
- }
329
- });
330
-
331
- waitsFor(function () {
332
- return endSpy.callCount;
333
- }, 'eventEnd');
334
-
335
- runs(function () {
336
- expect(readyCallCount).toEqual(1);
337
-
338
- expect(progressSpy).not.toHaveBeenCalled();
339
- expect(errorSpy).not.toHaveBeenCalled();
340
-
341
- expect(endSpy.callCount).toEqual(1);
342
- expect(endSpy.argsForCall[0][0].data).toBeTruthy();
343
- });
344
- });
345
-
346
- it("with chunks using streamed, given input is bigger than chunkSize", function () {
347
- spyOn(socketMock, 'write').andCallThrough();
348
-
349
- runs(function () {
350
- sck.init(MemcachedSocket.Operation.SET, key, {
351
- lifetime: lifetime,
352
- length: length,
353
- waitForReply: false,
354
- chunkSize: chunkSize,
355
- });
356
- sck.addEventListener(MemcachedSocket.Event.READY, function () {
357
- for(var i = 0, l = 2; i < l; i++) {
358
- sck.write(new Buffer(value + value));
359
- }
360
- readyCallCount++;
361
- });
362
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
363
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
364
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
365
- sck.setSocket(socketMock);
366
- });
367
-
368
- waitsFor(function () {
369
- return readyCallCount;
370
- }, 'eventReady');
371
-
372
- runs(function () {
373
- var calls = socketMock.write.argsForCall,
374
- l = socketMock.write.callCount,
375
- i = 0,
376
- chunk = 0;
377
-
378
- expect(l).toEqual(12);
379
-
380
- for (; i < l; i += 3) {
381
- //naglowek
382
- chunk++;
383
- expect(calls[i][0].toString()).toEqual(getHead([MemcachedSocket.Operation.SET, getKey(key, chunk), 0, lifetime, chunkSize, 'noreply']).toString());
384
- //dane
385
- expect(calls[i + 1][0].toString()).toEqual((new Buffer(value)).toString());
386
- //zakonczenie
387
- expect(calls[i + 2][0].toString()).toEqual(ending.toString());
388
- }
389
- });
390
-
391
- waitsFor(function () {
392
- return endSpy.callCount;
393
- }, 'eventEnd');
394
-
395
- runs(function () {
396
- expect(readyCallCount).toEqual(1);
397
-
398
- expect(progressSpy).not.toHaveBeenCalled();
399
- expect(errorSpy).not.toHaveBeenCalled();
400
-
401
- expect(endSpy.callCount).toEqual(1);
402
- expect(endSpy.argsForCall[0][0].data).toBeTruthy();
403
- });
404
- });
405
-
406
- it("with chunks using streamed, last chunk is smaller than other", function () {
407
- var length = 28, tmpValue = "1234", tmpChunkSize = 4;
408
-
409
- spyOn(socketMock, 'write').andCallThrough();
410
-
411
- runs(function () {
412
- sck.init(MemcachedSocket.Operation.SET, key, {
413
- lifetime: lifetime,
414
- length: length,
415
- waitForReply: false,
416
- chunkSize: chunkSize,
417
- });
418
- sck.addEventListener(MemcachedSocket.Event.READY, function () {
419
- for(var i = 0, l = 4; i < l; i++) {
420
- if (i < 3) {
421
- sck.write(new Buffer(value));
422
- } else {
423
- sck.write(new Buffer(tmpValue));
424
- }
425
- }
426
- readyCallCount++;
427
- });
428
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
429
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
430
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
431
- sck.setSocket(socketMock);
432
- });
433
-
434
- waitsFor(function () {
435
- return readyCallCount;
436
- }, 'eventReady');
437
-
438
- runs(function () {
439
- var calls = socketMock.write.argsForCall,
440
- l = socketMock.write.callCount,
441
- i = 0,
442
- chunk = 0;
443
-
444
- expect(l).toEqual(12);
445
-
446
- for (; i < l; i += 3) {
447
- chunk++;
448
-
449
- if (chunk < 4) {
450
- //naglowek
451
- expect(calls[i][0].toString()).toEqual(getHead([MemcachedSocket.Operation.SET, getKey(key, chunk), 0, lifetime, chunkSize, 'noreply']).toString());
452
- //dane
453
- expect(calls[i + 1][0].toString()).toEqual((new Buffer(value)).toString());
454
- } else {
455
- //naglowek
456
- expect(calls[i][0].toString()).toEqual(getHead([MemcachedSocket.Operation.SET, getKey(key, chunk), 0, lifetime, tmpChunkSize, 'noreply']).toString());
457
- //dane
458
- expect(calls[i + 1][0].toString()).toEqual((new Buffer(tmpValue)).toString());
459
- }
460
-
461
- //zakonczenie
462
- expect(calls[i + 2][0].toString()).toEqual(ending.toString());
463
- }
464
- });
465
-
466
- waitsFor(function () {
467
- return endSpy.callCount;
468
- }, 'eventEnd');
469
-
470
- runs(function () {
471
- expect(readyCallCount).toEqual(1);
472
-
473
- expect(progressSpy).not.toHaveBeenCalled();
474
- expect(errorSpy).not.toHaveBeenCalled();
475
-
476
- expect(endSpy.callCount).toEqual(1);
477
- expect(endSpy.argsForCall[0][0].data).toBeTruthy();
478
- });
479
- });
480
-
481
- it("withOUT chunks using static data with STORED reply", function () {
482
- socketMock.write = function (buff, encoding, cb) {
483
- if (buff.toString() == dataValue) {
484
- this.a = true;
485
- }
486
-
487
- if (buff.toString() == ending.toString()) {
488
- this.b = true;
489
- }
490
-
491
- if (this.a && this.b) {
492
- this.a = false;
493
- this.b = false;
494
- this.events.data(new Buffer("STORED\r\n"));
495
- }
496
-
497
- if (cb) {
498
- cb();
499
- }
500
- };
501
-
502
- spyOn(socketMock, 'write').andCallThrough();
503
-
504
- runs(function () {
505
- sck.init(MemcachedSocket.Operation.SET, key, {
506
- lifetime: lifetime,
507
- length: length,
508
- waitForReply: true,
509
- data: new Buffer(dataValue)
510
- });
511
- sck.addEventListener(MemcachedSocket.Event.READY, readySpy);
512
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
513
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
514
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
515
- sck.setSocket(socketMock);
516
- });
517
-
518
- waitsFor(function () {
519
- return readySpy.callCount;
520
- }, 'eventReady');
521
-
522
- runs(function () {
523
- var calls = socketMock.write.argsForCall;
524
-
525
- expect(calls.length).toEqual(3);
526
-
527
- //naglowek
528
- expect(calls[0][0].toString()).toEqual(getHead([MemcachedSocket.Operation.SET, getKey(key, 1), 0, lifetime, length]).toString());
529
- //dane
530
- expect(calls[1][0].toString()).toEqual((new Buffer(dataValue)).toString());
531
- //zakonczenie
532
- expect(calls[2][0].toString()).toEqual(ending.toString());
533
- });
534
-
535
- waitsFor(function () {
536
- return endSpy.callCount;
537
- }, 'eventEnd');
538
-
539
- runs(function () {
540
- expect(readySpy.callCount).toEqual(1);
541
-
542
- expect(progressSpy).not.toHaveBeenCalled();
543
- expect(errorSpy).not.toHaveBeenCalled();
544
-
545
- expect(endSpy.callCount).toEqual(1);
546
- expect(endSpy.argsForCall[0][0].data).toBeTruthy();
547
- });
548
- });
549
-
550
- it("withOUT chunks using static data with NOT STORED reply", function () {
551
- spyOn(socketMock, 'write').andCallThrough();
552
-
553
- runs(function () {
554
- sck.init(MemcachedSocket.Operation.SET, key, {
555
- lifetime: lifetime,
556
- length: length,
557
- waitForReply: true,
558
- data: new Buffer(dataValue)
559
- });
560
- sck.addEventListener(MemcachedSocket.Event.READY, readySpy);
561
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
562
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
563
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
564
- sck.setSocket(socketMock);
565
- });
566
-
567
- waitsFor(function () {
568
- return readySpy.callCount;
569
- }, 'eventReady');
570
-
571
- runs(function () {
572
- var calls = socketMock.write.argsForCall;
573
-
574
- expect(calls.length).toEqual(3);
575
-
576
- //naglowek
577
- expect(calls[0][0].toString()).toEqual(getHead([MemcachedSocket.Operation.SET, getKey(key, 1), 0, lifetime, length]).toString());
578
- //dane
579
- expect(calls[1][0].toString()).toEqual((new Buffer(dataValue)).toString());
580
- //zakonczenie
581
- expect(calls[2][0].toString()).toEqual(ending.toString());
582
-
583
- socketMock.events.data(new Buffer("NOT STORED\r\n"));
584
- });
585
-
586
- waitsFor(function () {
587
- return endSpy.callCount;
588
- }, 'eventEnd');
589
-
590
- runs(function () {
591
- expect(readySpy.callCount).toEqual(1);
592
-
593
- expect(progressSpy).not.toHaveBeenCalled();
594
-
595
- expect(errorSpy.argsForCall[0][0].code).toEqual(MemcachedSocket.Exception.NOT_STORED);
596
-
597
- expect(endSpy.callCount).toEqual(1);
598
- expect(endSpy.argsForCall[0][0].data).toBeNull();
599
- });
600
- });
601
-
602
- it("withOUT chunks using static data with UNKNOWN reply", function () {
603
- spyOn(socketMock, 'write').andCallThrough();
604
-
605
- runs(function () {
606
- sck.init(MemcachedSocket.Operation.SET, key, {
607
- lifetime: lifetime,
608
- length: length,
609
- waitForReply: true,
610
- data: new Buffer(dataValue)
611
- });
612
- sck.addEventListener(MemcachedSocket.Event.READY, readySpy);
613
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
614
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
615
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
616
- sck.setSocket(socketMock);
617
- });
618
-
619
- waitsFor(function () {
620
- return readySpy.callCount;
621
- }, 'eventReady');
622
-
623
- runs(function () {
624
- var calls = socketMock.write.argsForCall;
625
-
626
- expect(calls.length).toEqual(3);
627
-
628
- //naglowek
629
- expect(calls[0][0].toString()).toEqual(getHead([MemcachedSocket.Operation.SET, getKey(key, 1), 0, lifetime, length]).toString());
630
- //dane
631
- expect(calls[1][0].toString()).toEqual((new Buffer(dataValue)).toString());
632
- //zakonczenie
633
- expect(calls[2][0].toString()).toEqual(ending.toString());
634
-
635
- socketMock.events.data(new Buffer("EXISTS\r\n"));
636
- });
637
-
638
- waitsFor(function () {
639
- return endSpy.callCount;
640
- }, 'eventEnd');
641
-
642
- runs(function () {
643
- expect(readySpy.callCount).toEqual(1);
644
-
645
- expect(progressSpy).not.toHaveBeenCalled();
646
-
647
- expect(errorSpy.argsForCall[0][0].code).toEqual(MemcachedSocket.Exception.UNKNOWN_ERROR);
648
-
649
- expect(endSpy.callCount).toEqual(1);
650
- expect(endSpy.argsForCall[0][0].data).toBeNull();
651
- });
652
- });
653
-
654
- it("withOUT chunks using static data withOUT reply", function () {
655
- spyOn(socketMock, 'write').andCallThrough();
656
-
657
- runs(function () {
658
- sck.init(MemcachedSocket.Operation.SET, key, {
659
- lifetime: lifetime,
660
- length: length,
661
- waitForReply: false,
662
- data: new Buffer(dataValue)
663
- });
664
- sck.addEventListener(MemcachedSocket.Event.READY, readySpy);
665
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
666
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
667
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
668
- sck.setSocket(socketMock);
669
- });
670
-
671
- waitsFor(function () {
672
- return readySpy.callCount;
673
- }, 'eventReady');
674
-
675
- runs(function () {
676
- var calls = socketMock.write.argsForCall;
677
-
678
- expect(calls.length).toEqual(3);
679
-
680
- //naglowek
681
- expect(calls[0][0].toString()).toEqual(getHead([MemcachedSocket.Operation.SET, getKey(key, 1), 0, lifetime, length, 'noreply']).toString());
682
- //dane
683
- expect(calls[1][0].toString()).toEqual((new Buffer(dataValue)).toString());
684
- //zakonczenie
685
- expect(calls[2][0].toString()).toEqual(ending.toString());
686
- });
687
-
688
- waitsFor(function () {
689
- return endSpy.callCount;
690
- }, 'eventEnd');
691
-
692
- runs(function () {
693
- expect(readySpy.callCount).toEqual(1);
694
-
695
- expect(progressSpy).not.toHaveBeenCalled();
696
-
697
- expect(errorSpy).not.toHaveBeenCalled();
698
-
699
- expect(endSpy.callCount).toEqual(1);
700
- expect(endSpy.argsForCall[0][0].data).toBeTruthy();
701
- });
702
- });
703
-
704
- it("withOUT chunks using streamed data with reply", function () {
705
- socketMock.write = function (buff, encoding, cb) {
706
- if (buff.toString() == value) {
707
- this.a = true;
708
- }
709
-
710
- if (buff.toString() == ending.toString()) {
711
- this.b = true;
712
- }
713
-
714
- if (this.a && this.b) {
715
- this.a = false;
716
- this.b = false;
717
- this.events.data(new Buffer("STORED\r\n"));
718
- }
719
-
720
- if (cb) {
721
- cb();
722
- }
723
- };
724
-
725
- spyOn(socketMock, 'write').andCallThrough();
726
-
727
- runs(function () {
728
- sck.init(MemcachedSocket.Operation.SET, key, {
729
- lifetime: lifetime,
730
- length: length,
731
- waitForReply: true,
732
- });
733
- sck.addEventListener(MemcachedSocket.Event.READY, function () {
734
- for(var i = 0, l = 4; i < l; i++) {
735
- sck.write(new Buffer(value));
736
- }
737
- readyCallCount++;
738
- });
739
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
740
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
741
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
742
- sck.setSocket(socketMock);
743
- });
744
-
745
- waitsFor(function () {
746
- return readyCallCount;
747
- }, 'eventReady');
748
-
749
- runs(function () {
750
- var calls = socketMock.write.argsForCall,
751
- chunk = 0;
752
-
753
- expect(calls.length).toEqual(6);
754
-
755
- //naglowek
756
- chunk++;
757
- expect(calls[0][0].toString()).toEqual(getHead([MemcachedSocket.Operation.SET, getKey(key, chunk), 0, lifetime, length]).toString());
758
- //dane
759
- expect(calls[1][0].toString()).toEqual((new Buffer(value)).toString());
760
- expect(calls[2][0].toString()).toEqual((new Buffer(value)).toString());
761
- expect(calls[3][0].toString()).toEqual((new Buffer(value)).toString());
762
- expect(calls[4][0].toString()).toEqual((new Buffer(value)).toString());
763
- //zakonczenie
764
- expect(calls[5][0].toString()).toEqual(ending.toString());
765
- });
766
-
767
- waitsFor(function () {
768
- return endSpy.callCount;
769
- }, 'eventEnd');
770
-
771
- runs(function () {
772
- expect(readyCallCount).toEqual(1);
773
-
774
- expect(progressSpy).not.toHaveBeenCalled();
775
-
776
- expect(errorSpy).not.toHaveBeenCalled();
777
-
778
- expect(endSpy.callCount).toEqual(1);
779
- expect(endSpy.argsForCall[0][0].data).toBeTruthy();
780
- });
781
- });
782
-
783
- it("withOUT chunks using streamed data withOUT reply", function () {
784
- spyOn(socketMock, 'write').andCallThrough();
785
-
786
- runs(function () {
787
- sck.init(MemcachedSocket.Operation.SET, key, {
788
- lifetime: lifetime,
789
- length: length,
790
- waitForReply: false,
791
- });
792
- sck.addEventListener(MemcachedSocket.Event.READY, function () {
793
- for(var i = 0, l = 4; i < l; i++) {
794
- sck.write(new Buffer(value));
795
- }
796
- readyCallCount++;
797
- });
798
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
799
- sck.addEventListener(MemcachedSocket.Event.Error, errorSpy)
800
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
801
- sck.setSocket(socketMock);
802
- });
803
-
804
- waitsFor(function () {
805
- return readyCallCount;
806
- }, 'eventReady');
807
-
808
- runs(function () {
809
- var calls = socketMock.write.argsForCall;
810
-
811
- expect(calls.length).toEqual(6);
812
-
813
- //naglowek
814
- expect(calls[0][0].toString()).toEqual(getHead([MemcachedSocket.Operation.SET, getKey(key, 1), 0, lifetime, length, 'noreply']).toString());
815
- //dane
816
- expect(calls[1][0].toString()).toEqual((new Buffer(value)).toString());
817
- expect(calls[2][0].toString()).toEqual((new Buffer(value)).toString());
818
- expect(calls[3][0].toString()).toEqual((new Buffer(value)).toString());
819
- expect(calls[4][0].toString()).toEqual((new Buffer(value)).toString());
820
- //zakonczenie
821
- expect(calls[5][0].toString()).toEqual(ending.toString());
822
- });
823
-
824
- waitsFor(function () {
825
- return endSpy.callCount;
826
- }, 'eventEnd');
827
-
828
- runs(function () {
829
- expect(readyCallCount).toEqual(1);
830
-
831
- expect(progressSpy).not.toHaveBeenCalled();
832
-
833
- expect(errorSpy).not.toHaveBeenCalled();
834
-
835
- expect(endSpy.callCount).toEqual(1);
836
- expect(endSpy.argsForCall[0][0].data).toBeTruthy();
837
- });
838
- });
839
- });
840
-
841
- describe("get", function () {
842
- it("with chunks", function () {
843
- var currentChunk = 0, totalChunks = 4;
844
- socketMock.write = function (buff, encoding, cb) {
845
- if (currentChunk < totalChunks) {
846
- currentChunk++;
847
- this.events.data(new Buffer("VALUE " + key + " 0 8\r\n" + value + "\r\nEND\r\n"));
848
- } else {
849
- this.events.data(new Buffer("END\r\n"));
850
- }
851
-
852
- if (cb) {
853
- cb();
854
- }
855
- };
856
-
857
- runs(function () {
858
- sck.init(MemcachedSocket.Operation.GET, key, {
859
- chunkSize: chunkSize
860
- });
861
- sck.addEventListener(MemcachedSocket.Event.READY, readySpy);
862
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
863
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
864
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
865
- sck.setSocket(socketMock);
866
- });
867
-
868
- waitsFor(function () {
869
- return readySpy.callCount;
870
- }, 'eventReady');
871
-
872
- runs(function () {
873
- var calls = progressSpy.argsForCall,
874
- l = progressSpy.callCount,
875
- i = 0;
876
-
877
- expect(l).toEqual(4);
878
-
879
- for (; i < l; i++) {
880
- expect(calls[i][0].data.toString()).toEqual((new Buffer(value)).toString());
881
- }
882
- });
883
-
884
- waitsFor(function () {
885
- return endSpy.callCount;
886
- }, 'eventEnd');
887
-
888
- runs(function () {
889
- expect(readySpy.callCount).toEqual(1);
890
-
891
- expect(errorSpy).not.toHaveBeenCalled();
892
-
893
- expect(endSpy.callCount).toEqual(1);
894
- expect(endSpy.argsForCall[0][0].data.toString()).toEqual((new Buffer(dataValue)).toString());
895
- });
896
- });
897
-
898
- it("withOUT chunks", function () {
899
- var tmpValue = '', count = -1, maxCount = 20, timer = null;
900
- socketMock.write = function (buff, encoding, cb) {
901
- var self = this;
902
- timer = setInterval(function () {
903
- count++;
904
-
905
- if (count == 0) {
906
- tmpValue += value;
907
- self.events.data(new Buffer("VALUE " + key + " 0 160\r\n" + value));
908
- } else if (count > 0 && count < maxCount) {
909
- tmpValue += value;
910
- self.events.data(new Buffer(value));
911
- } else {
912
- self.events.data(new Buffer("\r\nEND\r\n"));
913
- clearInterval(timer);
914
- }
915
- }, 1);
916
-
917
- if (cb) {
918
- cb();
919
- }
920
- };
921
-
922
- spyOn(socketMock, 'write').andCallThrough();
923
-
924
- runs(function () {
925
- sck.init(MemcachedSocket.Operation.GET, key, {
926
- timeout: 1000
927
- });
928
- sck.addEventListener(MemcachedSocket.Event.READY, readySpy);
929
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
930
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
931
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
932
- sck.setSocket(socketMock);
933
- });
934
-
935
- waitsFor(function () {
936
- return readySpy.callCount && progressSpy.callCount == 20;
937
- }, 'eventReady');
938
-
939
- runs(function () {
940
- var calls = progressSpy.argsForCall,
941
- l = progressSpy.callCount,
942
- i = 0;
943
-
944
- expect(l).toEqual(20);
945
-
946
- for (; i < l; i++) {
947
- expect(calls[i][0].data.toString()).toEqual((new Buffer(value)).toString());
948
- }
949
- });
950
-
951
- waitsFor(function () {
952
- return endSpy.callCount;
953
- }, 'eventEnd');
954
-
955
- runs(function () {
956
- expect(readySpy.callCount).toEqual(1);
957
-
958
- expect(errorSpy).not.toHaveBeenCalled();
959
-
960
- expect(endSpy.callCount).toEqual(1);
961
- expect(endSpy.argsForCall[0][0].data.toString()).toEqual((new Buffer(tmpValue)).toString());
962
- });
963
- });
964
-
965
- it("timedout", function () {
966
- runs(function () {
967
- sck.init(MemcachedSocket.Operation.GET, key, {
968
- timeout: 1000
969
- });
970
- sck.addEventListener(MemcachedSocket.Event.READY, readySpy);
971
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
972
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
973
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
974
- sck.setSocket(socketMock);
975
- });
976
-
977
- waitsFor(function () {
978
- return readySpy.callCount && errorSpy.callCount;
979
- }, 'eventReady');
980
-
981
- runs(function () {
982
- expect(readySpy.callCount).toEqual(1);
983
-
984
- expect(progressSpy).not.toHaveBeenCalled();
985
-
986
- expect(errorSpy.callCount).toEqual(1);
987
- expect(errorSpy.argsForCall[0][0].code).toEqual(MemcachedSocket.Exception.TIMEDOUT);
988
- });
989
-
990
- waitsFor(function () {
991
- return endSpy.callCount;
992
- }, 'eventEnd');
993
-
994
- runs(function () {
995
- expect(endSpy.callCount).toEqual(1);
996
- expect(endSpy.argsForCall[0][0].data).toBeNull();
997
- });
998
- });
999
-
1000
- it("no data for given key", function () {
1001
- socketMock.write = function (buff, encoding, cb) {
1002
- this.events.data(new Buffer("END\r\n"));
1003
- };
1004
- runs(function () {
1005
- sck.init(MemcachedSocket.Operation.GET, key, {});
1006
- sck.addEventListener(MemcachedSocket.Event.READY, readySpy);
1007
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
1008
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
1009
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
1010
- sck.setSocket(socketMock);
1011
- });
1012
-
1013
- waitsFor(function () {
1014
- return readySpy.callCount && endSpy.callCount;
1015
- }, 'eventReady');
1016
-
1017
- runs(function () {
1018
- expect(readySpy.callCount).toEqual(1);
1019
-
1020
- expect(progressSpy).not.toHaveBeenCalled();
1021
-
1022
- expect(errorSpy).not.toHaveBeenCalled();
1023
-
1024
- expect(endSpy.callCount).toEqual(1);
1025
- expect(endSpy.argsForCall[0][0].data).toBeNull();
1026
- });
1027
- });
1028
-
1029
- it("bad command format", function () {
1030
- socketMock.write = function (buff, encoding, cb) {
1031
- this.events.data(new Buffer("BAD COMMAND FORMAT\r\n"));
1032
- };
1033
- runs(function () {
1034
- sck.init(MemcachedSocket.Operation.GET, key, {});
1035
- sck.addEventListener(MemcachedSocket.Event.READY, readySpy);
1036
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
1037
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
1038
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
1039
- sck.setSocket(socketMock);
1040
- });
1041
-
1042
- waitsFor(function () {
1043
- return readySpy.callCount && endSpy.callCount;
1044
- }, 'eventReady');
1045
-
1046
-
1047
- runs(function () {
1048
- expect(readySpy.callCount).toEqual(1);
1049
-
1050
- expect(progressSpy).not.toHaveBeenCalled();
1051
-
1052
- expect(errorSpy.callCount).toEqual(1);
1053
- expect(errorSpy.argsForCall[0][0].code).toEqual(MemcachedSocket.Exception.BAD_COMMAND_FORMAT);
1054
-
1055
- expect(endSpy.callCount).toEqual(1);
1056
- expect(endSpy.argsForCall[0][0].data).toBeNull();
1057
- });
1058
- });
1059
- });
1060
-
1061
- describe("delete", function() {
1062
- it("with reply: deleted", function () {
1063
- socketMock.write = function (buff, encoding, cb) {
1064
- this.events.data(new Buffer("DELETED\r\n"));
1065
-
1066
- if (cb) {
1067
- cb();
1068
- }
1069
- };
1070
-
1071
- runs(function () {
1072
- sck.init(MemcachedSocket.Operation.DELETE, key, {
1073
- waitForReply: true
1074
- });
1075
- sck.addEventListener(MemcachedSocket.Event.READY, readySpy);
1076
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
1077
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
1078
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
1079
- sck.setSocket(socketMock);
1080
- });
1081
-
1082
- waitsFor(function () {
1083
- return readySpy.callCount && endSpy.callCount;
1084
- }, "delete done");
1085
-
1086
- runs(function () {
1087
- expect(readySpy.callCount).toEqual(1);
1088
-
1089
- expect(progressSpy).not.toHaveBeenCalled();
1090
- expect(errorSpy).not.toHaveBeenCalled();
1091
-
1092
- expect(endSpy.callCount).toEqual(1);
1093
- expect(endSpy.argsForCall[0][0].data).toBeTruthy();
1094
- });
1095
- });
1096
-
1097
- it("with reply: not deleted", function () {
1098
- socketMock.write = function (buff, encoding, cb) {
1099
- this.events.data(new Buffer("NOT DELETED\r\n"));
1100
-
1101
- if (cb) {
1102
- cb();
1103
- }
1104
- };
1105
-
1106
- runs(function () {
1107
- sck.init(MemcachedSocket.Operation.DELETE, key, {
1108
- waitForReply: true
1109
- });
1110
- sck.addEventListener(MemcachedSocket.Event.READY, readySpy);
1111
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
1112
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
1113
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
1114
- sck.setSocket(socketMock);
1115
- });
1116
-
1117
- waitsFor(function () {
1118
- return readySpy.callCount && endSpy.callCount;
1119
- }, "delete done");
1120
-
1121
- runs(function () {
1122
- expect(readySpy.callCount).toEqual(1);
1123
-
1124
- expect(progressSpy).not.toHaveBeenCalled();
1125
-
1126
- expect(errorSpy.callCount).toEqual(1);
1127
- expect(errorSpy.argsForCall[0][0].code).toEqual(MemcachedSocket.Exception.NOT_DELETED);
1128
-
1129
- expect(endSpy.callCount).toEqual(1);
1130
- expect(endSpy.argsForCall[0][0].data).toBeNull();
1131
- });
1132
- });
1133
-
1134
- it("with reply: unknown error", function () {
1135
- socketMock.write = function (buff, encoding, cb) {
1136
- this.events.data(new Buffer("AAAAAAAAAAAAAAAAAAAAAAa\r\n"));
1137
-
1138
- if (cb) {
1139
- cb();
1140
- }
1141
- };
1142
-
1143
- runs(function () {
1144
- sck.init(MemcachedSocket.Operation.DELETE, key, {
1145
- waitForReply: true
1146
- });
1147
- sck.addEventListener(MemcachedSocket.Event.READY, readySpy);
1148
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
1149
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
1150
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
1151
- sck.setSocket(socketMock);
1152
- });
1153
-
1154
- waitsFor(function () {
1155
- return readySpy.callCount && endSpy.callCount;
1156
- }, "delete done");
1157
-
1158
- runs(function () {
1159
- expect(readySpy.callCount).toEqual(1);
1160
-
1161
- expect(progressSpy).not.toHaveBeenCalled();
1162
-
1163
- expect(errorSpy.callCount).toEqual(1);
1164
- expect(errorSpy.argsForCall[0][0].code).toEqual(MemcachedSocket.Exception.UNKNOWN_ERROR);
1165
-
1166
- expect(endSpy.callCount).toEqual(1);
1167
- expect(endSpy.argsForCall[0][0].data).toBeNull();
1168
- });
1169
- });
1170
-
1171
- it("withOUT reply", function () {
1172
- runs(function () {
1173
- sck.init(MemcachedSocket.Operation.DELETE, key, {
1174
- waitForReply: false
1175
- });
1176
- sck.addEventListener(MemcachedSocket.Event.READY, readySpy);
1177
- sck.addEventListener(MemcachedSocket.Event.PROGRESS, progressSpy);
1178
- sck.addEventListener(MemcachedSocket.Event.ERROR, errorSpy);
1179
- sck.addEventListener(MemcachedSocket.Event.END, endSpy);
1180
- sck.setSocket(socketMock);
1181
- });
1182
-
1183
- waitsFor(function () {
1184
- return readySpy.callCount && endSpy.callCount;
1185
- }, "delete done");
1186
-
1187
- runs(function () {
1188
- expect(readySpy.callCount).toEqual(1);
1189
-
1190
- expect(progressSpy).not.toHaveBeenCalled();
1191
- expect(errorSpy).not.toHaveBeenCalled();
1192
-
1193
- expect(endSpy.callCount).toEqual(1);
1194
- expect(endSpy.argsForCall[0][0].data).toBeTruthy();
1195
- });
1196
- });
1197
- });
1198
-
1199
- describe("misc", function () {
1200
- it("waiting for connect event", function () {
1201
- socketMock._connected = false;
1202
-
1203
- runs(function () {
1204
- sck.init(MemcachedSocket.Operation.GET, key, {});
1205
- sck.addEventListener(MemcachedSocket.Event.READY, readySpy);
1206
- sck.setSocket(socketMock);
1207
- });
1208
-
1209
- waitsFor(function () {
1210
- return socketMock.events.hasOwnProperty("connect");
1211
- });
1212
-
1213
- runs(function () {
1214
- expect(readySpy).not.toHaveBeenCalled();
1215
-
1216
- socketMock.events.connect();
1217
- });
1218
-
1219
- waitsFor(function () {
1220
- return readySpy.callCount;
1221
- });
1222
-
1223
- runs(function () {
1224
- expect(readySpy.callCount).toEqual(1);
1225
- });
1226
- });
1227
- });
1228
- });