<commit_before>package org.jgroups.tests;

import java.io.InputStream;
import java.io.OutputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;

import junit.framework.TestCase;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jgroups.Address;
import org.jgroups.Channel;
import org.jgroups.ChannelException;
import org.jgroups.ExtendedReceiver;
import org.jgroups.JChannel;
import org.jgroups.JChannelFactory;
import org.jgroups.Message;
import org.jgroups.View;
import org.jgroups.blocks.RpcDispatcher;
import org.jgroups.util.Util;

import EDU.oswego.cs.dl.util.concurrent.Semaphore;

/**
 * 
 * @author <NAME>
 * @author <NAME>
 * @author <a href="mailto://<EMAIL>"><NAME></a>
 * @version $Revision$
 */
public class ChannelTestBase extends TestCase
{
   private static Random random = new Random();
   
   private static String DEFAULT_MUX_FACTORY_COUNT = "4";

   static String CHANNEL_CONFIG = "udp.xml";  
   
   static String MUX_CHANNEL_CONFIG = "stacks.xml"; 
   
   static String MUX_CHANNEL_CONFIG_STACK_NAME ="udp";

   protected int active_threads = 0;
   
   protected JChannelFactory muxFactory[] = null;  

   protected String thread_dump = null;    

   protected final Log log = LogFactory.getLog(this.getClass());

   public ChannelTestBase()
   {
      super();
   }
   
   public ChannelTestBase(String name)
   {
      super(name);
   }

   public void setUp() throws Exception
   {
      super.setUp();     
      MUX_CHANNEL_CONFIG = System.getProperty("mux.conf", MUX_CHANNEL_CONFIG);
      MUX_CHANNEL_CONFIG_STACK_NAME = System.getProperty("mux.conf.stack", MUX_CHANNEL_CONFIG_STACK_NAME);
      CHANNEL_CONFIG = System.getProperty("channel.conf", CHANNEL_CONFIG);
      
      if (isMuxChannelUsed())
      {                
         muxFactory = new JChannelFactory[getMuxFactoryCount()];
         
         for (int i = 0; i < muxFactory.length; i++)
         {
            muxFactory[i] = new JChannelFactory();
            muxFactory[i].setMultiplexerConfig(MUX_CHANNEL_CONFIG);
         }                
      }
      
      if (shouldCompareThreadCount())
      {
         active_threads = Thread.activeCount();
         thread_dump = "active threads before (" + active_threads + "):\n" + Util.activeThreads();
      }             
   }

   public void tearDown() throws Exception
   {
      super.tearDown();

      if (isMuxChannelUsed())
      {
         for (int i = 0; i < muxFactory.length; i++)
         {
            muxFactory[i].destroy();
         }
      }
      
      Util.sleep(500); // remove this in 2.5 !

      if (shouldCompareThreadCount())
      {
         int current_active_threads = Thread.activeCount();

         String msg = "";
         if (active_threads != current_active_threads)
         {
            System.out.println(thread_dump);
            System.out.println("active threads after (" + current_active_threads + "):\n" + Util.activeThreads());
            msg = "active threads:\n" + dumpThreads();
         }
         assertEquals(msg, active_threads, current_active_threads);
      }
   }
   
   public void testDummy()
   {
      //in case someone runs his test 
      //we avoid having it fail by having this dummy test method
   }
   
