diff --git a/src/main/java/com/rabbitmq/client/impl/Frame.java b/src/main/java/com/rabbitmq/client/impl/Frame.java index f97e345b9..74043c175 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 26441a848..e78ec48a7 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 bb07a71f2..d39e87176 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))); } }