1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.ipc;
20
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertTrue;
23
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import org.apache.hadoop.hbase.Cell;
29 import org.apache.hadoop.hbase.CellScannable;
30 import org.apache.hadoop.hbase.CellScanner;
31 import org.apache.hadoop.hbase.SmallTests;
32 import org.apache.hadoop.hbase.util.Bytes;
33 import org.junit.Test;
34 import org.junit.experimental.categories.Category;
35
36
37 @Category(SmallTests.class)
38 public class TestPayloadCarryingRpcController {
39 @Test
40 public void testListOfCellScannerables() throws IOException {
41 List<CellScannable> cells = new ArrayList<CellScannable>();
42 final int count = 10;
43 for (int i = 0; i < count; i++) {
44 cells.add(createCell(i));
45 }
46 PayloadCarryingRpcController controller = new PayloadCarryingRpcController(cells);
47 CellScanner cellScanner = controller.cellScanner();
48 int index = 0;
49 for (; cellScanner.advance(); index++) {
50 Cell cell = cellScanner.current();
51 byte [] indexBytes = Bytes.toBytes(index);
52 assertTrue("" + index, Bytes.equals(indexBytes, 0, indexBytes.length, cell.getValueArray(),
53 cell.getValueOffset(), cell.getValueLength()));
54 }
55 assertEquals(count, index);
56 }
57
58
59
60
61
62 static CellScannable createCell(final int index) {
63 return new CellScannable() {
64 @Override
65 public CellScanner cellScanner() {
66 return new CellScanner() {
67 @Override
68 public Cell current() {
69
70
71 return new Cell() {
72 private final int i = index;
73
74 @Override
75 public byte[] getRowArray() {
76
77 return null;
78 }
79
80 @Override
81 public int getRowOffset() {
82
83 return 0;
84 }
85
86 @Override
87 public short getRowLength() {
88
89 return 0;
90 }
91
92 @Override
93 public byte[] getFamilyArray() {
94
95 return null;
96 }
97
98 @Override
99 public int getFamilyOffset() {
100
101 return 0;
102 }
103
104 @Override
105 public byte getFamilyLength() {
106
107 return 0;
108 }
109
110 @Override
111 public byte[] getQualifierArray() {
112
113 return null;
114 }
115
116 @Override
117 public int getQualifierOffset() {
118
119 return 0;
120 }
121
122 @Override
123 public int getQualifierLength() {
124
125 return 0;
126 }
127
128 @Override
129 public long getTimestamp() {
130
131 return 0;
132 }
133
134 @Override
135 public byte getTypeByte() {
136
137 return 0;
138 }
139
140 @Override
141 public long getMvccVersion() {
142
143 return 0;
144 }
145
146 @Override
147 public byte[] getValueArray() {
148 return Bytes.toBytes(this.i);
149 }
150
151 @Override
152 public int getValueOffset() {
153 return 0;
154 }
155
156 @Override
157 public int getValueLength() {
158 return Bytes.SIZEOF_INT;
159 }
160
161 @Override
162 public int getTagsOffset() {
163
164 return 0;
165 }
166
167 @Override
168 public int getTagsLengthUnsigned() {
169
170 return 0;
171 }
172
173 @Override
174 public short getTagsLength() {
175
176 return 0;
177 }
178
179 @Override
180 public byte[] getTagsArray() {
181
182 return null;
183 }
184
185 @Override
186 public byte[] getValue() {
187
188 return null;
189 }
190
191 @Override
192 public byte[] getFamily() {
193
194 return null;
195 }
196
197 @Override
198 public byte[] getQualifier() {
199
200 return null;
201 }
202
203 @Override
204 public byte[] getRow() {
205
206 return null;
207 }
208 };
209 }
210
211 private boolean hasCell = true;
212 @Override
213 public boolean advance() {
214
215 if (!hasCell) return hasCell;
216 hasCell = false;
217 return true;
218 }
219 };
220 }
221 };
222 }
223 }