   /**
    * Returns an array of mux application/service names with a guarantee that: 
    * <p>
    * - there are no application/service name collissions on top of one channel 
    * (i.e cannot have two application/service(s) with the same name on top of one channel)
    * <p>
    * - each generated application/service name is guaranteed to have a corresponding 
    * pair application/service with the same name on another channel     
    * 
    * @param muxApplicationstPerChannelCount
    * @return
    */
   protected String [] createMuxApplicationNames(int muxApplicationstPerChannelCount)
   {      
      int channelCount = getMuxFactoryCount();      
      int start = 64; //start with letter A
      String names [] = null;      
      int appCount = channelCount * muxApplicationstPerChannelCount;<commit_msg>remove testDummy (I am a dummy)<commit_after>package org.jgroups.tests;

import java.io.InputStream;
import java.io.OutputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;

import junit.framework.TestCase;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jgroups.Address;
import org.jgroups.Channel;
import org.jgroups.ChannelException;
import org.jgroups.ExtendedReceiver;
import org.jgroups.JChannel;
import org.jgroups.JChannelFactory;
import org.jgroups.Message;
import org.jgroups.View;
import org.jgroups.blocks.RpcDispatcher;
import org.jgroups.util.Util;

import EDU.oswego.cs.dl.util.concurrent.Semaphore;

/**
 * 
 * @author <NAME>
 * @author <NAME>
 * @author <a href="mailto://<EMAIL>"><NAME></a>
 * @version $Revision$
 */
public class ChannelTestBase extends TestCase
{
   private static Random random = new Random();
   
   private static String DEFAULT_MUX_FACTORY_COUNT = "4";

   static String CHANNEL_CONFIG = "udp.xml";  
   
   static String MUX_CHANNEL_CONFIG = "stacks.xml"; 
   
   static String MUX_CHANNEL_CONFIG_STACK_NAME ="udp";

   protected int active_threads = 0;
   
   protected JChannelFactory muxFactory[] = null;  

   protected String thread_dump = null;    

   protected final Log log = LogFactory.getLog(this.getClass());

   public ChannelTestBase()
   {
      super();
   }
   
   public ChannelTestBase(String name)
   {
      super(name);
   }

   public void setUp() throws Exception
   {
      super.setUp();     
      MUX_CHANNEL_CONFIG = System.getProperty("mux.conf", MUX_CHANNEL_CONFIG);
      MUX_CHANNEL_CONFIG_STACK_NAME = System.getProperty("mux.conf.stack", MUX_CHANNEL_CONFIG_STACK_NAME);
      CHANNEL_CONFIG = System.getProperty("channel.conf", CHANNEL_CONFIG);
      
      if (isMuxChannelUsed())
      {                
         muxFactory = new JChannelFactory[getMuxFactoryCount()];
         
         for (int i = 0; i < muxFactory.length; i++)
         {
            muxFactory[i] = new JChannelFactory();
            muxFactory[i].setMultiplexerConfig(MUX_CHANNEL_CONFIG);
         }                
      }
      
      if (shouldCompareThreadCount())
      {
         active_threads = Thread.activeCount();
         thread_dump = "active threads before (" + active_threads + "):\n" + Util.activeThreads();
      }             
   }

   public void tearDown() throws Exception
   {
      super.tearDown();

      if (isMuxChannelUsed())
      {
         for (int i = 0; i < muxFactory.length; i++)
         {
            muxFactory[i].destroy();
         }
      }
      
      Util.sleep(500); // remove this in 2.5 !

      if (shouldCompareThreadCount())
      {
         int current_active_threads = Thread.activeCount();

         String msg = "";
         if (active_threads != current_active_threads)
         {
            System.out.println(thread_dump);
            System.out.println("active threads after (" + current_active_threads + "):\n" + Util.activeThreads());
            msg = "active threads:\n" + dumpThreads();
         }
         assertEquals(msg, active_threads, current_active_threads);
      }
   }   
   
   /**
    * Returns an array of mux application/service names with a guarantee that: 
    * <p>
    * - there are no application/service name collissions on top of one channel 
    * (i.e cannot have two application/service(s) with the same name on top of one channel)
    * <p>
    * - each generated application/service name is guaranteed to have a corresponding 
    * pair application/service with the same name on another channel     
    * 
    * @param muxApplicationstPerChannelCount
    * @return
    */
   protected String [] createMuxApplicationNames(int muxApplicationstPerChannelCount)
   {      
      int channelCount = getMuxFactoryCount();      
      int start = 64; //start with letter A
      String names [] = null;      
      int appCount = channelCount * muxApplicationstPerChannelCount;
{'fraction_non_alphanumeric': 0.10250354274917337, 'fraction_numerical': 0.0025980160604629193, 'mean_word_length': 2.7226373626373626, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '1364860', 'n_tokens_mistral': 2507, 'n_tokens_neox': 2441, 'n_words': 584}