<commit_before>package com.ltsllc.miranda.cluster;

import com.ltsllc.miranda.Consumer;
import com.ltsllc.miranda.Message;
import com.ltsllc.miranda.MirandaException;
import com.ltsllc.miranda.cluster.states.ClusterLoadingState;
import com.ltsllc.miranda.file.Subscriber;
import com.ltsllc.miranda.miranda.Miranda;
import com.ltsllc.miranda.network.Network;
import com.ltsllc.miranda.node.Node;
import com.ltsllc.miranda.node.NodeElement;
import com.ltsllc.miranda.node.networkMessages.NewSessionWireMessage;
import com.ltsllc.miranda.property.MirandaProperties;
import com.ltsllc.miranda.servlet.objects.UserObject;
import com.ltsllc.miranda.session.Session;
import com.ltsllc.miranda.user.User;
import com.ltsllc.miranda.user.messages.UpdateUserMessage;
import com.ltsllc.miranda.writer.Writer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.ltsllc.miranda.test.TestCase;
import org.mockito.Matchers;
import org.mockito.Mock;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

/**
 * Created by Clark on 2/20/2017.
 */
public class TestCluster extends TestCase {
    private Cluster cluster;

    @Mock
    private ClusterFile mockClusterFile;

    @Mock
    private Node mockNode;

    @Mock
    private Node mockNode2;

    public Node getMockNode2() {
        return mockNode2;
    }

    public ClusterFile getMockClusterFile() {
        return mockClusterFile;
    }

    public Node getMockNode() {
        return mockNode;
    }

    public com.ltsllc.miranda.cluster.Cluster getCluster() {
        return cluster;
    }

    private static final String CLUSTER_FILENAME = "cluster.json";

    private static final String[] CLUSTER_FILE_CONTENTS = {
            "[",
            "    {",
            "        \"dns\" : \"foo.com\",",
            "        \"ip\" : \"192.168.1.1\",",
            "        \"port\" : 6789,",
            "        \"description\" : \"a ssltest node\",",
            "        \"expires\" : " + Long.MAX_VALUE,
            "    }",
            "]"
    };


    public void reset () {
        super.reset();

        this.cluster = null;
        this.mockClusterFile = null;
        this.mockNode = null;
        this.mockNode2 = null;
    }

    @Before
    public void setup () {
        reset();

        super.setup();

        setuplog4j();
        setupMockWriter();
        setupMockProperties();
        setupMockMiranda();
        setupMockTimer();

        setupTrustStore();

        deleteFile(CLUSTER_FILENAME);
        Cluster.reset();

        this.mockClusterFile = mock(ClusterFile.class);
        this.mockNode = mock(Node.class);

        this.cluster = new Cluster(getMockNetwork(), mockClusterFile);

        this.mockNode2 = mock(Node.class);
    }

    @After
    public void cleanup () {
        cleanupTrustStore();
        deleteFile(CLUSTER_FILENAME);
    }

    @Test
    public void testConstructor () {
        assert (null != getCluster().getClusterFile());
        assert (getCluster().getCurrentState() instanceof ClusterLoadingState);
        assert (isSubscriber(getCluster(), getCluster().getClusterFile().getSubscribers()));
    }

