Best JavaScript code snippet using wpt
ComplexObject.spec.js
Source:ComplexObject.spec.js
1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17'use strict';18require('jasmine-expect');19const Util = require('util');20const TestingHelper = require('../TestingHelper');21const { IgniteClient, ObjectType, MapObjectType, ComplexObjectType, BinaryObject } = require('apache-ignite-client');22const CACHE_NAME = '__test_cache';23const ONE_BYTE_MAX_OFFSET = 0x100 - 1;24const TWO_BYTES_MAX_OFFSET = 0x10000 - 1;25const COMPLEX_OBJECT_HEADER_LENGTH = 24;26class Class1 {27 constructor() {28 this.field_1_1 = null;29 this.field_1_2 = new Class2();30 this.field_1_3 = null;31 }32}33class SubClass1 extends Class1 {34 constructor() {35 super();36 this.field_1_4 = null;37 this.field_1_5 = new Class3();38 this.field_1_6 = null;39 this.field_1_7 = null;40 this.field_1_8 = null;41 }42}43class Class2 {44 constructor() {45 this.field_2_1 = null;46 this.field_2_2 = null;47 }48}49class Class3 {50 constructor() {51 this.field_3_1 = null;52 this.field_3_2 = null;53 }54}55describe('complex object test suite >', () => {56 let igniteClient = null;57 beforeAll((done) => {58 Promise.resolve().59 then(async () => {60 await TestingHelper.init();61 igniteClient = TestingHelper.igniteClient;62 await testSuiteCleanup(done);63 await igniteClient.getOrCreateCache(CACHE_NAME);64 }).65 then(done).66 catch(error => done.fail(error));67 }, TestingHelper.TIMEOUT);68 afterAll((done) => {69 Promise.resolve().70 then(async () => {71 await testSuiteCleanup(done);72 await TestingHelper.cleanUp();73 }).74 then(done).75 catch(error => done.fail(error));76 }, TestingHelper.TIMEOUT);77 it('put get complex objects', (done) => {78 Promise.resolve().79 then(async () => {80 const value1 = new Class1();81 value1.field_1_1 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.BYTE);82 value1.field_1_2.field_2_1 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.SHORT);83 value1.field_1_2.field_2_2 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.INTEGER);84 value1.field_1_3 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.LONG);85 const valueType1 = new ComplexObjectType(new Class1()).86 setFieldType('field_1_1', ObjectType.PRIMITIVE_TYPE.BYTE).87 setFieldType('field_1_2', new ComplexObjectType(new Class2(), 'Class2ShortInteger').88 setFieldType('field_2_1', ObjectType.PRIMITIVE_TYPE.SHORT).89 setFieldType('field_2_2', ObjectType.PRIMITIVE_TYPE.INTEGER)).90 setFieldType('field_1_3', ObjectType.PRIMITIVE_TYPE.LONG);91 const value2 = new SubClass1();92 value2.field_1_1 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.FLOAT);93 value2.field_1_2.field_2_1 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.DOUBLE);94 value2.field_1_2.field_2_2 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.CHAR);95 value2.field_1_3 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.BOOLEAN);96 value2.field_1_4 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.STRING);97 value2.field_1_5.field_3_1 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.DATE);98 value2.field_1_5.field_3_2 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.UUID);99 value2.field_1_6 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.DECIMAL);100 value2.field_1_7 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.TIMESTAMP);101 value2.field_1_8 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.TIME);102 const valueType2 = new ComplexObjectType(new SubClass1()).103 setFieldType('field_1_1', ObjectType.PRIMITIVE_TYPE.FLOAT).104 setFieldType('field_1_2', new ComplexObjectType(new Class2(), 'Class2DoubleChar').105 setFieldType('field_2_1', ObjectType.PRIMITIVE_TYPE.DOUBLE).106 setFieldType('field_2_2', ObjectType.PRIMITIVE_TYPE.CHAR)).107 setFieldType('field_1_3', ObjectType.PRIMITIVE_TYPE.BOOLEAN).108 setFieldType('field_1_4', ObjectType.PRIMITIVE_TYPE.STRING).109 setFieldType('field_1_5', new ComplexObjectType(new Class3()).110 setFieldType('field_3_1', ObjectType.PRIMITIVE_TYPE.DATE).111 setFieldType('field_3_2', ObjectType.PRIMITIVE_TYPE.UUID)).112 setFieldType('field_1_6', ObjectType.PRIMITIVE_TYPE.DECIMAL).113 setFieldType('field_1_7', ObjectType.PRIMITIVE_TYPE.TIMESTAMP).114 setFieldType('field_1_8', ObjectType.PRIMITIVE_TYPE.TIME);115 await putGetComplexObjectsWithDifferentTypes(116 value1, value2, valueType1, valueType2, Class1, SubClass1);117 }).118 then(done).119 catch(error => done.fail(error));120 });121 it('put get unnamed complex objects', (done) => {122 Promise.resolve().123 then(async () => {124 const value1 = {};125 value1.field_1_1 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.BYTE);126 value1.field_1_2 = {};127 value1.field_1_2.field_2_1 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.SHORT);128 value1.field_1_2.field_2_2 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.INTEGER);129 value1.field_1_3 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.LONG);130 const valueType1 = new ComplexObjectType(value1, 'ObjectWithByteObjLong').131 setFieldType('field_1_1', ObjectType.PRIMITIVE_TYPE.BYTE).132 setFieldType('field_1_2', new ComplexObjectType(value1.field_1_2, 'ObjectWithShortInteger').133 setFieldType('field_2_1', ObjectType.PRIMITIVE_TYPE.SHORT).134 setFieldType('field_2_2', ObjectType.PRIMITIVE_TYPE.INTEGER)).135 setFieldType('field_1_3', ObjectType.PRIMITIVE_TYPE.LONG);136 const value2 = {};137 value2.field_1_1 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.FLOAT);138 value2.field_1_2 = {};139 value2.field_1_2.field_2_1 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.DOUBLE);140 value2.field_1_2.field_2_2 = {};141 value2.field_1_2.field_2_2.field_3_1 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.CHAR);142 value2.field_1_2.field_2_2.field_3_2 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.BOOLEAN);143 value2.field_1_3 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.STRING);144 value2.field_1_4 = getPrimitiveValue(ObjectType.PRIMITIVE_TYPE.DATE);145 const valueType2 = new ComplexObjectType(value2, 'ObjectWithFloatObjStringDate').146 setFieldType('field_1_1', ObjectType.PRIMITIVE_TYPE.FLOAT).147 setFieldType('field_1_2', new ComplexObjectType(value2.field_1_2, 'ObjectWithDoubleObj').148 setFieldType('field_2_1', ObjectType.PRIMITIVE_TYPE.DOUBLE).149 setFieldType('field_2_2', new ComplexObjectType(value2.field_1_2.field_2_2, 'ObjectWithCharBoolean').150 setFieldType('field_3_1', ObjectType.PRIMITIVE_TYPE.CHAR).151 setFieldType('field_3_2', ObjectType.PRIMITIVE_TYPE.BOOLEAN))).152 setFieldType('field_1_3', ObjectType.PRIMITIVE_TYPE.STRING).153 setFieldType('field_1_4', ObjectType.PRIMITIVE_TYPE.DATE);154 await putGetComplexObjects(value1, value2,155 valueType1, valueType2, value2);156 await putGetComplexObjects({}, {},157 new ComplexObjectType({}), new ComplexObjectType({}), {});158 let binaryKey = await BinaryObject.fromObject(value1, valueType1);159 let binaryValue = await BinaryObject.fromObject(value2, valueType2);160 await putGetComplexObjects(binaryKey, binaryValue,161 null, null, value2);162 binaryKey = await BinaryObject.fromObject({});163 binaryValue = await BinaryObject.fromObject({});164 await putGetComplexObjects(binaryKey, binaryValue,165 null, null, {});166 }).167 then(done).168 catch(error => done.fail(error));169 });170 it('put get complex objects with arrays', (done) => {171 Promise.resolve().172 then(async () => {173 const value1 = new Class1();174 value1.field_1_1 = getArrayValues(ObjectType.PRIMITIVE_TYPE.BYTE_ARRAY);175 value1.field_1_2.field_2_1 = getArrayValues(ObjectType.PRIMITIVE_TYPE.SHORT_ARRAY);176 value1.field_1_2.field_2_2 = getArrayValues(ObjectType.PRIMITIVE_TYPE.INTEGER_ARRAY);177 value1.field_1_3 = getArrayValues(ObjectType.PRIMITIVE_TYPE.LONG_ARRAY);178 const valueType1 = new ComplexObjectType(new Class1(), 'Class1WithArrays').179 setFieldType('field_1_1', ObjectType.PRIMITIVE_TYPE.BYTE_ARRAY).180 setFieldType('field_1_2', new ComplexObjectType(new Class2(), 'Class2WithShortIntegerArrays').181 setFieldType('field_2_1', ObjectType.PRIMITIVE_TYPE.SHORT_ARRAY).182 setFieldType('field_2_2', ObjectType.PRIMITIVE_TYPE.INTEGER_ARRAY)).183 setFieldType('field_1_3', ObjectType.PRIMITIVE_TYPE.LONG_ARRAY);184 const value2 = new SubClass1();185 value2.field_1_1 = getArrayValues(ObjectType.PRIMITIVE_TYPE.FLOAT_ARRAY);186 value2.field_1_2.field_2_1 = getArrayValues(ObjectType.PRIMITIVE_TYPE.DOUBLE_ARRAY);187 value2.field_1_2.field_2_2 = getArrayValues(ObjectType.PRIMITIVE_TYPE.CHAR_ARRAY);188 value2.field_1_3 = getArrayValues(ObjectType.PRIMITIVE_TYPE.BOOLEAN_ARRAY);189 value2.field_1_4 = getArrayValues(ObjectType.PRIMITIVE_TYPE.STRING_ARRAY);190 value2.field_1_5.field_3_1 = getArrayValues(ObjectType.PRIMITIVE_TYPE.DATE_ARRAY);191 value2.field_1_5.field_3_2 = getArrayValues(ObjectType.PRIMITIVE_TYPE.UUID_ARRAY);192 value2.field_1_6 = getArrayValues(ObjectType.PRIMITIVE_TYPE.DECIMAL_ARRAY);193 value2.field_1_7 = getArrayValues(ObjectType.PRIMITIVE_TYPE.TIMESTAMP_ARRAY);194 value2.field_1_8 = getArrayValues(ObjectType.PRIMITIVE_TYPE.TIME_ARRAY);195 const valueType2 = new ComplexObjectType(new SubClass1(), 'SubClass1WithArrays').196 setFieldType('field_1_1', ObjectType.PRIMITIVE_TYPE.FLOAT_ARRAY).197 setFieldType('field_1_2', new ComplexObjectType(new Class2(), 'Class2WithDoubleCharArrays').198 setFieldType('field_2_1', ObjectType.PRIMITIVE_TYPE.DOUBLE_ARRAY).199 setFieldType('field_2_2', ObjectType.PRIMITIVE_TYPE.CHAR_ARRAY)).200 setFieldType('field_1_3', ObjectType.PRIMITIVE_TYPE.BOOLEAN_ARRAY).201 setFieldType('field_1_4', ObjectType.PRIMITIVE_TYPE.STRING_ARRAY).202 setFieldType('field_1_5', new ComplexObjectType(new Class3(), 'Class3WithArrays').203 setFieldType('field_3_1', ObjectType.PRIMITIVE_TYPE.DATE_ARRAY).204 setFieldType('field_3_2', ObjectType.PRIMITIVE_TYPE.UUID_ARRAY)).205 setFieldType('field_1_6', ObjectType.PRIMITIVE_TYPE.DECIMAL_ARRAY).206 setFieldType('field_1_7', ObjectType.PRIMITIVE_TYPE.TIMESTAMP_ARRAY).207 setFieldType('field_1_8', ObjectType.PRIMITIVE_TYPE.TIME_ARRAY);208 await putGetComplexObjectsWithDifferentTypes(209 value1, value2, valueType1, valueType2, Class1, SubClass1, true);210 }).211 then(done).212 catch(error => done.fail(error));213 });214 it('put get complex objects with maps', (done) => {215 Promise.resolve().216 then(async () => {217 const value1 = new Class1();218 value1.field_1_1 = getMapValue(ObjectType.PRIMITIVE_TYPE.BYTE);219 value1.field_1_2.field_2_1 = getMapValue(ObjectType.PRIMITIVE_TYPE.SHORT);220 value1.field_1_2.field_2_2 = getMapValue(ObjectType.PRIMITIVE_TYPE.INTEGER);221 value1.field_1_3 = getMapValue(ObjectType.PRIMITIVE_TYPE.LONG);222 const valueType1 = new ComplexObjectType(new Class1(), 'Class1WithMaps').223 setFieldType('field_1_1', new MapObjectType(224 MapObjectType.MAP_SUBTYPE.HASH_MAP, ObjectType.PRIMITIVE_TYPE.BYTE, ObjectType.PRIMITIVE_TYPE.BYTE)).225 setFieldType('field_1_2', new ComplexObjectType(new Class2(), 'Class2WithShortIntegerMaps').226 setFieldType('field_2_1', new MapObjectType(227 MapObjectType.MAP_SUBTYPE.HASH_MAP, ObjectType.PRIMITIVE_TYPE.SHORT, ObjectType.PRIMITIVE_TYPE.SHORT)).228 setFieldType('field_2_2', new MapObjectType(229 MapObjectType.MAP_SUBTYPE.HASH_MAP, ObjectType.PRIMITIVE_TYPE.INTEGER, ObjectType.PRIMITIVE_TYPE.INTEGER))).230 setFieldType('field_1_3', new MapObjectType(231 MapObjectType.MAP_SUBTYPE.HASH_MAP, ObjectType.PRIMITIVE_TYPE.LONG, ObjectType.PRIMITIVE_TYPE.LONG));232 const value2 = new SubClass1();233 value2.field_1_1 = getMapValue(ObjectType.PRIMITIVE_TYPE.FLOAT);234 value2.field_1_2.field_2_1 = getMapValue(ObjectType.PRIMITIVE_TYPE.DOUBLE);235 value2.field_1_2.field_2_2 = getMapValue(ObjectType.PRIMITIVE_TYPE.CHAR);236 value2.field_1_3 = getMapValue(ObjectType.PRIMITIVE_TYPE.BOOLEAN);237 value2.field_1_4 = getMapValue(ObjectType.PRIMITIVE_TYPE.STRING);238 value2.field_1_5.field_3_1 = getMapValue(ObjectType.PRIMITIVE_TYPE.DATE);239 value2.field_1_5.field_3_2 = getMapValue(ObjectType.PRIMITIVE_TYPE.UUID);240 value2.field_1_6 = getMapValue(ObjectType.PRIMITIVE_TYPE.DECIMAL);241 value2.field_1_7 = getMapValue(ObjectType.PRIMITIVE_TYPE.TIMESTAMP);242 value2.field_1_8 = getMapValue(ObjectType.PRIMITIVE_TYPE.TIME);243 const valueType2 = new ComplexObjectType(new SubClass1(), 'SubClass1WithMaps').244 setFieldType('field_1_1', new MapObjectType(245 MapObjectType.MAP_SUBTYPE.HASH_MAP, ObjectType.PRIMITIVE_TYPE.STRING, ObjectType.PRIMITIVE_TYPE.FLOAT)).246 setFieldType('field_1_2', new ComplexObjectType(new Class2(), 'Class2WithDoubleCharMaps').247 setFieldType('field_2_1', new MapObjectType(248 MapObjectType.MAP_SUBTYPE.HASH_MAP, ObjectType.PRIMITIVE_TYPE.STRING, ObjectType.PRIMITIVE_TYPE.DOUBLE)).249 setFieldType('field_2_2', new MapObjectType(250 MapObjectType.MAP_SUBTYPE.HASH_MAP, ObjectType.PRIMITIVE_TYPE.CHAR, ObjectType.PRIMITIVE_TYPE.CHAR))).251 setFieldType('field_1_3', new MapObjectType(252 MapObjectType.MAP_SUBTYPE.HASH_MAP, ObjectType.PRIMITIVE_TYPE.BOOLEAN, ObjectType.PRIMITIVE_TYPE.BOOLEAN)).253 setFieldType('field_1_4', new MapObjectType(254 MapObjectType.MAP_SUBTYPE.HASH_MAP, ObjectType.PRIMITIVE_TYPE.STRING, ObjectType.PRIMITIVE_TYPE.STRING)).255 setFieldType('field_1_5', new ComplexObjectType(new Class3(), 'Class3WithMaps').256 setFieldType('field_3_1', new MapObjectType(257 MapObjectType.MAP_SUBTYPE.HASH_MAP, ObjectType.PRIMITIVE_TYPE.STRING, ObjectType.PRIMITIVE_TYPE.DATE)).258 setFieldType('field_3_2', new MapObjectType(259 MapObjectType.MAP_SUBTYPE.HASH_MAP, ObjectType.PRIMITIVE_TYPE.STRING, ObjectType.PRIMITIVE_TYPE.UUID))).260 setFieldType('field_1_6', new MapObjectType(261 MapObjectType.MAP_SUBTYPE.HASH_MAP, ObjectType.PRIMITIVE_TYPE.STRING, ObjectType.PRIMITIVE_TYPE.DECIMAL)).262 setFieldType('field_1_7', new MapObjectType(263 MapObjectType.MAP_SUBTYPE.HASH_MAP, ObjectType.PRIMITIVE_TYPE.STRING, ObjectType.PRIMITIVE_TYPE.TIMESTAMP)).264 setFieldType('field_1_8', new MapObjectType(265 MapObjectType.MAP_SUBTYPE.HASH_MAP, ObjectType.PRIMITIVE_TYPE.STRING, ObjectType.PRIMITIVE_TYPE.TIME));266 await putGetComplexObjectsWithDifferentTypes(267 value1, value2, valueType1, valueType2, Class1, SubClass1, true);268 }).269 then(done).270 catch(error => done.fail(error));271 });272 it('put get binary objects from objects', (done) => {273 Promise.resolve().274 then(async () => {275 const valueType = new ComplexObjectType(new Class1(), 'Class1WithStringObjStringArray').276 setFieldType('field_1_1', ObjectType.PRIMITIVE_TYPE.STRING).277 setFieldType('field_1_2', new ComplexObjectType(new Class2(), 'Class2WithShortBoolean').278 setFieldType('field_2_1', ObjectType.PRIMITIVE_TYPE.SHORT).279 setFieldType('field_2_2', ObjectType.PRIMITIVE_TYPE.BOOLEAN)).280 setFieldType('field_1_3', ObjectType.PRIMITIVE_TYPE.STRING_ARRAY);281 await putGetBinaryObjects(valueType);282 const defaultValueType = new ComplexObjectType(new Class1(), 'Class1Default').283 setFieldType('field_1_2', new ComplexObjectType(new Class2(), 'Class2Default'));284 await putGetBinaryObjects(defaultValueType);285 }).286 then(done).287 catch(error => done.fail(error));288 });289 it('put get complex objects with one byte offset', (done) => {290 Promise.resolve().291 then(async () => {292 const key = new Date();293 const valueType = new ComplexObjectType(new Class2(), 'Class2WithStrings');294 const value = new Class2();295 value.field_2_1 = 'x';296 value.field_2_2 = 'y';297 await putGetComplexObjects(key, value, null, valueType, value);298 const oneByteMaxLen = getMaxFieldLength(true);299 value.field_2_1 = 'x'.repeat(oneByteMaxLen);300 value.field_2_2 = 'y';301 await putGetComplexObjects(key, value, null, valueType, value);302 }).303 then(done).304 catch(error => done.fail(error));305 });306 it('put get complex objects with two bytes offset', (done) => {307 Promise.resolve().308 then(async () => {309 const key = new Date();310 const valueType = new ComplexObjectType(new Class2(), 'Class2WithStrings');311 const value = new Class2();312 const oneByteMaxLen = getMaxFieldLength(true);313 value.field_2_1 = 'x'.repeat(oneByteMaxLen + 1);314 value.field_2_2 = 'y';315 await putGetComplexObjects(key, value, null, valueType, value);316 const twoBytesMaxLen = getMaxFieldLength(false);317 value.field_2_1 = 'x'.repeat(twoBytesMaxLen);318 value.field_2_2 = 'y';319 await putGetComplexObjects(key, value, null, valueType, value);320 }).321 then(done).322 catch(error => done.fail(error));323 });324 it('put get complex objects with four bytes offset', (done) => {325 Promise.resolve().326 then(async () => {327 const key = new Date();328 const valueType = new ComplexObjectType(new Class2(), 'Class2WithStrings');329 const value = new Class2();330 const twoBytesMaxLen = getMaxFieldLength(false);331 value.field_2_1 = 'x'.repeat(twoBytesMaxLen + 1);332 value.field_2_2 = 'y';333 await putGetComplexObjects(key, value, null, valueType, value);334 value.field_2_1 = 'x'.repeat(twoBytesMaxLen * 2);335 value.field_2_2 = 'y';336 await putGetComplexObjects(key, value, null, valueType, value);337 }).338 then(done).339 catch(error => done.fail(error));340 });341 it('put get complex objects without schema', (done) => {342 Promise.resolve().343 then(async () => {344 const key = new Date();345 const valueType = new ComplexObjectType({});346 const value = {};347 await putGetComplexObjects(key, value, null, valueType, value);348 }).349 then(done).350 catch(error => done.fail(error));351 });352 function getMaxFieldLength(oneByte) {353 const maxOffset = oneByte ? ONE_BYTE_MAX_OFFSET : TWO_BYTES_MAX_OFFSET;354 // max offset - field type code - field type (string) length - complex object header length355 return maxOffset - 1 - 4 - COMPLEX_OBJECT_HEADER_LENGTH;356 }357 async function testSuiteCleanup(done) {358 await TestingHelper.destroyCache(CACHE_NAME, done);359 }360 async function putGetComplexObjects(key, value, keyType, valueType, valuePattern) {361 const cache = igniteClient.getCache(CACHE_NAME).setKeyType(keyType).setValueType(valueType);362 try {363 await cache.put(key, value);364 const result = await cache.get(key);365 expect(await TestingHelper.compare(valuePattern, result)).toBe(true,366 `values are not equal: put value=${TestingHelper.printValue(valuePattern)}, get value=${TestingHelper.printValue(result)}`);367 }368 finally {369 await cache.removeAll();370 }371 }372 async function binaryObjectEquals(binaryObj, valuePattern, valueType) {373 expect(await TestingHelper.compare(valuePattern, binaryObj)).toBe(true,374 `binary values are not equal: put value=${TestingHelper.printValue(valuePattern)}, get value=${TestingHelper.printValue(binaryObj)}`);375 let value1, value2;376 for (let key of Object.keys(valuePattern)) {377 value1 = valuePattern[key];378 value2 = await binaryObj.getField(key, valueType ? valueType._getFieldType(key) : null);379 expect(await TestingHelper.compare(value1, value2)).toBe(true,380 `values for key ${key} are not equal: put value=${TestingHelper.printValue(value1)381 }, get value=${TestingHelper.printValue(value2)}`);382 }383 if (valueType) {384 const toObject = await binaryObj.toObject(valueType);385 expect(await TestingHelper.compare(valuePattern, toObject)).toBe(true,386 `values are not equal: put value=${TestingHelper.printValue(valuePattern)}, get value=${TestingHelper.printValue(toObject)}`);387 }388 }389 async function putGetComplexObjectsWithDifferentTypes(390 key, value, keyType, valueType, keyClass, valueClass, isNullable = false) {391 await putGetComplexObjects(key, value, keyType, valueType, value);392 if (isNullable) {393 await putGetComplexObjects(new keyClass(), new valueClass(), keyType, valueType, new valueClass());394 }395 let binaryKey = await BinaryObject.fromObject(key, keyType);396 let binaryValue = await BinaryObject.fromObject(value, valueType);397 await putGetComplexObjects(binaryKey, binaryValue, null, null, value);398 if (isNullable) {399 binaryKey = await BinaryObject.fromObject(new keyClass(), keyType);400 binaryValue = await BinaryObject.fromObject(new valueClass(), valueType);401 await putGetComplexObjects(binaryKey, binaryValue, null, null, new valueClass());402 }403 }404 async function putGetBinaryObjects(valueType) {405 const value1 = new Class1();406 value1.field_1_1 = 'abc';407 value1.field_1_2.field_2_1 = 1234;408 value1.field_1_2.field_2_2 = true;409 value1.field_1_3 = ['a', 'bb', 'ccc'];410 const value2 = new Class1();411 value2.field_1_1 = 'def';412 value2.field_1_2.field_2_1 = 5432;413 value2.field_1_2.field_2_2 = false;414 value2.field_1_3 = ['a', 'bb', 'ccc', 'dddd'];415 const value3 = new Class1();416 value3.field_1_1 = 'defdef';417 value3.field_1_2.field_2_1 = 543;418 value3.field_1_2.field_2_2 = false;419 value3.field_1_3 = ['a', 'bb', 'ccc', 'dddd', 'eeeee'];420 const field_1_2_Type = valueType ? valueType._getFieldType('field_1_2') : null;421 const binaryValue1 = await BinaryObject.fromObject(value1, valueType);422 const binaryValue2 = await BinaryObject.fromObject(value2, valueType);423 const binaryValue3 = await BinaryObject.fromObject(value3, valueType);424 const cache = igniteClient.getCache(CACHE_NAME);425 try {426 await cache.put(binaryValue1, binaryValue2);427 let result = await cache.get(binaryValue1);428 await binaryObjectEquals(result, value2, valueType);429 binaryValue1.setField('field_1_1', 'abcde');430 result = await cache.get(binaryValue1);431 expect(result === null).toBe(true);432 binaryValue2.setField('field_1_1', value3.field_1_1);433 binaryValue2.setField('field_1_2', value3.field_1_2, field_1_2_Type);434 binaryValue2.setField('field_1_3', value3.field_1_3);435 await cache.put(binaryValue1, binaryValue2);436 result = await cache.get(binaryValue1);437 await binaryObjectEquals(result, value3, valueType);438 binaryValue1.setField('field_1_1', 'abc');439 binaryValue1.setField('field_1_3', await binaryValue1.getField('field_1_3'));440 result = await cache.get(binaryValue1);441 await binaryObjectEquals(result, value2, valueType);442 result = await cache.get(binaryValue1);443 await binaryObjectEquals(result, value2, valueType);444 binaryValue3.setField('field_1_1', await result.getField('field_1_1'));445 binaryValue3.setField('field_1_2', await result.getField('field_1_2', field_1_2_Type), field_1_2_Type);446 binaryValue3.setField('field_1_3', await result.getField('field_1_3'));447 await cache.put(binaryValue1, binaryValue3);448 result = await cache.get(binaryValue1);449 await binaryObjectEquals(result, value2, valueType);450 }451 finally {452 await cache.removeAll();453 }454 }455 function getPrimitiveValue(typeCode) {456 return TestingHelper.primitiveValues[typeCode].values[0];457 }458 function getArrayValues(typeCode) {459 return TestingHelper.primitiveValues[TestingHelper.arrayValues[typeCode].elemType].values;460 }461 function getMapValue(typeCode) {462 const map = new Map();463 const values = TestingHelper.primitiveValues[typeCode].values;464 const length = values.length;465 values.forEach((value, index) => {466 if (!TestingHelper.primitiveValues[typeCode].isMapKey) {467 value = Util.format("%s", value);468 }469 map.set(value, values[length - index - 1]);470 });471 return map;472 }...
PartitionAwarenessMultipleConnections.spec.js
Source:PartitionAwarenessMultipleConnections.spec.js
1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17'use strict';18require('jasmine-expect');19const TestingHelper = require('../TestingHelper');20const PartitionAwarenessTestUtils = require('./PartitionAwarenessTestUtils');21const { ObjectType } = require('apache-ignite-client');22const CACHE_NAME = '__test_cache';23const CUSTOM_AFFINITY_CACHE = 'custom-affinity';24const PARTITIONED_0_CACHE = 'partitioned0';25const PARTITIONED_1_CACHE = 'partitioned1';26const PARTITIONED_3_CACHE = 'partitioned3';27const REPLICATED_CACHE = 'replicated';28const SERVER_NUM = 3;29describe('partition awareness multiple connections test suite >', () => {30 let igniteClient = null;31 beforeAll((done) => {32 Promise.resolve().33 then(async () => {34 await TestingHelper.init(true, SERVER_NUM, true);35 igniteClient = TestingHelper.igniteClient;36 await testSuiteCleanup(done);37 }).38 then(done).39 catch(error => done.fail(error));40 }, TestingHelper.TIMEOUT);41 afterAll((done) => {42 Promise.resolve().43 then(async () => {44 await testSuiteCleanup(done);45 await TestingHelper.cleanUp();46 }).47 then(done).48 catch(_error => done());49 }, TestingHelper.TIMEOUT);50 it('all cache operations with partition awareness and multiple connections', (done) => {51 Promise.resolve().52 then(async () => {53 const cache = await getOrCreateCache(ObjectType.PRIMITIVE_TYPE.INTEGER, ObjectType.PRIMITIVE_TYPE.INTEGER);54 await PartitionAwarenessTestUtils.testAllCacheOperations(cache);55 }).56 then(done).57 catch(error => done.fail(error));58 });59 it('all cache operations with partition awareness and bad affinity', (done) => {60 Promise.resolve().61 then(async () => {62 const cache = await getOrCreateCache(ObjectType.PRIMITIVE_TYPE.INTEGER, ObjectType.PRIMITIVE_TYPE.INTEGER, CUSTOM_AFFINITY_CACHE);63 await PartitionAwarenessTestUtils.testRandomNode(cache);64 }).65 then(done).66 catch(error => done.fail(error));67 });68 69 it('put with partition awareness and unknown cache', (done) => {70 Promise.resolve().71 then(async () => {72 const cache = await getCache(ObjectType.PRIMITIVE_TYPE.INTEGER, ObjectType.PRIMITIVE_TYPE.INTEGER, '__unknown_cache_359f72tg');73 let key = 42;74 try {75 await cache.put(key, key);76 }77 catch (error) {78 expect(error.message).toContain('Cache does not exist');79 return;80 }81 fail('Exception was expected');82 }).83 then(done).84 catch(error => done.fail(error));85 });86 it('get or create null cache with partition awareness', (done) => {87 Promise.resolve().88 then(async () => {89 try {90 await getOrCreateCache(ObjectType.PRIMITIVE_TYPE.INTEGER, ObjectType.PRIMITIVE_TYPE.INTEGER, null);91 }92 catch (error) {93 expect(error.toString()).toContain('"name" argument should not be empty');94 return;95 }96 fail('Exception was expected');97 }).98 then(done).99 catch(error => done.fail(error));100 });101 it('get or create null cache with partition awareness', (done) => {102 Promise.resolve().103 then(async () => {104 try {105 await getOrCreateCache(ObjectType.PRIMITIVE_TYPE.INTEGER, ObjectType.PRIMITIVE_TYPE.INTEGER, null);106 }107 catch (error) {108 expect(error.toString()).toContain('"name" argument should not be empty');109 return;110 }111 fail('Exception was expected');112 }).113 then(done).114 catch(error => done.fail(error));115 });116 it('all cache operations with partition awareness and partitioned cache with 0 backups', (done) => {117 Promise.resolve().118 then(async () => {119 const cache = await getCache(ObjectType.PRIMITIVE_TYPE.INTEGER, ObjectType.PRIMITIVE_TYPE.INTEGER, PARTITIONED_0_CACHE);120 121 // Update partition mapping122 await TestingHelper.ensureStableTopology(igniteClient, cache, 0, true);123 await PartitionAwarenessTestUtils.testAllCacheOperationsOnTheSameKey(cache, 42);124 }).125 then(done).126 catch(error => done.fail(error));127 });128 it('all cache operations with partition awareness and partitioned cache with 1 backups', (done) => {129 Promise.resolve().130 then(async () => {131 const cache = await getCache(ObjectType.PRIMITIVE_TYPE.INTEGER, ObjectType.PRIMITIVE_TYPE.INTEGER, PARTITIONED_1_CACHE);132 133 // Update partition mapping134 await TestingHelper.ensureStableTopology(igniteClient, cache, 0, true);135 await PartitionAwarenessTestUtils.testAllCacheOperationsOnTheSameKey(cache, 100500);136 }).137 then(done).138 catch(error => done.fail(error));139 });140 it('all cache operations with partition awareness and partitioned cache with 3 backups', (done) => {141 Promise.resolve().142 then(async () => {143 const cache = await getCache(ObjectType.PRIMITIVE_TYPE.INTEGER, ObjectType.PRIMITIVE_TYPE.INTEGER, PARTITIONED_3_CACHE);144 145 // Update partition mapping146 await TestingHelper.ensureStableTopology(igniteClient, cache, 0, true);147 await PartitionAwarenessTestUtils.testAllCacheOperationsOnTheSameKey(cache, 1337);148 }).149 then(done).150 catch(error => done.fail(error));151 });152 it('all cache operations with partition awareness and replicated cache', (done) => {153 Promise.resolve().154 then(async () => {155 const cache = await getCache(ObjectType.PRIMITIVE_TYPE.INTEGER, ObjectType.PRIMITIVE_TYPE.INTEGER, REPLICATED_CACHE);156 await PartitionAwarenessTestUtils.testAllCacheOperations(cache);157 }).158 then(done).159 catch(error => done.fail(error));160 });161 async function getOrCreateCache(keyType, valueType, cacheName = CACHE_NAME, cacheCfg = null) {162 return await PartitionAwarenessTestUtils.getOrCreateCache(igniteClient, keyType, valueType, cacheName, cacheCfg);163 }164 async function getCache(keyType, valueType, cacheName = CACHE_NAME, cacheCfg = null) {165 return (await igniteClient.getCache(cacheName, cacheCfg)).166 setKeyType(keyType).167 setValueType(valueType);168 }169 170 async function clearCache(name) {171 await (await igniteClient.getCache(name)).clear();172 }173 async function testSuiteCleanup(done) {174 await clearCache(CUSTOM_AFFINITY_CACHE);175 await clearCache(PARTITIONED_0_CACHE);176 await clearCache(PARTITIONED_1_CACHE);177 await clearCache(PARTITIONED_3_CACHE);178 await clearCache(REPLICATED_CACHE);179 await TestingHelper.destroyCache(CACHE_NAME, done);180 }...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.primitive_type('test', function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7var wpt = require('webpagetest');8var wpt = new WebPageTest('www.webpagetest.org');9wpt.test_status('test', function(err, data) {10 if (err) return console.error(err);11 console.log(data);12});13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org');15wpt.test_results('test', function(err, data) {16 if (err) return console.error(err);17 console.log(data);18});19var wpt = require('webpagetest');20var wpt = new WebPageTest('www.webpagetest.org');21wpt.test_results('test', function(err, data) {22 if (err) return console.error(err);23 console.log(data);24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');27wpt.locations(function(err, data) {28 if (err) return console.error(err);29 console.log(data);30});31var wpt = require('webpagetest');32var wpt = new WebPageTest('www.webpagetest.org');33wpt.location_info('test', function(err, data) {34 if (err) return console.error(err);35 console.log(data);36});37var wpt = require('webpagetest');
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.primitive_type('test', function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7var wpt = require('webpagetest');8var wpt = new WebPageTest('www.webpagetest.org');9 if (err) return console.error(err);10 console.log(data);11});12var wpt = require('webpagetest');13var wpt = new WebPageTest('www.webpagetest.org');14}, function(err, data) {15 if (err) return console.error(err);16 console.log(data);17});18var wpt = require('webpagetest');19var wpt = new WebPageTest('www.webpagetest.org');20}, function(err, data) {21 if (err) return console.error(err);22 console.log(data);23});24var wpt = require('webpagetest');25var wpt = new WebPageTest('www.webpagetest.org');26}, function(err, data) {27 if (err) return console.error(err);28 console.log(data);29});30var wpt = require('webpagetest');31var wpt = new WebPageTest('www.webpagetest.org
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.primitive_type(url, function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7### WebPageTest([host], [port], [key])8### .runTest(url, [options], callback)9* `options` - (optional) An object containing any of the following options:
Using AI Code Generation
1var wpt = require('wpt');2var wptObj = new wpt();3wptObj.primitive_type(function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10### `wptObj.request_data(callback)`11var wpt = require('wpt');12var wptObj = new wpt();13wptObj.request_data(function(err, data) {14 if (err) {15 console.log(err);16 } else {17 console.log(data);18 }19});20### `wptObj.request_headers(callback)`21var wpt = require('wpt');22var wptObj = new wpt();23wptObj.request_headers(function(err, data) {24 if (err) {25 console.log(err);26 } else {27 console.log(data);28 }29});30### `wptObj.result(callback)`31var wpt = require('wpt');32var wptObj = new wpt();33wptObj.result(function(err, data) {34 if (err) {35 console.log(err);36 } else {37 console.log(data);38 }39});40### `wptObj.run_test(options, callback)`
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5 if (err) return console.error(err);6 console.log('Test submitted to WebPageTest for %s', data.data.testUrl);7 console.log('View your test at %s', data.data.userUrl);8});
Using AI Code Generation
1var wpt = require('wpt');2var options = {3 videoParams: {4 }5};6wpt.primitive_type(options, function(err, data) {7 if (err) return console.error(err);8 console.log(data);9});10MIT © [Saurabh Kumar](
Using AI Code Generation
1var wptool = require('wptool');2var path = require('path');3var test = path.resolve(__dirname, 'test.wpt');4var tool = new wptool(test);5tool.primitive_type('test', function(err, data) {6 if (err) {7 console.log(err);8 } else {9 console.log(data);10 }11});
Using AI Code Generation
1var wpt = require('webpagetest');2var wptObject = new wpt('A.1c7a4a4c4b7d4c9a4d7b6f1b6a7d6a8');3wptObject.primitive_type(function(err, data) {4 console.log(data);5});6var wpt = require('webpagetest');7var wptObject = new wpt('A.1c7a4a4c4b7d4c9a4d7b6f1b6a7d6a8');8var options = {9};10wptObject.runTest(url, options, function(err, data) {11 console.log(data);12});13var wpt = require('webpagetest');14var wptObject = new wpt('A.1c7a4a4c4b7d4c9a4d7b6f1b6a7d6a8');15var options = {16};17wptObject.runTestAndWait(url, options, function(err, data) {18 console.log(data);19});20var wpt = require('webpagetest');21var wptObject = new wpt('A.1c7a4a4c4b7d4c9a4d7b6f1b6a7d6a8');
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!