Package net.helipilot50.entry

Source Code of net.helipilot50.entry.ClientTest

package net.helipilot50.entry;

import java.util.ArrayList;
import java.util.List;

import net.citrusleaf.CitrusleafClient;
import net.citrusleaf.CitrusleafClient.ClBin;
import net.citrusleaf.CitrusleafClient.ClResult;
import net.citrusleaf.CitrusleafClient.ClResultCode;


public class ClientTest {

  public static void main(String[] args){

    CitrusleafClient cc = new net.citrusleaf.CitrusleafClient( "192.168.51.128", 3000);

    // wait for connection
    long startTime = System.currentTimeMillis();
    while( !cc.isConnected() && (System.currentTimeMillis() < startTime + 4000)) {
      try {
        Thread.sleep(10) ;
      } catch (Exception e) {
        ;
      }
    }
    if( !cc.isConnected() ){
      System.out.println("Could not connect to cluster - have correct host and port?");
      return;
    }
    try {
      if( cc.isConnected() ){
        final int COUNT = 10;
        int success = 0;
//        // Single writes
//        System.out.println("Writing " + COUNT);
//        long start = System.currentTimeMillis();
//        for (int i = 0; i < COUNT; i++){
//          ClResultCode rc = cc.set("test","myset","mykey",
//              "mybinInt" + i, 100,  null , null);
//          if (rc == ClResultCode.OK)
//            success++;
//        }
//        long stop = System.currentTimeMillis();
//        System.out.println("Completed " + success + " successful write operations in " + (stop-start) + " milliseconds");
//       
//        // Single reads
//        System.out.println("Reading " + COUNT);
//        success = 0;
//        start = System.currentTimeMillis();
//        for (int i = 0; i < COUNT; i++){
//          ClResult cr = cc.get("test", "myset", "mykey", "mybinInt" + i, null);
//          if (cr.resultCode == ClResultCode.OK)
//            success++;
//        }
//        stop = System.currentTimeMillis();
//        System.out.println("Completed " + success + " successful read operations in " + (stop-start) + " milliseconds");

        //List writes
        List<ClBin> mylist = new ArrayList<ClBin>();
        System.out.println("Writing a Person record ");
        long start = System.currentTimeMillis();
        mylist.add(new ClBin("firstName", "Peter"));
        mylist.add(new ClBin("lastName", "Milne"));
        mylist.add(new ClBin("eyeColour", "swamp"));
        mylist.add(new ClBin("height", 177));
        mylist.add(new ClBin("weight", 75));
        String key = mylist.get(0).value.toString() + mylist.get(1).value.toString();
        ClResultCode rc = cc.set("test","people",key, mylist, null, null);
        long stop = System.currentTimeMillis();
        if (rc == ClResultCode.OK)
          System.out.println("Completed write a person in "+ (stop-start) + " milliseconds");
        else
          System.out.println("Failure write a person with " + rc + "  in "+ (stop-start) + " milliseconds");
       
        //List reads
        System.out.println("Read a person");
        start = System.currentTimeMillis();
        ClResult cr = cc.getAll("test", "people", key, null);
        stop = System.currentTimeMillis();
       
        System.out.println("Completed read person of " + cr.results.keySet().size() + " bins holding integers in " + (stop-start) + " milliseconds");

        cc.delete("test", "people", key, null, null);
      }
    } finally {
      if( cc.isConnected() ){
        cc.close();
      }
    }
  }
  public static void readingSingleValue(CitrusleafClient cc, String namespace){
    ClResult cr = cc.get(namespace, "myset", "mykey", "name", null);
    if (cr.result != null) {
      System.out.println("read single value:" + cr.result);
    }
  }
  public void readingMultipleValues(CitrusleafClient cc, String namespace){
    ClResult cr = cc.getAll(namespace, "myset", "mykey", null);
    if (cr.results != null) {
      for (String binName : cr.results.keySet()) {
        System.out.println("got " + binName + ":"+cr.results.get(binName));
      }
    }
  }

  public void delete(CitrusleafClient cc, String namespace){
    cc.delete(namespace, "myset", "mykey", null, null);
  }
}
TOP

Related Classes of net.helipilot50.entry.ClientTest

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.