Package com.caringo.client.examples

Source Code of com.caringo.client.examples.SCSPRemoteTest

/**
*
*/
package com.caringo.client.examples;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import com.caringo.client.ScspClient;
import com.caringo.client.ScspHeaders;
import com.caringo.client.ScspQueryArgs;
import com.caringo.client.ScspResponse;

/**
* Copyright (c) 2009 by Caringo, Inc. -- All rights reserved<br>
* This is free software, distributed under the terms of the New BSD license.<br>
* See the LICENSE.txt file included in this archive.<br>
* <br>
*
* @author pray
* @created Dec 21, 2009
* @id $Id: SCSPRemoteTest.java 52121 2012-08-28 17:31:56Z jafshar $
*/
//These examples all require the use of two CAStor clusters with the SCSP Proxy
//between those clusters. The Proxy serves as a direct front end to the "local"
//CAStor cluster. The "remote" cluster is the other cluster. In terms of Proxy
//configuration, the "local" cluster IP address is specified by the '[proxy] interface'
//parameter in scspproxy.cfg and the "remote" cluster IP address is identified by
//the 'ClusterName' configuration parameter in hosts.cfg. The value of 'ClusterName'
//must be 'drcluster' for these examples to work.
//
//Starting with SDK version 1.2, all requests to the Proxy must start with the path
//'_proxy', as shown in these examples.
//
//Global definitions:
//'lrc' is 'local response/result code', indicating the request goes directly
//to the local cluster.
//'prc' is 'proxy response/result code', indicating the request goes through
//the Proxy and can be sent to either the local or remote cluster.
public final class SCSPRemoteTest {

  /**
   * @param args
   */
  private static final String ANY_HOST = "_proxy/any";
  private static final String REMOTE_HOST = "_proxy/remote";
 
  public static void main(String[] args) {
    String[] hosts = new String[1];
    String[] localHosts = new String[1];
    hosts[0] = "10.0.0.103";
    localHosts[0] = "10.136.1.1";
    ScspClient client = new ScspClient(hosts,80,4,4);
    ScspClient localClient = new ScspClient(localHosts, 80, 4, 4);
    try
   
      client.start();
      localClient.start();
    }
    catch (Exception ex)
    {
      ex.printStackTrace(); // might as well continue, we're going down regardless
    }
   
