<commit_before>package nl.erwinvaneyk.communication;

// TODO: needs cluster-joins to be able to test
public class ConnectorImplTest {}<commit_msg>Added basic tests for ConnectorImpl<commit_after>package nl.erwinvaneyk.communication;

import nl.erwinvaneyk.communication.exceptions.CommunicationException;
import nl.erwinvaneyk.core.ClusterFactory;
import nl.erwinvaneyk.core.Node;
import org.junit.Before;
import org.junit.Test;

import java.rmi.RemoteException;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

// TODO: needs cluster-joins to be able to test
public class ConnectorImplTest {
    private boolean receivedOwnMessage = false;

    @Before
    public void reset() {
        receivedOwnMessage = false;
    }

    @Test
    public void connectorBroadcastSingleProcessNoFilter() throws RemoteException {
        // Setup cluster
        Node node1 = ClusterFactory.getBasicFactory().startCluster(1819, "test-cluster");
        node1.getMessageHandler().bind(new MessageReceivedHandler() {
            @Override
            public Message onMessage(Message message) throws CommunicationException {
                ConnectorImplTest.this.receivedOwnMessage = true;
                return null;
            }

            @Override
            public String getContext() {
                return "test-cluster";
            }
        });

        ConnectorImpl connector = (ConnectorImpl) node1.getConnector();

        Message message = new BasicMessage("test-cluster", node1.getState().getAddress());
        connector.broadcast(message);

        assertTrue(receivedOwnMessage);

        // Shutdown
        node1.disconnect();
    }


    @Test
    public void connectorBroadcastSingleProcessWithFilter() throws RemoteException {
        // Setup cluster
        Node node1 = ClusterFactory.getBasicFactory().startCluster(1820, "test-cluster");
        node1.getMessageHandler().bind(new MessageReceivedHandler() {
            @Override
            public Message onMessage(Message message) throws CommunicationException {
                ConnectorImplTest.this.receivedOwnMessage = true;
                return null;
            }

            @Override
            public String getContext() {
                return "test-cluster";
            }
        });

        ConnectorImpl connector = (ConnectorImpl) node1.getConnector();

        Message message = new BasicMessage("test-cluster", node1.getState().getAddress());
        connector.broadcast(message, "randomId");

        assertFalse(receivedOwnMessage);

        // Shutdown
        node1.disconnect();
    }
}
{'fraction_non_alphanumeric': 0.0882800608828006, 'fraction_numerical': 0.00684931506849315, 'mean_word_length': 2.661559888579387, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3227883', 'n_tokens_mistral': 680, 'n_tokens_neox': 650, 'n_words': 147}