Example usage for org.apache.commons.httpclient HttpClient getHttpConnectionManager

List of usage examples for org.apache.commons.httpclient HttpClient getHttpConnectionManager

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpClient getHttpConnectionManager.

Prototype

public HttpConnectionManager getHttpConnectionManager()

Source Link

Usage

From source file:talonetl.getproperties_0_4.getProperties.java

public void tFileFetch_1Process(final java.util.Map<String, Object> globalMap) throws TalendException {
    globalMap.put("tFileFetch_1_SUBPROCESS_STATE", 0);

    final boolean execStat = this.execStat;

    String iterateId = "";
    int iterateLoop = 0;
    String currentComponent = "";

    try {/*from w w w . ja  v a 2  s.  c  o  m*/

        String currentMethodName = new Exception().getStackTrace()[0].getMethodName();
        boolean resumeIt = currentMethodName.equals(resumeEntryMethodName);
        if (resumeEntryMethodName == null || resumeIt || globalResumeTicket) {// start
            // the
            // resume
            globalResumeTicket = true;

            /**
             * [tFileFetch_1 begin ] start
             */

            ok_Hash.put("tFileFetch_1", false);
            start_Hash.put("tFileFetch_1", System.currentTimeMillis());
            currentComponent = "tFileFetch_1";

            int tos_count_tFileFetch_1 = 0;

            /**
             * [tFileFetch_1 begin ] stop
             */
            /**
             * [tFileFetch_1 main ] start
             */

            currentComponent = "tFileFetch_1";

            java.io.InputStream retIS_tFileFetch_1 = null;

            org.apache.commons.httpclient.HttpClient client_tFileFetch_1 = new org.apache.commons.httpclient.HttpClient();
            client_tFileFetch_1.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
            client_tFileFetch_1.getParams()
                    .setCookiePolicy(org.apache.commons.httpclient.cookie.CookiePolicy.DEFAULT);

            org.apache.commons.httpclient.methods.GetMethod method_tFileFetch_1 = new org.apache.commons.httpclient.methods.GetMethod(
                    context.propertySourceUri);

            boolean isContinue_tFileFetch_1 = true;
            int status_tFileFetch_1;
            String finalURL_tFileFetch_1 = context.propertySourceUri;

            try { // B_01

                status_tFileFetch_1 = client_tFileFetch_1.executeMethod(method_tFileFetch_1);

                if (status_tFileFetch_1 != org.apache.commons.httpclient.HttpStatus.SC_OK) {
                    throw new Exception("Method failed: " + method_tFileFetch_1.getStatusLine());
                }

            } catch (Exception e) {

                throw (e);

            }

            if (isContinue_tFileFetch_1) {

                retIS_tFileFetch_1 = method_tFileFetch_1.getResponseBodyAsStream();

            } // B_01
            java.io.InputStream streamtFileFetch_1 = (java.io.InputStream) globalMap
                    .get("tFileFetch_1_INPUT_STREAM");
            if (streamtFileFetch_1 != null) {
                streamtFileFetch_1.close();
            }
            globalMap.put("tFileFetch_1_INPUT_STREAM", retIS_tFileFetch_1);

            tos_count_tFileFetch_1++;

            /**
             * [tFileFetch_1 main ] stop
             */
            /**
             * [tFileFetch_1 end ] start
             */

            currentComponent = "tFileFetch_1";

            ok_Hash.put("tFileFetch_1", true);
            end_Hash.put("tFileFetch_1", System.currentTimeMillis());

            /**
             * [tFileFetch_1 end ] stop
             */

        } // end the resume

        if (resumeEntryMethodName == null || globalResumeTicket) {
            resumeUtil.addLog("CHECKPOINT", "CONNECTION:SUBJOB_OK:tFileFetch_1:OnSubjobOk", "",
                    Thread.currentThread().getId() + "", "", "", "", "", "");
        }

        tJava_3Process(globalMap);

    } catch (Exception e) {

        throw new TalendException(e, currentComponent, globalMap);

    } catch (java.lang.Error error) {

        throw new java.lang.Error(error);

    }

    globalMap.put("tFileFetch_1_SUBPROCESS_STATE", 1);
}

From source file:talonetl.getpropfinacials_0_1.getPropFinacials.java

