Lots of buffered counter increments from multiple threads.
()
| 571 | |
| 572 | /** Lots of buffered counter increments from multiple threads. */ |
| 573 | @Test |
| 574 | public void bufferedIncrementStressTest() throws Exception { |
| 575 | client.setFlushInterval(FAST_FLUSH); |
| 576 | final byte[] table = TestIntegration.table.getBytes(); |
| 577 | final byte[] key1 = "cnt1".getBytes(); // Spread the increments.. |
| 578 | final byte[] key2 = "cnt2".getBytes(); // .. over these two counters. |
| 579 | final byte[] family = TestIntegration.family.getBytes(); |
| 580 | final byte[] qual = { 'q' }; |
| 581 | final DeleteRequest del1 = new DeleteRequest(table, key1, family, qual); |
| 582 | final DeleteRequest del2 = new DeleteRequest(table, key2, family, qual); |
| 583 | Deferred.group(client.delete(del1), client.delete(del2)).join(); |
| 584 | |
| 585 | final int nthreads = Runtime.getRuntime().availableProcessors() * 2; |
| 586 | // The magic number comes from the limit on callbacks that Deferred |
| 587 | // imposes. We spread increments over two counters, hence the x 2. |
| 588 | final int incr_per_thread = 8192 / nthreads * 2; |
| 589 | final boolean[] successes = new boolean[nthreads]; |
| 590 | |
| 591 | final class IncrementThread extends Thread { |
| 592 | private final int num; |
| 593 | public IncrementThread(final int num) { |
| 594 | super("IncrementThread-" + num); |
| 595 | this.num = num; |
| 596 | } |
| 597 | public void run() { |
| 598 | try { |
| 599 | doIncrements(); |
| 600 | successes[num] = true; |
| 601 | } catch (Throwable e) { |
| 602 | successes[num] = false; |
| 603 | LOG.error("Uncaught exception", e); |
| 604 | } |
| 605 | } |
| 606 | private void doIncrements() { |
| 607 | for (int i = 0; i < incr_per_thread; i++) { |
| 608 | final byte[] key = i % 2 == 0 ? key1 : key2; |
| 609 | bufferIncrement(table, key, family, qual, 1); |
| 610 | } |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | final IncrementThread[] threads = new IncrementThread[nthreads]; |
| 615 | for (int i = 0; i < nthreads; i++) { |
| 616 | threads[i] = new IncrementThread(i); |
| 617 | } |
| 618 | LOG.info("Starting to generate increments"); |
| 619 | for (int i = 0; i < nthreads; i++) { |
| 620 | threads[i].start(); |
| 621 | } |
| 622 | for (int i = 0; i < nthreads; i++) { |
| 623 | threads[i].join(); |
| 624 | } |
| 625 | |
| 626 | LOG.info("Flushing all buffered increments."); |
| 627 | client.flush().joinUninterruptibly(); |
| 628 | LOG.info("Done flushing all buffered increments."); |
| 629 | |
| 630 | // Check that we the counters have the expected value. |
nothing calls this directly
no test coverage detected