Mercurial > hg > Members > shoshi > TreeCMSv1
annotate src/treecms/proto/cassandra/v1/test/CassGetSliceTest.java @ 51:d4709911e0ed
moved old Cassandra Monotonic-Tree implementation from "cassandra" to "cassandra.v1"
author | shoshi |
---|---|
date | Fri, 11 Feb 2011 15:07:57 +0900 |
parents | src/treecms/proto/cassandra/test/CassGetSliceTest.java@a72718a0bccf |
children |
rev | line source |
---|---|
51
d4709911e0ed
moved old Cassandra Monotonic-Tree implementation from "cassandra" to "cassandra.v1"
shoshi
parents:
50
diff
changeset
|
1 package treecms.proto.cassandra.v1.test; |
41 | 2 |
43 | 3 /* |
4 * Cassandra get_slice , get_range_slice test | |
5 * | |
6 * 2011/01/19 Shoshi TAMAKI | |
7 */ | |
8 | |
48 | 9 import java.util.HashMap; |
10 import java.util.LinkedList; | |
41 | 11 import java.util.List; |
48 | 12 import java.util.Map; |
13 | |
41 | 14 import org.apache.cassandra.thrift.Cassandra; |
48 | 15 import org.apache.cassandra.thrift.Column; |
41 | 16 import org.apache.cassandra.thrift.ColumnOrSuperColumn; |
17 import org.apache.cassandra.thrift.ColumnParent; | |
18 import org.apache.cassandra.thrift.ColumnPath; | |
19 import org.apache.cassandra.thrift.ConsistencyLevel; | |
20 import org.apache.cassandra.thrift.InvalidRequestException; | |
21 import org.apache.cassandra.thrift.KeySlice; | |
22 import org.apache.cassandra.thrift.NotFoundException; | |
23 import org.apache.cassandra.thrift.SlicePredicate; | |
24 import org.apache.cassandra.thrift.SliceRange; | |
25 import org.apache.cassandra.thrift.TimedOutException; | |
26 import org.apache.cassandra.thrift.UnavailableException; | |
27 import org.apache.thrift.TException; | |
28 import org.apache.thrift.protocol.TBinaryProtocol; | |
29 import org.apache.thrift.protocol.TProtocol; | |
30 import org.apache.thrift.transport.TSocket; | |
31 import org.apache.thrift.transport.TTransport; | |
32 | |
33 public class CassGetSliceTest | |
34 { | |
35 public static void main(String _args[])throws Exception | |
36 { | |
37 Cassandra.Client client; | |
38 | |
39 String host = "localhost"; | |
40 int port = 9160; | |
41 | |
42 TTransport tr = new TSocket(host,port); | |
43 TProtocol proto = new TBinaryProtocol(tr); | |
44 client = new Cassandra.Client(proto); | |
45 | |
46 tr.open(); | |
47 | |
48 System.out.println("ClusterName = "+client.describe_cluster_name()); | |
50 | 49 testGetRangeSlice(client); |
50 //testBatchInsert(client); | |
41 | 51 |
52 tr.close(); | |
53 } | |
54 | |
48 | 55 public static void testBatchInsert(Cassandra.Client _client) throws InvalidRequestException, UnavailableException, TimedOutException, TException |
56 { | |
57 List<ColumnOrSuperColumn> list = new LinkedList<ColumnOrSuperColumn>(); | |
58 | |
59 ColumnOrSuperColumn c1 = new ColumnOrSuperColumn(); | |
60 c1.column = new Column(); | |
61 c1.column.name = "hogehoge".getBytes(); | |
62 c1.column.value = "fugafuga".getBytes(); | |
63 c1.column.timestamp = System.currentTimeMillis()/1000; | |
64 | |
65 ColumnOrSuperColumn c2 = new ColumnOrSuperColumn(); | |
66 c2.column = new Column(); | |
67 c2.column.name = "abc".getBytes(); | |
68 c2.column.value = "abcabc".getBytes(); | |
69 c2.column.timestamp = System.currentTimeMillis()/1000; | |
70 | |
71 ColumnOrSuperColumn c3 = new ColumnOrSuperColumn(); | |
72 c3.column = new Column(); | |
73 c3.column.name = "def".getBytes(); | |
74 c3.column.value = "defdef".getBytes(); | |
75 c3.column.timestamp = System.currentTimeMillis()/1000; | |
76 | |
77 list.add(c1); | |
78 list.add(c2); | |
79 list.add(c3); | |
80 | |
81 Map<String,List<ColumnOrSuperColumn>> map = new HashMap<String,List<ColumnOrSuperColumn>>(); | |
82 map.put("TreeCMSCF01",list); | |
83 | |
84 _client.batch_insert("TreeCMSKS","hoge",map,ConsistencyLevel.ONE); | |
85 | |
86 SliceRange sr = new SliceRange(); | |
87 sr.setStart(new byte[0]); | |
88 sr.setFinish(new byte[0]); | |
89 | |
90 SlicePredicate sp = new SlicePredicate(); | |
91 sp.setSlice_range(sr); | |
92 | |
93 List<ColumnOrSuperColumn> result = _client.get_slice("TreeCMSKS","hoge",new ColumnParent("TreeCMSCF01"),sp,ConsistencyLevel.ONE); | |
94 | |
95 for(ColumnOrSuperColumn val : result){ | |
96 System.out.print("name:"+new String(val.column.name)); | |
97 System.out.println("\tvalue:"+new String(val.column.value)); | |
98 } | |
99 } | |
100 | |
41 | 101 public static void testGet(Cassandra.Client _client) throws InvalidRequestException, NotFoundException, UnavailableException, TimedOutException, TException |
102 { | |
103 ColumnPath path = new ColumnPath(); | |
104 path.column_family = "TreeCMSCF01"; | |
105 path.column = "value".getBytes(); | |
106 | |
107 ColumnOrSuperColumn value = _client.get("TreeCMSKS","uuid@01",path,ConsistencyLevel.ONE); | |
108 | |
109 System.out.println(new String(value.column.getValue())); | |
110 } | |
111 | |
112 public static void testGetSlice(Cassandra.Client _client) throws InvalidRequestException, NotFoundException, UnavailableException, TimedOutException, TException | |
113 { | |
114 SliceRange sliceRange = new SliceRange(); | |
115 sliceRange.setStart(new byte[0]); | |
116 sliceRange.setFinish(new byte[0]); | |
117 | |
118 SlicePredicate slicePredicate = new SlicePredicate(); | |
119 slicePredicate.setSlice_range(sliceRange); | |
120 | |
50 | 121 List<ColumnOrSuperColumn> values = _client.get_slice("TreeCMSKS","",new ColumnParent("TreeCMSCF03"),slicePredicate,ConsistencyLevel.ONE); |
41 | 122 |
123 for(ColumnOrSuperColumn value : values){ | |
124 System.out.println(new String(value.column.getName())+":"+new String(value.column.getValue())); | |
125 } | |
126 } | |
127 | |
128 public static void testGetRangeSlice(Cassandra.Client _client) throws InvalidRequestException, NotFoundException, UnavailableException, TimedOutException, TException | |
129 { | |
130 SliceRange sliceRange = new SliceRange(); | |
131 sliceRange.setStart(new byte[0]); | |
132 sliceRange.setFinish(new byte[0]); | |
133 | |
134 SlicePredicate slicePredicate = new SlicePredicate(); | |
135 slicePredicate.setSlice_range(sliceRange); | |
136 | |
50 | 137 List<KeySlice> values = _client.get_range_slice("TreeCMSKS",new ColumnParent("TreeCMSCF03"),slicePredicate,"","",100,ConsistencyLevel.ONE); |
41 | 138 |
139 for(KeySlice key : values){ | |
140 System.out.println(new String(key.getKey())); | |
141 for(ColumnOrSuperColumn column : key.getColumns()){ | |
142 System.out.println("\t"+new String(column.column.getName())+":"+new String(column.column.getValue())); | |
143 } | |
144 } | |
145 } | |
146 } |