public void tFileFetch_1Process(final java.util.Map<String, Object> globalMap) throws TalendException {
    globalMap.put("tFileFetch_1_SUBPROCESS_STATE", 0);

    final boolean execStat = this.execStat;

    String iterateId = "";
    int iterateLoop = 0;
    String currentComponent = "";

    try {// w w  w  .j a  v  a2s.  c o  m

        String currentMethodName = new Exception().getStackTrace()[0].getMethodName();
        boolean resumeIt = currentMethodName.equals(resumeEntryMethodName);
        if (resumeEntryMethodName == null || resumeIt || globalResumeTicket) {// start
            // the
            // resume
            globalResumeTicket = true;

            /**
             * [tFileFetch_1 begin ] start
             */

            ok_Hash.put("tFileFetch_1", false);
            start_Hash.put("tFileFetch_1", System.currentTimeMillis());
            currentComponent = "tFileFetch_1";

            int tos_count_tFileFetch_1 = 0;

            /**
             * [tFileFetch_1 begin ] stop
             */
            /**
             * [tFileFetch_1 main ] start
             */

            currentComponent = "tFileFetch_1";

            java.io.InputStream retIS_tFileFetch_1 = null;

            org.apache.commons.httpclient.HttpClient client_tFileFetch_1 = new org.apache.commons.httpclient.HttpClient();
            client_tFileFetch_1.getHttpConnectionManager().getParams().setConnectionTimeout(1000);
            client_tFileFetch_1.getParams()
                    .setCookiePolicy(org.apache.commons.httpclient.cookie.CookiePolicy.DEFAULT);

            org.apache.commons.httpclient.methods.GetMethod method_tFileFetch_1 = new org.apache.commons.httpclient.methods.GetMethod(
                    context.propertySourceUri);

            boolean isContinue_tFileFetch_1 = true;
            int status_tFileFetch_1;
            String finalURL_tFileFetch_1 = context.propertySourceUri;

            try { // B_01

                status_tFileFetch_1 = client_tFileFetch_1.executeMethod(method_tFileFetch_1);

                if (status_tFileFetch_1 != org.apache.commons.httpclient.HttpStatus.SC_OK) {
                    throw new Exception("Method failed: " + method_tFileFetch_1.getStatusLine());
                }

            } catch (Exception e) {

                throw (e);

            }

            if (isContinue_tFileFetch_1) {

                retIS_tFileFetch_1 = method_tFileFetch_1.getResponseBodyAsStream();

            } // B_01
            java.io.InputStream streamtFileFetch_1 = (java.io.InputStream) globalMap
                    .get("tFileFetch_1_INPUT_STREAM");
            if (streamtFileFetch_1 != null) {
                streamtFileFetch_1.close();
            }
            globalMap.put("tFileFetch_1_INPUT_STREAM", retIS_tFileFetch_1);

            tos_count_tFileFetch_1++;

            /**
             * [tFileFetch_1 main ] stop
             */
            /**
             * [tFileFetch_1 end ] start
             */

            currentComponent = "tFileFetch_1";

            ok_Hash.put("tFileFetch_1", true);
            end_Hash.put("tFileFetch_1", System.currentTimeMillis());

            /**
             * [tFileFetch_1 end ] stop
             */

        } // end the resume

        if (resumeEntryMethodName == null || globalResumeTicket) {
            resumeUtil.addLog("CHECKPOINT", "CONNECTION:SUBJOB_OK:tFileFetch_1:OnSubjobOk", "",
                    Thread.currentThread().getId() + "", "", "", "", "", "");
        }

        tFileInputXML_1Process(globalMap);

    } catch (Exception e) {

        throw new TalendException(e, currentComponent, globalMap);

    } catch (java.lang.Error error) {

        throw new java.lang.Error(error);

    }

    globalMap.put("tFileFetch_1_SUBPROCESS_STATE", 1);
}

From source file:talonetl.getpropfinacials_0_2.getPropFinacials.java

