This is an automated email from the ASF dual-hosted git repository.
tabish pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git
The following commit(s) were added to refs/heads/main by this push:
new 3df0019b PROTON-2887 Minor code cleanups from analysis
3df0019b is described below
commit 3df0019b3956c2c10e57c86a87a2f60708870fe7
Author: Timothy Bish <[email protected]>
AuthorDate: Tue Apr 22 16:42:29 2025 -0400
PROTON-2887 Minor code cleanups from analysis
Fix some tests to correct assertions and other minor code cleanups
---
.../apache/qpid/protonj2/client/SaslOptions.java | 8 +++----
.../protonj2/client/impl/ClientDeliveryState.java | 8 +++++++
.../protonj2/client/impl/StreamReceiverTest.java | 22 ++++---------------
.../client/transport/netty4/NettyServer.java | 4 ++--
.../apache/qpid/protonj2/engine/util/SplayMap.java | 2 +-
.../codec/primitives/UUIDTypeCodecTest.java | 25 ++++++++++------------
.../protonj2/engine/impl/ProtonSenderTest.java | 5 ++++-
7 files changed, 34 insertions(+), 40 deletions(-)
diff --git
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/SaslOptions.java
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/SaslOptions.java
index 95b9fc63..e6add2df 100644
---
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/SaslOptions.java
+++
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/SaslOptions.java
@@ -24,11 +24,11 @@ import java.util.Set;
/**
* Connection options that are applied to the SASL layer.
*/
-public class SaslOptions {
+public class SaslOptions implements Cloneable {
- /**
- * The client default configuration value for SASL enabled state
(default is true)
- */
+ /**
+ * The client default configuration value for SASL enabled state (default
is true)
+ */
public static final boolean DEFAULT_SASL_ENABLED = true;
private boolean saslEnabled = DEFAULT_SASL_ENABLED;
diff --git
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientDeliveryState.java
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientDeliveryState.java
index 8ef7dbd3..3320c7a7 100644
---
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientDeliveryState.java
+++
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientDeliveryState.java
@@ -128,6 +128,10 @@ public abstract class ClientDeliveryState implements
DeliveryState {
private static final ClientAccepted INSTANCE = new ClientAccepted();
+ private ClientAccepted() {
+ // Singleton
+ }
+
@Override
public Type getType() {
return Type.ACCEPTED;
@@ -153,6 +157,10 @@ public abstract class ClientDeliveryState implements
DeliveryState {
private static final ClientReleased INSTANCE = new ClientReleased();
+ private ClientReleased() {
+ // Singleton
+ }
+
@Override
public Type getType() {
return Type.RELEASED;
diff --git
a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/StreamReceiverTest.java
b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/StreamReceiverTest.java
index 680d33d6..f3fe77a9 100644
---
a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/StreamReceiverTest.java
+++
b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/StreamReceiverTest.java
@@ -1827,7 +1827,6 @@ class StreamReceiverTest extends ImperativeClientTestCase
{
}
}
- @SuppressWarnings("resource")
@Test
public void testStreamReceiverSessionCannotCreateNewResources() throws
Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
@@ -1884,8 +1883,7 @@ class StreamReceiverTest extends ImperativeClientTestCase
{
private void testReadPayloadInChunksFromLargerMessage(boolean
readWithArgs) throws Exception {
final byte[] body = new byte[100];
- final Random random = new Random();
- random.setSeed(System.currentTimeMillis());
+ final Random random = new Random(System.currentTimeMillis());
random.nextBytes(body);
final byte[] payload = createEncodedMessage(new Data(body));
@@ -1960,7 +1958,6 @@ class StreamReceiverTest extends ImperativeClientTestCase
{
}
}
- @SuppressWarnings("resource")
@Test
public void testStreamReceiverMessageThrowsOnAnyMessageModificationAPI()
throws Exception {
final byte[] body = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
@@ -2051,8 +2048,7 @@ class StreamReceiverTest extends ImperativeClientTestCase
{
@Test
public void testSkipPayloadInChunksFromSingleTransferMessage() throws
Exception {
final byte[] body = new byte[100];
- final Random random = new Random();
- random.setSeed(System.currentTimeMillis());
+ final Random random = new Random(System.currentTimeMillis());
random.nextBytes(body);
final byte[] payload = createEncodedMessage(new Data(body));
@@ -2130,13 +2126,11 @@ class StreamReceiverTest extends
ImperativeClientTestCase {
}
private void testReadPayloadInChunksFromLargerMultiTransferMessage(boolean
readWithArgs) throws Exception {
- final Random random = new Random();
final long seed = System.currentTimeMillis();
+ final Random random = new Random(seed);
final int numChunks = 4;
final int chunkSize = 30;
- random.setSeed(seed);
-
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
@@ -2227,13 +2221,11 @@ class StreamReceiverTest extends
ImperativeClientTestCase {
@Test
public void
testReadPayloadFromSplitFrameTransferWithBufferLargerThanTotalPayload() throws
Exception {
- final Random random = new Random();
final long seed = System.currentTimeMillis();
+ final Random random = new Random(seed);
final int numChunks = 4;
final int chunkSize = 30;
- random.setSeed(seed);
-
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
@@ -2654,7 +2646,6 @@ class StreamReceiverTest extends ImperativeClientTestCase
{
}
}
- @SuppressWarnings("resource")
@Test
public void testStreamDeliveryHandlesInvalidHeaderEncoding() throws
Exception {
final byte[] payload = createInvalidHeaderEncoding();
@@ -2704,7 +2695,6 @@ class StreamReceiverTest extends ImperativeClientTestCase
{
}
}
- @SuppressWarnings("resource")
@Test
public void testStreamDeliveryHandlesInvalidDeliveryAnnotationsEncoding()
throws Exception {
final byte[] payload = createInvalidDeliveryAnnotationsEncoding();
@@ -2754,7 +2744,6 @@ class StreamReceiverTest extends ImperativeClientTestCase
{
}
}
- @SuppressWarnings("resource")
@Test
public void testStreamDeliveryHandlesInvalidMessageAnnotationsEncoding()
throws Exception {
final byte[] payload = createInvalidMessageAnnotationsEncoding();
@@ -2804,7 +2793,6 @@ class StreamReceiverTest extends ImperativeClientTestCase
{
}
}
- @SuppressWarnings("resource")
@Test
public void testStreamDeliveryHandlesInvalidPropertiesEncoding() throws
Exception {
final byte[] payload = createInvalidPropertiesEncoding();
@@ -2854,7 +2842,6 @@ class StreamReceiverTest extends ImperativeClientTestCase
{
}
}
- @SuppressWarnings("resource")
@Test
public void
testStreamDeliveryHandlesInvalidApplicationPropertiesEncoding() throws
Exception {
final byte[] payload = createInvalidApplicationPropertiesEncoding();
@@ -2904,7 +2891,6 @@ class StreamReceiverTest extends ImperativeClientTestCase
{
}
}
- @SuppressWarnings("resource")
@Test
public void
testStreamDeliveryHandlesInvalidHeaderEncodingDuringBodyStreamOpen() throws
Exception {
final byte[] payload = createInvalidHeaderEncoding();
diff --git
a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/transport/netty4/NettyServer.java
b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/transport/netty4/NettyServer.java
index 6164acb9..5c6b0fe5 100644
---
a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/transport/netty4/NettyServer.java
+++
b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/transport/netty4/NettyServer.java
@@ -84,9 +84,9 @@ public abstract class NettyServer implements AutoCloseable {
private Channel serverChannel;
private final TransportOptions options;
private final SslOptions sslOptions;
- private int serverPort = SERVER_CHOOSES_PORT;
+ private volatile int serverPort = SERVER_CHOOSES_PORT;
private final boolean needClientAuth;
- private int maxFrameSize =
TransportOptions.DEFAULT_WEBSOCKET_MAX_FRAME_SIZE;
+ private volatile int maxFrameSize =
TransportOptions.DEFAULT_WEBSOCKET_MAX_FRAME_SIZE;
private String webSocketPath = WEBSOCKET_PATH;
private volatile boolean fragmentWrites;
private volatile SslHandler sslHandler;
diff --git
a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/util/SplayMap.java
b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/util/SplayMap.java
index 92244de8..c9d6ca9b 100644
--- a/protonj2/src/main/java/org/apache/qpid/protonj2/engine/util/SplayMap.java
+++ b/protonj2/src/main/java/org/apache/qpid/protonj2/engine/util/SplayMap.java
@@ -1240,7 +1240,7 @@ public class SplayMap<E> implements
NavigableMap<UnsignedInteger, E> {
SplayedEntry<E> linkPrev;
public SplayedEntry() {
- initialize(key, value);
+ initialize(0, null);
}
public SplayedEntry<E> initialize(int key, E value) {
diff --git
a/protonj2/src/test/java/org/apache/qpid/protonj2/codec/primitives/UUIDTypeCodecTest.java
b/protonj2/src/test/java/org/apache/qpid/protonj2/codec/primitives/UUIDTypeCodecTest.java
index f39bfbcd..c719a6d5 100644
---
a/protonj2/src/test/java/org/apache/qpid/protonj2/codec/primitives/UUIDTypeCodecTest.java
+++
b/protonj2/src/test/java/org/apache/qpid/protonj2/codec/primitives/UUIDTypeCodecTest.java
@@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
@@ -247,23 +248,19 @@ public class UUIDTypeCodecTest extends CodecTestSupport {
public void testWriteUUIDArrayWithMixedNullAndNotNullValues() throws
IOException {
ProtonBuffer buffer =
ProtonBufferAllocator.defaultAllocator().allocate();
- UUID[] source = new UUID[2];
- source[0] = UUID.randomUUID();
- source[1] = null;
+ final UUID[] source1 = new UUID[2];
+ source1[0] = UUID.randomUUID();
+ source1[1] = null;
- try {
- encoder.writeArray(buffer, encoderState, source);
- fail("Should not be able to encode array with mixed null and
non-null values");
- } catch (Exception e) {}
+ assertThrows(Exception.class, () -> encoder.writeArray(buffer,
encoderState, source1),
+ "Should not be able to encode array with mixed null and non-null
values");
- source = new UUID[2];
- source[0] = null;
- source[1] = UUID.randomUUID();
+ final UUID[] source2 = new UUID[2];
+ source2[0] = null;
+ source2[1] = UUID.randomUUID();
- try {
- encoder.writeArray(buffer, encoderState, source);
- fail("Should not be able to encode array with mixed null and
non-null values");
- } catch (Exception e) {}
+ assertThrows(Exception.class, () -> encoder.writeArray(buffer,
encoderState, source2),
+ "Should not be able to encode array with mixed null and non-null
values");
}
@Test
diff --git
a/protonj2/src/test/java/org/apache/qpid/protonj2/engine/impl/ProtonSenderTest.java
b/protonj2/src/test/java/org/apache/qpid/protonj2/engine/impl/ProtonSenderTest.java
index 168aa2fc..d8220e79 100644
---
a/protonj2/src/test/java/org/apache/qpid/protonj2/engine/impl/ProtonSenderTest.java
+++
b/protonj2/src/test/java/org/apache/qpid/protonj2/engine/impl/ProtonSenderTest.java
@@ -20,6 +20,7 @@ import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -3196,11 +3197,13 @@ public class ProtonSenderTest extends
ProtonEngineTestSupport {
if (!sendSettled) {
delivery.settle();
}
+
+ sent.add(delivery);
}
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
- sent.forEach(delivery -> assertEquals(delivery.getTag().tagBytes() ,
expectedTag));
+ sent.forEach(delivery ->
assertArrayEquals(delivery.getTag().tagBytes(), expectedTag));
peer.expectDetach().respond();
peer.expectClose().respond();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]