Skip to content

Commit

Permalink
Merge pull request #878 from rabbitmq/remove-dependency-on-sql-timestamp
Browse files Browse the repository at this point in the history
Remove dependency on java.sql.Timestamp
  • Loading branch information
acogoluegnes authored Nov 14, 2022
2 parents 4113329 + 11e20dd commit 270123f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 49 deletions.
5 changes: 2 additions & 3 deletions src/main/java/com/rabbitmq/client/impl/Frame.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
44 changes: 0 additions & 44 deletions src/test/java/com/rabbitmq/client/test/FrameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -106,46 +102,6 @@ public void close() throws IOException {
}
}

private static class AccumulatorReadableByteChannel implements ReadableByteChannel {

private List<Byte> bytesOfFrames = new LinkedList<Byte>();

@Override
public int read(ByteBuffer dst) throws IOException {
int remaining = dst.remaining();
int read = 0;
if(remaining > 0) {
Iterator<Byte> 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);
Expand Down
15 changes: 13 additions & 2 deletions src/test/java/com/rabbitmq/client/test/TableTest.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.*;
Expand Down Expand Up @@ -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<String, Object> table = new HashMap<String, Object>();
Map<String, Object> table = new HashMap<>();
table.put("a", 1);
assertEquals(table, unmarshal(marshal(table)));

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

table.put("e", -126);
assertEquals(table, unmarshal(marshal(table)));

Timestamp timestamp = timestamp();
table.put("f", timestamp);
Map<String, Object> tableWithTimestampAsDate = new HashMap<>(table);
tableWithTimestampAsDate.put("f", new Date(timestamp.getTime()));
assertEquals(tableWithTimestampAsDate, unmarshal(marshal(table)));
}
}

0 comments on commit 270123f

Please sign in to comment.