Skip to content

Commit

Permalink
Enabled checking that all AbstractCloseable are closed after test, Op…
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-lawrey committed May 28, 2020
1 parent ae36946 commit f686f1f
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions src/main/java/net/openhft/chronicle/bytes/MappedFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import net.openhft.chronicle.core.*;
import net.openhft.chronicle.core.io.AbstractCloseable;
import net.openhft.chronicle.core.io.Closeable;
import net.openhft.chronicle.core.io.IORuntimeException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -50,7 +49,6 @@
*/
@SuppressWarnings({"rawtypes", "unchecked", "restriction"})
public class MappedFile extends AbstractCloseable implements ReferenceCounted {
static final Map<MappedFile, StackTrace> MAPPED_FILE_STACK_TRACE_MAP = Collections.synchronizedMap(new WeakHashMap<>());
private static final long DEFAULT_CAPACITY = 128L << 40;

// A single JVM cannot lock a distinct canonical file more than once
Expand Down Expand Up @@ -95,9 +93,6 @@ protected MappedFile(@NotNull final File file,
doNotCloseOnInterrupt9(this.fileChannel);
else
doNotCloseOnInterrupt(this.fileChannel);

if (Jvm.isResourceTracing())
registerMappedFile(this);
}

private static void logNewChunk(final String filename,
Expand All @@ -115,21 +110,8 @@ private static void logNewChunk(final String filename,
Jvm.debug().on(MappedFile.class, message);
}

private static void registerMappedFile(final MappedFile mappedFile) {
MAPPED_FILE_STACK_TRACE_MAP.put(mappedFile, new StackTrace("Created here, file=" + mappedFile.file()));
}

public static void checkMappedFiles() {
AssertionError openFiles = new AssertionError("Files still open");
synchronized (MAPPED_FILE_STACK_TRACE_MAP) {
for (Map.Entry<MappedFile, StackTrace> entry : MAPPED_FILE_STACK_TRACE_MAP.entrySet()) {
if (!entry.getKey().isClosed())
openFiles.addSuppressed(entry.getValue());
Closeable.closeQuietly(entry.getKey());
}
}
if (openFiles.getSuppressed().length > 0)
throw openFiles;
AbstractCloseable.assertCloseablesClosed();
}

@NotNull
Expand Down

0 comments on commit f686f1f

Please sign in to comment.