public void tFileFetch_1Process(final java.util.Map<String, Object> globalMap) throws TalendException {
    globalMap.put("tFileFetch_1_SUBPROCESS_STATE", 0);

    final boolean execStat = this.execStat;

    String iterateId = "";
    int iterateLoop = 0;
    String currentComponent = "";

    try {/*from w w w . j  ava2s  . c  o  m*/

        String currentMethodName = new Exception().getStackTrace()[0].getMethodName();
        boolean resumeIt = currentMethodName.equals(resumeEntryMethodName);
        if (resumeEntryMethodName == null || resumeIt || globalResumeTicket) {// start
            // the
            // resume
            globalResumeTicket = true;

            /**
             * [tFileFetch_1 begin ] start
             */

            ok_Hash.put("tFileFetch_1", false);
            start_Hash.put("tFileFetch_1", System.currentTimeMillis());
            currentComponent = "tFileFetch_1";

            int tos_count_tFileFetch_1 = 0;

            /**
             * [tFileFetch_1 begin ] stop
             */
            /**
             * [tFileFetch_1 main ] start
             */

            currentComponent = "tFileFetch_1";

            java.io.InputStream retIS_tFileFetch_1 = null;

            org.apache.commons.httpclient.HttpClient client_tFileFetch_1 = new org.apache.commons.httpclient.HttpClient();
            client_tFileFetch_1.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
            client_tFileFetch_1.getParams()
                    .setCookiePolicy(org.apache.commons.httpclient.cookie.CookiePolicy.DEFAULT);

            org.apache.commons.httpclient.methods.GetMethod method_tFileFetch_1 = new org.apache.commons.httpclient.methods.GetMethod(
                    context.propertySourceUri);

            boolean isContinue_tFileFetch_1 = true;
            int status_tFileFetch_1;
            String finalURL_tFileFetch_1 = context.propertySourceUri;

            try { // B_01

                status_tFileFetch_1 = client_tFileFetch_1.executeMethod(method_tFileFetch_1);

                if (status_tFileFetch_1 != org.apache.commons.httpclient.HttpStatus.SC_OK) {
                    throw new Exception("Method failed: " + method_tFileFetch_1.getStatusLine());
                }

            } catch (Exception e) {

                throw (e);

            }

            if (isContinue_tFileFetch_1) {

                retIS_tFileFetch_1 = method_tFileFetch_1.getResponseBodyAsStream();

            } // B_01
            java.io.InputStream streamtFileFetch_1 = (java.io.InputStream) globalMap
                    .get("tFileFetch_1_INPUT_STREAM");
            if (streamtFileFetch_1 != null) {
                streamtFileFetch_1.close();
            }
            globalMap.put("tFileFetch_1_INPUT_STREAM", retIS_tFileFetch_1);

            tos_count_tFileFetch_1++;

            /**
             * [tFileFetch_1 main ] stop
             */
            /**
             * [tFileFetch_1 end ] start
             */

            currentComponent = "tFileFetch_1";

            ok_Hash.put("tFileFetch_1", true);
            end_Hash.put("tFileFetch_1", System.currentTimeMillis());

            /**
             * [tFileFetch_1 end ] stop
             */

        } // end the resume

        if (resumeEntryMethodName == null || globalResumeTicket) {
            resumeUtil.addLog("CHECKPOINT", "CONNECTION:SUBJOB_OK:tFileFetch_1:OnSubjobOk", "",
                    Thread.currentThread().getId() + "", "", "", "", "", "");
        }

        tFileInputXML_1Process(globalMap);

    } catch (Exception e) {

        throw new TalendException(e, currentComponent, globalMap);

    } catch (java.lang.Error error) {

        throw new java.lang.Error(error);

    }

    globalMap.put("tFileFetch_1_SUBPROCESS_STATE", 1);
}

From source file:talonetl.getpropfinacials_0_3.getPropFinacials.java

