Skip to content

Commit 5849049

Browse files
committed
Refine tests
1 parent 0b1203d commit 5849049

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/test/java/com/rabbitmq/stream/impl/DedupIdempotencyTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.function.Supplier;
4444
import java.util.stream.Collectors;
4545
import java.util.stream.IntStream;
46+
import org.junit.jupiter.api.AfterEach;
4647
import org.junit.jupiter.api.BeforeEach;
4748
import org.junit.jupiter.api.Test;
4849

@@ -57,7 +58,12 @@ public class DedupIdempotencyTest {
5758
void init() {
5859
EnvironmentBuilder environmentBuilder =
5960
Environment.builder().netty().eventLoopGroup(eventLoopGroup).environmentBuilder();
60-
environment = environmentBuilder.build();
61+
this.environment = environmentBuilder.build();
62+
}
63+
64+
@AfterEach
65+
void tearDown() {
66+
this.environment.close();
6167
}
6268

6369
@Test

src/test/java/com/rabbitmq/stream/impl/StreamProducerUnitTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@
3939
import com.rabbitmq.stream.impl.Client.OutboundEntityWriteCallback;
4040
import io.netty.buffer.ByteBuf;
4141
import io.netty.buffer.ByteBufAllocator;
42+
import io.netty.buffer.UnpooledByteBufAllocator;
4243
import io.netty.channel.Channel;
4344
import io.netty.channel.ChannelFuture;
4445
import java.time.Duration;
46+
import java.util.Queue;
4547
import java.util.Set;
4648
import java.util.concurrent.ConcurrentHashMap;
49+
import java.util.concurrent.ConcurrentLinkedQueue;
4750
import java.util.concurrent.CountDownLatch;
4851
import java.util.concurrent.Executors;
4952
import java.util.concurrent.ScheduledExecutorService;
@@ -70,7 +73,7 @@ public class StreamProducerUnitTest {
7073
@Mock Channel channel;
7174
@Mock ChannelFuture channelFuture;
7275

73-
Set<ByteBuf> buffers = ConcurrentHashMap.newKeySet();
76+
Queue<ByteBuf> buffers = new ConcurrentLinkedQueue<>();
7477

7578
ScheduledExecutorService executorService;
7679
Clock clock = new Clock();
@@ -82,15 +85,16 @@ public class StreamProducerUnitTest {
8285
void init() {
8386
mocks = MockitoAnnotations.openMocks(this);
8487
executorService = Executors.newScheduledThreadPool(2);
85-
when(channel.alloc()).thenReturn(Utils.byteBufAllocator());
88+
ByteBufAllocator allocator = new UnpooledByteBufAllocator(false);
89+
when(channel.alloc()).thenReturn(allocator);
8690
when(channel.writeAndFlush(Mockito.any())).thenReturn(channelFuture);
8791
when(client.allocateNoCheck(any(ByteBufAllocator.class), anyInt()))
8892
.thenAnswer(
8993
(Answer<ByteBuf>)
9094
invocation -> {
91-
ByteBufAllocator allocator = invocation.getArgument(0);
95+
ByteBufAllocator alloc = invocation.getArgument(0);
9296
int capacity = invocation.getArgument(1);
93-
ByteBuf buffer = allocator.buffer(capacity);
97+
ByteBuf buffer = alloc.buffer(capacity);
9498
buffers.add(buffer);
9599
return buffer;
96100
});

0 commit comments

Comments
 (0)