<commit_before>package org.jgroups.blocks;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.jgroups.Address;
import org.jgroups.stack.IpAddress;
import org.jgroups.util.Util;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.lang.management.ThreadInfo;


/**
 * Tests ConnectionTable
 * @author <NAME>
 * @version $Id: ConnectionTableTest.java,v 1.4 2007/03/06 12:31:15 belaban Exp $
 */
public class ConnectionTableTest extends TestCase {
    private BasicConnectionTable ct1, ct2;
    static InetAddress loopback_addr=null;
    static byte[] data=new byte[]{'b', 'e', 'l', 'a'};
    Address addr1, addr2;
    int active_threads=0;

    static {
        try {
            loopback_addr=InetAddress.getByName("127.0.0.1");
        }
        catch(UnknownHostException e) {
            e.printStackTrace();
        }
    }


    public ConnectionTableTest(String testName) {
        super(testName);
    }


    protected void setUp() throws Exception {
        super.setUp();
        active_threads=Thread.activeCount();
        System.out.println("active threads before (" + active_threads + "):\n" + Util.activeThreads());
        addr1=new IpAddress(loopback_addr, 7500);
        addr2=new IpAddress(loopback_addr, 8000);
    }


    protected void tearDown() throws Exception {
        if(ct2 != null) {
            ct2.stop();
            ct2=null;
        }
        if(ct1 != null) {
            ct1.stop();
            ct1=null;
        }
        super.tearDown();
    }



    public void testStopConnectionTableNoSendQueues() throws Exception {
        ct1=new ConnectionTable(new DummyReceiver(), loopback_addr, null, 7500, 7500, 60000, 120000);
        ct1.setUseSendQueues(false);
        ct2=new ConnectionTable(new DummyReceiver(), loopback_addr, null, 8000, 8000, 60000, 120000);
        ct2.setUseSendQueues(false);
        _testStop(ct1, ct2);
    }
<commit_msg>added testBlockingQueue()<commit_after>package org.jgroups.blocks;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.jgroups.Address;
import org.jgroups.stack.IpAddress;
import org.jgroups.util.Util;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.lang.management.ThreadInfo;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;


/**
 * Tests ConnectionTable
 * @author <NAME>
 * @version $Id: ConnectionTableTest.java,v 1.5 2007/06/08 16:11:46 belaban Exp $
 */
public class ConnectionTableTest extends TestCase {
    private BasicConnectionTable ct1, ct2;
    static InetAddress loopback_addr=null;
    static byte[] data=new byte[]{'b', 'e', 'l', 'a'};
    Address addr1, addr2;
    int active_threads=0;

    static {
        try {
            loopback_addr=InetAddress.getByName("127.0.0.1");
        }
        catch(UnknownHostException e) {
            e.printStackTrace();
        }
    }


    public ConnectionTableTest(String testName) {
        super(testName);
    }


    protected void setUp() throws Exception {
        super.setUp();
        active_threads=Thread.activeCount();
        System.out.println("active threads before (" + active_threads + "):\n" + Util.activeThreads());
        addr1=new IpAddress(loopback_addr, 7500);
        addr2=new IpAddress(loopback_addr, 8000);
    }


    protected void tearDown() throws Exception {
        if(ct2 != null) {
            ct2.stop();
            ct2=null;
        }
        if(ct1 != null) {
            ct1.stop();
            ct1=null;
        }
        super.tearDown();
    }


    public void testBlockingQueue() {
        final BlockingQueue queue=new LinkedBlockingQueue();

        Thread taker=new Thread() {

            public void run() {
                try {
                    System.out.println("taking an element from the queue");
                    Object obj=queue.take();
                    System.out.println("clear");
                }
                catch(InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        taker.start();

        Util.sleep(500);

        queue.clear(); // does this release the taker thread ?
        Util.sleep(200);
        assertFalse("taker: " + taker, taker.isAlive());
    }


    public void testStopConnectionTableNoSendQueues() throws Exception {
        ct1=new ConnectionTable(new DummyReceiver(), loopback_addr, null, 7500, 7500, 60000, 120000);
        ct1.setUseSendQueues(false);
        ct2=new ConnectionTable(new DummyReceiver(), loopback_addr, null, 8000, 8000, 60000, 120000);
        ct2.setUseSendQueues(false);
        _testStop(ct1, ct2);
    }

{'fraction_non_alphanumeric': 0.11377002636382072, 'fraction_numerical': 0.03650375177448793, 'mean_word_length': 2.607900512070227, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2888150', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1451, 'n_words': 304}