public void tFileFetch_1Process(final java.util.Map<String, Object> globalMap) throws TalendException {
    globalMap.put("tFileFetch_1_SUBPROCESS_STATE", 0);

    final boolean execStat = this.execStat;

    String iterateId = "";
    int iterateLoop = 0;
    String currentComponent = "";

    try {//from w w w.  j  a v a2 s  .  c om

        String currentMethodName = new Exception().getStackTrace()[0].getMethodName();
        boolean resumeIt = currentMethodName.equals(resumeEntryMethodName);
        if (resumeEntryMethodName == null || resumeIt || globalResumeTicket) {// start
            // the
            // resume
            globalResumeTicket = true;

            /**
             * [tFileFetch_1 begin ] start
             */

            ok_Hash.put("tFileFetch_1", false);
            start_Hash.put("tFileFetch_1", System.currentTimeMillis());
            currentComponent = "tFileFetch_1";

            int tos_count_tFileFetch_1 = 0;

            /**
             * [tFileFetch_1 begin ] stop
             */
            /**
             * [tFileFetch_1 main ] start
             */

            currentComponent = "tFileFetch_1";

            java.io.InputStream retIS_tFileFetch_1 = null;

            org.apache.commons.httpclient.HttpClient client_tFileFetch_1 = new org.apache.commons.httpclient.HttpClient();
            client_tFileFetch_1.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
            client_tFileFetch_1.getParams()
                    .setCookiePolicy(org.apache.commons.httpclient.cookie.CookiePolicy.DEFAULT);

            org.apache.commons.httpclient.methods.GetMethod method_tFileFetch_1 = new org.apache.commons.httpclient.methods.GetMethod(
                    context.propertySourceUri);

            boolean isContinue_tFileFetch_1 = true;
            int status_tFileFetch_1;
            String finalURL_tFileFetch_1 = context.propertySourceUri;

            try { // B_01

                status_tFileFetch_1 = client_tFileFetch_1.executeMethod(method_tFileFetch_1);

                if (status_tFileFetch_1 != org.apache.commons.httpclient.HttpStatus.SC_OK) {
                    throw new Exception("Method failed: " + method_tFileFetch_1.getStatusLine());
                }

            } catch (Exception e) {

                throw (e);

            }

            if (isContinue_tFileFetch_1) {

                retIS_tFileFetch_1 = method_tFileFetch_1.getResponseBodyAsStream();

            } // B_01
            java.io.InputStream streamtFileFetch_1 = (java.io.InputStream) globalMap
                    .get("tFileFetch_1_INPUT_STREAM");
            if (streamtFileFetch_1 != null) {
                streamtFileFetch_1.close();
            }
            globalMap.put("tFileFetch_1_INPUT_STREAM", retIS_tFileFetch_1);

            tos_count_tFileFetch_1++;

            /**
             * [tFileFetch_1 main ] stop
             */
            /**
             * [tFileFetch_1 end ] start
             */

            currentComponent = "tFileFetch_1";

            ok_Hash.put("tFileFetch_1", true);
            end_Hash.put("tFileFetch_1", System.currentTimeMillis());

            tFileInputXML_1Process(globalMap);
            tFileInputXML_2Process(globalMap);

            /**
             * [tFileFetch_1 end ] stop
             */

        } // end the resume

    } catch (Exception e) {

        throw new TalendException(e, currentComponent, globalMap);

    } catch (java.lang.Error error) {

        throw new java.lang.Error(error);

    }

    globalMap.put("tFileFetch_1_SUBPROCESS_STATE", 1);
}

From source file:talonetl.loadpropertyimages_0_1.loadPropertyImages.java

public void tFileFetch_1Process(final java.util.Map<String, Object> globalMap) throws TalendException {
    globalMap.put("tFileFetch_1_SUBPROCESS_STATE", 0);

    final boolean execStat = this.execStat;

    String iterateId = "";
    int iterateLoop = 0;
    String currentComponent = "";

    try {//from   w ww .  j  a v a2 s .  c o m

        String currentMethodName = new Exception().getStackTrace()[0].getMethodName();
        boolean resumeIt = currentMethodName.equals(resumeEntryMethodName);
        if (resumeEntryMethodName == null || resumeIt || globalResumeTicket) {// start
            // the
            // resume
            globalResumeTicket = true;

            /**
             * [tFileFetch_1 begin ] start
             */

            ok_Hash.put("tFileFetch_1", false);
            start_Hash.put("tFileFetch_1", System.currentTimeMillis());
            currentComponent = "tFileFetch_1";

            int tos_count_tFileFetch_1 = 0;

            /**
             * [tFileFetch_1 begin ] stop
             */
            /**
             * [tFileFetch_1 main ] start
             */

            currentComponent = "tFileFetch_1";

            java.io.InputStream retIS_tFileFetch_1 = null;

            org.apache.commons.httpclient.HttpClient client_tFileFetch_1 = new org.apache.commons.httpclient.HttpClient();
            client_tFileFetch_1.getHttpConnectionManager().getParams().setConnectionTimeout(1000);
            client_tFileFetch_1.getParams()
                    .setCookiePolicy(org.apache.commons.httpclient.cookie.CookiePolicy.DEFAULT);

            org.apache.commons.httpclient.methods.GetMethod method_tFileFetch_1 = new org.apache.commons.httpclient.methods.GetMethod(
                    context.propertySourceUri);

            boolean isContinue_tFileFetch_1 = true;
            int status_tFileFetch_1;
            String finalURL_tFileFetch_1 = context.propertySourceUri;

            try { // B_01

                status_tFileFetch_1 = client_tFileFetch_1.executeMethod(method_tFileFetch_1);

                if (status_tFileFetch_1 != org.apache.commons.httpclient.HttpStatus.SC_OK) {
                    throw new Exception("Method failed: " + method_tFileFetch_1.getStatusLine());
                }

            } catch (Exception e) {

                throw (e);

            }

            if (isContinue_tFileFetch_1) {

                retIS_tFileFetch_1 = method_tFileFetch_1.getResponseBodyAsStream();

            } // B_01
            java.io.InputStream streamtFileFetch_1 = (java.io.InputStream) globalMap
                    .get("tFileFetch_1_INPUT_STREAM");
            if (streamtFileFetch_1 != null) {
                streamtFileFetch_1.close();
            }
            globalMap.put("tFileFetch_1_INPUT_STREAM", retIS_tFileFetch_1);

            tos_count_tFileFetch_1++;

            /**
             * [tFileFetch_1 main ] stop
             */
            /**
             * [tFileFetch_1 end ] start
             */

            currentComponent = "tFileFetch_1";

            ok_Hash.put("tFileFetch_1", true);
            end_Hash.put("tFileFetch_1", System.currentTimeMillis());

            tJava_4Process(globalMap);

            /**
             * [tFileFetch_1 end ] stop
             */

        } // end the resume

    } catch (Exception e) {

        throw new TalendException(e, currentComponent, globalMap);

    } catch (java.lang.Error error) {

        throw new java.lang.Error(error);

    }

    globalMap.put("tFileFetch_1_SUBPROCESS_STATE", 1);
}

