Basic scan test.
()
| 369 | |
| 370 | /** Basic scan test. */ |
| 371 | @Test |
| 372 | public void basicScan() throws Exception { |
| 373 | client.setFlushInterval(FAST_FLUSH); |
| 374 | final PutRequest put1 = new PutRequest(table, "s1", family, "q", "v1"); |
| 375 | final PutRequest put2 = new PutRequest(table, "s2", family, "q", "v2"); |
| 376 | final PutRequest put3 = new PutRequest(table, "s3", family, "q", "v3"); |
| 377 | Deferred.group(client.put(put1), client.put(put2), |
| 378 | client.put(put3)).join(); |
| 379 | // Scan the same 3 rows created above twice. |
| 380 | for (int i = 0; i < 2; i++) { |
| 381 | LOG.info("------------ iteration #" + i); |
| 382 | final Scanner scanner = client.newScanner(table); |
| 383 | scanner.setStartKey("s0"); |
| 384 | scanner.setStopKey("s9"); |
| 385 | // Callback class to keep scanning recursively. |
| 386 | class cb implements Callback<Object, ArrayList<ArrayList<KeyValue>>> { |
| 387 | private int n = 0; |
| 388 | public Object call(final ArrayList<ArrayList<KeyValue>> rows) { |
| 389 | if (rows == null) { |
| 390 | return null; |
| 391 | } |
| 392 | n++; |
| 393 | try { |
| 394 | assertSizeIs(1, rows); |
| 395 | final ArrayList<KeyValue> kvs = rows.get(0); |
| 396 | final KeyValue kv = kvs.get(0); |
| 397 | assertSizeIs(1, kvs); |
| 398 | assertEq("s" + n, kv.key()); |
| 399 | assertEq("q", kv.qualifier()); |
| 400 | assertEq("v" + n, kv.value()); |
| 401 | return scanner.nextRows(1).addCallback(this); |
| 402 | } catch (AssertionError e) { |
| 403 | // Deferred doesn't catch Errors on purpose, so transform any |
| 404 | // assertion failure into an Exception. |
| 405 | throw new RuntimeException("Asynchronous failure", e); |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | try { |
| 410 | scanner.nextRows(1).addCallback(new cb()).join(); |
| 411 | } finally { |
| 412 | scanner.close().join(); |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | /** Scan which closes before reaching end of results. */ |
| 418 | @Test |
nothing calls this directly
no test coverage detected