Source:
<code>private void test(String t1, String t2, Connector c, IteratorSetting itset, int numEntriesToWritePerEntry) throws Exception { c.tableOperations().create(t1); Key k = new Key(new Text("row"), new Text("cf"), new Text("cq")); Value v = new Value("1".getBytes()); { BatchWriterConfig config = new BatchWriterConfig(); config.setMaxMemory(0); BatchWriter writer = c.createBatchWriter(t1, config); Mutation m = new Mutation(k.getRow()); m.put(k.getColumnFamily(), k.getColumnQualifier(), v); writer.addMutation(m); writer.close(); } c.tableOperations().create(t2); IteratorSetting summer = new IteratorSetting(2, "summer", SummingCombiner.class); LongCombiner.setEncodingType(summer, LongCombiner.Type.STRING); LongCombiner.setCombineAllColumns(summer, true); c.tableOperations().attachIterator(t2, summer); Map.Entry<Key,Value> actual; Scanner scanner = null; try { scanner = c.createScanner(t1, Authorizations.EMPTY); scanner.addScanIterator(itset); actual = Iterators.getOnlyElement(scanner.iterator()); Assert.assertTrue(actual.getKey().equals(k, PartialKey.ROW_COLFAM_COLQUAL)); Assert.assertEquals(BatchWriterIterator.SUCCESS_VALUE, actual.getValue()); } finally { if (scanner != null) { scanner.close(); } } try { scanner = c.createScanner(t2, Authorizations.EMPTY); actual = Iterators.getOnlyElement(scanner.iterator()); log.debug("t2 entry is " + actual.getKey().toStringNoTime() + " -> " + actual.getValue()); Assert.assertTrue(actual.getKey().equals(k, PartialKey.ROW_COLFAM_COLQUAL)); Assert.assertEquals(numEntriesToWritePerEntry, Integer.parseInt(actual.getValue().toString())); } finally { if (scanner != null) { scanner.close(); } <START> } <END> c.tableOperations().delete(t1); c.tableOperations().delete(t2); }</code><technical_language>in this class try-with-resources also. variable declared instead of reused</technical_language>

Target:
private void test(String t1, String t2, Connector c, IteratorSetting itset, int numEntriesToWritePerEntry) throws Exception { c.tableOperations().create(t1); Key k = new Key(new Text("row"), new Text("cf"), new Text("cq")); Value v = new Value("1".getBytes()); { BatchWriterConfig config = new BatchWriterConfig(); config.setMaxMemory(0); BatchWriter writer = c.createBatchWriter(t1, config); Mutation m = new Mutation(k.getRow()); m.put(k.getColumnFamily(), k.getColumnQualifier(), v); writer.addMutation(m); writer.close(); } c.tableOperations().create(t2); IteratorSetting summer = new IteratorSetting(2, "summer", SummingCombiner.class); LongCombiner.setEncodingType(summer, LongCombiner.Type.STRING); LongCombiner.setCombineAllColumns(summer, true); c.tableOperations().attachIterator(t2, summer); Map.Entry<Key,Value> actual; try (Scanner scanner = c.createScanner(t1, Authorizations.EMPTY)) { scanner.addScanIterator(itset); actual = Iterators.getOnlyElement(scanner.iterator()); Assert.assertTrue(actual.getKey().equals(k, PartialKey.ROW_COLFAM_COLQUAL)); Assert.assertEquals(BatchWriterIterator.SUCCESS_VALUE, actual.getValue()); } try (Scanner scanner = c.createScanner(t2, Authorizations.EMPTY)) { actual = Iterators.getOnlyElement(scanner.iterator()); log.debug("t2 entry is " + actual.getKey().toStringNoTime() + " -> " + actual.getValue()); Assert.assertTrue(actual.getKey().equals(k, PartialKey.ROW_COLFAM_COLQUAL)); Assert.assertEquals(numEntriesToWritePerEntry, Integer.parseInt(actual.getValue().toString())); } c.tableOperations().delete(t1); c.tableOperations().delete(t2); }