/*
* Copyright (C) 2012, 2016 higherfrequencytrading.com
* Copyright (C) 2016 Roman Leventov
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
package net.openhft.chronicle.map;
import com.google.common.collect.Lists;
import net.openhft.chronicle.bytes.NoBytesStore;
import net.openhft.chronicle.core.OS;
import net.openhft.chronicle.core.values.IntValue;
import net.openhft.chronicle.hash.serialization.impl.StringSizedReader;
import net.openhft.chronicle.hash.serialization.impl.StringUtf8DataAccess;
import net.openhft.chronicle.values.Values;
import org.junit.*;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import sun.misc.Cleaner;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.ref.WeakReference;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
@RunWith(Parameterized.class)
public class MemoryLeaksTest {
/**
* Accounting {@link CountedStringReader} creation and finalization. All serializers,
* created since the map creation, should become unreachable after map.close() or collection by
* Cleaner, it means that map contexts (referencing serializers) are collected by the GC
*/
private final AtomicInteger serializerCount = new AtomicInteger();
private final List> serializers = new ArrayList<>();
@Rule
public TemporaryFolder folder = new TemporaryFolder();
private boolean persisted;
private ChronicleMapBuilder builder;
private boolean closeWithinContext;
public MemoryLeaksTest(String testType, boolean replicated, boolean persisted, boolean closeWithinContext) {
this.persisted = persisted;
this.closeWithinContext = closeWithinContext;
builder = ChronicleMap
.of(IntValue.class, String.class)
.valueReaderAndDataAccess(new CountedStringReader(), new StringUtf8DataAccess());
if (replicated)
builder.replication((byte) 1);
builder.entries(1).averageValueSize(1);
}
@Parameterized.Parameters(name = "{0}")
public static Collection