Get the tests passing again

This commit is contained in:
Chris Vest 2021-06-01 10:28:42 +02:00
parent c840a41e31
commit 60df2393f3
6 changed files with 18 additions and 2 deletions

View File

@ -891,6 +891,9 @@ public final class CompositeBuffer extends ResourceSupport<Buffer, CompositeBuff
throw new IllegalArgumentException("The split offset cannot be greater than the buffer capacity, " + throw new IllegalArgumentException("The split offset cannot be greater than the buffer capacity, " +
"but the split offset was " + splitOffset + ", and capacity is " + capacity() + '.'); "but the split offset was " + splitOffset + ", and capacity is " + capacity() + '.');
} }
if (!isAccessible()) {
throw attachTrace(bufferIsClosed(this));
}
if (!isOwned()) { if (!isOwned()) {
throw new IllegalStateException("Cannot split a buffer that is not owned."); throw new IllegalStateException("Cannot split a buffer that is not owned.");
} }

View File

@ -459,6 +459,9 @@ class NioBuffer extends ResourceSupport<Buffer, NioBuffer> implements Buffer, Re
throw new IllegalArgumentException("The split offset cannot be greater than the buffer capacity, " + throw new IllegalArgumentException("The split offset cannot be greater than the buffer capacity, " +
"but the split offset was " + splitOffset + ", and capacity is " + capacity() + '.'); "but the split offset was " + splitOffset + ", and capacity is " + capacity() + '.');
} }
if (!isAccessible()) {
throw attachTrace(bufferIsClosed(this));
}
if (!isOwned()) { if (!isOwned()) {
throw attachTrace(new IllegalStateException("Cannot split a buffer that is not owned.")); throw attachTrace(new IllegalStateException("Cannot split a buffer that is not owned."));
} }

View File

@ -108,6 +108,9 @@ public abstract class ResourceSupport<I extends Resource<I>, T extends ResourceS
*/ */
@Override @Override
public final Send<I> send() { public final Send<I> send() {
if (acquires < 0) {
throw attachTrace(createResourceClosedException());
}
if (!isOwned()) { if (!isOwned()) {
throw notSendableException(); throw notSendableException();
} }

View File

@ -506,6 +506,9 @@ class UnsafeBuffer extends ResourceSupport<Buffer, UnsafeBuffer> implements Buff
throw new IllegalArgumentException("The split offset cannot be greater than the buffer capacity, " + throw new IllegalArgumentException("The split offset cannot be greater than the buffer capacity, " +
"but the split offset was " + splitOffset + ", and capacity is " + capacity() + '.'); "but the split offset was " + splitOffset + ", and capacity is " + capacity() + '.');
} }
if (!isAccessible()) {
throw attachTrace(bufferIsClosed(this));
}
if (!isOwned()) { if (!isOwned()) {
throw attachTrace(new IllegalStateException("Cannot split a buffer that is not owned.")); throw attachTrace(new IllegalStateException("Cannot split a buffer that is not owned."));
} }

View File

@ -584,6 +584,9 @@ class MemSegBuffer extends ResourceSupport<Buffer, MemSegBuffer> implements Buff
throw new IllegalArgumentException("The split offset cannot be greater than the buffer capacity, " + throw new IllegalArgumentException("The split offset cannot be greater than the buffer capacity, " +
"but the split offset was " + splitOffset + ", and capacity is " + capacity() + '.'); "but the split offset was " + splitOffset + ", and capacity is " + capacity() + '.');
} }
if (!isAccessible()) {
throw attachTrace(bufferIsClosed(this));
}
if (!isOwned()) { if (!isOwned()) {
throw attachTrace(new IllegalStateException("Cannot split a buffer that is not owned.")); throw attachTrace(new IllegalStateException("Cannot split a buffer that is not owned."));
} }

View File

@ -17,6 +17,7 @@ package io.netty.buffer.api.tests;
import io.netty.buffer.api.Buffer; import io.netty.buffer.api.Buffer;
import io.netty.buffer.api.BufferAllocator; import io.netty.buffer.api.BufferAllocator;
import io.netty.buffer.api.BufferClosedException;
import io.netty.buffer.api.BufferRef; import io.netty.buffer.api.BufferRef;
import io.netty.buffer.api.Send; import io.netty.buffer.api.Send;
import io.netty.buffer.api.internal.ResourceSupport; import io.netty.buffer.api.internal.ResourceSupport;
@ -110,9 +111,9 @@ public class BufferSendTest extends BufferTestSupport {
try (BufferAllocator allocator = fixture.createAllocator(); try (BufferAllocator allocator = fixture.createAllocator();
Buffer buf = allocator.allocate(8)) { Buffer buf = allocator.allocate(8)) {
var send = buf.send(); var send = buf.send();
var exc = assertThrows(IllegalStateException.class, () -> buf.send()); var exc = assertThrows(BufferClosedException.class, () -> buf.send());
send.receive().close(); send.receive().close();
assertThat(exc).hasMessageContaining("Cannot send()"); assertThat(exc).hasMessageContaining("closed");
} }
} }