Skip to content

Commit 11e20dd

Browse files
committed
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
1 parent 4113329 commit 11e20dd

File tree

3 files changed

+15
-49
lines changed

3 files changed

+15
-49
lines changed

src/main/java/com/rabbitmq/client/impl/Frame.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
1+
// Copyright (c) 2007-2022 VMware, Inc. or its affiliates. All rights reserved.
22
//
33
// This software, the RabbitMQ Java client library, is triple-licensed under the
44
// Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
@@ -22,7 +22,6 @@
2222
import java.io.*;
2323
import java.math.BigDecimal;
2424
import java.net.SocketTimeoutException;
25-
import java.sql.Timestamp;
2625
import java.util.Date;
2726
import java.util.List;
2827
import java.util.Map;
@@ -268,7 +267,7 @@ else if(value instanceof Integer) {
268267
else if(value instanceof BigDecimal) {
269268
acc += 5;
270269
}
271-
else if(value instanceof Date || value instanceof Timestamp) {
270+
else if(value instanceof Date) {
272271
acc += 8;
273272
}
274273
else if(value instanceof Map) {

src/test/java/com/rabbitmq/client/test/FrameTest.java

-44
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
import com.rabbitmq.client.impl.nio.ByteBufferOutputStream;
66
import org.junit.Test;
77

8-
import java.io.ByteArrayOutputStream;
98
import java.io.DataOutputStream;
109
import java.io.IOException;
1110
import java.nio.ByteBuffer;
12-
import java.nio.channels.ReadableByteChannel;
1311
import java.nio.channels.WritableByteChannel;
1412
import java.util.ArrayList;
15-
import java.util.Iterator;
16-
import java.util.LinkedList;
1713
import java.util.List;
1814
import java.util.Random;
1915

@@ -106,46 +102,6 @@ public void close() throws IOException {
106102
}
107103
}
108104

109-
private static class AccumulatorReadableByteChannel implements ReadableByteChannel {
110-
111-
private List<Byte> bytesOfFrames = new LinkedList<Byte>();
112-
113-
@Override
114-
public int read(ByteBuffer dst) throws IOException {
115-
int remaining = dst.remaining();
116-
int read = 0;
117-
if(remaining > 0) {
118-
Iterator<Byte> iterator = bytesOfFrames.iterator();
119-
while(iterator.hasNext() && read < remaining) {
120-
dst.put(iterator.next());
121-
iterator.remove();
122-
read++;
123-
}
124-
}
125-
return read;
126-
}
127-
128-
@Override
129-
public boolean isOpen() {
130-
return false;
131-
}
132-
133-
@Override
134-
public void close() throws IOException {
135-
136-
}
137-
138-
void add(Frame frame) throws IOException {
139-
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(frame.size());
140-
DataOutputStream outputStream = new DataOutputStream(byteArrayOutputStream);
141-
frame.writeTo(outputStream);
142-
outputStream.flush();
143-
for (byte b : byteArrayOutputStream.toByteArray()) {
144-
bytesOfFrames.add(b);
145-
}
146-
}
147-
}
148-
149105
public static void drain(WritableByteChannel channel, ByteBuffer buffer) throws IOException {
150106
buffer.flip();
151107
while(buffer.hasRemaining() && channel.write(buffer) != -1);

src/test/java/com/rabbitmq/client/test/TableTest.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
1+
// Copyright (c) 2007-2022 VMware, Inc. or its affiliates. All rights reserved.
22
//
33
// This software, the RabbitMQ Java client library, is triple-licensed under the
44
// Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
@@ -17,6 +17,7 @@
1717
package com.rabbitmq.client.test;
1818

1919
import com.rabbitmq.client.impl.*;
20+
import java.sql.Timestamp;
2021
import org.junit.Test;
2122

2223
import java.io.*;
@@ -59,10 +60,14 @@ public Date secondDate()
5960
return new Date((System.currentTimeMillis()/1000)*1000);
6061
}
6162

63+
private static Timestamp timestamp() {
64+
return new Timestamp((System.currentTimeMillis()/1000)*1000);
65+
}
66+
6267
@Test public void loop()
6368
throws IOException
6469
{
65-
Map<String, Object> table = new HashMap<String, Object>();
70+
Map<String, Object> table = new HashMap<>();
6671
table.put("a", 1);
6772
assertEquals(table, unmarshal(marshal(table)));
6873

@@ -77,5 +82,11 @@ public Date secondDate()
7782

7883
table.put("e", -126);
7984
assertEquals(table, unmarshal(marshal(table)));
85+
86+
Timestamp timestamp = timestamp();
87+
table.put("f", timestamp);
88+
Map<String, Object> tableWithTimestampAsDate = new HashMap<>(table);
89+
tableWithTimestampAsDate.put("f", new Date(timestamp.getTime()));
90+
assertEquals(tableWithTimestampAsDate, unmarshal(marshal(table)));
8091
}
8192
}

0 commit comments

Comments
 (0)