Skip to content

Remove dependency on java.sql.Timestamp #878

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)));
}
}