Skip to content

Commit

Permalink
Apply Compact Serialization Updates for Hz v5.2.0 I [API-1637] (#1409)
Browse files Browse the repository at this point in the history
* Make ReadResultSet iterable [API-1315]

* Make ReadResultSet iterable [API-1315]

* Changes made according to comments on PR.[API-1315]

* Apply Compact Serialization Updates for Hz v5.2.0 I [API-1637]

* Version change 5.2.0 => 5.2

* hazelcast-enterprise-tests.jar was removed from repo.

* SSL tests were skipped, because of tests.jar was removed.

* Changes have been made related to review comments. [API-1637]

* Changes have been made related to review comments. [API-1637]

* Some changes related to PR comments

* verifyDefaultSerializersNotOverriddenWithCompact method was modified

* Some fixes related to review comments.

* LONG_SYMBOL not used and removed.

* Change the name of variable.

* Some fixes related to PR comments

* Some fixes related to PR comments

* Fixes related to PR comments.
  • Loading branch information
harunalpak committed Nov 17, 2022
1 parent 2ac53b4 commit 871a812
Show file tree
Hide file tree
Showing 35 changed files with 932 additions and 308 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"plugin:mocha/recommended"
],
"rules": {
"mocha/no-skipped-tests": "off",
"mocha/no-hooks-for-single-case": "off",
"mocha/no-setup-in-describe": "off",
"camelcase": "off",
Expand Down
15 changes: 8 additions & 7 deletions scripts/download-rc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const HZ_VERSION = '5.1';
const HZ_TEST_VERSION = '5.1';
const HZ_VERSION = '5.2.0';
const HZ_TEST_VERSION = '5.2.0';
const HAZELCAST_TEST_VERSION = HZ_TEST_VERSION;
const HAZELCAST_VERSION = HZ_VERSION;
const HAZELCAST_ENTERPRISE_VERSION = HZ_VERSION;
Expand All @@ -22,7 +22,7 @@ const downloadRC = () => {
let REPO;
let ENTERPRISE_REPO;
let TEST_REPO;
let ENTERPRISE_TEST_REPO;
// let ENTERPRISE_TEST_REPO;

if (HZ_VERSION.endsWith('-SNAPSHOT')) {
REPO = SNAPSHOT_REPO;
Expand All @@ -34,10 +34,10 @@ const downloadRC = () => {

if (HZ_TEST_VERSION.endsWith('-SNAPSHOT')) {
TEST_REPO = SNAPSHOT_REPO;
ENTERPRISE_TEST_REPO = ENTERPRISE_SNAPSHOT_REPO;
// ENTERPRISE_TEST_REPO = ENTERPRISE_SNAPSHOT_REPO;
} else {
TEST_REPO = RELEASE_REPO;
ENTERPRISE_TEST_REPO = ENTERPRISE_RELEASE_REPO;
// ENTERPRISE_TEST_REPO = ENTERPRISE_RELEASE_REPO;
}

if (fs.existsSync(`hazelcast-remote-controller-${HAZELCAST_RC_VERSION}.jar`)) {
Expand Down Expand Up @@ -132,7 +132,8 @@ const downloadRC = () => {
+ `com.hazelcast:hazelcast-enterprise:${HAZELCAST_ENTERPRISE_VERSION} ${subprocessTrace}`;
}
}

// TODO hazelcast-enterprise-tests.jar was removed from repo.
/*
if (fs.existsSync(`hazelcast-enterprise-${HAZELCAST_TEST_VERSION}-tests.jar`)) {
console.log('hazelcast-enterprise-tests.jar already exists, not downloading from maven.');
} else {
Expand All @@ -154,7 +155,7 @@ const downloadRC = () => {
throw 'Failed to download hazelcast enterprise test jar '
+ `com.hazelcast:hazelcast-enterprise:${HAZELCAST_TEST_VERSION}:jar:tests ${subprocessTrace}`;
}
}
}*/
console.log('Starting Remote Controller ... enterprise ...');
} else {
if (fs.existsSync(`hazelcast-${HAZELCAST_VERSION}.jar`)) {
Expand Down
2 changes: 0 additions & 2 deletions src/config/CompactSerializationConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import {CompactSerializer} from '../serialization/compact/CompactSerializer';

/**
* Compact serialization config for the client.
*
* This API is currently in BETA and can change at any time.
*/
export interface CompactSerializationConfig {

Expand Down
6 changes: 5 additions & 1 deletion src/config/ConfigBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {LoadBalancerType} from './LoadBalancerConfig';
import {LogLevel} from '../logging';
import {TokenCredentialsImpl, TokenEncoding, UsernamePasswordCredentialsImpl,} from '../security';
import {MetricsConfig} from './MetricsConfig';
import * as Util from '../util/Util';

/**
* Responsible for user-defined config validation. Builds the effective config with necessary defaults.
Expand Down Expand Up @@ -471,7 +472,10 @@ export class ConfigBuilder {
private handleSerialization(jsonObject: any): void {
for (const key in jsonObject) {
if (key === 'defaultNumberType') {
this.effectiveConfig.serialization.defaultNumberType = tryGetString(jsonObject[key]).toLowerCase();
const defaultNumberType = tryGetString(jsonObject[key]).toLowerCase();
// For checking expected value for defaultNumberType. If get unexpected value, throw RangeError.
Util.getTypeKeyForDefaultNumberType(defaultNumberType);
this.effectiveConfig.serialization.defaultNumberType = defaultNumberType;
} else if (key === 'isBigEndian') {
this.effectiveConfig.serialization.isBigEndian = tryGetBoolean(jsonObject[key]);
} else if (key === 'portableVersion') {
Expand Down
201 changes: 130 additions & 71 deletions src/serialization/SerializationService.ts

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions src/serialization/SerializationSymbols.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2008-2022, Hazelcast, Inc. All Rights Reserved.
*
* Licensed 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.
*/
/** @ignore *//** */

/** @internal */
export class SerializationSymbols {
static readonly BYTE_SYMBOL = Symbol();
static readonly NULL_SYMBOL = Symbol();
static readonly SHORT_SYMBOL = Symbol();
static readonly INTEGER_SYMBOL = Symbol();
static readonly FLOAT_SYMBOL = Symbol();
static readonly DOUBLE_SYMBOL = Symbol();
static readonly CHAR_SYMBOL = Symbol();
static readonly JAVACLASS_SYMBOL = Symbol();
static readonly ARRAYLIST_SYMBOL = Symbol();
static readonly LINKEDLIST_SYMBOL = Symbol();
static readonly JAVA_ARRAY_SYMBOL = Symbol();
static readonly COMPACT_SYMBOL = Symbol();
static readonly IDENTIFIED_SYMBOL = Symbol();
static readonly PORTABLE_SYMBOL = Symbol();
static readonly JSON_SYMBOL = Symbol();
static readonly GLOBAL_SYMBOL = Symbol();
}
1 change: 0 additions & 1 deletion src/serialization/compact/CompactReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {FieldKind} from '../generic_record';
* might be especially useful if the class might evolve in future, either by adding or
* removing fields.
*
* This API is currently in Beta and can change at any time.
*/
export interface CompactReader {
/**
Expand Down
1 change: 0 additions & 1 deletion src/serialization/compact/CompactSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {CompactWriter} from './CompactWriter';
*
* {@link write} and {@link read} methods must be consistent with each other.
*
* This API is currently in Beta and can change at any time.
*/
export interface CompactSerializer<C> {
/**
Expand Down
4 changes: 3 additions & 1 deletion src/serialization/compact/CompactWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {BigDecimal, LocalDate, LocalDateTime, LocalTime, OffsetDateTime} from '.
/**
* Provides means of writing compact serialized fields to the binary data.
*
* This API is currently in Beta and can change at any time.
*/
export interface CompactWriter {
/**
Expand Down Expand Up @@ -242,6 +241,9 @@ export interface CompactWriter {
/**
* Writes an array of nested compact objects.
*
* For compact objects, if an array contains different item types or undefined
* a {@link HazelcastSerializationError} will be thrown.
*
* @param fieldName name of the field.
* @param value to be written.
*/
Expand Down
58 changes: 58 additions & 0 deletions src/serialization/compact/DefaultCompactWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ export class DefaultCompactWriter implements CompactWriter {
}

writeArrayOfCompact<T>(fieldName: string, value: (T | null)[] | null): void {
const singleTypeCompactArrayItemChecker = new SingleTypeCompactArrayItemChecker();
return this.writeArrayOfVariableSizes(fieldName, FieldKind.ARRAY_OF_COMPACT, value, (out, value) => {
singleTypeCompactArrayItemChecker.check(value);
return this.serializer.writeObject(out, value);
});
}
Expand Down Expand Up @@ -298,7 +300,9 @@ export class DefaultCompactWriter implements CompactWriter {
}

writeArrayOfGenericRecord(fieldName: string, value: GenericRecord[]) : void {
const singleSchemaCompactArrayItemChecker = new SingleSchemaCompactArrayItemChecker();
return this.writeArrayOfVariableSizes(fieldName, FieldKind.ARRAY_OF_COMPACT, value, (out, value) => {
singleSchemaCompactArrayItemChecker.check(value);
return this.serializer.writeGenericRecord(out, value as CompactGenericRecordImpl);
});
}
Expand Down Expand Up @@ -425,3 +429,57 @@ export class DefaultCompactWriter implements CompactWriter {
}
}
}

/**
* Checks that the Compact serializable array items that are written are of
* a single type.
*/
export class SingleTypeCompactArrayItemChecker<T> {

// eslint-disable-next-line @typescript-eslint/ban-types
private clazz: Function;

public check(value: T): void {
if (value === undefined) {
throw new HazelcastSerializationError('The value undefined can not be used in an Array of Compact value.');
}
if (value.constructor === undefined) {
throw new HazelcastSerializationError('While checking if all elements in a compact array are of same type, '
+ 'encountered with a value with undefined contructor. Can not continue with single type checking.');
}
const clazzType = value.constructor;
if (this.clazz == null) {
this.clazz = clazzType;
}
if (this.clazz !== clazzType) {
throw new HazelcastSerializationError('It is not allowed to '
+ 'serialize an array of Compact serializable objects '
+ 'containing different item types. Expected array item '
+ 'type: ' + this.clazz.name + ', current item type: ' + clazzType.name);
}
}
}
/**
* Checks that the Compact serializable GenericRecord array items that are
* written are of a single schema.
*/
export class SingleSchemaCompactArrayItemChecker {

private schema: Schema;

public check(value: GenericRecord): void {
const record: CompactGenericRecordImpl = value as CompactGenericRecordImpl;
const schema = record.getSchema();
if (this.schema == null) {
this.schema = schema;
}

if (!this.schema.schemaId.equals(schema.schemaId)) {
throw new HazelcastSerializationError('It is not allowed to '
+ 'serialize an array of Compact serializable '
+ 'GenericRecord objects containing different schemas. '
+ 'Expected array item schema: ' + this.schema
+ ', current schema: ' + schema);
}
}
}
Loading

0 comments on commit 871a812

Please sign in to comment.