<commit_before>package net.openhft.chronicle.map;

import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
import org.junit.*;

import java.io.Closeable;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

/**
 * @author <NAME>.
 */
public class TcpReplicationSoakTest {


    private ChronicleMap<Integer, CharSequence> map1;
    private ChronicleMap<Integer, CharSequence> map2;

    static int s_port = 8010;
    int valueSize = 1000000;

    char[] value = new char[valueSize];


    @Before
    public void setup() throws IOException {
        Arrays.fill(value, 'X');

        int keySize = 4;
        int entrySize = keySize + valueSize;

        final InetSocketAddress endpoint = new InetSocketAddress("localhost", s_port + 1);

        {
            final TcpTransportAndNetworkConfig tcpConfig1 = TcpTransportAndNetworkConfig.of(s_port,
                    endpoint).autoReconnectedUponDroppedConnection(true).name("      map1")
                    .heartBeatInterval(1, TimeUnit.SECONDS)
                    .packetSize(1024 * 64);


            map1 = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
                    .entries(entrySize)
                    .actualSegments(1)
                    .replication((byte) 1, tcpConfig1)
                    .instance()
                    .name("map1")
                    .create();
        }
        {
            final TcpTransportAndNetworkConfig tcpConfig2 = TcpTransportAndNetworkConfig.of
                    (s_port + 1).autoReconnectedUponDroppedConnection(true).name("map2")
                    .heartBeatInterval(1, TimeUnit.SECONDS)
                    .packetSize(1024 * 64);

            map2 = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
                    .entries(entrySize)
                    .replication((byte) 2, tcpConfig2)
                    .instance()
                    .name("map2")
                    .create();

        }
        s_port += 2;
    }


    @After
    public void tearDown() throws InterruptedException {

        for (final Closeable closeable : new Closeable[]{map1, map2}) {
            try {
                closeable.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        System.gc();
    }

    Set<Thread> threads;

    @Before
    public void sampleThreads() {
        threads = Thread.getAllStackTraces().keySet();
    }

    @After
    public void checkThreadsShutdown() {
        StatelessClientTest.checkThreadsShutdown(threads);
    }

    @Ignore("HCOLL-246 Tcp Replication fails with large values or entries sizes that don't " +
            "included internal replication bytes")
    @Test
    public void testLargeValues() throws IOException, InterruptedException {

        map1.put(1, new String(value));

        Thread.sleep(1000);
        System.out.println("\nwaiting till equal");

        waitTillEqual(10000);

        Assert.assertEquals(map1, map2);

    }


    private void waitTillEqual(final int timeOutMs) throws InterruptedException {

        Map map1UnChanged = new HashMap();
        Map map2UnChanged = new HashMap();<commit_msg>updated tests<commit_after>package net.openhft.chronicle.map;

import net.openhft.chronicle.hash.replication.TcpTransportAndNetworkConfig;
import org.junit.*;

import java.io.Closeable;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

/**
 * @author <NAME>.
 */
public class TcpReplicationSoakTest {


    private ChronicleMap<Integer, CharSequence> map1;
    private ChronicleMap<Integer, CharSequence> map2;

    static int s_port = 8010;
    int valueSize = 1000000;

    char[] value = new char[valueSize];


    @Before
    public void setup() throws IOException {
        Arrays.fill(value, 'X');

        int keySize = 4;
        int entrySize = keySize + valueSize;

        final InetSocketAddress endpoint = new InetSocketAddress("localhost", s_port + 1);

        {
            final TcpTransportAndNetworkConfig tcpConfig1 = TcpTransportAndNetworkConfig.of(s_port,
                    endpoint).autoReconnectedUponDroppedConnection(true).name("      map1")
                    .heartBeatInterval(1, TimeUnit.SECONDS)
                    .packetSize(1024 * 64);


            map1 = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
                    .entries(entrySize)
                    .actualSegments(1)
                    .replication((byte) 1, tcpConfig1)
                    .instance()
                    .name("map1")
                    .create();
        }
        {
            final TcpTransportAndNetworkConfig tcpConfig2 = TcpTransportAndNetworkConfig.of
                    (s_port + 1).autoReconnectedUponDroppedConnection(true).name("map2")
                    .heartBeatInterval(1, TimeUnit.SECONDS)
                    .packetSize(1024 * 64);

            map2 = ChronicleMapBuilder.of(Integer.class, CharSequence.class)
                    .entries(entrySize)
                    .replication((byte) 2, tcpConfig2)
                    .instance()
                    .name("map2")
                    .create();

        }
        s_port += 2;
    }


    @After
    public void tearDown() throws InterruptedException {

        for (final Closeable closeable : new Closeable[]{map1, map2}) {
            try {
                closeable.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        System.gc();
    }

    Set<Thread> threads;

    @Before
    public void sampleThreads() {
        threads = Thread.getAllStackTraces().keySet();
    }

    @After
    public void checkThreadsShutdown() {
        StatelessClientTest.checkThreadsShutdown(threads);
    }

    @Ignore("HCOLL-246 Tcp Replication fails with large values or entries sizes that don't " +
            "included internal replication bytes")
    @Test
    public void testLargeValues() throws IOException, InterruptedException {

        map1.put(1, new String(value));
        System.out.println("\nwaiting till equal");

        waitTillEqual(10000);

        Assert.assertEquals(map1, map2);

    }


    private void waitTillEqual(final int timeOutMs) throws InterruptedException {

        Map map1UnChanged = new HashMap();
        Map map2UnChanged = new HashMap();
{'fraction_non_alphanumeric': 0.09611606468188001, 'fraction_numerical': 0.01873961009520931, 'mean_word_length': 2.0824406148113646, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5012694', 'n_tokens_mistral': 1926, 'n_tokens_neox': 1741, 'n_words': 383}