From source file:talonetl.loadpropertyimages_0_2.loadPropertyImages.java

public void tFileFetch_1Process(final java.util.Map<String, Object> globalMap) throws TalendException {
    globalMap.put("tFileFetch_1_SUBPROCESS_STATE", 0);

    final boolean execStat = this.execStat;

    String iterateId = "";
    int iterateLoop = 0;
    String currentComponent = "";

    try {/*w  ww.  j  ava  2 s  . co m*/

        String currentMethodName = new Exception().getStackTrace()[0].getMethodName();
        boolean resumeIt = currentMethodName.equals(resumeEntryMethodName);
        if (resumeEntryMethodName == null || resumeIt || globalResumeTicket) {// start
            // the
            // resume
            globalResumeTicket = true;

            /**
             * [tFileFetch_1 begin ] start
             */

            ok_Hash.put("tFileFetch_1", false);
            start_Hash.put("tFileFetch_1", System.currentTimeMillis());
            currentComponent = "tFileFetch_1";

            int tos_count_tFileFetch_1 = 0;

            /**
             * [tFileFetch_1 begin ] stop
             */
            /**
             * [tFileFetch_1 main ] start
             */

            currentComponent = "tFileFetch_1";

            java.io.InputStream retIS_tFileFetch_1 = null;

            org.apache.commons.httpclient.HttpClient client_tFileFetch_1 = new org.apache.commons.httpclient.HttpClient();
            client_tFileFetch_1.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
            client_tFileFetch_1.getParams()
                    .setCookiePolicy(org.apache.commons.httpclient.cookie.CookiePolicy.DEFAULT);

            org.apache.commons.httpclient.methods.GetMethod method_tFileFetch_1 = new org.apache.commons.httpclient.methods.GetMethod(
                    context.propertySourceUri);

            boolean isContinue_tFileFetch_1 = true;
            int status_tFileFetch_1;
            String finalURL_tFileFetch_1 = context.propertySourceUri;

            try { // B_01

                status_tFileFetch_1 = client_tFileFetch_1.executeMethod(method_tFileFetch_1);

                if (status_tFileFetch_1 != org.apache.commons.httpclient.HttpStatus.SC_OK) {
                    throw new Exception("Method failed: " + method_tFileFetch_1.getStatusLine());
                }

            } catch (Exception e) {

                throw (e);

            }

            if (isContinue_tFileFetch_1) {

                retIS_tFileFetch_1 = method_tFileFetch_1.getResponseBodyAsStream();

            } // B_01
            java.io.InputStream streamtFileFetch_1 = (java.io.InputStream) globalMap
                    .get("tFileFetch_1_INPUT_STREAM");
            if (streamtFileFetch_1 != null) {
                streamtFileFetch_1.close();
            }
            globalMap.put("tFileFetch_1_INPUT_STREAM", retIS_tFileFetch_1);

            tos_count_tFileFetch_1++;

            /**
             * [tFileFetch_1 main ] stop
             */
            /**
             * [tFileFetch_1 end ] start
             */

            currentComponent = "tFileFetch_1";

            ok_Hash.put("tFileFetch_1", true);
            end_Hash.put("tFileFetch_1", System.currentTimeMillis());

            tJava_4Process(globalMap);

            /**
             * [tFileFetch_1 end ] stop
             */

        } // end the resume

    } catch (Exception e) {

        throw new TalendException(e, currentComponent, globalMap);

    } catch (java.lang.Error error) {

        throw new java.lang.Error(error);

    }

    globalMap.put("tFileFetch_1_SUBPROCESS_STATE", 1);
}

