Skip to content

Commit

Permalink
[API-1014] Correct the FieldType values for Portable. (#592)
Browse files Browse the repository at this point in the history
Correct the FieldType values
  • Loading branch information
mehmettokgoz committed Dec 8, 2022
1 parent 975bb48 commit 5829049
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 20 deletions.
16 changes: 8 additions & 8 deletions hazelcast/serialization/portable/classdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ class FieldType:
UTF_ARRAY = 19 # Defined for backward compatibility.
STRING_ARRAY = 19
DECIMAL = 20
TIME = 21
DATE = 22
TIMESTAMP = 23
TIMESTAMP_WITH_TIMEZONE = 24
DECIMAL_ARRAY = 25
TIME_ARRAY = 26
DATE_ARRAY = 27
TIMESTAMP_ARRAY = 28
DECIMAL_ARRAY = 21
TIME = 22
TIME_ARRAY = 23
DATE = 24
DATE_ARRAY = 25
TIMESTAMP = 26
TIMESTAMP_ARRAY = 27
TIMESTAMP_WITH_TIMEZONE = 28
TIMESTAMP_WITH_TIMEZONE_ARRAY = 29


Expand Down
Binary file not shown.
48 changes: 36 additions & 12 deletions tests/unit/serialization/binary_compatibility/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.UUID;
import java.util.*;

import static java.util.Arrays.asList;

Expand Down Expand Up @@ -167,31 +164,58 @@ class ReferenceObjects {
anInnerPortable, null,
aCustomStreamSerializable,
aCustomByteArraySerializable, aData);
static APortable aPortable = new APortable(
aBoolean, aByte, aChar, aDouble, aShort, aFloat, anInt, aLong, anSqlString, anInnerPortable,
booleans, bytes, chars, doubles, shorts, floats, ints, longs, strings, portables,
anIdentifiedDataSerializable,
aCustomStreamSerializable,
aCustomByteArraySerializable, aData);

static LocalDate aLocalDate;
static LocalTime aLocalTime;
static LocalDateTime aLocalDateTime;
static OffsetDateTime anOffsetDateTime;
static LocalDate[] localDates;
static LocalTime[] localTimes;
static LocalDateTime[] localDateTimes;
static OffsetDateTime[] offsetDateTimes;

static {
Calendar calendar = Calendar.getInstance();
calendar.set(1990, Calendar.FEBRUARY, 1, 0, 0, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.set(Calendar.ZONE_OFFSET, 0);
calendar.set(Calendar.DST_OFFSET, 0);

aLocalDate = LocalDate.of(2021, 6, 28);
aLocalTime = LocalTime.of(11, 22, 41, 123456000);
aLocalDateTime = LocalDateTime.of(aLocalDate, aLocalTime);
anOffsetDateTime = OffsetDateTime.of(aLocalDateTime, ZoneOffset.ofHours(18));
localDates= new LocalDate[]{
LocalDate.of(2021, 6, 28),
LocalDate.of(1923, 4, 23),
LocalDate.of(1938, 11, 10)};
localTimes = new LocalTime[]{
LocalTime.of(9, 5, 10, 123456000),
LocalTime.of(18, 30, 55, 567891000),
LocalTime.of(15, 44, 39, 192837000)};
localDateTimes= new LocalDateTime[]{
LocalDateTime.of(LocalDate.of(1938, 11, 10), LocalTime.of(9, 5, 10, 123456000)),
LocalDateTime.of(LocalDate.of(1923, 4, 23), LocalTime.of(15, 44, 39, 192837000)),
LocalDateTime.of(LocalDate.of(2021, 6, 28), LocalTime.of(18, 30, 55, 567891000))};
offsetDateTimes= new OffsetDateTime[]{
OffsetDateTime.of(LocalDate.of(1938, 11, 10), LocalTime.of(9, 5, 10, 123456000),
ZoneOffset.ofHours(18)),
OffsetDateTime.of(LocalDateTime.of(LocalDate.of(1923, 4, 23), LocalTime.of(15, 44, 39, 192837000)),
ZoneOffset.ofHours(5)),
OffsetDateTime.of(LocalDateTime.of(LocalDate.of(2021, 6, 28), LocalTime.of(18, 30, 55, 567891000)),
ZoneOffset.ofHours(-10))};
}
static BigDecimal aBigDecimal = new BigDecimal("31231.12331");
static BigDecimal[] decimals = {aBigDecimal, aBigDecimal ,aBigDecimal};
static APortable aPortable = new APortable(
aBoolean, aByte, aChar, aDouble, aShort, aFloat, anInt, aLong, anSqlString, aBigDecimal,
aLocalDate, aLocalTime, aLocalDateTime, anOffsetDateTime, anInnerPortable,
booleans, bytes, chars, doubles, shorts, floats, ints, longs, strings, decimals,
localDates, localTimes, localDateTimes, offsetDateTimes, portables,
anIdentifiedDataSerializable,
aCustomStreamSerializable,
aCustomByteArraySerializable, aData);

static BigInteger aBigInteger = new BigInteger("1314432323232411");
static BigDecimal aBigDecimal = new BigDecimal("31231.12331");
static Class aClass = BigDecimal.class;

static ArrayList nonNullList = new ArrayList(asList(
Expand Down
96 changes: 96 additions & 0 deletions tests/unit/serialization/binary_compatibility/reference_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ def __init__(
i=None,
l=None,
string=None,
bd=None,
ld=None,
lt=None,
ldt=None,
odt=None,
p=None,
booleans=None,
bytes_=None,
Expand All @@ -344,6 +349,11 @@ def __init__(
ints=None,
longs=None,
strings=None,
decimals=None,
dates=None,
times=None,
dateTimes=None,
offsetDateTimes=None,
portables=None,
identified=None,
custom_serializable=None,
Expand All @@ -359,6 +369,11 @@ def __init__(
self.i = i
self.l = l
self.string = string
self.bd = bd
self.ld = ld
self.lt = lt
self.ldt = ldt
self.odt = odt
self.p = p

self.booleans = booleans
Expand All @@ -370,6 +385,11 @@ def __init__(
self.ints = ints
self.longs = longs
self.strings = strings
self.decimals = decimals
self.dates = dates
self.times = times
self.dateTimes = dateTimes
self.offsetDateTimes = offsetDateTimes
self.portables = portables

self.booleans_none = None
Expand Down Expand Up @@ -405,6 +425,11 @@ def write_portable(self, writer):
writer.write_int("i", self.i)
writer.write_long("l", self.l)
writer.write_string("str", self.string)
writer.write_decimal("bd", self.bd)
writer.write_date("ld", self.ld)
writer.write_time("lt", self.lt)
writer.write_timestamp("ldt", self.ldt)
writer.write_timestamp_with_timezone("odt", self.odt)
if self.p:
writer.write_portable("p", self.p)
else:
Expand All @@ -419,6 +444,11 @@ def write_portable(self, writer):
writer.write_int_array("is", self.ints)
writer.write_long_array("ls", self.longs)
writer.write_string_array("strs", self.strings)
writer.write_decimal_array("decimals", self.decimals)
writer.write_date_array("dates", self.dates)
writer.write_time_array("times", self.times)
writer.write_timestamp_array("dateTimes", self.dateTimes)
writer.write_timestamp_with_timezone_array("offsetDateTimes", self.offsetDateTimes)
writer.write_portable_array("ps", self.portables)

writer.write_boolean_array("booleansNull", self.booleans_none)
Expand Down Expand Up @@ -491,6 +521,11 @@ def read_portable(self, reader):
self.i = reader.read_int("i")
self.l = reader.read_long("l")
self.string = reader.read_string("str")
self.bd = reader.read_decimal("bd")
self.ld = reader.read_date("ld")
self.lt = reader.read_time("lt")
self.ldt = reader.read_timestamp("ldt")
self.odt = reader.read_timestamp_with_timezone("odt")
self.p = reader.read_portable("p")

self.booleans = reader.read_boolean_array("booleans")
Expand All @@ -502,6 +537,11 @@ def read_portable(self, reader):
self.ints = reader.read_int_array("is")
self.longs = reader.read_long_array("ls")
self.strings = reader.read_string_array("strs")
self.decimals = reader.read_decimal_array("decimals")
self.dates = reader.read_date_array("dates")
self.times = reader.read_time_array("times")
self.dateTimes = reader.read_timestamp_array("dateTimes")
self.offsetDateTimes = reader.read_timestamp_with_timezone_array("offsetDateTimes")
self.portables = reader.read_portable_array("ps")

self.booleans_none = reader.read_boolean_array("booleansNull")
Expand Down Expand Up @@ -588,6 +628,11 @@ def __eq__(self, other):
and self.unsigned_byte == other.unsigned_byte
and self.unsigned_short == other.unsigned_short
and self.string == other.string
and self.bd == other.bd
and self.ld == other.ld
and self.lt == other.lt
and self.ldt == other.ldt
and self.odt == other.odt
and self.p == other.p
and self.booleans == other.booleans
and self.bytes_ == other.bytes_
Expand All @@ -598,6 +643,11 @@ def __eq__(self, other):
and self.ints == other.ints
and self.longs == other.longs
and self.strings == other.strings
and self.decimals == other.decimals
and self.dates == other.dates
and self.times == other.times
and self.dateTimes == other.dateTimes
and self.offsetDateTimes == other.offsetDateTimes
and self.portables == other.portables
and self.booleans_none == other.booleans_none
and self.bytes_none == other.bytes_none
Expand Down Expand Up @@ -657,6 +707,42 @@ def __eq__(self, other):
"Class": "java.math.BigDecimal",
}

_big_decimal_array = [
decimal.Decimal("31231.12331"),
decimal.Decimal("31231.12331"),
decimal.Decimal("31231.12331"),
]

_local_date_array = [
datetime.date(2021, 6, 28),
datetime.date(1923, 4, 23),
datetime.date(1938, 11, 10),
]

_local_time_array = [
datetime.time(9, 5, 10, 123456),
datetime.time(18, 30, 55, 567891),
datetime.time(15, 44, 39, 192837),
]

_local_date_time_array = [
datetime.datetime(1938, 11, 10, 9, 5, 10, 123456),
datetime.datetime(1923, 4, 23, 15, 44, 39, 192837),
datetime.datetime(2021, 6, 28, 18, 30, 55, 567891),
]

_offset_date_time_array = [
datetime.datetime(
1938, 11, 10, 9, 5, 10, 123456, datetime.timezone(datetime.timedelta(hours=18))
),
datetime.datetime(
1923, 4, 23, 15, 44, 39, 192837, datetime.timezone(datetime.timedelta(hours=5))
),
datetime.datetime(
2021, 6, 28, 18, 30, 55, 567891, datetime.timezone(datetime.timedelta(hours=-10))
),
]

_data = Data(bytearray([49, 49, 49, 51, 49, 51, 49, 50, 51, 49, 51, 49, 51, 49, 51, 49, 51, 49]))

_inner_portable = AnInnerPortable(REFERENCE_OBJECTS["Integer"], REFERENCE_OBJECTS["Float"])
Expand Down Expand Up @@ -707,6 +793,11 @@ def __eq__(self, other):
REFERENCE_OBJECTS["Integer"],
REFERENCE_OBJECTS["Long"],
_sql_string,
REFERENCE_OBJECTS["BigDecimal"],
REFERENCE_OBJECTS["LocalDate"],
REFERENCE_OBJECTS["LocalTime"],
REFERENCE_OBJECTS["LocalDateTime"],
REFERENCE_OBJECTS["OffsetDateTime"],
_inner_portable,
REFERENCE_OBJECTS["boolean[]"],
REFERENCE_OBJECTS["byte[]"],
Expand All @@ -717,6 +808,11 @@ def __eq__(self, other):
REFERENCE_OBJECTS["int[]"],
REFERENCE_OBJECTS["long[]"],
REFERENCE_OBJECTS["String[]"],
_big_decimal_array,
_local_date_array,
_local_time_array,
_local_date_time_array,
_offset_date_time_array,
_portables,
_identified,
_custom_serializable,
Expand Down

0 comments on commit 5829049

Please sign in to comment.