<commit_before>package io.github.jbalancer.node.checker;

import io.github.jbalancer.node.Node;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URI;

import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class TcpCheckerTest {

    private ServerSocket serverSocket;

    @Mock
    private Node node;

    private TcpChecker tcpChecker;

    @After
    public void tearDown() throws Exception {

        if (null != serverSocket) {
            serverSocket.close();
        }
    }

    @Test
    public void noInteractionsWhenStatusNodeIsNull() throws Exception {

        when(node.getStatus()).thenReturn(null);
        givenTcpChecker();

        tcpChecker.check(node);

        verify(node, never()).setActive(anyBoolean());
        verify(node, never()).setAlive(anyBoolean());
    }

    @Test
    public void nodeAliveAndActiveWhenTcpOk() throws Exception {

        int port = givenServerSocket();
        when(node.getStatus()).thenReturn(URI.create("tcp://localhost:" + port));
        givenTcpChecker();

        tcpChecker.check(node);

        verify(node, times(1)).setActive(true);
        verify(node, times(1)).setAlive(true);
    }

    @Test
    public void nodeAliveAndNotActiveWhenSocketTimeoutException() throws Exception {

        int port = givenServerSocket();
        when(node.getStatus()).thenReturn(URI.create("tcp://localhost:" + port));
        givenTcpChecker(100);

        try (Socket backlogSocket = new Socket("localhost", port)) {

            tcpChecker.check(node);

            verify(node, times(1)).setActive(false);
            verify(node, times(1)).setAlive(true);
            verify(node, times(1)).setCheckStatus(anyString());
        }
    }

    @Test
    public void nodeAliveAndNotActiveWhenException() throws Exception {

        givenTcpChecker();
        when(node.getStatus()).thenReturn(URI.create("tcp://localhost:44000"));

        tcpChecker.check(node);

        verify(node, times(1)).setActive(false);
        verify(node, times(1)).setAlive(false);
        verify(node, times(1)).setCheckStatus(anyString());
    }

    private void givenTcpChecker(int connectionTimeout) {

        tcpChecker = new TcpChecker(connectionTimeout);
    }
<commit_msg>fixed TcpCheckerTest<commit_after>package io.github.jbalancer.node.checker;

import io.github.jbalancer.node.Node;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.URI;

import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class TcpCheckerTest {

    private ServerSocket serverSocket;

    @Mock
    private Node node;

    private TcpChecker tcpChecker;

    @After
    public void tearDown() throws Exception {

        if (null != serverSocket) {
            serverSocket.close();
        }
    }

    @Test
    public void noInteractionsWhenStatusNodeIsNull() throws Exception {

        when(node.getStatus()).thenReturn(null);
        givenTcpChecker();

        tcpChecker.check(node);

        verify(node, never()).setActive(anyBoolean());
        verify(node, never()).setAlive(anyBoolean());
    }

    @Test
    public void nodeAliveAndActiveWhenTcpOk() throws Exception {

        int port = givenServerSocket();
        when(node.getStatus()).thenReturn(URI.create("tcp://localhost:" + port));
        givenTcpChecker();

        tcpChecker.check(node);

        verify(node, times(1)).setActive(true);
        verify(node, times(1)).setAlive(true);
    }

    @Test
    public void nodeAliveAndNotActiveWhenSocketTimeoutException() throws Exception {

        int port = givenServerSocket();
        when(node.getStatus()).thenReturn(URI.create("tcp://10.0.0.0:" + port));
        givenTcpChecker(10);

        tcpChecker.check(node);

        verify(node, times(1)).setActive(false);
        verify(node, times(1)).setAlive(true);
        verify(node, times(1)).setCheckStatus(anyString());
    }

    @Test
    public void nodeAliveAndNotActiveWhenException() throws Exception {

        givenTcpChecker();
        when(node.getStatus()).thenReturn(URI.create("tcp://localhost:44000"));

        tcpChecker.check(node);

        verify(node, times(1)).setActive(false);
        verify(node, times(1)).setAlive(false);
        verify(node, times(1)).setCheckStatus(anyString());
    }

    private void givenTcpChecker(int connectionTimeout) {

        tcpChecker = new TcpChecker(connectionTimeout);
    }

{'fraction_non_alphanumeric': 0.1269109947643979, 'fraction_numerical': 0.007539267015706806, 'mean_word_length': 3.222811671087533, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '6889502', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1396, 'n_words': 245}