Skip to content

Commit 408f6a9

Browse files
committed
add serialVersion, changelog, tests
1 parent df360dd commit 408f6a9

File tree

8 files changed

+84
-22
lines changed

8 files changed

+84
-22
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## [Unreleased]
44

5+
## [0.9.1] - 2022-10-26
6+
- Support Datetime type ([#293](https://github.com/tarantool/cartridge-java/pull/293))
7+
58
## [0.9.1] - 2022-10-13
69

710
- Changed TarantoolNullField class to singleton ([#195](https://github.com/tarantool/cartridge-java/pull/275))

src/main/java/io/tarantool/driver/api/tuple/TarantoolTuple.java

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.tarantool.driver.protocol.Packable;
44

55
import java.math.BigDecimal;
6+
import java.time.Instant;
67
import java.util.List;
78
import java.util.Map;
89
import java.util.Optional;
@@ -16,7 +17,7 @@
1617
public interface TarantoolTuple extends Iterable<TarantoolField>, Packable {
1718
/**
1819
* Get a tuple field by its position
19-
* @param fieldPosition the field position from the the tuple start, starting from 0
20+
* @param fieldPosition the field position from the tuple start, starting from 0
2021
* @return field or empty optional if the field position is out of tuple length
2122
*/
2223
Optional<TarantoolField> getField(int fieldPosition);
@@ -38,7 +39,7 @@ public interface TarantoolTuple extends Iterable<TarantoolField>, Packable {
3839

3940
/**
4041
* Get a tuple field value by its position specifying the target value type
41-
* @param fieldPosition field position from the the tuple start, starting from 0
42+
* @param fieldPosition field position from the tuple start, starting from 0
4243
* @param objectClass target value type class
4344
* @param <O> target value type
4445
* @return nullable value of a field wrapped in Optional, possibly converted to a Java type
@@ -47,7 +48,7 @@ public interface TarantoolTuple extends Iterable<TarantoolField>, Packable {
4748

4849
/**
4950
* Check if a tuple field exists and can be converted to the target value type
50-
* @param fieldPosition field position from the the tuple start, starting from 0
51+
* @param fieldPosition field position from the tuple start, starting from 0
5152
* @param objectClass target value type class
5253
* @return true, if the field exists and can be converted to the given type, false otherwise
5354
*/
@@ -72,7 +73,7 @@ public interface TarantoolTuple extends Iterable<TarantoolField>, Packable {
7273

7374
/**
7475
* Get a tuple field value as a raw object
75-
* @param fieldPosition field position from the the tuple start, starting from 0
76+
* @param fieldPosition field position from the tuple start, starting from 0
7677
* @return nullable value of a field wrapped in Optional
7778
*/
7879
Optional<?> getObject(int fieldPosition);
@@ -94,7 +95,7 @@ public interface TarantoolTuple extends Iterable<TarantoolField>, Packable {
9495
/**
9596
* Set a tuple field by field position
9697
*
97-
* @param fieldPosition the field position from the the tuple start, starting from 0
98+
* @param fieldPosition the field position from the tuple start, starting from 0
9899
* @param field new field
99100
*/
100101
void setField(int fieldPosition, TarantoolField field);
@@ -110,7 +111,7 @@ public interface TarantoolTuple extends Iterable<TarantoolField>, Packable {
110111
/**
111112
* Set a tuple field value from an object by field position
112113
*
113-
* @param fieldPosition the field position from the the tuple start, starting from 0
114+
* @param fieldPosition the field position from the tuple start, starting from 0
114115
* @param value new field value
115116
*/
116117
void putObject(int fieldPosition, Object value);
@@ -126,7 +127,7 @@ public interface TarantoolTuple extends Iterable<TarantoolField>, Packable {
126127
/**
127128
* Get the field value converted to {@code byte[]}
128129
*
129-
* @param fieldPosition the field position from the the tuple start, starting from 0
130+
* @param fieldPosition the field position from the tuple start, starting from 0
130131
* @return value
131132
*/
132133
byte[] getByteArray(int fieldPosition);
@@ -142,7 +143,7 @@ public interface TarantoolTuple extends Iterable<TarantoolField>, Packable {
142143
/**
143144
* Get the field value converted to {@code Boolean}
144145
*
145-
* @param fieldPosition the field position from the the tuple start, starting from 0
146+
* @param fieldPosition the field position from the tuple start, starting from 0
146147
* @return value
147148
*/
148149
Boolean getBoolean(int fieldPosition);
@@ -158,7 +159,7 @@ public interface TarantoolTuple extends Iterable<TarantoolField>, Packable {
158159
/**
159160
* Get the field value converted to {@code Double}
160161
*
161-
* @param fieldPosition the field position from the the tuple start, starting from 0
162+
* @param fieldPosition the field position from the tuple start, starting from 0
162163
* @return value
163164
*/
164165
Double getDouble(int fieldPosition);
@@ -174,7 +175,7 @@ public interface TarantoolTuple extends Iterable<TarantoolField>, Packable {
174175
/**
175176
* Get the field value converted to {@code Float}
176177
*
177-
* @param fieldPosition the field position from the the tuple start, starting from 0
178+
* @param fieldPosition the field position from the tuple start, starting from 0
178179
* @return value
179180
*/
180181
Float getFloat(int fieldPosition);
@@ -190,7 +191,7 @@ public interface TarantoolTuple extends Iterable<TarantoolField>, Packable {
190191
/**
191192
* Get the field value converted to {@code Integer}
192193
*
193-
* @param fieldPosition the field position from the the tuple start, starting from 0
194+
* @param fieldPosition the field position from the tuple start, starting from 0
194195
* @return value
195196
*/
196197
Integer getInteger(int fieldPosition);
@@ -206,7 +207,7 @@ public interface TarantoolTuple extends Iterable<TarantoolField>, Packable {
206207
/**
207208
* Get the field value converted to {@code Long}
208209
*
209-
* @param fieldPosition the field position from the the tuple start, starting from 0
210+
* @param fieldPosition the field position from the tuple start, starting from 0
210211
* @return value
211212
*/
212213
Long getLong(int fieldPosition);
@@ -222,7 +223,7 @@ public interface TarantoolTuple extends Iterable<TarantoolField>, Packable {
222223
/**
223224
* Get the field value converted to {@code String}
224225
*
225-
* @param fieldPosition the field position from the the tuple start, starting from 0
226+
* @param fieldPosition the field position from the tuple start, starting from 0
226227
* @return value
227228
*/
228229
String getString(int fieldPosition);
@@ -238,7 +239,7 @@ public interface TarantoolTuple extends Iterable<TarantoolField>, Packable {
238239
/**
239240
* Get the field value converted to {@code Character}
240241
*
241-
* @param fieldPosition the field position from the the tuple start, starting from 0
242+
* @param fieldPosition the field position from the tuple start, starting from 0
242243
* @return value
243244
*/
244245
Character getCharacter(int fieldPosition);
@@ -254,7 +255,7 @@ public interface TarantoolTuple extends Iterable<TarantoolField>, Packable {
254255
/**
255256
* Get the field value converted to {@link UUID}
256257
*
257-
* @param fieldPosition the field position from the the tuple start, starting from 0
258+
* @param fieldPosition the field position from the tuple start, starting from 0
258259
* @return value
259260
*/
260261
UUID getUUID(int fieldPosition);
@@ -267,10 +268,26 @@ public interface TarantoolTuple extends Iterable<TarantoolField>, Packable {
267268
*/
268269
UUID getUUID(String fieldName);
269270

271+
/**
272+
* Get the field value converted to {@link Instant}
273+
*
274+
* @param fieldPosition the field position from the tuple start, starting from 0
275+
* @return value
276+
*/
277+
Instant getInstant(int fieldPosition);
278+
279+
/**
280+
* Get the field value converted to {@link Instant}
281+
*
282+
* @param fieldName the field name, must not be null
283+
* @return value
284+
*/
285+
Instant getInstant(String fieldName);
286+
270287
/**
271288
* Get the field value converted to {@link BigDecimal}
272289
*
273-
* @param fieldPosition the field position from the the tuple start, starting from 0
290+
* @param fieldPosition the field position from the tuple start, starting from 0
274291
* @return value
275292
*/
276293
BigDecimal getDecimal(int fieldPosition);
@@ -286,7 +303,7 @@ public interface TarantoolTuple extends Iterable<TarantoolField>, Packable {
286303
/**
287304
* Get the field value converted to {@link List}
288305
*
289-
* @param fieldPosition the field position from the the tuple start, starting from 0
306+
* @param fieldPosition the field position from the tuple start, starting from 0
290307
* @return value
291308
*/
292309
List<?> getList(int fieldPosition);
@@ -302,7 +319,7 @@ public interface TarantoolTuple extends Iterable<TarantoolField>, Packable {
302319
/**
303320
* Get the field value converted to {@link Map}
304321
*
305-
* @param fieldPosition the field position from the the tuple start, starting from 0
322+
* @param fieldPosition the field position from the tuple start, starting from 0
306323
* @return value
307324
*/
308325
Map<?, ?> getMap(int fieldPosition);

src/main/java/io/tarantool/driver/mappers/converters/object/DefaultInstantToExtensionValueConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
*/
1515
public class DefaultInstantToExtensionValueConverter implements ObjectConverter<Instant, ExtensionValue> {
1616

17-
private static final long serialVersionUID = 20220418L;
17+
private static final long serialVersionUID = 20221025L;
1818

1919
private static final byte DATETIME_TYPE = 0x04;
2020

2121
private byte[] toBytes(Instant value) {
22-
ByteBuffer buffer = ByteBuffer.wrap(new byte[16]);
22+
ByteBuffer buffer = ByteBuffer.wrap(new byte[8]);
2323
buffer.putLong(0, value.getEpochSecond());
2424
return buffer.array();
2525
}

src/main/java/io/tarantool/driver/mappers/converters/value/DefaultExtensionValueToInstantConverter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* @author Anastasiia Romanova
1313
*/
1414
public class DefaultExtensionValueToInstantConverter implements ValueConverter<ExtensionValue, Instant> {
15+
16+
private static final long serialVersionUID = 20221025L;
1517
private static final byte DATETIME_TYPE = 0x04;
1618

1719
private Instant fromBytes(byte[] bytes) {

src/test/java/io/tarantool/driver/TarantoolUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public static boolean versionWithUUID() {
3131
return versionGreaterThen("2.4");
3232
}
3333

34+
public static boolean versionWithInstant() {
35+
return versionGreaterThen("2.10");
36+
}
37+
3438
public static boolean versionWithVarbinary() {
3539
return versionGreaterThen("2.2.1");
3640
}

src/test/java/io/tarantool/driver/integration/ConvertersWithClusterClientIT.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.junit.jupiter.api.Test;
1616
import org.junit.jupiter.api.condition.EnabledIf;
1717

18+
import java.time.Instant;
1819
import java.util.UUID;
1920
import org.testcontainers.shaded.org.apache.commons.lang.ArrayUtils;
2021

@@ -65,6 +66,23 @@ public void test_boxSelect_shouldReturnTupleWithUUID() throws Exception {
6566
Assertions.assertEquals(uuid, fields.getUUID("uuid_field"));
6667
}
6768

69+
@Test
70+
@EnabledIf("io.tarantool.driver.TarantoolUtils#versionWithInstant")
71+
public void test_boxSelect_shouldReturnTupleWithInstant() throws Exception {
72+
//given
73+
Instant instant = Instant.now();
74+
client.space("space_with_instant")
75+
.insert(tupleFactory.create(1, instant)).get();
76+
77+
//when
78+
TarantoolTuple fields = client
79+
.space("space_with_instant")
80+
.select(Conditions.equals("id", 1)).get().get(0);
81+
82+
//then
83+
Assertions.assertEquals(instant, fields.getInstant("instant_field"));
84+
}
85+
6886
@Test
6987
@EnabledIf("io.tarantool.driver.TarantoolUtils#versionWithVarbinary")
7088
public void test_boxOperations_shouldWorkWithVarbinary() throws Exception {

src/test/java/io/tarantool/driver/integration/ConvertersWithProxyClientIT.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.junit.jupiter.api.Test;
1414
import org.junit.jupiter.api.condition.EnabledIf;
1515

16+
import java.time.Instant;
1617
import java.util.UUID;
1718
import org.junit.jupiter.api.Disabled;
1819
import org.testcontainers.shaded.org.apache.commons.lang.ArrayUtils;
@@ -65,6 +66,23 @@ public void test_crudSelect_shouldReturnTupleWithUUID() throws Exception {
6566
Assertions.assertEquals(uuid, fields.getUUID("uuid_field"));
6667
}
6768

69+
@Test
70+
@EnabledIf("io.tarantool.driver.TarantoolUtils#versionWithInstant")
71+
public void test_crudSelect_shouldReturnTupleWithInstant() throws Exception {
72+
//given
73+
Instant instant = Instant.now();
74+
client.space("space_with_instant")
75+
.insert(tupleFactory.create(1, instant)).get();
76+
77+
//when
78+
TarantoolTuple fields = client
79+
.space("space_with_instant")
80+
.select(Conditions.equals("id", 1)).get().get(0);
81+
82+
//then
83+
Assertions.assertEquals(instant, fields.getInstant("instant_field"));
84+
}
85+
6886
@Test
6987
@Disabled("Until https://github.com/tarantool/tarantool/issues/1629 is fixed")
7088
@EnabledIf("io.tarantool.driver.TarantoolUtils#versionWithVarbinary")

src/test/java/io/tarantool/driver/mappers/DefaultInstantConverterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ void toValue() throws IOException {
3232
Base64.Encoder encoder = Base64.getEncoder();
3333
Instant instant = LocalDateTime.parse("2022-10-25T12:03:58").toInstant(ZoneOffset.UTC);
3434
byte[] result = ((MessageBufferPacker) packer.packValue(converter.toValue(instant))).toByteArray();
35-
assertEquals("2AQAAAAAY1fQrgAAAAAAAAAA", encoder.encodeToString(result));
35+
assertEquals("1wQAAAAAY1fQrg==", encoder.encodeToString(result));
3636
}
3737

3838
@Test
3939
void fromValue() throws IOException {
4040
DefaultExtensionValueToInstantConverter converter = new DefaultExtensionValueToInstantConverter();
4141
Base64.Decoder base64decoder = Base64.getDecoder();
4242
Instant instant = LocalDateTime.parse("2022-10-25T12:03:58").toInstant(ZoneOffset.UTC);
43-
byte[] packed = base64decoder.decode("2AQAAAAAY1fQrgAAAAAAAAAA");
43+
byte[] packed = base64decoder.decode("1wQAAAAAY1fQrg==");
4444
ExtensionValue value = MessagePack.newDefaultUnpacker(packed).unpackValue().asExtensionValue();
4545
assertEquals(instant, converter.fromValue(value));
4646
}

0 commit comments

Comments
 (0)