Update netty

This commit is contained in:
Andrea Cavalli 2021-09-22 13:41:20 +02:00
parent a4beebf355
commit 9ba0b16f41
5 changed files with 32 additions and 9 deletions

View File

@ -273,8 +273,7 @@ class MemSegBuffer extends AdaptableBuffer<MemSegBuffer> implements Buffer, Read
}
// </editor-fold>
@Override
public long nativeAddress() {
private long nativeAddress() {
if (!isAccessible()) {
throw bufferIsClosed(this);
}

View File

@ -17,6 +17,7 @@ package io.netty.buffer.api.tests;
import io.netty.buffer.api.Buffer;
import io.netty.buffer.api.BufferAllocator;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@ -233,7 +234,12 @@ public class BufferBulkAccessTest extends BufferTestSupport {
public void heapBufferMustHaveZeroAddress(Fixture fixture) {
try (BufferAllocator allocator = fixture.createAllocator();
Buffer buf = allocator.allocate(8)) {
assertThat(buf.nativeAddress()).isZero();
AtomicLong nativeAddress = new AtomicLong();
buf.forEachWritable(0, (index, component) -> {
nativeAddress.set(component.writableNativeAddress());
return false;
});
assertThat(nativeAddress.get()).isZero();
}
}
@ -242,7 +248,12 @@ public class BufferBulkAccessTest extends BufferTestSupport {
public void directBufferMustHaveNonZeroAddress(Fixture fixture) {
try (BufferAllocator allocator = fixture.createAllocator();
Buffer buf = allocator.allocate(8)) {
assertThat(buf.nativeAddress()).isNotZero();
AtomicLong nativeAddress = new AtomicLong();
buf.forEachWritable(0, (index, component) -> {
nativeAddress.set(component.writableNativeAddress());
return false;
});
assertThat(nativeAddress.get()).isNotZero();
}
}

View File

@ -22,17 +22,25 @@ import io.netty.buffer.api.BufferReadOnlyException;
import io.netty.buffer.api.CompositeBuffer;
import io.netty.buffer.api.Send;
import io.netty.buffer.api.internal.ResourceSupport;
import io.netty.buffer.api.internal.Statics;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import static io.netty.buffer.api.internal.Statics.acquire;
import static io.netty.buffer.api.internal.Statics.isOwned;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class BufferCompositionTest extends BufferTestSupport {
private static boolean isOwned(CompositeBuffer composite) {
return (Statics.isOwned((ResourceSupport<?, ?>) composite));
}
private static boolean isOwned(Buffer composite) {
return (Statics.isOwned((ResourceSupport<?, ?>) composite));
}
@Test
public void compositeBuffersCannotHaveDuplicateComponents() {
try (BufferAllocator allocator = BufferAllocator.onHeapUnpooled()) {
@ -56,7 +64,7 @@ public class BufferCompositionTest extends BufferTestSupport {
allocator.allocate(8).send(),
allocator.allocate(8).send())) {
assertEquals(24, composite.capacity());
assertTrue(isOwned((ResourceSupport<?, ?>) composite));
assertTrue(isOwned(composite));
}
}
@ -113,7 +121,7 @@ public class BufferCompositionTest extends BufferTestSupport {
Buffer a = allocator.allocate(8);
Buffer b = allocator.allocate(8);
CompositeBuffer composed = CompositeBuffer.compose(allocator, a.send())) {
try (Buffer ignore = acquire(composed)) {
try (Buffer ignore = Statics.acquire((ResourceSupport<?, ?>) composed)) {
var exc = assertThrows(IllegalStateException.class, () -> composed.extendWith(b.send()));
assertThat(exc).hasMessageContaining("owned");
}

View File

@ -617,6 +617,11 @@ public abstract class ByteToMessageDecoder extends ChannelHandlerAdapter {
return ctx.alloc();
}
@Override
public BufferAllocator bufferAllocator() {
return ctx.bufferAllocator();
}
@Override
@Deprecated
public <T> Attribute<T> attr(AttributeKey<T> key) {

View File

@ -71,7 +71,7 @@
<netty.version>5.0.0.Final-SNAPSHOT</netty.version>
<netty.build.version>29</netty.build.version>
<!-- Java version for source and bytecode compatibility. -->
<java.compatibility>11</java.compatibility>
<java.compatibility>17</java.compatibility>
<!-- Java version actually used to perform the build; compiling and testing. -->
<java.version>17</java.version>
<junit.version>5.7.0</junit.version>