From source file:voldemort.performance.HttpClientBench.java

private static HttpClient createClient() {
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpClient httpClient = new HttpClient(connectionManager);
    HttpClientParams clientParams = httpClient.getParams();
    clientParams.setConnectionManagerTimeout(DEFAULT_CONNECTION_MANAGER_TIMEOUT);
    clientParams.setSoTimeout(500);/* ww w. j a v  a 2  s.c  o  m*/
    clientParams.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false));
    clientParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
    clientParams.setBooleanParameter("http.tcp.nodelay", false);
    clientParams.setIntParameter("http.socket.receivebuffer", 60000);
    clientParams.setParameter("http.useragent", VOLDEMORT_USER_AGENT);
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.setHost("localhost");
    hostConfig.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
    httpClient.setHostConfiguration(hostConfig);
    HttpConnectionManagerParams managerParams = httpClient.getHttpConnectionManager().getParams();
    managerParams.setConnectionTimeout(DEFAULT_CONNECTION_MANAGER_TIMEOUT);
    managerParams.setMaxTotalConnections(DEFAULT_MAX_CONNECTIONS);
    managerParams.setMaxConnectionsPerHost(httpClient.getHostConfiguration(), DEFAULT_MAX_HOST_CONNECTIONS);
    managerParams.setStaleCheckingEnabled(false);

    return httpClient;
}

From source file:voldemort.performance.RemoteStoreComparisonTest.java

