Skip to content
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 @@ -24,15 +24,15 @@ public class CountingNettyResourceLeakDetector<T> extends ResourceLeakDetector<T
*/
public static void activate() {
ResourceLeakDetectorFactory.setResourceLeakDetectorFactory(new CountingNettyResourceLeakDetector.MyResourceLeakDetectorFactory());
CountingNettyResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID);
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID);
numLeaksFoundAtomic.set(0);
}

/**
* Do everything necessary to turn leak detection on with the highest sensitivity.
*/
public static void deactivate() {
CountingNettyResourceLeakDetector.setLevel(Level.DISABLED);
ResourceLeakDetector.setLevel(Level.DISABLED);
numLeaksFoundAtomic.set(0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.lang.management.ManagementFactory;

public class HeapDumper {
private HeapDumper() {}
/**
* Utility method to create an hmap file to show all of the objects within the JVM.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public class NettyLeakCheckTestExtension implements InvocationInterceptor {
private final boolean allLeakChecksAreDisabled;
public NettyLeakCheckTestExtension() {
allLeakChecksAreDisabled =
System.getProperty("disableMemoryLeakTests", "").toLowerCase().equals("true");
System.getProperty("disableMemoryLeakTests", "").equalsIgnoreCase("true");
}

private void wrapWithLeakChecks(ExtensionContext extensionContext, Callable repeatCall, Callable finalCall)
throws Throwable {
private <T> void wrapWithLeakChecks(ExtensionContext extensionContext,
Callable<T> repeatCall, Callable<T> finalCall) throws Throwable {
if (allLeakChecksAreDisabled ||
getAnnotation(extensionContext).map(a -> a.disableLeakChecks()).orElse(false)) {
CountingNettyResourceLeakDetector.deactivate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ private JSONObject jsonFromHttpDataUnsafe(List<byte[]> data) throws IOException
Scanner scanner = new Scanner(collatedStream, StandardCharsets.UTF_8);
scanner.useDelimiter("\r\n\r\n"); // The headers are seperated from the body with two newlines.
String head = scanner.next();
int header_length = head.getBytes(StandardCharsets.UTF_8).length + 4; // The extra 4 bytes accounts for the two newlines.
int headerLength = head.getBytes(StandardCharsets.UTF_8).length + 4; // The extra 4 bytes accounts for the two newlines.
// SequenceInputStreams cannot be reset, so it's recreated from the original data.
SequenceInputStream bodyStream = ReplayUtils.byteArraysToInputStream(data);
bodyStream.skip(header_length);
for (int leftToSkip = headerLength; leftToSkip > 0; leftToSkip -= bodyStream.skip(leftToSkip)) {}

// There are several limitations introduced by using the HTTP.toJSONObject call.
// 1. We need to replace "\r\n" with "\n" which could mask differences in the responses.
// 2. It puts all headers as top level keys in the JSON object, instead of e.g. inside a "header" object.
// We deal with this in the code that reads these JSONs, but it's a more brittle and error-prone format
// than it would be otherwise.
// TODO: Refactor how messages are converted to JSON and consider using a more sophisticated HTTP parsing strategy.
JSONObject message = HTTP.toJSONObject(head.replaceAll("\r\n", "\n"));
JSONObject message = HTTP.toJSONObject(head.replace("\r\n", "\n"));
String base64body = Base64.getEncoder().encodeToString(bodyStream.readAllBytes());
message.put("body", base64body);
return message;
Expand All @@ -100,7 +100,7 @@ private JSONObject jsonFromHttpData(@NonNull List<byte[]> data, Duration latency
return message;
}

private JSONObject toJSONObject(SourceTargetCaptureTuple triple) throws IOException {
private JSONObject toJSONObject(SourceTargetCaptureTuple triple) {
// TODO: Use Netty to parse the packets as HTTP rather than json.org (we can also remove it as a dependency)
JSONObject meta = new JSONObject();
meta.put("sourceRequest", jsonFromHttpData(triple.sourcePair.requestData.packetBytes));
Expand Down
Loading