package com.huatek.busi.ws.client;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.huatek.busi.ws.xstream.XStreamTest;

public class XydlServiceTest {
    private ExecutorService executorService;
    private XydlService[] services;
    private int clients;

    @Before
    public void init() {
        this.clients = 2;
        this.executorService = Executors.newFixedThreadPool(10);
        services = new XydlService[this.clients];
        for (int i = 0; i < this.clients; i++) {
            services[i] = new XydlServiceImplService().getXydlServiceImplPort();
        }
    }

    @Test
    public void uploadCACDataTest() {
        /*
         * String strXMLParams = XStreamTest.toXml(); XydlService service = new
         * XydlServiceImplService().getXydlServiceImplPort();
         * System.out.println(service.uploadCACData(strXMLParams));
         */
        for (int i = 0; i < this.clients; i++) {
            executorService.execute(new TaskBean(services[i]));
        }
        while (!executorService.isTerminated()) {
        }
    }

    @After
    public void destroy() {
        executorService.shutdown();
    }

    static class TaskBean implements Runnable {
        private XydlService service;

        public TaskBean(XydlService service) {
            this.service = service;
        }

        @Override
        public void run() {
            long start = System.currentTimeMillis();
            service.uploadCACData(XStreamTest.toXml());
            System.out.println("" + start + "\t" + (System.currentTimeMillis() - start));
        }

    }
}
