<commit_before>package org.jgroups.tests;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.jgroups.Message;
import org.jgroups.util.Util;

/**
 * Tests correct state transfer while other members continue sending messages to
 * the group
 * 
 * @author <NAME>
 * @version $Id: StateTransferTest.java,v 1.12 2007/06/28 19:08:27 vlada Exp $
 */
public class StateTransferTest extends ChannelTestBase {
	private static final int MSG_SEND_COUNT = 10000;
	private static final int APP_COUNT = 2;

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

	public void testStateTransferWhileSending() throws Exception {
		StateTransferApplication[] apps = new StateTransferApplication[APP_COUNT];

		// Create a semaphore and take all its permits
		Semaphore semaphore = new Semaphore(APP_COUNT);
		semaphore.acquire(APP_COUNT);

		int from = 0, to = MSG_SEND_COUNT;
		String[] names = createApplicationNames(APP_COUNT);
		for(int i = 0;i < apps.length;i++){
			apps[i] = new StateTransferApplication(semaphore, names[i], from, to);
			from += MSG_SEND_COUNT;
			to += MSG_SEND_COUNT;
		}

		for(int i = 0;i < apps.length;i++){
			StateTransferApplication app = apps[i];
			app.start();
			semaphore.release();
			Util.sleep(500);
		}

		// Reacquire the semaphore tickets; when we have them all
		// we know the threads are done
		semaphore.tryAcquire(APP_COUNT, 30, TimeUnit.SECONDS);
		
		//have we received all and the correct messages?
		for(int i = 0;i < apps.length;i++){
			StateTransferApplication w = apps[i];
			Map m = w.getMap();
			log("map has " + m.size() + " elements");
			assertEquals(MSG_SEND_COUNT * APP_COUNT, m.size());
		}

		Set keys = apps[0].getMap().keySet();
		for(int i = 0;i < apps.length;i++){
			StateTransferApplication app = apps[i];<commit_msg>give 40 sec for this test to finish<commit_after>package org.jgroups.tests;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.jgroups.Message;
import org.jgroups.util.Util;

/**
 * Tests correct state transfer while other members continue sending messages to
 * the group
 * 
 * @author <NAME>
 * @version $Id: StateTransferTest.java,v 1.13 2007/07/03 13:46:59 vlada Exp $
 */
public class StateTransferTest extends ChannelTestBase {
	private static final int MSG_SEND_COUNT = 10000;
	private static final int APP_COUNT = 2;

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

	public void testStateTransferWhileSending() throws Exception {
		StateTransferApplication[] apps = new StateTransferApplication[APP_COUNT];

		// Create a semaphore and take all its permits
		Semaphore semaphore = new Semaphore(APP_COUNT);
		semaphore.acquire(APP_COUNT);

		int from = 0, to = MSG_SEND_COUNT;
		String[] names = createApplicationNames(APP_COUNT);
		for(int i = 0;i < apps.length;i++){
			apps[i] = new StateTransferApplication(semaphore, names[i], from, to);
			from += MSG_SEND_COUNT;
			to += MSG_SEND_COUNT;
		}

		for(int i = 0;i < apps.length;i++){
			StateTransferApplication app = apps[i];
			app.start();
			semaphore.release();
			Util.sleep(500);
		}

		// Reacquire the semaphore tickets; when we have them all
		// we know the threads are done
		semaphore.tryAcquire(APP_COUNT, 40, TimeUnit.SECONDS);
		
		
		Util.sleep(1000);
		//have we received all and the correct messages?
		for(int i = 0;i < apps.length;i++){
			StateTransferApplication w = apps[i];
			Map m = w.getMap();
			log("map has " + m.size() + " elements");
			assertEquals(MSG_SEND_COUNT * APP_COUNT, m.size());
		}

		Set keys = apps[0].getMap().keySet();
		for(int i = 0;i < apps.length;i++){
			StateTransferApplication app = apps[i];
{'fraction_non_alphanumeric': 0.11794057609435246, 'fraction_numerical': 0.01678385121342708, 'mean_word_length': 4.451174289245983, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '2886492', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1422, 'n_words': 377}