public static void main(String[] args) throws Exception {
    if (args.length != 2)
        Utils.croak("USAGE: java " + RemoteStoreComparisonTest.class.getName()
                + " numRequests numThreads [useNio]");

    int numRequests = Integer.parseInt(args[0]);
    int numThreads = Integer.parseInt(args[1]);
    boolean useNio = args.length > 2 ? args[2].equals("true") : false;

    /** * In memory test ** */
    final Store<byte[], byte[], byte[]> memStore = new InMemoryStorageEngine<byte[], byte[], byte[]>("test");
    PerformanceTest memWriteTest = new PerformanceTest() {

        @Override// w  w w . j a v  a 2s  . c o  m
        public void doOperation(int i) {
            byte[] key = String.valueOf(i).getBytes();
            memStore.put(key, new Versioned<byte[]>(key), null);
        }
    };
    System.out.println("###########################################");
    System.out.println("Performing memory write test.");
    memWriteTest.run(numRequests, numThreads);
    memWriteTest.printStats();
    System.out.println();

    PerformanceTest memReadTest = new PerformanceTest() {

        @Override
        public void doOperation(int i) {
            try {
                memStore.get(String.valueOf(i).getBytes(), null);
            } catch (Exception e) {
                System.out.println("Failure on i = " + i);
                e.printStackTrace();
            }
        }
    };
    System.out.println("Performing memory read test.");
    memReadTest.run(numRequests, numThreads);
    memReadTest.printStats();
    System.out.println();
    System.out.println();

    /** * Do Socket tests ** */
    String storeName = "test";
    StoreRepository repository = new StoreRepository();
    repository.addLocalStore(new InMemoryStorageEngine<ByteArray, byte[], byte[]>(storeName));
    SocketStoreFactory storeFactory = new ClientRequestExecutorPool(10, 1000, 1000, 32 * 1024);
    final Store<ByteArray, byte[], byte[]> socketStore = storeFactory.create(storeName, "localhost", 6666,
            RequestFormatType.VOLDEMORT_V1, RequestRoutingType.NORMAL);
    RequestHandlerFactory factory = ServerTestUtils.getSocketRequestHandlerFactory(repository);
    AbstractSocketService socketService = ServerTestUtils.getSocketService(useNio, factory, 6666, 50, 50, 1000);
    socketService.start();

    PerformanceTest socketWriteTest = new PerformanceTest() {

        @Override
        public void doOperation(int i) {
            byte[] bytes = String.valueOf(i).getBytes();
            ByteArray key = new ByteArray(bytes);
            socketStore.put(key, new Versioned<byte[]>(bytes), null);
        }
    };
    System.out.println("###########################################");
    System.out.println("Performing socket write test.");
    socketWriteTest.run(numRequests, numThreads);
    socketWriteTest.printStats();
    System.out.println();

    PerformanceTest socketReadTest = new PerformanceTest() {

        @Override
        public void doOperation(int i) {
            try {
                socketStore.get(TestUtils.toByteArray(String.valueOf(i)), null);
            } catch (Exception e) {
                System.out.println("Failure on i = " + i);
                e.printStackTrace();
            }
        }
    };
    System.out.println("Performing socket read test.");
    socketReadTest.run(numRequests, 1);
    socketReadTest.printStats();
    System.out.println();
    System.out.println();

    socketStore.close();
    storeFactory.close();
    socketService.stop();

    /** * Do HTTP tests ** */
    repository.addLocalStore(new InMemoryStorageEngine<ByteArray, byte[], byte[]>(storeName));
    HttpService httpService = new HttpService(null, null, repository, RequestFormatType.VOLDEMORT_V0,
            numThreads, 8080);
    httpService.start();
    HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
    HttpClientParams clientParams = httpClient.getParams();
    clientParams.setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false));
    clientParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
    clientParams.setParameter("http.useragent", "test-agent");
    HostConfiguration hostConfig = new HostConfiguration();
    hostConfig.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
    httpClient.setHostConfiguration(hostConfig);
    HttpConnectionManagerParams managerParams = httpClient.getHttpConnectionManager().getParams();
    managerParams.setConnectionTimeout(10000);
    managerParams.setMaxTotalConnections(numThreads);
    managerParams.setStaleCheckingEnabled(false);
    managerParams.setMaxConnectionsPerHost(httpClient.getHostConfiguration(), numThreads);
    final HttpStore httpStore = new HttpStore("test", "localhost", 8080, httpClient,
            new RequestFormatFactory().getRequestFormat(RequestFormatType.VOLDEMORT_V0), false);
    Thread.sleep(400);

    PerformanceTest httpWriteTest = new PerformanceTest() {

        @Override
        public void doOperation(int i) {
            byte[] key = String.valueOf(i).getBytes();
            httpStore.put(new ByteArray(key), new Versioned<byte[]>(key), null);
        }
    };
    System.out.println("###########################################");
    System.out.println("Performing HTTP write test.");
    httpWriteTest.run(numRequests, numThreads);
    httpWriteTest.printStats();
    System.out.println();

    PerformanceTest httpReadTest = new PerformanceTest() {

        @Override
        public void doOperation(int i) {
            httpStore.get(new ByteArray(String.valueOf(i).getBytes()), null);
        }
    };
    System.out.println("Performing HTTP read test.");
    httpReadTest.run(numRequests, numThreads);
    httpReadTest.printStats();

    httpService.stop();
}

From source file:voldemort.store.http.HttpStoreTest.java

public <T extends Exception> void testBadUrlOrPort(String url, int port, Class<T> expected) {
    ByteArray key = new ByteArray("test".getBytes());
    RequestFormat requestFormat = new RequestFormatFactory().getRequestFormat(RequestFormatType.VOLDEMORT_V1);
    HttpClient client = new HttpClient();
    client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
    HttpStore badUrlHttpStore = new HttpStore("test", url, port, client, requestFormat, false);
    try {/*from   www  .  j  a v a2s.c  o  m*/
        badUrlHttpStore.put(key, new Versioned<byte[]>("value".getBytes(), new VectorClock()), null);
    } catch (Exception e) {
        assertTrue(e.getClass().equals(expected));
    }
    try {
        badUrlHttpStore.get(key, null);
    } catch (Exception e) {
        assertTrue(e.getClass().equals(expected));
    }
    try {
        badUrlHttpStore.delete(key, new VectorClock());
    } catch (Exception e) {
        assertTrue(e.getClass().equals(expected));
    }
}