    if (!CheckConnections(client)) {
      PrintUsage();
    }
    else {
      try
      {
        RunExamples(client, localClient);
      }
     
      finally
      {
        client.stop();
        localClient.stop();
      }
    }
  }
    private static void RunImmutableRemoteOnlyClientExamples(ScspClient client, ScspClient localClient)
    {
        //[[DOC SNIPPET START | Remote Examples | SCSP operations on unnmamed immutable objects in local and remote clusters]]
        //Performs SCSP operations on immutable objects located in a remote cluster.
      String rcn = "_proxy/drcluster";
        System.out.println(">>>>>> Immutable Client Tests <<<<<<<<");
        String testData = "Hello world";
        String testUpdateData = "I'm Here";
        ByteArrayInputStream inputStream = new ByteArrayInputStream(testData.getBytes());
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try
        {
            System.out.println(">>>>>> Write <<<<<<<<");
            ScspQueryArgs args = new ScspQueryArgs();
            ScspResponse wcResponse = client.write(rcn, inputStream, testData.getBytes().length, args, new ScspHeaders()); //write to the remote cluster
            String uuid = wcResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);
            System.out.println(wcResponse.toString());
           
            System.out.println(">>>>>> Read <<<<<<<<");
            ScspResponse rcResponse = client.read("", rcn + "/" + uuid, outputStream, args, new ScspHeaders()); //read from the remote cluster
            System.out.println(rcResponse.toString());
            System.out.println("Body Received");
            System.out.println(outputStream.toString());

            System.out.println(">>>>>> Read Local<<<<<<<<");
            outputStream.reset();
            ScspResponse lrcResponse = localClient.read("", uuid, outputStream, args, new ScspHeaders()); //read directly from the local cluster
            System.out.println(lrcResponse.toString());
            System.out.println("Body Received");
            System.out.println(outputStream.toString());

            System.out.println(">>>>>> Read Proxy Local<<<<<<<<");
            outputStream.reset();
            ScspResponse prcResponse = client.read("", uuid, outputStream, args, new ScspHeaders()); //read from the local cluster using the Proxy
            System.out.println(prcResponse.toString());
            System.out.println("Body Received");
            System.out.println(outputStream.toString());

            System.out.println(">>>>>> Info <<<<<<<<");
            ScspResponse icResponse = client.info("", rcn + "/" + uuid, args, new ScspHeaders()); //info in the remote cluster
            System.out.println(icResponse.toString());
           
            System.out.println(">>>>>> Delete <<<<<<<<");
            ScspResponse dcResponse = client.deleteMutable("", rcn + "/" + uuid, args, new ScspHeaders()); //delete from the remote cluster
            System.out.println(dcResponse.toString());
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
    //[[DOC SNIPPET END]]
       
    private static void RunImmutableAnyRemoteClientExamples(ScspClient client, ScspClient localClient)
    {
        //[[DOC SNIPPET START | Remote Examples | SCSP operations on unnmamed immutable objects in local and remote clusters using the Proxy]]
        //Performs SCSP operations on immutable objects located in either a local cluster or in a remote cluster
        //using the SCSP Proxy. The remote cluster must be named 'drcluster'. Requests that include the variable
        //'REMOTE_HOST' work only in the remote cluster, while requests that include the variable 'ANY_HOST'
        //work in either a local or remote cluster.
      String rcn = "_proxy/drcluster";
        System.out.println(">>>>>> Immutable Remote/Any Client Tests <<<<<<<<");
        String testData = "Hello world";
        ByteArrayInputStream inputStream = new ByteArrayInputStream(testData.getBytes());
        try
        {
            System.out.println(">>>>>> Write Remote <<<<<<<<");
            ScspQueryArgs args = new ScspQueryArgs();
            ScspResponse wcResponse = client.write(rcn, inputStream, testData.getBytes().length, args, new ScspHeaders());
            String uuid = wcResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);
            System.out.println(wcResponse.toString());
           
            System.out.println(">>>>>> Info Remote Remote <<<<<<<<");
            ScspResponse icResponse = client.info("", REMOTE_HOST + "/" + uuid, args, new ScspHeaders());
            System.out.println(icResponse.toString());
           
            System.out.println(">>>>>> Info Remote Any <<<<<<<<");
            icResponse = client.info("", ANY_HOST + "/" + uuid, args, new ScspHeaders());
            System.out.println(icResponse.toString());

            System.out.println(">>>>>> Write Local <<<<<<<<");
             
            inputStream.reset();
            wcResponse = client.write(null, inputStream, testData.getBytes().length, args, new ScspHeaders());
            uuid = wcResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);
            System.out.println(wcResponse.toString());
           
            System.out.println(">>>>>> Info Local Remote <<<<<<<<");
            icResponse = client.info("", REMOTE_HOST + "/" + uuid, args, new ScspHeaders());
            System.out.println(icResponse.toString());

            System.out.println(">>>>>> Info Local Any <<<<<<<<");
            icResponse = client.info("", ANY_HOST + "/" + uuid, args, new ScspHeaders());
            System.out.println(icResponse.toString());
           

        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
    //[[DOC SNIPPET END]]
    private static void RunImmutableAggregateInfoLocalClientExamples(ScspClient client, ScspClient localClient)
    {
        //[[DOC SNIPPET START | Remote Examples | AggregateInfo example on unnamed immutable objects in a local cluster using the Proxy]]
        //Writes immutable objects and gets aggregate info on them in a local cluster using the SCSP Proxy.
        //The Proxy's AggregateInfo method validates that a set of content exists in a cluster.
        //Although it can be issued against a local cluster, it is usually used to validate remote
        //replication. First, create a "consistency checkpoint" and then INFO requests in the AggregateInfo
        //method are issued for each name or UUID in the consistency checkpoint. Either object metadata
        //or an error response is returned in the concatenated response body. The response for a successful
        //AggregateInfo method execution is a 200 code.
      String rcn = "_proxy/drcluster";
        System.out.println(">>>>>> Immutable AggregateInfo Local Client Tests <<<<<<<<");
        String testData = "Hello world";
        ByteArrayInputStream inputStream = new ByteArrayInputStream(testData.getBytes());
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try
        {
          String checkPoint = "";
            ScspQueryArgs args = new ScspQueryArgs();
            System.out.println(">>>>>> Write Non-Mutable Streams <<<<<<<<");
            for (int i = 0; i < 4; i++) {
              inputStream.reset();
              ScspResponse wcResponse = client.write("", inputStream, testData.getBytes().length, args, new ScspHeaders());
              String uuid = wcResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);
              checkPoint = checkPoint + uuid + "\r\n";
            }
            System.out.println("Writing checkpoint: " + checkPoint);
            ByteArrayInputStream cpStream = new ByteArrayInputStream(checkPoint.getBytes());
            // Note that checkpoint goes to the local cluster
            ScspResponse wcResponse = client.write("", cpStream, checkPoint.getBytes().length, args, new ScspHeaders());
            String uuid = wcResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);
           
            System.out.println(">>>>>> Aggregate Info <<<<<<<<");
            ScspResponse aiResponse = client.aggregateInfo("", uuid, outputStream, args, new ScspHeaders());
            System.out.println(aiResponse.toString());
            System.out.println(outputStream.toString());

        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
    //[[DOC SNIPPET END]]
    private static void RunImmutableAggregateInfoRemoteClientExamples(ScspClient client, ScspClient localClient)
    {
      String rcn = "_proxy/drcluster";
        System.out.println(">>>>>> Immutable AggregateInfo Remote Client Tests <<<<<<<<");
        String testData = "Hello world";
        ByteArrayInputStream inputStream = new ByteArrayInputStream(testData.getBytes());
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try
        {
          String checkPoint = "";
            ScspQueryArgs args = new ScspQueryArgs();
            System.out.println(">>>>>> Write Immutable Streams <<<<<<<<");
            for (int i = 1; i < 4; i++) {
              inputStream.reset();
              ScspResponse wcResponse = client.write(rcn, inputStream, testData.getBytes().length, args, new ScspHeaders());
              String uuid = wcResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);
              checkPoint = checkPoint + uuid + "\r\n";
            }
            System.out.println("Writing checkpoint: " + checkPoint);
            ByteArrayInputStream cpStream = new ByteArrayInputStream(checkPoint.getBytes());
            // Note that this is a local checkpoint stream
            ScspResponse wcResponse = client.write("", cpStream, checkPoint.getBytes().length, args, new ScspHeaders());
            String uuid = wcResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);
           
            System.out.println(">>>>>> Aggregate Info <<<<<<<<");
            ScspResponse aiResponse = client.aggregateInfo("", rcn + "/" + uuid, outputStream, args, new ScspHeaders());
            System.out.println(aiResponse.toString());
            System.out.println(outputStream.toString());

        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
    private static void RunMutableAggregateInfoLocalClientExamples(ScspClient client, ScspClient localClient)
    {
      String rcn = "_proxy/drcluster";
        System.out.println(">>>>>> Mutable AggregateInfo Local Client Tests <<<<<<<<");
        String testData = "Hello world";
        ByteArrayInputStream inputStream = new ByteArrayInputStream(testData.getBytes());
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try
        {
          String checkPoint = "";
            ScspQueryArgs args = new ScspQueryArgs();
            System.out.println(">>>>>> Write Mutable Streams <<<<<<<<");
            for (int i = 0; i < 4; i++) {
              inputStream.reset();
              ScspResponse wcResponse = client.writeMutable("", inputStream, testData.getBytes().length, args, new ScspHeaders());
              String uuid = wcResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);
              checkPoint = checkPoint + uuid + " mutable\r\n";
            }
            System.out.println("Writing checkpoint: " + checkPoint);
            ByteArrayInputStream cpStream = new ByteArrayInputStream(checkPoint.getBytes());
            // Note that checkpoint goes to the local cluster
            ScspResponse wcResponse = client.write("", cpStream, checkPoint.getBytes().length, args, new ScspHeaders());
            String uuid = wcResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);
           
            System.out.println(">>>>>> Aggregate Info <<<<<<<<");
            ScspResponse aiResponse = client.aggregateInfo("", uuid, outputStream, args, new ScspHeaders());
            System.out.println(aiResponse.toString());
            System.out.println(outputStream.toString());

        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
    private static void RunMutableAggregateInfoRemoteClientExamples(ScspClient client, ScspClient localClient)
    {
      String rcn = "_proxy/drcluster";
        System.out.println(">>>>>> Mutable AggregateInfo Remote Client Tests <<<<<<<<");
        String testData = "Hello world";
        ByteArrayInputStream inputStream = new ByteArrayInputStream(testData.getBytes());
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try
        {
          String checkPoint = "";
            ScspQueryArgs args = new ScspQueryArgs();
            System.out.println(">>>>>> Write Mutable Streams <<<<<<<<");
            for (int i = 1; i < 4; i++) {
              inputStream.reset();
              ScspResponse wcResponse = client.writeMutable(rcn, inputStream, testData.getBytes().length, args, new ScspHeaders());
              String uuid = wcResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);
              checkPoint = checkPoint + uuid + " mutable\r\n";
            }
            System.out.println("Writing checkpoint: " + checkPoint);
            ByteArrayInputStream cpStream = new ByteArrayInputStream(checkPoint.getBytes());
            // Note that this is a local checkpoint stream
            ScspResponse wcResponse = client.write("", cpStream, checkPoint.getBytes().length, args, new ScspHeaders());
            String uuid = wcResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);
           
            System.out.println(">>>>>> Aggregate Info <<<<<<<<");
            ScspResponse aiResponse = client.aggregateInfo("", rcn + "/" + uuid, outputStream, args, new ScspHeaders());
            System.out.println(aiResponse.toString());
            System.out.println(outputStream.toString());

        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
    private static void RunMixedAggregateInfoLocalClientExamples(ScspClient client, ScspClient localClient)
    {
      String rcn = "_proxy/drcluster";
        System.out.println(">>>>>> Mixed AggregateInfo Local Client Tests <<<<<<<<");
        String testData = "Hello world";
        ByteArrayInputStream inputStream = new ByteArrayInputStream(testData.getBytes());
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try
        {
          String checkPoint = "";
            System.out.println(">>>>>> Write Mixed Streams <<<<<<<<");
            for (int i = 1; i < 4; i++) {
                ScspQueryArgs args = new ScspQueryArgs();
              inputStream.reset();
              String mutable = "";
              String uuid = "";
              if (i % 2 == 0) {
                ScspResponse wcResponse = client.writeMutable("", inputStream, testData.getBytes().length, args, new ScspHeaders());
                  uuid = wcResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);
                mutable = " mutable";
              }
              else {
                ScspResponse wcResponse = client.write("", inputStream, testData.getBytes().length, args, new ScspHeaders());
                  uuid = wcResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);               
              }
              checkPoint = checkPoint + uuid + mutable + "\r\n";
            }
            ScspQueryArgs args = new ScspQueryArgs();
            System.out.println("Writing checkpoint: " + checkPoint);
            ByteArrayInputStream cpStream = new ByteArrayInputStream(checkPoint.getBytes());
            // Note that this is a local checkpoint stream
            ScspResponse wcResponse = client.write("", cpStream, checkPoint.getBytes().length, args, new ScspHeaders());
            String uuid = wcResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);
           
            System.out.println(">>>>>> Aggregate Info <<<<<<<<");
            ScspResponse aiResponse = client.aggregateInfo("", uuid, outputStream, args, new ScspHeaders());
            System.out.println(aiResponse.toString());
            System.out.println(outputStream.toString());

        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
    private static void RunMixedAggregateInfoRemoteClientExamples(ScspClient client, ScspClient localClient)
    {
      String rcn = "_proxy/drcluster";
        System.out.println(">>>>>> Mixed AggregateInfo Remote Client Tests <<<<<<<<");
        String testData = "Hello world";
        ByteArrayInputStream inputStream = new ByteArrayInputStream(testData.getBytes());
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try
        {
          String checkPoint = "";
            System.out.println(">>>>>> Write Mixed Streams <<<<<<<<");
            for (int i = 1; i < 20; i++) {
                ScspQueryArgs args = new ScspQueryArgs();
              inputStream.reset();
              String mutable = "";
              String uuid = "";
              if (i % 2 == 0) {
                ScspResponse wcResponse = client.writeMutable(rcn, inputStream, testData.getBytes().length, args, new ScspHeaders());
                  uuid = wcResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);
                mutable = " mutable";
              }
              else {
                ScspResponse wcResponse = client.write(rcn, inputStream, testData.getBytes().length, args, new ScspHeaders());
                  uuid = wcResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);               
              }
              checkPoint = checkPoint + uuid + mutable + "\r\n";
            }
            System.out.println("Writing checkpoint: " + checkPoint);
            ScspQueryArgs args = new ScspQueryArgs();
            ByteArrayInputStream cpStream = new ByteArrayInputStream(checkPoint.getBytes());
            // Note that this is a local checkpoint stream
            ScspResponse wcResponse = client.write("", cpStream, checkPoint.getBytes().length, args, new ScspHeaders());
            String uuid = wcResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);
           
            System.out.println(">>>>>> Aggregate Info <<<<<<<<");
            ScspResponse aiResponse = client.aggregateInfo("", rcn + "/" + uuid, outputStream, args, new ScspHeaders());
            System.out.println(aiResponse.toString());
            System.out.println(outputStream.toString());
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
   
    private static void RunRSWExamples(ScspClient client, ScspClient localClient)
    {
        //[[DOC SNIPPET START | Remote Examples | Remote Synchronous Write example]]
        //Remote Synchronous Write enables you to write or update a copy of the same stream both locally
        //and remotely as part of the same request. A Remote Synchronous Write first writes two copies
        //of the object to the local cluster. If the local write fails for any reason, the error
        //response is returned to the requestor and the operation is abandoned.
        //If the local write succeeds, the Proxy writes the updated object to the specified remote cluster.
        //This request is authenticated using the CAStor administrator credentials specified in the
        //configuration of the remote cluster.
      String rcn = "_proxy/drcluster";
        System.out.println(">>>>>> RSW Tests <<<<<<<<");
        String testData = "Hello world";
        String testUpdateData = "I'm Here";
        ByteArrayInputStream inputStream = new ByteArrayInputStream(testData.getBytes());
        ByteArrayInputStream updateStream = new ByteArrayInputStream(testUpdateData.getBytes());
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try
        {
            System.out.println(">>>>>> Write <<<<<<<<");
            ScspQueryArgs rswArgs = new ScspQueryArgs();
            rswArgs.setValue("replicate","immediate"); //adds the required '?replicate=immediate' query argument
            ScspQueryArgs args = new ScspQueryArgs();
            ScspResponse wcResponse = client.writeMutable(rcn, inputStream, testData.getBytes().length, rswArgs, new ScspHeaders()); //writes a mutable object to the local and remote clusters
            String uuid = wcResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);
            System.out.println(wcResponse.toString());

            //Updates the mutable object in the remote cluster
            System.out.println(">>>>>> Update <<<<<<<<");
            ScspResponse ucResponse = client.updateMutable("", rcn + "/" + uuid, updateStream, testUpdateData.getBytes().length, rswArgs, new ScspHeaders());
            uuid = ucResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);
            System.out.println(ucResponse.toString());

            //Copies metadata to the mutable object in the remote cluster
            System.out.println(">>>>>> Copy (Remote) <<<<<<<<");
            ScspHeaders headers = new ScspHeaders();
            headers.addValue("Castor-color", "blue");
            ScspResponse ccResponse = client.copyMutable("", rcn + "/" + uuid, rswArgs, headers);
            uuid = ccResponse.getResponseHeaders().getHeaderValues("Content-UUID").get(0);
            System.out.println(ccResponse.toString());

            //Reads the mutable object directly from the remote cluster
            System.out.println(">>>>>> Read Remote <<<<<<<<");
            ScspResponse rcResponse = client.readMutable("", rcn + "/" + uuid, outputStream, args, new ScspHeaders());
            System.out.println(rcResponse.toString());
            System.out.println("Body Received");
            System.out.println(outputStream.toString());

            //Reads the mutable object directly from the local cluster
            System.out.println(">>>>>> Read Local<<<<<<<<");
            outputStream.reset();
            ScspResponse lrcResponse = localClient.readMutable("", uuid, outputStream, args, new ScspHeaders());
            System.out.println(lrcResponse.toString());
            System.out.println("Body Received");
            System.out.println(outputStream.toString());

            //Reads the mutable object from the local cluster using the Proxy
            System.out.println(">>>>>> Read Proxy Local<<<<<<<<");
            outputStream.reset();
            ScspResponse prcResponse = client.readMutable("", uuid, outputStream, args, new ScspHeaders());
            System.out.println(prcResponse.toString());
            System.out.println("Body Received");
            System.out.println(outputStream.toString());

            //Infos the mutable object in the remote cluster
            System.out.println(">>>>>> Info (Remote) <<<<<<<<");
            ScspResponse icResponse = client.infoMutable("", uuid, args, new ScspHeaders());
            System.out.println(icResponse.toString());

            //Deletes the object in the remote cluster
            System.out.println(">>>>>> Delete <<<<<<<<");
            ScspResponse dcResponse = client.deleteMutable("", uuid, args, new ScspHeaders());
            System.out.println(dcResponse.toString());
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
    //[[DOC SNIPPET END]]

  private static void RunExamples(ScspClient proxyClient, ScspClient localClient) {
    RunImmutableRemoteOnlyClientExamples(proxyClient, localClient);
    RunImmutableAnyRemoteClientExamples(proxyClient, localClient);
    RunImmutableAggregateInfoLocalClientExamples(proxyClient, localClient);
    RunImmutableAggregateInfoRemoteClientExamples(proxyClient, localClient);
    RunMutableAggregateInfoLocalClientExamples(proxyClient, localClient);
    RunMutableAggregateInfoRemoteClientExamples(proxyClient, localClient);
    RunMixedAggregateInfoLocalClientExamples(proxyClient, localClient);
    RunMixedAggregateInfoRemoteClientExamples(proxyClient, localClient);
    RunRSWExamples(proxyClient, localClient);
  }
 
  private static boolean CheckConnections(ScspClient proxyClient) {
      boolean res = true;
      String rcn = "_proxy/drcluster";
        String testData = "Hello world";
        ByteArrayInputStream inputStream = new ByteArrayInputStream(testData.getBytes());
        try
        {
            ScspResponse wcResponse = proxyClient.write("", inputStream, testData.getBytes().length, new ScspQueryArgs(), new ScspHeaders());
            if (wcResponse.getResultCode() == ScspResponse.ScspResultCode.ScspRCFailure) {
              System.out.println("Unabled to write to proxy.");
              res = false;
            }
            else {
              wcResponse = proxyClient.write(rcn, inputStream, testData.getBytes().length, new ScspQueryArgs(), new ScspHeaders());
              if (wcResponse.getResultCode() == ScspResponse.ScspResultCode.ScspRCFailure) {
                  System.out.println("Unabled to write to remote cluster.");
                res = false;
              }
            }
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
      return res;
  }
 
  private static void PrintUsage() {
    System.out.println("THIS TEST REQUIRES CONFIGURATION OF A PROXY SERVER AND TWO CASTOR CLUSTERS ");
    System.out.println("ON THE NETWORK. THE TESTS WILL FAIL WITHOUT ALL THREE.");
    System.out.println("");
    System.out.println("To configure a network for running these examples, start two castor clusters, ");
      System.out.println("one for proxy local access and the other for proxy remote access. Configure");
      System.out.println("your hosts.config to include a line specifying a remote cluster name");
      System.out.println("'drcluster' pointing at the remote cluster with the right configuration");
      System.out.println("information. Make sure your scspproxy.cfg points to the correct hosts.cfg");
      System.out.println("and specifies the same host ip as you specify in your hosts at the start ");
      System.out.println("of this file, and then run your scspproxy.");
  }

}
TOP

Related Classes of com.caringo.client.examples.SCSPRemoteTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.