Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

revert 9a4be21 for close configuring channel auto-read #356

Merged
merged 1 commit into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.kafka.common.protocol.ApiKeys.API_VERSIONS;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Queues;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
Expand Down Expand Up @@ -84,15 +83,6 @@ public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exceptio
if (log.isDebugEnabled()) {
log.debug("Channel writability has changed to: {}", ctx.channel().isWritable());
}
if (ctx.channel().isWritable()) {
// set auto read to true if channel is writable.
ctx.channel().config().setAutoRead(true);
} else {
log.debug("channel is not writable, disable auto reading for back pressing");
ctx.channel().config().setAutoRead(false);
ctx.flush();
}
ctx.fireChannelWritabilityChanged();
}

// turn input ByteBuf msg, which send from client side, into KafkaHeaderAndRequest
Expand Down Expand Up @@ -527,9 +517,4 @@ public static ResponseAndRequest of(CompletableFuture<AbstractResponse> response
this.request = request;
}
}

@VisibleForTesting
public ChannelHandlerContext getCtx() {
return ctx;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import com.google.common.collect.Sets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.CharsetUtil;
import io.streamnative.pulsar.handlers.kop.KafkaCommandDecoder.KafkaHeaderAndRequest;
import io.streamnative.pulsar.handlers.kop.KafkaCommandDecoder.KafkaHeaderAndResponse;
import io.streamnative.pulsar.handlers.kop.coordinator.group.GroupCoordinator;
Expand All @@ -45,11 +43,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import java.util.stream.LongStream;

Expand Down Expand Up @@ -159,36 +153,6 @@ protected void cleanup() throws Exception {
super.internalCleanup();
}

@Test
public void testAutoReadEnableDisable() {
final ByteBuf buffer = Unpooled.copiedBuffer("Test", CharsetUtil.US_ASCII);
final EmbeddedChannel channel = new EmbeddedChannel(handler);
ByteBuf[] buffers = new ByteBuf[1000000];
for (int i = 0; i < buffers.length; i++) {
buffers[i] = buffer.duplicate().retain();
}
AtomicBoolean isChannelWritable = new AtomicBoolean(true);
ExecutorService service = Executors.newSingleThreadExecutor();

service.execute(() -> {
int count = 0;
while (count < 10) {
boolean isWritable = handler.getCtx().channel().isWritable();
if (!isWritable) {
isChannelWritable.set(false);
break;
}
count += 1;
try {
TimeUnit.MILLISECONDS.sleep(50);
} catch (Exception ignored) {}

}
});
channel.writeOutbound(buffers);
Assert.assertFalse(isChannelWritable.get());
}

@Test
public void testByteBufToRequest() {
int correlationId = 7777;
Expand Down