Skip to content

Commit

Permalink
RATIS-2191. Add ResourceLeakDetector to Netty tests (#1180)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivandika3 authored Nov 22, 2024
1 parent 06affdf commit 04396ca
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public abstract class FileStoreStreamingBaseTest <CLUSTER extends MiniRaftCluste
FileStoreStateMachine.class, StateMachine.class);
ConfUtils.setFile(p::setFile, FileStoreCommon.STATEMACHINE_DIR_KEY,
new File(getClassTestDir(), "filestore"));
DataStreamTestUtils.enableResourceLeakDetector();
}

static final int NUM_PEERS = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public abstract class DataStreamClusterTests<CLUSTER extends MiniRaftCluster> ex
implements MiniRaftCluster.Factory.Get<CLUSTER> {
{
setStateMachine(MultiDataStreamStateMachine.class);
DataStreamTestUtils.enableResourceLeakDetector();
}

public static final int NUM_SERVERS = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
import org.apache.ratis.statemachine.TransactionContext;
import org.apache.ratis.statemachine.impl.BaseStateMachine;
import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
import org.apache.ratis.thirdparty.io.netty.buffer.ByteBufUtil;
import org.apache.ratis.thirdparty.io.netty.util.ResourceLeakDetector;
import org.apache.ratis.thirdparty.io.netty.util.ResourceLeakDetector.Level;
import org.apache.ratis.util.CollectionUtils;
import org.apache.ratis.util.FileUtils;
import org.apache.ratis.util.JavaUtils;
Expand Down Expand Up @@ -418,4 +421,13 @@ static void assertLogEntry(RaftServer.Division division, SingleDataStream stream
final LogEntryProto entryFromLog = searchLogEntry(ClientInvocationId.valueOf(request), division.getRaftLog());
Assertions.assertEquals(entryFromStream, entryFromLog);
}

ResourceLeakDetector.LeakListener LEAK_LISTENER = (resourceType, records) -> {
throw new IllegalStateException("Leak detected for resource type: " + resourceType + records);
};

static void enableResourceLeakDetector() {
ResourceLeakDetector.setLevel(Level.PARANOID);
ByteBufUtil.setLeakListener(DataStreamTestUtils.LEAK_LISTENER);
}
}

0 comments on commit 04396ca

Please sign in to comment.