From 11e20dda94510a36968e2c24891aaea30c542553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Cogolu=C3=A8gnes?= Date: Mon, 14 Nov 2022 09:14:31 +0100 Subject: [PATCH] Remove dependency on java.sql.Timestamp Only one condition test refers to java.sql.Timestamp and it's unnecessary anyway because it also refers to java.util.Date (Timestamp inherits from Date). Only the Date API is then used to marshall and unmarshall values. This avoids a dependency on the java.sql module, which some SDK does not seem to contain (e.g. JavaFX, reported by a user). This should also avoid needing this module in some Docker images (e.g. PerfTest, which pulls this module in its stripped JRE just for this reference apparently). Mailing list thread: https://groups.google.com/g/rabbitmq-users/c/ORX91PwYhnw/m/xlMR9JTTAQAJ --- .../java/com/rabbitmq/client/impl/Frame.java | 5 +-- .../com/rabbitmq/client/test/FrameTest.java | 44 ------------------- .../com/rabbitmq/client/test/TableTest.java | 15 ++++++- 3 files changed, 15 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/rabbitmq/client/impl/Frame.java b/src/main/java/com/rabbitmq/client/impl/Frame.java index f97e345b9c..74043c175c 100644 --- a/src/main/java/com/rabbitmq/client/impl/Frame.java +++ b/src/main/java/com/rabbitmq/client/impl/Frame.java @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved. +// Copyright (c) 2007-2022 VMware, Inc. or its affiliates. All rights reserved. // // This software, the RabbitMQ Java client library, is triple-licensed under the // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2 @@ -22,7 +22,6 @@ import java.io.*; import java.math.BigDecimal; import java.net.SocketTimeoutException; -import java.sql.Timestamp; import java.util.Date; import java.util.List; import java.util.Map; @@ -268,7 +267,7 @@ else if(value instanceof Integer) { else if(value instanceof BigDecimal) { acc += 5; } - else if(value instanceof Date || value instanceof Timestamp) { + else if(value instanceof Date) { acc += 8; } else if(value instanceof Map) { diff --git a/src/test/java/com/rabbitmq/client/test/FrameTest.java b/src/test/java/com/rabbitmq/client/test/FrameTest.java index 26441a848b..e78ec48a70 100644 --- a/src/test/java/com/rabbitmq/client/test/FrameTest.java +++ b/src/test/java/com/rabbitmq/client/test/FrameTest.java @@ -5,15 +5,11 @@ import com.rabbitmq.client.impl.nio.ByteBufferOutputStream; import org.junit.Test; -import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.channels.ReadableByteChannel; import java.nio.channels.WritableByteChannel; import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Random; @@ -106,46 +102,6 @@ public void close() throws IOException { } } - private static class AccumulatorReadableByteChannel implements ReadableByteChannel { - - private List bytesOfFrames = new LinkedList(); - - @Override - public int read(ByteBuffer dst) throws IOException { - int remaining = dst.remaining(); - int read = 0; - if(remaining > 0) { - Iterator iterator = bytesOfFrames.iterator(); - while(iterator.hasNext() && read < remaining) { - dst.put(iterator.next()); - iterator.remove(); - read++; - } - } - return read; - } - - @Override - public boolean isOpen() { - return false; - } - - @Override - public void close() throws IOException { - - } - - void add(Frame frame) throws IOException { - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(frame.size()); - DataOutputStream outputStream = new DataOutputStream(byteArrayOutputStream); - frame.writeTo(outputStream); - outputStream.flush(); - for (byte b : byteArrayOutputStream.toByteArray()) { - bytesOfFrames.add(b); - } - } - } - public static void drain(WritableByteChannel channel, ByteBuffer buffer) throws IOException { buffer.flip(); while(buffer.hasRemaining() && channel.write(buffer) != -1); diff --git a/src/test/java/com/rabbitmq/client/test/TableTest.java b/src/test/java/com/rabbitmq/client/test/TableTest.java index bb07a71f21..d39e871760 100644 --- a/src/test/java/com/rabbitmq/client/test/TableTest.java +++ b/src/test/java/com/rabbitmq/client/test/TableTest.java @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved. +// Copyright (c) 2007-2022 VMware, Inc. or its affiliates. All rights reserved. // // This software, the RabbitMQ Java client library, is triple-licensed under the // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2 @@ -17,6 +17,7 @@ package com.rabbitmq.client.test; import com.rabbitmq.client.impl.*; +import java.sql.Timestamp; import org.junit.Test; import java.io.*; @@ -59,10 +60,14 @@ public Date secondDate() return new Date((System.currentTimeMillis()/1000)*1000); } + private static Timestamp timestamp() { + return new Timestamp((System.currentTimeMillis()/1000)*1000); + } + @Test public void loop() throws IOException { - Map table = new HashMap(); + Map table = new HashMap<>(); table.put("a", 1); assertEquals(table, unmarshal(marshal(table))); @@ -77,5 +82,11 @@ public Date secondDate() table.put("e", -126); assertEquals(table, unmarshal(marshal(table))); + + Timestamp timestamp = timestamp(); + table.put("f", timestamp); + Map tableWithTimestampAsDate = new HashMap<>(table); + tableWithTimestampAsDate.put("f", new Date(timestamp.getTime())); + assertEquals(tableWithTimestampAsDate, unmarshal(marshal(table))); } }