1717 */
1818package org .apache .hadoop .hbase ;
1919
20+ import static org .junit .Assert .assertArrayEquals ;
2021import static org .junit .Assert .assertEquals ;
2122import static org .junit .Assert .assertFalse ;
23+ import static org .junit .Assert .assertNotEquals ;
2224import static org .junit .Assert .assertNotNull ;
2325import static org .junit .Assert .assertTrue ;
2426
5254import org .slf4j .Logger ;
5355import org .slf4j .LoggerFactory ;
5456
57+ import org .apache .hbase .thirdparty .com .google .common .collect .Iterables ;
58+
5559/**
5660 * Port of old TestScanMultipleVersions, TestTimestamp and TestGetRowVersions
5761 * from old testing framework to {@link HBaseTestingUtil}.
@@ -129,6 +133,7 @@ public void flushcache() throws IOException {
129133
130134 /**
131135 * Verifies versions across a cluster restart.
136+ * <p/>
132137 * Port of old TestGetRowVersions test to here so can better utilize the spun
133138 * up cluster running more than a single test per spin up. Keep old tests'
134139 * crazyness.
@@ -170,26 +175,26 @@ public void testGetRowVersions() throws Exception {
170175 Result r = table .get (get );
171176 assertNotNull (r );
172177 assertFalse (r .isEmpty ());
173- assertTrue ( r .size () == 1 );
178+ assertEquals ( 1 , r .size ());
174179 byte [] value = r .getValue (contents , contents );
175- assertTrue ( value .length != 0 );
180+ assertNotEquals ( 0 , value .length );
176181 assertTrue (Bytes .equals (value , value2 ));
177182 // Now check getRow with multiple versions
178183 get = new Get (row );
179184 get .readAllVersions ();
180185 r = table .get (get );
181- assertTrue ( r .size () == 2 );
186+ assertEquals ( 2 , r .size ());
182187 value = r .getValue (contents , contents );
183- assertTrue ( value .length != 0 );
184- assertTrue ( Bytes . equals ( value , value2 ) );
188+ assertNotEquals ( 0 , value .length );
189+ assertArrayEquals ( value , value2 );
185190 NavigableMap <byte [], NavigableMap <byte [], NavigableMap <Long , byte []>>> map =
186191 r .getMap ();
187192 NavigableMap <byte [], NavigableMap <Long , byte []>> familyMap =
188193 map .get (contents );
189194 NavigableMap <Long , byte []> versionMap = familyMap .get (contents );
190- assertTrue ( versionMap .size () == 2 );
191- assertTrue ( Bytes . equals ( value1 , versionMap .get (timestamp1 ) ));
192- assertTrue ( Bytes . equals ( value2 , versionMap .get (timestamp2 ) ));
195+ assertEquals ( 2 , versionMap .size ());
196+ assertArrayEquals ( value1 , versionMap .get (timestamp1 ));
197+ assertArrayEquals ( value2 , versionMap .get (timestamp2 ));
193198 table .close ();
194199 }
195200
@@ -220,11 +225,11 @@ public void testScanMultipleVersions() throws Exception {
220225
221226 for (int i = 0 ; i < startKeys .length ; i ++) {
222227 if (i == 0 ) {
223- assertTrue ( Bytes . equals ( HConstants .EMPTY_START_ROW , startKeys [i ]) );
224- assertTrue ( Bytes . equals ( endKeys [i ], splitRows [0 ]) );
228+ assertArrayEquals ( HConstants .EMPTY_START_ROW , startKeys [i ]);
229+ assertArrayEquals ( endKeys [i ], splitRows [0 ]);
225230 } else if (i == 1 ) {
226- assertTrue ( Bytes . equals ( splitRows [0 ], startKeys [i ]) );
227- assertTrue ( Bytes . equals ( endKeys [i ], HConstants .EMPTY_END_ROW ) );
231+ assertArrayEquals ( splitRows [0 ], startKeys [i ]);
232+ assertArrayEquals ( endKeys [i ], HConstants .EMPTY_END_ROW );
228233 }
229234 }
230235 // Insert data
@@ -244,100 +249,59 @@ public void testScanMultipleVersions() throws Exception {
244249 get .addFamily (HConstants .CATALOG_FAMILY );
245250 get .setTimestamp (timestamp [j ]);
246251 Result result = table .get (get );
247- int cellCount = 0 ;
248- for (@ SuppressWarnings ("unused" )Cell kv : result .listCells ()) {
249- cellCount ++;
250- }
251- assertTrue (cellCount == 1 );
252+ int cellCount = result .rawCells ().length ;
253+ assertEquals (1 , cellCount );
252254 }
253255 }
254256
255257 // Case 1: scan with LATEST_TIMESTAMP. Should get two rows
256- int count = 0 ;
258+ int count ;
257259 Scan scan = new Scan ();
258260 scan .addFamily (HConstants .CATALOG_FAMILY );
259- ResultScanner s = table .getScanner (scan );
260- try {
261- for (Result rr = null ; (rr = s .next ()) != null ;) {
262- System .out .println (rr .toString ());
263- count += 1 ;
264- }
265- assertEquals ("Number of rows should be 2" , 2 , count );
266- } finally {
267- s .close ();
261+ try (ResultScanner s = table .getScanner (scan )) {
262+ count = Iterables .size (s );
268263 }
264+ assertEquals ("Number of rows should be 2" , 2 , count );
269265
270266 // Case 2: Scan with a timestamp greater than most recent timestamp
271267 // (in this case > 1000 and < LATEST_TIMESTAMP. Should get 2 rows.
272-
273- count = 0 ;
274268 scan = new Scan ();
275269 scan .setTimeRange (1000L , Long .MAX_VALUE );
276270 scan .addFamily (HConstants .CATALOG_FAMILY );
277-
278- s = table .getScanner (scan );
279- try {
280- while (s .next () != null ) {
281- count += 1 ;
282- }
283- assertEquals ("Number of rows should be 2" , 2 , count );
284- } finally {
285- s .close ();
271+ try (ResultScanner s = table .getScanner (scan )) {
272+ count = Iterables .size (s );
286273 }
274+ assertEquals ("Number of rows should be 2" , 2 , count );
287275
288276 // Case 3: scan with timestamp equal to most recent timestamp
289277 // (in this case == 1000. Should get 2 rows.
290-
291- count = 0 ;
292278 scan = new Scan ();
293279 scan .setTimestamp (1000L );
294280 scan .addFamily (HConstants .CATALOG_FAMILY );
295-
296- s = table .getScanner (scan );
297- try {
298- while (s .next () != null ) {
299- count += 1 ;
300- }
301- assertEquals ("Number of rows should be 2" , 2 , count );
302- } finally {
303- s .close ();
281+ try (ResultScanner s = table .getScanner (scan )) {
282+ count = Iterables .size (s );
304283 }
284+ assertEquals ("Number of rows should be 2" , 2 , count );
305285
306286 // Case 4: scan with timestamp greater than first timestamp but less than
307287 // second timestamp (100 < timestamp < 1000). Should get 2 rows.
308-
309- count = 0 ;
310288 scan = new Scan ();
311289 scan .setTimeRange (100L , 1000L );
312290 scan .addFamily (HConstants .CATALOG_FAMILY );
313-
314- s = table .getScanner (scan );
315- try {
316- while (s .next () != null ) {
317- count += 1 ;
318- }
319- assertEquals ("Number of rows should be 2" , 2 , count );
320- } finally {
321- s .close ();
291+ try (ResultScanner s = table .getScanner (scan )) {
292+ count = Iterables .size (s );
322293 }
294+ assertEquals ("Number of rows should be 2" , 2 , count );
323295
324296 // Case 5: scan with timestamp equal to first timestamp (100)
325297 // Should get 2 rows.
326-
327- count = 0 ;
328298 scan = new Scan ();
329299 scan .setTimestamp (100L );
330300 scan .addFamily (HConstants .CATALOG_FAMILY );
331-
332- s = table .getScanner (scan );
333- try {
334- while (s .next () != null ) {
335- count += 1 ;
336- }
337- assertEquals ("Number of rows should be 2" , 2 , count );
338- } finally {
339- s .close ();
301+ try (ResultScanner s = table .getScanner (scan )) {
302+ count = Iterables .size (s );
340303 }
304+ assertEquals ("Number of rows should be 2" , 2 , count );
341305 }
342306
343307}
0 commit comments