/*
 *      Copyright (C) 2015  higherfrequencytrading.com
 *
 *      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 <http://www.gnu.org/licenses/>.
 */

package net.openhft.chronicle.map;

import net.openhft.chronicle.core.OS;
import net.openhft.chronicle.set.Builder;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.io.IOException;

public class MaximumChronicleMapSizeTest {

    @Before
    public void assumeLinux() {
        Assume.assumeTrue(OS.isLinux());
    }

    @Test
    public void maximumInMemoryChronicleMapSizeTest() {
        long maxSize = 1 << 30;
        for (; ; maxSize *= 2) {
            try (ChronicleMap<Long, Long> map = ChronicleMap
                    .of(Long.class, Long.class)
                    .entries(maxSize)
                    .create()) {
                map.put(1L, 1L);
            } catch (Throwable e) {
                e.printStackTrace();
                break;
            }
        }
        System.out.println("Max in-memory chronicle map size is " + (maxSize / 2));
    }

    @Test
    public void maximumPersistedChronicleMapSizeTest() throws IOException {
        File file = Builder.getPersistenceFile();
        long maxSize = 1 << 30;
        for (; ; maxSize *= 2) {
            try (ChronicleMap<Long, Long> map = ChronicleMap
                    .of(Long.class, Long.class)
                    .entries(maxSize)
                    .createPersistedTo(file)) {
                map.put(1L, 1L);
            } catch (Throwable e) {
                e.printStackTrace();
                break;
            } finally {
                file.delete();
            }
        }
        System.out.println("Max persisted chronicle map size is " + (maxSize / 2));
    }
}

@@ -1191,33 +1191,33 @@
  maxSize = 1 %3C%3C 
-3
+2
 0;%0A        for (
@@ -1441,32 +1441,114 @@
 ap.put(1L, 1L);%0A
+                System.out.println(%22In-memory chronicle map size is %22 + maxSize);%0A
             %7D ca
@@ -1655,92 +1655,8 @@
   %7D%0A
-        System.out.println(%22Max in-memory chronicle map size is %22 + (maxSize / 2));%0A
     
@@ -1822,17 +1822,17 @@
  = 1 %3C%3C 
-3
+2
 0;%0A     
@@ -2079,32 +2079,114 @@
 ap.put(1L, 1L);%0A
+                System.out.println(%22Persisted chronicle map size is %22 + maxSize);%0A
             %7D ca
@@ -2348,91 +2348,8 @@
   %7D%0A
-        System.out.println(%22Max persisted chronicle map size is %22 + (maxSize / 2));
 %0A   

Print progress in MaximumChronicleMapSizeTest