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();
}
}
}