GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Move test to shared testsuite (#16928) (#16942) · netty/netty@31967ae

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • testsuite/src/main/java/io/netty/testsuite/transport/socket
    • DatagramUnicastIPv6MappedTest.java
    • DatagramUnicastTest.java
  • transport-native-epoll/src/test/java/io/netty/channel/epoll
    • EpollDatagramUnicastTest.java
  • transport-native-io_uring/src/test/java/io/netty/channel/uring
    • IoUringDatagramConnectedWriteExceptionTest.java
    • IoUringDatagramUnicastTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎testsuite/src/main/java/io/netty/testsuite/transport/socket/DatagramUnicastIPv6MappedTest.java‎

Copy file name to clipboardExpand all lines: testsuite/src/main/java/io/netty/testsuite/transport/socket/DatagramUnicastIPv6MappedTest.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected SocketAddress newSocketAddress() {
3232
}
3333

3434
@Override
35-
protected InetSocketAddress sendToAddress(InetSocketAddress serverAddress) {
35+
protected InetSocketAddress convertAnyAddress(InetSocketAddress serverAddress) {
3636
InetAddress addr = serverAddress.getAddress();
3737
if (addr.isAnyLocalAddress()) {
3838
return new InetSocketAddress(NetUtil.LOCALHOST4, serverAddress.getPort());
Collapse file

‎testsuite/src/main/java/io/netty/testsuite/transport/socket/DatagramUnicastTest.java‎

Copy file name to clipboardExpand all lines: testsuite/src/main/java/io/netty/testsuite/transport/socket/DatagramUnicastTest.java
+87-5Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import io.netty.bootstrap.Bootstrap;
1919
import io.netty.buffer.ByteBuf;
20+
import io.netty.buffer.ByteBufHolder;
2021
import io.netty.buffer.CompositeByteBuf;
2122
import io.netty.buffer.Unpooled;
2223
import io.netty.channel.Channel;
@@ -33,6 +34,7 @@
3334
import io.netty.util.internal.EmptyArrays;
3435
import org.junit.jupiter.api.Test;
3536
import org.junit.jupiter.api.TestInfo;
37+
import org.junit.jupiter.api.Timeout;
3638
import org.opentest4j.TestAbortedException;
3739

3840
import java.net.BindException;
@@ -44,14 +46,18 @@
4446
import java.net.SocketException;
4547
import java.nio.channels.NotYetConnectedException;
4648
import java.nio.channels.UnresolvedAddressException;
49+
import java.nio.charset.StandardCharsets;
4750
import java.util.ArrayList;
4851
import java.util.List;
52+
import java.util.concurrent.CompletableFuture;
4953
import java.util.concurrent.CountDownLatch;
5054
import java.util.concurrent.Semaphore;
5155
import java.util.concurrent.TimeUnit;
5256
import java.util.concurrent.atomic.AtomicReference;
5357

5458
import static org.assertj.core.api.Assumptions.assumeThat;
59+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
60+
import static org.junit.jupiter.api.Assertions.assertEquals;
5561
import static org.junit.jupiter.api.Assertions.assertFalse;
5662
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
5763
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -61,6 +67,8 @@
6167

6268
public abstract class DatagramUnicastTest extends AbstractDatagramTest {
6369

70+
private static final byte[] BAD_PREFIX = "BAD-PREFIX-".getBytes(StandardCharsets.UTF_8);
71+
private static final byte[] EXPECTED = "EXPECTED-direct-reader-index".getBytes(StandardCharsets.UTF_8);
6472
private static final byte[] BYTES = {0, 1, 2, 3};
6573
protected enum WrapType {
6674
NONE, DUP, SLICE, READ_ONLY
@@ -236,7 +244,7 @@ protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throw
236244
throw e;
237245
}
238246
SocketAddress sendAddress = address instanceof InetSocketAddress ?
239-
sendToAddress((InetSocketAddress) address) : address;
247+
convertAnyAddress((InetSocketAddress) address) : address;
240248
for (int i = 0; i < 100; i++) {
241249
try {
242250
client.send(new java.net.DatagramPacket(EmptyArrays.EMPTY_BYTES, 0, sendAddress));
@@ -277,7 +285,7 @@ protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) {
277285
Channel cc = cb.option(ChannelOption.DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION, true).
278286
handler(new ChannelInboundHandler() { }).register().get();
279287
try {
280-
InetSocketAddress goodHost = sendToAddress((InetSocketAddress) sc.localAddress());
288+
InetSocketAddress goodHost = convertAnyAddress((InetSocketAddress) sc.localAddress());
281289
InetSocketAddress unresolvedHost = new InetSocketAddress("NOT_A_REAL_ADDRESS", goodHost.getPort());
282290

283291
assertFalse(goodHost.isUnresolved());
@@ -333,7 +341,7 @@ public void channelRead0(ChannelHandlerContext ctx, Object msgs) {
333341

334342
SocketAddress localAddr = sc.localAddress();
335343
SocketAddress addr = localAddr instanceof InetSocketAddress ?
336-
sendToAddress((InetSocketAddress) sc.localAddress()) : localAddr;
344+
convertAnyAddress((InetSocketAddress) sc.localAddress()) : localAddr;
337345
List<Future<Void>> futures = new ArrayList<>(count);
338346
for (int i = 0; i < count; i++) {
339347
futures.add(write(cc, buf, addr, wrapType));
@@ -385,7 +393,7 @@ private void testSimpleSendWithConnect0(Bootstrap sb, Bootstrap cb, ByteBuf buf,
385393

386394
SocketAddress localAddr = sc.localAddress();
387395
SocketAddress addr = localAddr instanceof InetSocketAddress ?
388-
sendToAddress((InetSocketAddress) sc.localAddress()) : localAddr;
396+
convertAnyAddress((InetSocketAddress) sc.localAddress()) : localAddr;
389397
cc.connect(addr).syncUninterruptibly();
390398

391399
List<Future<Void>> futures = new ArrayList<>();
@@ -468,6 +476,80 @@ private static Future<Void> write(Channel cc, ByteBuf buf, WrapType wrapType) {
468476
}
469477
}
470478

479+
@Test
480+
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
481+
public void testWriteOffsetBytebuf(TestInfo testInfo) throws Throwable {
482+
run(testInfo, new Runner<Bootstrap, Bootstrap>() {
483+
@Override
484+
public void run(Bootstrap sb, Bootstrap cb) throws Throwable {
485+
testWriteOffsetBytebuf(sb, cb);
486+
}
487+
});
488+
}
489+
490+
private void testWriteOffsetBytebuf(Bootstrap sb, Bootstrap cb) throws Throwable {
491+
ByteBuf buf = Unpooled.directBuffer(BAD_PREFIX.length + EXPECTED.length);
492+
buf.writeBytes(BAD_PREFIX);
493+
buf.writeBytes(EXPECTED);
494+
buf.readerIndex(BAD_PREFIX.length);
495+
try {
496+
for (WrapType type : WrapType.values()) {
497+
testWriteOffsetBytebuf0(sb, cb, buf.retain(), EXPECTED, type);
498+
}
499+
assertEquals(1, buf.refCnt());
500+
} finally {
501+
buf.release();
502+
}
503+
}
504+
505+
private void testWriteOffsetBytebuf0(Bootstrap sb, Bootstrap cb, ByteBuf buf, byte[] expected,
506+
WrapType wrapType) throws Throwable {
507+
CompletableFuture<byte[]> received = new CompletableFuture<>();
508+
sb.handler(new SimpleChannelInboundHandler<ByteBufHolder>() {
509+
@Override
510+
protected void channelRead0(ChannelHandlerContext ctx, ByteBufHolder packet) {
511+
ByteBuf content = packet.content();
512+
byte[] bytes = new byte[content.readableBytes()];
513+
content.getBytes(content.readerIndex(), bytes);
514+
received.complete(bytes);
515+
}
516+
});
517+
518+
Channel sc = null;
519+
Channel cc = null;
520+
try {
521+
sc = sb.bind(newSocketAddress()).get();
522+
SocketAddress serverAddress = sc.localAddress();
523+
if (serverAddress instanceof InetSocketAddress) {
524+
// Correctly ha
525+
serverAddress = convertAnyAddress((InetSocketAddress) serverAddress);
526+
}
527+
cb.handler(new SimpleChannelInboundHandler<ByteBufHolder>() {
528+
@Override
529+
protected void channelRead0(ChannelHandlerContext ctx, ByteBufHolder msg) {
530+
// no-op
531+
}
532+
});
533+
534+
cc = cb.connect(serverAddress).get();
535+
Future<Void> wf = write(cc, buf, wrapType);
536+
cc.flush();
537+
wf.sync();
538+
byte[] actual = received.join();
539+
assertArrayEquals(expected, actual);
540+
} finally {
541+
// release as we used buf.retain() before
542+
buf.release();
543+
544+
if (cc != null) {
545+
cc.close().sync();
546+
}
547+
if (sc != null) {
548+
sc.close().sync();
549+
}
550+
}
551+
}
552+
471553
protected abstract boolean isConnected(Channel channel);
472554

473555
protected abstract Channel setupClientChannel(Bootstrap cb, byte[] bytes, CountDownLatch latch,
@@ -491,7 +573,7 @@ protected static void closeChannel(Channel channel) throws Exception {
491573
}
492574
}
493575

494-
protected InetSocketAddress sendToAddress(InetSocketAddress serverAddress) {
576+
protected InetSocketAddress convertAnyAddress(InetSocketAddress serverAddress) {
495577
InetAddress addr = serverAddress.getAddress();
496578
if (addr.isAnyLocalAddress()) {
497579
if (addr instanceof Inet6Address) {
Collapse file

‎transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDatagramUnicastTest.java‎

Copy file name to clipboardExpand all lines: transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollDatagramUnicastTest.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void channelRead0(ChannelHandlerContext ctx, DatagramPacket packet) {
158158
if (sc instanceof EpollDatagramChannel) {
159159
assertEquals(gro, sc.config().getOption(EpollChannelOption.UDP_GRO));
160160
}
161-
InetSocketAddress addr = sendToAddress((InetSocketAddress) sc.localAddress());
161+
InetSocketAddress addr = convertAnyAddress((InetSocketAddress) sc.localAddress());
162162
final ByteBuf buffer;
163163
if (composite) {
164164
CompositeByteBuf compositeBuffer = Unpooled.compositeBuffer();
Collapse file

‎transport-native-io_uring/src/test/java/io/netty/channel/uring/IoUringDatagramConnectedWriteExceptionTest.java‎

Copy file name to clipboardExpand all lines: transport-native-io_uring/src/test/java/io/netty/channel/uring/IoUringDatagramConnectedWriteExceptionTest.java
-77Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -16,92 +16,15 @@
1616
package io.netty.channel.uring;
1717

1818
import io.netty.bootstrap.Bootstrap;
19-
import io.netty.buffer.ByteBuf;
20-
import io.netty.buffer.ByteBufAllocator;
21-
import io.netty.channel.Channel;
22-
import io.netty.channel.ChannelHandlerContext;
23-
import io.netty.channel.ChannelOption;
24-
import io.netty.channel.SimpleChannelInboundHandler;
25-
import io.netty.channel.socket.DatagramPacket;
2619
import io.netty.testsuite.transport.TestsuitePermutation;
2720
import io.netty.testsuite.transport.socket.DatagramConnectedWriteExceptionTest;
28-
import io.netty.util.NetUtil;
29-
import org.junit.jupiter.api.Test;
30-
import org.junit.jupiter.api.TestInfo;
31-
import org.junit.jupiter.api.Timeout;
3221

33-
import java.net.InetSocketAddress;
34-
import java.nio.charset.StandardCharsets;
3522
import java.util.List;
36-
import java.util.concurrent.CompletableFuture;
37-
import java.util.concurrent.TimeUnit;
38-
39-
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4023

4124
public class IoUringDatagramConnectedWriteExceptionTest extends DatagramConnectedWriteExceptionTest {
4225

43-
private static final byte[] BAD_PREFIX = "BAD-PREFIX-".getBytes(StandardCharsets.UTF_8);
44-
private static final byte[] EXPECTED = "EXPECTED-direct-reader-index".getBytes(StandardCharsets.UTF_8);
45-
4626
@Override
4727
protected List<TestsuitePermutation.BootstrapFactory<Bootstrap>> newFactories() {
4828
return IoUringSocketTestPermutation.INSTANCE.datagramSocket();
4929
}
50-
51-
@Test
52-
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
53-
public void testWriteOffsetBytebuf(TestInfo testInfo) throws Throwable {
54-
run(testInfo, (Runner<Bootstrap>) this::testWriteOffsetBytebuf);
55-
}
56-
57-
private void testWriteOffsetBytebuf(Bootstrap clientBootstrap) throws Throwable {
58-
CompletableFuture<byte[]> received = new CompletableFuture<>();
59-
Bootstrap serverBootstrap = clientBootstrap.clone()
60-
.option(ChannelOption.SO_BROADCAST, false)
61-
.handler(new SimpleChannelInboundHandler<DatagramPacket>() {
62-
@Override
63-
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket packet) {
64-
ByteBuf content = packet.content();
65-
byte[] bytes = new byte[content.readableBytes()];
66-
content.getBytes(content.readerIndex(), bytes);
67-
received.complete(bytes);
68-
}
69-
});
70-
71-
Channel serverChannel = serverBootstrap.bind(new InetSocketAddress(NetUtil.LOCALHOST, 0)).get();
72-
InetSocketAddress serverAddress = (InetSocketAddress) serverChannel.localAddress();
73-
74-
clientBootstrap.option(ChannelOption.AUTO_READ, false)
75-
.handler(new SimpleChannelInboundHandler<DatagramPacket>() {
76-
@Override
77-
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) {
78-
// no-op
79-
}
80-
});
81-
82-
Channel clientChannel = clientBootstrap.connect(serverAddress).get();
83-
try {
84-
ByteBuf content = directReaderIndex(serverChannel.alloc());
85-
clientChannel.writeAndFlush(new DatagramPacket(content, serverAddress)).sync();
86-
87-
byte[] actual = received.join();
88-
assertArrayEquals(EXPECTED, actual);
89-
} finally {
90-
if (clientChannel != null) {
91-
clientChannel.close().sync();
92-
}
93-
if (serverChannel != null) {
94-
serverChannel.close().sync();
95-
}
96-
}
97-
}
98-
99-
private static ByteBuf directReaderIndex(ByteBufAllocator alloc) {
100-
ByteBuf buf = alloc.directBuffer(BAD_PREFIX.length + EXPECTED.length);
101-
buf.writeBytes(BAD_PREFIX);
102-
buf.writeBytes(EXPECTED);
103-
buf.readerIndex(BAD_PREFIX.length);
104-
return buf;
105-
}
106-
10730
}
Collapse file

‎transport-native-io_uring/src/test/java/io/netty/channel/uring/IoUringDatagramUnicastTest.java‎

Copy file name to clipboardExpand all lines: transport-native-io_uring/src/test/java/io/netty/channel/uring/IoUringDatagramUnicastTest.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void channelReadComplete(ChannelHandlerContext ctx) {
8484
}
8585
}).option(ChannelOption.RECVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(2048))
8686
.bind(newSocketAddress()).get();
87-
InetSocketAddress addr = sendToAddress((InetSocketAddress) sc.localAddress());
87+
InetSocketAddress addr = convertAnyAddress((InetSocketAddress) sc.localAddress());
8888
cc.writeAndFlush(new DatagramPacket(cc.alloc().buffer().writeZero(512), addr)).sync();
8989

9090
readLatch.await();

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.