This is an automated email from the ASF dual-hosted git repository. isapego pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ignite-nodejs-thin-client.git
commit c8a89a757121173c09d7d79d23c4cf273b97b0e3 Author: ekaterina-nbl <[email protected]> AuthorDate: Wed May 15 19:47:18 2019 +0300 IGNITE-11597 Fix for Node.js thin client UUID marshalling Co-Authored-By: Ruslan Ragimov <[email protected]> Co-Authored-By: ekaterina-nbl <[email protected]> Co-Authored-By: sergey-nbl <[email protected]> Co-Authored-By: dmelnichuk <[email protected]> Co-Authored-By: snork-nbl <[email protected]> Co-Authored-By: Pavel Petroshenko <[email protected]> Co-Authored-By: alexey-nbl <[email protected]> This closes #6527 --- examples/CachePutGetExample.js | 6 +- lib/BinaryObject.js | 2 +- lib/CacheClient.js | 2 +- lib/CacheConfiguration.js | 48 +++++++-------- lib/IgniteClient.js | 2 +- lib/ObjectType.js | 14 ++--- lib/Query.js | 2 +- lib/internal/BinaryCommunicator.js | 6 +- lib/internal/BinaryType.js | 2 +- lib/internal/ClientFailoverSocket.js | 2 +- lib/internal/MessageBuffer.js | 8 +-- package.json | 18 +++++- spec/TestingHelper.js | 4 +- spec/cache/CachePutGetDiffTypes.spec.js | 42 ++++++------- spec/cache/UUID.spec.js | 105 ++++++++++++++++++++++++++++++++ spec/config.js | 2 +- spec/query/SqlQuery.spec.js | 2 +- 17 files changed, 193 insertions(+), 74 deletions(-) diff --git a/examples/CachePutGetExample.js b/examples/CachePutGetExample.js index 94060bd..b37f573 100644 --- a/examples/CachePutGetExample.js +++ b/examples/CachePutGetExample.js @@ -62,7 +62,7 @@ class CachePutGetExample { constructor() { this._personCache = null; this._personObjectType = null; - this._binaryObjectCache = null; + this._binaryObjectCache = null; } async start() { @@ -127,7 +127,7 @@ class CachePutGetExample { new CacheEntry(await personBinaryObject1.getField('id'), personBinaryObject1), new CacheEntry(await personBinaryObject2.getField('id'), personBinaryObject2) ]); - + console.log('Binary Objects put successfully using putAll()'); } @@ -138,7 +138,7 @@ class CachePutGetExample { this.printPersonObject(person.getValue()); } } - + async getBinaryObjects() { const personBinaryObject = await this._binaryObjectCache.get(3); console.log('Binary Object get:'); diff --git a/lib/BinaryObject.js b/lib/BinaryObject.js index 9be60da..478dbaf 100644 --- a/lib/BinaryObject.js +++ b/lib/BinaryObject.js @@ -491,7 +491,7 @@ class BinaryObjectField { else if (offset < 0x10000) { return BinaryUtils.TYPE_CODE.SHORT; } - return BinaryUtils.TYPE_CODE.INTEGER; + return BinaryUtils.TYPE_CODE.INTEGER; } static _fromBuffer(communicator, buffer, offset, length, id) { diff --git a/lib/CacheClient.js b/lib/CacheClient.js index f59910b..fad8e71 100644 --- a/lib/CacheClient.js +++ b/lib/CacheClient.js @@ -729,7 +729,7 @@ class CacheEntry { * @param {*} key - key corresponding to this entry. * @param {*} value - value associated with the key. * - * @return {CacheEntry} - new CacheEntry instance + * @return {CacheEntry} - new CacheEntry instance */ constructor(key, value) { this._key = key; diff --git a/lib/CacheConfiguration.js b/lib/CacheConfiguration.js index ccf20b9..75f0155 100644 --- a/lib/CacheConfiguration.js +++ b/lib/CacheConfiguration.js @@ -29,7 +29,7 @@ const Errors = require('./Errors'); * * All configuration settings are optional and have defaults which are defined on a server side. * - * See Apache Ignite documentation for details of every configuration setting. + * See Apache Ignite documentation for details of every configuration setting. */ class CacheKeyConfiguration { @@ -112,7 +112,7 @@ class CacheKeyConfiguration { * * All configuration settings are optional and have defaults which are defined on a server side. * - * See Apache Ignite documentation for details of every configuration setting. + * See Apache Ignite documentation for details of every configuration setting. */ class QueryEntity { @@ -238,7 +238,7 @@ class QueryEntity { } /** - * + * * * @param {Array<QueryField>} fields * @@ -250,7 +250,7 @@ class QueryEntity { } /** - * + * * * @return {Array<QueryField>} */ @@ -259,7 +259,7 @@ class QueryEntity { } /** - * + * * * @param {Map<string, string>} aliases * @@ -271,7 +271,7 @@ class QueryEntity { } /** - * + * * * @return {Map<string, string>} */ @@ -280,7 +280,7 @@ class QueryEntity { } /** - * + * * * @param {Array<QueryIndex>} indexes * @@ -292,7 +292,7 @@ class QueryEntity { } /** - * + * * * @return {Array<QueryIndex>} */ @@ -394,7 +394,7 @@ class QueryEntity { * * All configuration settings are optional and have defaults which are defined on a server side. * - * See Apache Ignite documentation for details of every configuration setting. + * See Apache Ignite documentation for details of every configuration setting. */ class QueryField { @@ -629,7 +629,7 @@ class QueryField { } /** - * + * * @typedef QueryIndex.INDEX_TYPE * @enum * @readonly @@ -648,10 +648,10 @@ class QueryField { * * All configuration settings are optional and have defaults which are defined on a server side. * - * See Apache Ignite documentation for details of every configuration setting. + * See Apache Ignite documentation for details of every configuration setting. */ class QueryIndex { - + /** * Public constructor. * @@ -738,7 +738,7 @@ class QueryIndex { } /** - * + * * * @param {Map<string, boolean>} fields * @@ -750,7 +750,7 @@ class QueryIndex { } /** - * + * * * @return {Map<string, boolean>} */ @@ -862,7 +862,7 @@ const PROP_TYPES = Object.freeze({ }); /** - * + * * @typedef CacheConfiguration.CACHE_ATOMICITY_MODE * @enum * @readonly @@ -875,7 +875,7 @@ const CACHE_ATOMICITY_MODE = Object.freeze({ }); /** - * + * * @typedef CacheConfiguration.CACHE_MODE * @enum * @readonly @@ -890,7 +890,7 @@ const CACHE_MODE = Object.freeze({ }); /** - * + * * @typedef CacheConfiguration.PARTITION_LOSS_POLICY * @enum * @readonly @@ -909,7 +909,7 @@ const PARTITION_LOSS_POLICY = Object.freeze({ }); /** - * + * * @typedef CacheConfiguration.REABALANCE_MODE * @enum * @readonly @@ -924,7 +924,7 @@ const REABALANCE_MODE = Object.freeze({ }); /** - * + * * @typedef CacheConfiguration.WRITE_SYNCHRONIZATION_MODE * @enum * @readonly @@ -943,7 +943,7 @@ const WRITE_SYNCHRONIZATION_MODE = Object.freeze({ * * All configuration settings are optional and have defaults which are defined on a server side. * - * See Apache Ignite documentation for details of every configuration setting. + * See Apache Ignite documentation for details of every configuration setting. */ class CacheConfiguration { @@ -1559,7 +1559,7 @@ class CacheConfiguration { } /** - * + * * * @param {...CacheKeyConfiguration} keyConfigurations * @@ -1574,7 +1574,7 @@ class CacheConfiguration { } /** - * + * * * @return {Array<CacheKeyConfiguration>} */ @@ -1583,7 +1583,7 @@ class CacheConfiguration { } /** - * + * * * @param {...QueryEntity} queryEntities * @@ -1598,7 +1598,7 @@ class CacheConfiguration { } /** - * + * * * @return {Array<QueryEntity>} */ diff --git a/lib/IgniteClient.js b/lib/IgniteClient.js index 544c37f..1974352 100644 --- a/lib/IgniteClient.js +++ b/lib/IgniteClient.js @@ -53,7 +53,7 @@ const STATE = Object.freeze({ /** * Class representing Ignite client. - * + * */ class IgniteClient { diff --git a/lib/ObjectType.js b/lib/ObjectType.js index f1facfd..00c4d56 100644 --- a/lib/ObjectType.js +++ b/lib/ObjectType.js @@ -109,7 +109,7 @@ const COMPOSITE_TYPE = Object.freeze({ COMPLEX_OBJECT : 103 }); -/** +/** * Base class representing a type of Ignite object. * * The class has no public constructor. Only subclasses may be instantiated. @@ -351,8 +351,8 @@ class MapObjectType extends CompositeType { * If key and/or value type is not specified then during operations the Ignite client * will try to make automatic mapping between JavaScript types and Ignite object types - * according to the mapping table defined in the description of the {@link ObjectType} class. - * - * @param {MapObjectType.MAP_SUBTYPE} [mapSubType=MAP_SUBTYPE.HASH_MAP] - map subtype, one of the + * + * @param {MapObjectType.MAP_SUBTYPE} [mapSubType=MAP_SUBTYPE.HASH_MAP] - map subtype, one of the * {@link MapObjectType.MAP_SUBTYPE} constants. * @param {ObjectType.PRIMITIVE_TYPE | CompositeType} [keyType=null] - type of the keys in the map: * - either a type code of primitive (simple) type @@ -424,8 +424,8 @@ class CollectionObjectType extends CompositeType { * If the type of elements is not specified then during operations the Ignite client * will try to make automatic mapping between JavaScript types and Ignite object types - * according to the mapping table defined in the description of the {@link ObjectType} class. - * - * @param {CollectionObjectType.COLLECTION_SUBTYPE} collectionSubType - collection subtype, one of the + * + * @param {CollectionObjectType.COLLECTION_SUBTYPE} collectionSubType - collection subtype, one of the * {@link CollectionObjectType.COLLECTION_SUBTYPE} constants. * @param {ObjectType.PRIMITIVE_TYPE | CompositeType} [elementType=null] - type of elements in the collection: * - either a type code of primitive (simple) type @@ -529,7 +529,7 @@ class ComplexObjectType extends CompositeType { * * By default, the name of the complex type is the name of the JavaScript Object. * The name may be explicitely specified using optional typeName parameter in the constructor. - * + * * @param {object} jsObject - instance of JavaScript Object which will be mapped to/from this complex type. * @param {string} [typeName] - name of the complex type. * @@ -560,7 +560,7 @@ class ComplexObjectType extends CompositeType { * If the type is not specified then during operations the Ignite client * will try to make automatic mapping between JavaScript types and Ignite object types - * according to the mapping table defined in the description of the {@link ObjectType} class. - * + * * @param {string} fieldName - name of the field. * @param {ObjectType.PRIMITIVE_TYPE | CompositeType} fieldType - type of the field: * - either a type code of primitive (simple) type diff --git a/lib/Query.js b/lib/Query.js index 029ec3d..d3f6f87 100644 --- a/lib/Query.js +++ b/lib/Query.js @@ -469,7 +469,7 @@ class ScanQuery extends Query { /** * Sets a partition number over which this query should iterate. * - * If negative, the query will iterate over all partitions in the cache. + * If negative, the query will iterate over all partitions in the cache. * * @param {number} partitionNumber - partition number over which this query should iterate. * diff --git a/lib/internal/BinaryCommunicator.js b/lib/internal/BinaryCommunicator.js index 9418d36..20ddcff 100644 --- a/lib/internal/BinaryCommunicator.js +++ b/lib/internal/BinaryCommunicator.js @@ -51,7 +51,7 @@ class BinaryCommunicator { buffer.writeString(value); } } - + async send(opCode, payloadWriter, payloadReader = null) { await this._socket.send(opCode, payloadWriter, payloadReader); } @@ -218,7 +218,7 @@ class BinaryCommunicator { } _readUUID(buffer) { - return [...buffer.readBuffer(BinaryUtils.getSize(BinaryUtils.TYPE_CODE.UUID))]; + return [...buffer.readBuffer(BinaryUtils.getSize(BinaryUtils.TYPE_CODE.UUID)).swap64()]; } async _readEnum(buffer) { @@ -314,7 +314,7 @@ class BinaryCommunicator { } _writeUUID(buffer, value) { - buffer.writeBuffer(Buffer.from(value)); + buffer.writeBuffer(Buffer.from(value).swap64()); } async _writeEnum(buffer, enumValue) { diff --git a/lib/internal/BinaryType.js b/lib/internal/BinaryType.js index a111ed0..4a36426 100644 --- a/lib/internal/BinaryType.js +++ b/lib/internal/BinaryType.js @@ -393,7 +393,7 @@ class BinaryTypeBuilder { result._fromComplexObjectType(complexObjectType, jsObject); BinaryTypeStorage.setByComplexObjectType(complexObjectType, result._type, result._schema); } - return result; + return result; } getTypeId() { diff --git a/lib/internal/ClientFailoverSocket.js b/lib/internal/ClientFailoverSocket.js index 3ef9c76..770c5c6 100644 --- a/lib/internal/ClientFailoverSocket.js +++ b/lib/internal/ClientFailoverSocket.js @@ -60,7 +60,7 @@ class ClientFailoverSocket { } async _onSocketDisconnect(error = null) { - this._changeState(IgniteClient.STATE.CONNECTING, null, error); + this._changeState(IgniteClient.STATE.CONNECTING, null, error); this._socket = null; this._endpointIndex++; try { diff --git a/lib/internal/MessageBuffer.js b/lib/internal/MessageBuffer.js index b3be7e9..e282967 100644 --- a/lib/internal/MessageBuffer.js +++ b/lib/internal/MessageBuffer.js @@ -115,7 +115,7 @@ class MessageBuffer { this._buffer.writeInt8(value, this._position); } else { - this._buffer.writeUInt8(value, this._position); + this._buffer.writeUInt8(value, this._position); } break; case BinaryUtils.TYPE_CODE.SHORT: @@ -123,7 +123,7 @@ class MessageBuffer { this._buffer.writeInt16LE(value, this._position); } else { - this._buffer.writeUInt16LE(value, this._position); + this._buffer.writeUInt16LE(value, this._position); } break; case BinaryUtils.TYPE_CODE.INTEGER: @@ -131,7 +131,7 @@ class MessageBuffer { this._buffer.writeInt32LE(value, this._position); } else { - this._buffer.writeUInt32LE(value, this._position); + this._buffer.writeUInt32LE(value, this._position); } break; case BinaryUtils.TYPE_CODE.FLOAT: @@ -260,7 +260,7 @@ class MessageBuffer { if (end === undefined) { end = buffer.length; } - const size = end - start; + const size = end - start; this._ensureCapacity(size); buffer.copy(this._buffer, this._position, start, end); this._position += size; diff --git a/package.json b/package.json index 4ffb809..cca390e 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,22 @@ { "name": "apache-ignite-client", - "version": "1.0.0", - "description": "", + "version": "1.0.1", + "description": "NodeJS Client for Apache Ignite", "main": "index.js", + "files": [ + "/examples", + "/lib", + "index.js" + ], + "repository": { + "type": "git", + "url": "https://github.com/apache/ignite/tree/master/modules/platforms/nodejs" + }, + "keywords": [ + "apache", + "ignite", + "client" + ], "author": "", "license": "Apache-2.0", "engines": { diff --git a/spec/TestingHelper.js b/spec/TestingHelper.js index 78df0cb..25465bb 100644 --- a/spec/TestingHelper.js +++ b/spec/TestingHelper.js @@ -62,7 +62,7 @@ const decimalValueModificator = (data) => { return data.add(12345); }; const timestampValueModificator = (data) => { return new Timestamp(new Date(data.getTime() + 12345), data.getNanos() + 123); }; const primitiveValues = { - [ObjectType.PRIMITIVE_TYPE.BYTE] : { + [ObjectType.PRIMITIVE_TYPE.BYTE] : { values : [-128, 0, 127], isMapKey : true, modificator : numericValueModificator @@ -385,7 +385,7 @@ class TestingHelper { } return true; } - } + } } module.exports = TestingHelper; diff --git a/spec/cache/CachePutGetDiffTypes.spec.js b/spec/cache/CachePutGetDiffTypes.spec.js index a6e1bba..5fd370e 100644 --- a/spec/cache/CachePutGetDiffTypes.spec.js +++ b/spec/cache/CachePutGetDiffTypes.spec.js @@ -132,7 +132,7 @@ describe('cache put get test suite >', () => { map); await putGetMaps( new MapObjectType( - MapObjectType.MAP_SUBTYPE.LINKED_HASH_MAP, type1, type2), + MapObjectType.MAP_SUBTYPE.LINKED_HASH_MAP, type1, type2), map); if (typeInfo1.typeOptional) { await putGetMaps(new MapObjectType(MapObjectType.MAP_SUBTYPE.HASH_MAP, null, type2), @@ -177,7 +177,7 @@ describe('cache put get test suite >', () => { new MapObjectType(MapObjectType.MAP_SUBTYPE.HASH_MAP, type1, type2), map); await putGetMaps( - new MapObjectType(MapObjectType.MAP_SUBTYPE.LINKED_HASH_MAP, type1, type2), + new MapObjectType(MapObjectType.MAP_SUBTYPE.LINKED_HASH_MAP, type1, type2), map); if (typeInfo1.typeOptional) { await putGetMaps(new MapObjectType(MapObjectType.MAP_SUBTYPE.HASH_MAP, null, type2), @@ -284,14 +284,14 @@ describe('cache put get test suite >', () => { map = new Map([...map.entries()].map(([key, value]) => [typeInfo1.modificator(key), typeInfo2.modificator(value)])); array.push(map); } - await putGetObjectArrays(new ObjectArrayType(new MapObjectType(MapObjectType.MAP_SUBTYPE.HASH_MAP, type1, type2)), + await putGetObjectArrays(new ObjectArrayType(new MapObjectType(MapObjectType.MAP_SUBTYPE.HASH_MAP, type1, type2)), array); if (typeInfo1.typeOptional) { - await putGetObjectArrays(new ObjectArrayType(new MapObjectType(MapObjectType.MAP_SUBTYPE.LINKED_HASH_MAP, null, type2)), + await putGetObjectArrays(new ObjectArrayType(new MapObjectType(MapObjectType.MAP_SUBTYPE.LINKED_HASH_MAP, null, type2)), array); } if (typeInfo2.typeOptional) { - await putGetObjectArrays(new ObjectArrayType(new MapObjectType(MapObjectType.MAP_SUBTYPE.LINKED_HASH_MAP, type1)), + await putGetObjectArrays(new ObjectArrayType(new MapObjectType(MapObjectType.MAP_SUBTYPE.LINKED_HASH_MAP, type1)), array); } if (typeInfo1.typeOptional && typeInfo2.typeOptional) { @@ -318,7 +318,7 @@ describe('cache put get test suite >', () => { array.push(value); } await putGetObjectArrays( - new ObjectArrayType(type), + new ObjectArrayType(type), array); if (typeInfo.typeOptional) { await putGetObjectArrays(new ObjectArrayType(), array); @@ -338,14 +338,14 @@ describe('cache put get test suite >', () => { const primitiveType = typeInfo.elemType; const primitiveTypeInfo = TestingHelper.primitiveValues[primitiveType]; let values = primitiveTypeInfo.values; - + const array = new Array(); for (let i = 0; i < 10; i++) { values = values.map((value) => primitiveTypeInfo.modificator(value)); array.push(values); } await putGetObjectArrays( - new ObjectArrayType(type), + new ObjectArrayType(type), array); if (typeInfo.typeOptional) { await putGetObjectArrays(new ObjectArrayType(), array); @@ -372,13 +372,13 @@ describe('cache put get test suite >', () => { array.push(set); } await putGetObjectArrays( - new ObjectArrayType(new CollectionObjectType(CollectionObjectType.COLLECTION_SUBTYPE.USER_SET, type)), + new ObjectArrayType(new CollectionObjectType(CollectionObjectType.COLLECTION_SUBTYPE.USER_SET, type)), array); await putGetObjectArrays( - new ObjectArrayType(new CollectionObjectType(CollectionObjectType.COLLECTION_SUBTYPE.HASH_SET, type)), + new ObjectArrayType(new CollectionObjectType(CollectionObjectType.COLLECTION_SUBTYPE.HASH_SET, type)), array); await putGetObjectArrays( - new ObjectArrayType(new CollectionObjectType(CollectionObjectType.COLLECTION_SUBTYPE.LINKED_HASH_SET, type)), + new ObjectArrayType(new CollectionObjectType(CollectionObjectType.COLLECTION_SUBTYPE.LINKED_HASH_SET, type)), array); if (typeInfo.typeOptional) { await putGetObjectArrays(new ObjectArrayType(), array); @@ -406,17 +406,17 @@ describe('cache put get test suite >', () => { array.push(list); } await putGetObjectArrays( - new ObjectArrayType(new CollectionObjectType(CollectionObjectType.COLLECTION_SUBTYPE.USER_COL, type)), + new ObjectArrayType(new CollectionObjectType(CollectionObjectType.COLLECTION_SUBTYPE.USER_COL, type)), array); await putGetObjectArrays( - new ObjectArrayType(new CollectionObjectType(CollectionObjectType.COLLECTION_SUBTYPE.ARRAY_LIST, type)), + new ObjectArrayType(new CollectionObjectType(CollectionObjectType.COLLECTION_SUBTYPE.ARRAY_LIST, type)), array); await putGetObjectArrays( - new ObjectArrayType(new CollectionObjectType(CollectionObjectType.COLLECTION_SUBTYPE.LINKED_LIST, type)), + new ObjectArrayType(new CollectionObjectType(CollectionObjectType.COLLECTION_SUBTYPE.LINKED_LIST, type)), array); if (typeInfo.typeOptional) { await putGetObjectArrays( - new ObjectArrayType(new CollectionObjectType(CollectionObjectType.COLLECTION_SUBTYPE.ARRAY_LIST)), + new ObjectArrayType(new CollectionObjectType(CollectionObjectType.COLLECTION_SUBTYPE.ARRAY_LIST)), array); } } @@ -613,7 +613,7 @@ describe('cache put get test suite >', () => { await cache.clearKey(key); expect(result instanceof Array).toBe(true, `result is not Array: arrayType=${valueType}, result=${result}`); - expect(await TestingHelper.compare(value, result)).toBe(true, + expect(await TestingHelper.compare(value, result)).toBe(true, `Arrays are not equal: arrayType=${valueType}, put array=${TestingHelper.printValue(value) }, get array=${TestingHelper.printValue(result)}`); } @@ -630,7 +630,7 @@ describe('cache put get test suite >', () => { let result = await cache.get(key); expect(result instanceof Map).toBe(true, `result is not Map: mapType=${mapType}, result=${result}`); - expect(await TestingHelper.compare(value, result)).toBe(true, + expect(await TestingHelper.compare(value, result)).toBe(true, `Maps are not equal: valueType=${mapType._valueType}, put value=${TestingHelper.printValue(value) }, get value=${TestingHelper.printValue(result)}`); } @@ -647,11 +647,11 @@ describe('cache put get test suite >', () => { if (!setType || setType._subType !== CollectionObjectType.COLLECTION_SUBTYPE.LINKED_HASH_SET) { const valueArr = [...value].sort(); const resultArr = [...result].sort(); - expect(await TestingHelper.compare(valueArr, resultArr)).toBe(true, `Sets are not equal: valueType=${setType ? setType._elementType : + expect(await TestingHelper.compare(valueArr, resultArr)).toBe(true, `Sets are not equal: valueType=${setType ? setType._elementType : null}, put value=${TestingHelper.printValue(valueArr)}, get value=${TestingHelper.printValue(resultArr)}`); } else { - expect(await TestingHelper.compare(value, result)).toBe(true, `Sets are not equal: valueType=${setType ? setType._elementType : + expect(await TestingHelper.compare(value, result)).toBe(true, `Sets are not equal: valueType=${setType ? setType._elementType : null}, put value=${TestingHelper.printValue(value)}, get value=${TestingHelper.printValue(result)}`); } } @@ -664,7 +664,7 @@ describe('cache put get test suite >', () => { let result = await cache.get(key); expect(result instanceof Array).toBe(true, `result is not Array: listType=${listType}, result=${result}`); - expect(await TestingHelper.compare(value, result)).toBe(true, `Lists are not equal: valueType=${listType ? listType._elementType : + expect(await TestingHelper.compare(value, result)).toBe(true, `Lists are not equal: valueType=${listType ? listType._elementType : null}, put value=${TestingHelper.printValue(value)}, get value=${TestingHelper.printValue(result)}`); } @@ -676,7 +676,7 @@ describe('cache put get test suite >', () => { let result = await cache.get(key); expect(result instanceof Array).toBe(true, `result is not Array: arrayType=${arrayType}, result=${result}`); - expect(await TestingHelper.compare(value, result)).toBe(true, `Arrays are not equal: valueType=${arrayType ? arrayType._elementType : + expect(await TestingHelper.compare(value, result)).toBe(true, `Arrays are not equal: valueType=${arrayType ? arrayType._elementType : null}, put value=${TestingHelper.printValue(value)}, get value=${TestingHelper.printValue(result)}`); } diff --git a/spec/cache/UUID.spec.js b/spec/cache/UUID.spec.js new file mode 100644 index 0000000..1715113 --- /dev/null +++ b/spec/cache/UUID.spec.js @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +require('jasmine-expect'); + +const TestingHelper = require('../TestingHelper'); +const IgniteClient = require('apache-ignite-client'); +const CacheConfiguration = IgniteClient.CacheConfiguration; +const SqlFieldsQuery = IgniteClient.SqlFieldsQuery; +const ObjectType = IgniteClient.ObjectType; + +const CACHE_NAME = '__test_cache'; +const TABLE_NAME = '__test_UUID_table'; +const UUID_STRINGS = [ + 'd57babad-7bc1-4c82-9f9c-e72841b92a85', + '5946c0c0-2b76-479d-8694-a2e64a3968da', + 'a521723d-ad5d-46a6-94ad-300f850ef704' +]; + +describe('uuid test suite >', () => { + let igniteClient = null; + + beforeAll((done) => { + Promise.resolve(). + then(async () => { + await TestingHelper.init(); + igniteClient = TestingHelper.igniteClient; + await testSuiteCleanup(done); + await igniteClient.getOrCreateCache(CACHE_NAME, new CacheConfiguration().setSqlSchema('PUBLIC')); + }). + then(done). + catch(error => done.fail(error)); + }, TestingHelper.TIMEOUT); + + afterAll((done) => { + Promise.resolve(). + then(async () => { + await testSuiteCleanup(done); + await TestingHelper.cleanUp(); + }). + then(done). + catch(error => done.fail(error)); + }, TestingHelper.TIMEOUT); + + it('insert byte array and select string to check uuid marshalling', (done) => { + Promise.resolve(). + then(async () => { + const cache = igniteClient.getCache(CACHE_NAME); + const createTable = `CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (id INTEGER PRIMARY KEY, uuid_field UUID)`; + (await cache.query(new SqlFieldsQuery(createTable))).getAll(); + + const insertQuery = new SqlFieldsQuery(`INSERT INTO ${TABLE_NAME} (id, uuid_field) VALUES (?, ?)`); + const dataTypes = [ObjectType.PRIMITIVE_TYPE.INTEGER, ObjectType.PRIMITIVE_TYPE.UUID]; + + let id = 1; + for (let uuidStr of UUID_STRINGS) { + const args = [id++, uuidToBytes(uuidStr)]; + (await cache.query(insertQuery.setArgs(...args).setArgTypes(...dataTypes))).getAll(); + } + + const selectQuery = `SELECT * FROM ${TABLE_NAME} WHERE uuid_field = ?`; + + for (let uuidStr of UUID_STRINGS) { + const cursor = await cache.query(new SqlFieldsQuery(selectQuery).setArgs(uuidStr)); + const rows = await cursor.getAll(); + expect(rows.length).toBe(1); + expect(rows[0][1]).toEqual(uuidToBytes(uuidStr)); + } + }). + then(done). + catch(error => done.fail(error)); + }); + + function uuidToBytes(uuidStr) { + const buf = []; + uuidStr.toLowerCase().replace(/[0-9a-f]{2}/g, function(oct) { + buf.push(parseInt(oct, 16)); + }); + + return buf; + } + + async function testSuiteCleanup(done) { + const cache = await igniteClient.getOrCreateCache(CACHE_NAME, new CacheConfiguration().setSqlSchema('PUBLIC')); + const dropTable = `DROP TABLE IF EXISTS ${TABLE_NAME}`; + (await cache.query(new SqlFieldsQuery(dropTable))).getAll(); + await TestingHelper.destroyCache(CACHE_NAME, done); + } +}); diff --git a/spec/config.js b/spec/config.js index 4e89875..747170a 100644 --- a/spec/config.js +++ b/spec/config.js @@ -19,7 +19,7 @@ exports.endpoints = process.env.APACHE_IGNITE_CLIENT_ENDPOINTS ? process.env.APACHE_IGNITE_CLIENT_ENDPOINTS.split(',') : []; -exports.debug = process.env.APACHE_IGNITE_CLIENT_DEBUG === 'true' || +exports.debug = process.env.APACHE_IGNITE_CLIENT_DEBUG === 'true' || process.env.APACHE_IGNITE_CLIENT_DEBUG === '1'; diff --git a/spec/query/SqlQuery.spec.js b/spec/query/SqlQuery.spec.js index 2bbd0e5..c2e2bb1 100644 --- a/spec/query/SqlQuery.spec.js +++ b/spec/query/SqlQuery.spec.js @@ -45,7 +45,7 @@ describe('sql query test suite >', () => { igniteClient = TestingHelper.igniteClient; await testSuiteCleanup(done); await igniteClient.getOrCreateCache( - CACHE_NAME, + CACHE_NAME, new CacheConfiguration(). setQueryEntities( new QueryEntity().
