<commit_before>package com.orbekk.paxos;

import com.googlecode.jsonrpc4j.JsonRpcServer;
import com.orbekk.same.ConnectionManagerImpl;
import com.orbekk.same.RpcHandler;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.junit.Before;
import org.junit.Test;

public class PaxosServiceFunctionalTest {
    ConnectionManagerImpl connections = new ConnectionManagerImpl(500, 500);
    List<String> paxosUrls = new ArrayList<String>();
    RpcHandler handler = new RpcHandler(null);
    TestServer server;
    String myUrl;

    @Before
    public void setUp() throws Exception {
        server = TestServer.create(handler);
        myUrl = "http://localhost:" + server.port + "/";
        setupPaxos(5);
    }
    
    public void setupPaxos(int instances) {
        for (int i = 1; i <= instances; i++) {
            JsonRpcServer jsonServer = new JsonRpcServer(
                    new PaxosServiceImpl("" + i), PaxosService.class);
            String serviceId = "/PaxosService" + i + ".json";
            handler.addRpcServer(serviceId, jsonServer);
        }
    }

    @Test
    public void nullTest() {
    }

    public static class TestServer {<commit_msg>Add multi-threaded Paxos test code.<commit_after>package com.orbekk.paxos;

import static org.junit.Assert.*;

import com.googlecode.jsonrpc4j.JsonRpcServer;
import com.orbekk.same.ConnectionManagerImpl;
import com.orbekk.same.RpcHandler;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.junit.Before;
import org.junit.Test;

public class PaxosServiceFunctionalTest {
    ConnectionManagerImpl connections = new ConnectionManagerImpl(500, 500);
    List<String> paxosUrls = new ArrayList<String>();
    RpcHandler handler = new RpcHandler(null);
    TestServer server;
    String myUrl;

    @Before
    public void setUp() throws Exception {
        server = TestServer.create(handler);
        myUrl = "http://localhost:" + server.port;
        setupPaxos(5);
    }
    
    public void setupPaxos(int instances) {
        for (int i = 1; i <= instances; i++) {
            JsonRpcServer jsonServer = new JsonRpcServer(
                    new PaxosServiceImpl("P" + i + ": "), PaxosService.class);
            String serviceId = "/PaxosService" + i + ".json";
            handler.addRpcServer(serviceId, jsonServer);
            paxosUrls.add(myUrl + serviceId);
        }
    }

    @Test
    public void testMasterElection() {
        MasterProposer m1 = new MasterProposer("http://client1", paxosUrls,
                connections);
        assertTrue(m1.propose(1, 1));
    }

    @Test
    public void testWithCompetition() {
        int proposers = 5;
        List<Thread> masterProposers = new ArrayList<Thread>(); 
        for (int i = 1; i <= proposers; i++) {
            final int j = i;
            masterProposers.add(new Thread() {
                @Override public void run() {
                    MasterProposer client =
                            new MasterProposer("http:/client" + j, paxosUrls,
                                    connections);
                    client.propose(1, 1);
                }
            });
        }
        for (Thread t : masterProposers) {
            t.start();
        }
        for (Thread t : masterProposers) {
            try {
                t.join();
            } catch (InterruptedException e) {
                // Ignore.
            }
        }
    }

    public static class TestServer {
{'fraction_non_alphanumeric': 0.10608983190961697, 'fraction_numerical': 0.0074400661339211905, 'mean_word_length': 2.27027027027027, 'pattern_counts': {'":': 1, '<': 12, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2370467', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1052, 'n_words': 243}