    /**
     * Ensure that {@link com.ltsllc.miranda.cluster.Cluster} created a
     * {@link ClusterFile}.
     */
    @Test
    public void testInitialize() {
        putFile(CLUSTER_FILENAME, CLUSTER_FILE_CONTENTS);
        com.ltsllc.miranda.cluster.Cluster.reset();
        com.ltsllc.miranda.cluster.Cluster.initialize(CLUSTER_FILENAME, Writer.getInstance(), getMockNetwork());
        this.cluster = com.ltsllc.miranda.cluster.Cluster.getInstance();<commit_msg>Modifcations to TestCluster<commit_after>package com.ltsllc.miranda.cluster;

import com.ltsllc.miranda.Consumer;
import com.ltsllc.miranda.Message;
import com.ltsllc.miranda.MirandaException;
import com.ltsllc.miranda.cluster.states.ClusterLoadingState;
import com.ltsllc.miranda.file.Subscriber;
import com.ltsllc.miranda.file.messages.Notification;
import com.ltsllc.miranda.miranda.Miranda;
import com.ltsllc.miranda.network.Network;
import com.ltsllc.miranda.node.Node;
import com.ltsllc.miranda.node.NodeElement;
import com.ltsllc.miranda.node.networkMessages.NewSessionWireMessage;
import com.ltsllc.miranda.property.MirandaProperties;
import com.ltsllc.miranda.servlet.objects.UserObject;
import com.ltsllc.miranda.session.Session;
import com.ltsllc.miranda.user.User;
import com.ltsllc.miranda.user.messages.UpdateUserMessage;
import com.ltsllc.miranda.writer.Writer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.ltsllc.miranda.test.TestCase;
import org.mockito.Matchers;
import org.mockito.Mock;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

/**
 * Created by Clark on 2/20/2017.
 */
public class TestCluster extends TestCase {
    private Cluster cluster;

    @Mock
    private ClusterFile mockClusterFile;

    @Mock
    private Node mockNode;

    @Mock
    private Node mockNode2;

    public Node getMockNode2() {
        return mockNode2;
    }

    public ClusterFile getMockClusterFile() {
        return mockClusterFile;
    }

    public Node getMockNode() {
        return mockNode;
    }

    public com.ltsllc.miranda.cluster.Cluster getCluster() {
        return cluster;
    }

    private static final String CLUSTER_FILENAME = "cluster.json";

    private static final String[] CLUSTER_FILE_CONTENTS = {
            "[",
            "    {",
            "        \"dns\" : \"foo.com\",",
            "        \"ip\" : \"192.168.1.1\",",
            "        \"port\" : 6789,",
            "        \"description\" : \"a ssltest node\",",
            "        \"expires\" : " + Long.MAX_VALUE,
            "    }",
            "]"
    };


    public void reset () {
        super.reset();

        this.cluster = null;
        this.mockClusterFile = null;
        this.mockNode = null;
        this.mockNode2 = null;
    }

    @Before
    public void setup () {
        reset();

        super.setup();

        setuplog4j();
        setupMockWriter();
        setupMockProperties();
        setupMockMiranda();
        setupMockTimer();

        setupTrustStore();

        deleteFile(CLUSTER_FILENAME);
        Cluster.reset();

        this.mockClusterFile = mock(ClusterFile.class);
        this.mockNode = mock(Node.class);

        this.cluster = new Cluster(getMockNetwork(), mockClusterFile);

        this.mockNode2 = mock(Node.class);
    }

    @After
    public void cleanup () {
        cleanupTrustStore();
        deleteFile(CLUSTER_FILENAME);
    }

    @Test
    public void testConstructor () {
        assert (null != getCluster().getClusterFile());
        assert (getCluster().getCurrentState() instanceof ClusterLoadingState);
        verify (getMockClusterFile(), atLeastOnce()).addSubscriber(Matchers.any(BlockingQueue.class),
                Matchers.any(Notification.class));
    }

    /**
     * Ensure that {@link com.ltsllc.miranda.cluster.Cluster} created a
     * {@link ClusterFile}.
     */
    @Test
    public void testInitialize() {
        putFile(CLUSTER_FILENAME, CLUSTER_FILE_CONTENTS);
        com.ltsllc.miranda.cluster.Cluster.reset();
        com.ltsllc.miranda.cluster.Cluster.initialize(CLUSTER_FILENAME, Writer.getInstance(), getMockNetwork());
        this.cluster = com.ltsllc.miranda.cluster.Cluster.getInstance();
{'fraction_non_alphanumeric': 0.11788617886178862, 'fraction_numerical': 0.0063516260162601625, 'mean_word_length': 2.7887391722810393, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4937160', 'n_tokens_mistral': 2509, 'n_tokens_neox': 2411, 'n_words': 424}