Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B3555200C87 for ; Wed, 17 May 2017 16:58:14 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id B1F1C160BCD; Wed, 17 May 2017 14:58:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A5CE1160BD3 for ; Wed, 17 May 2017 16:58:11 +0200 (CEST) Received: (qmail 91003 invoked by uid 500); 17 May 2017 14:58:10 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 90195 invoked by uid 99); 17 May 2017 14:58:10 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 May 2017 14:58:10 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 01943E1835; Wed, 17 May 2017 14:58:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: git-site-role@apache.org To: commits@hbase.apache.org Date: Wed, 17 May 2017 14:58:12 -0000 Message-Id: <8c5cbd40bbe64694b57db601670d72dc@git.apache.org> In-Reply-To: <3cf7c95906ce45e2a761102abb07ed40@git.apache.org> References: <3cf7c95906ce45e2a761102abb07ed40@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [04/20] hbase-site git commit: Published site at 82d554e3783372cc6b05489452c815b57c06f6cd. archived-at: Wed, 17 May 2017 14:58:14 -0000 http://git-wip-us.apache.org/repos/asf/hbase-site/blob/986c93ca/testdevapidocs/src-html/org/apache/hadoop/hbase/client/AbstractTestAsyncTableScan.html ---------------------------------------------------------------------- diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/client/AbstractTestAsyncTableScan.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/client/AbstractTestAsyncTableScan.html index d262284..25f3605 100644 --- a/testdevapidocs/src-html/org/apache/hadoop/hbase/client/AbstractTestAsyncTableScan.html +++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/client/AbstractTestAsyncTableScan.html @@ -38,247 +38,258 @@ 030 031import org.apache.hadoop.hbase.HBaseTestingUtility; 032import org.apache.hadoop.hbase.TableName; -033import org.apache.hadoop.hbase.util.Bytes; -034import org.apache.hadoop.hbase.util.Pair; -035import org.junit.AfterClass; -036import org.junit.BeforeClass; -037import org.junit.Test; -038 -039public abstract class AbstractTestAsyncTableScan { -040 -041 protected static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); -042 -043 protected static TableName TABLE_NAME = TableName.valueOf("async"); -044 -045 protected static byte[] FAMILY = Bytes.toBytes("cf"); -046 -047 protected static byte[] CQ1 = Bytes.toBytes("cq1"); -048 -049 protected static byte[] CQ2 = Bytes.toBytes("cq2"); -050 -051 protected static int COUNT = 1000; -052 -053 protected static AsyncConnection ASYNC_CONN; -054 -055 @BeforeClass -056 public static void setUp() throws Exception { -057 TEST_UTIL.startMiniCluster(3); -058 byte[][] splitKeys = new byte[8][]; -059 for (int i = 111; i < 999; i += 111) { -060 splitKeys[i / 111 - 1] = Bytes.toBytes(String.format("%03d", i)); -061 } -062 TEST_UTIL.createTable(TABLE_NAME, FAMILY, splitKeys); -063 TEST_UTIL.waitTableAvailable(TABLE_NAME); -064 ASYNC_CONN = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get(); -065 ASYNC_CONN.getRawTable(TABLE_NAME).putAll(IntStream.range(0, COUNT) -066 .mapToObj(i -> new Put(Bytes.toBytes(String.format("%03d", i))) -067 .addColumn(FAMILY, CQ1, Bytes.toBytes(i)).addColumn(FAMILY, CQ2, Bytes.toBytes(i * i))) -068 .collect(Collectors.toList())).get(); -069 } -070 -071 @AfterClass -072 public static void tearDown() throws Exception { -073 ASYNC_CONN.close(); -074 TEST_UTIL.shutdownMiniCluster(); -075 } -076 -077 protected static Scan createNormalScan() { -078 return new Scan(); -079 } -080 -081 protected static Scan createBatchScan() { -082 return new Scan().setBatch(1); -083 } -084 -085 // set a small result size for testing flow control -086 protected static Scan createSmallResultSizeScan() { -087 return new Scan().setMaxResultSize(1); -088 } -089 -090 protected static Scan createBatchSmallResultSizeScan() { -091 return new Scan().setBatch(1).setMaxResultSize(1); -092 } -093 -094 protected static List<Pair<String, Supplier<Scan>>> getScanCreater() { -095 return Arrays.asList(Pair.newPair("normal", AbstractTestAsyncTableScan::createNormalScan), -096 Pair.newPair("batch", AbstractTestAsyncTableScan::createBatchScan), -097 Pair.newPair("smallResultSize", AbstractTestAsyncTableScan::createSmallResultSizeScan), -098 Pair.newPair("batchSmallResultSize", -099 AbstractTestAsyncTableScan::createBatchSmallResultSizeScan)); -100 } -101 -102 protected abstract Scan createScan(); -103 -104 protected abstract List<Result> doScan(Scan scan) throws Exception; -105 -106 protected final List<Result> convertFromBatchResult(List<Result> results) { -107 assertTrue(results.size() % 2 == 0); -108 return IntStream.range(0, results.size() / 2).mapToObj(i -> { -109 try { -110 return Result -111 .createCompleteResult(Arrays.asList(results.get(2 * i), results.get(2 * i + 1))); -112 } catch (IOException e) { -113 throw new UncheckedIOException(e); -114 } -115 }).collect(Collectors.toList()); -116 } -117 -118 @Test -119 public void testScanAll() throws Exception { -120 List<Result> results = doScan(createScan()); -121 // make sure all scanners are closed at RS side -122 TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer()) -123 .forEach(rs -> assertEquals( -124 "The scanner count of " + rs.getServerName() + " is " + -125 rs.getRSRpcServices().getScannersCount(), -126 0, rs.getRSRpcServices().getScannersCount())); -127 assertEquals(COUNT, results.size()); -128 IntStream.range(0, COUNT).forEach(i -> { -129 Result result = results.get(i); -130 assertEquals(String.format("%03d", i), Bytes.toString(result.getRow())); -131 assertEquals(i, Bytes.toInt(result.getValue(FAMILY, CQ1))); -132 }); -133 } -134 -135 private void assertResultEquals(Result result, int i) { -136 assertEquals(String.format("%03d", i), Bytes.toString(result.getRow())); -137 assertEquals(i, Bytes.toInt(result.getValue(FAMILY, CQ1))); -138 assertEquals(i * i, Bytes.toInt(result.getValue(FAMILY, CQ2))); -139 } -140 -141 @Test -142 public void testReversedScanAll() throws Exception { -143 List<Result> results = doScan(createScan().setReversed(true)); -144 assertEquals(COUNT, results.size()); -145 IntStream.range(0, COUNT).forEach(i -> assertResultEquals(results.get(i), COUNT - i - 1)); -146 } -147 -148 @Test -149 public void testScanNoStopKey() throws Exception { -150 int start = 345; -151 List<Result> results = -152 doScan(createScan().withStartRow(Bytes.toBytes(String.format("%03d", start)))); -153 assertEquals(COUNT - start, results.size()); -154 IntStream.range(0, COUNT - start).forEach(i -> assertResultEquals(results.get(i), start + i)); -155 } -156 -157 @Test -158 public void testReverseScanNoStopKey() throws Exception { -159 int start = 765; -160 List<Result> results = doScan( -161 createScan().withStartRow(Bytes.toBytes(String.format("%03d", start))).setReversed(true)); -162 assertEquals(start + 1, results.size()); -163 IntStream.range(0, start + 1).forEach(i -> assertResultEquals(results.get(i), start - i)); -164 } -165 -166 private void testScan(int start, boolean startInclusive, int stop, boolean stopInclusive, -167 int limit) throws Exception { -168 Scan scan = -169 createScan().withStartRow(Bytes.toBytes(String.format("%03d", start)), startInclusive) -170 .withStopRow(Bytes.toBytes(String.format("%03d", stop)), stopInclusive); -171 if (limit > 0) { -172 scan.setLimit(limit); -173 } -174 List<Result> results = doScan(scan); -175 int actualStart = startInclusive ? start : start + 1; -176 int actualStop = stopInclusive ? stop + 1 : stop; -177 int count = actualStop - actualStart; -178 if (limit > 0) { -179 count = Math.min(count, limit); -180 } -181 assertEquals(count, results.size()); -182 IntStream.range(0, count).forEach(i -> assertResultEquals(results.get(i), actualStart + i)); -183 } -184 -185 private void testReversedScan(int start, boolean startInclusive, int stop, boolean stopInclusive, -186 int limit) throws Exception { -187 Scan scan = createScan() -188 .withStartRow(Bytes.toBytes(String.format("%03d", start)), startInclusive) -189 .withStopRow(Bytes.toBytes(String.format("%03d", stop)), stopInclusive).setReversed(true); -190 if (limit > 0) { -191 scan.setLimit(limit); -192 } -193 List<Result> results = doScan(scan); -194 int actualStart = startInclusive ? start : start - 1; -195 int actualStop = stopInclusive ? stop - 1 : stop; -196 int count = actualStart - actualStop; -197 if (limit > 0) { -198 count = Math.min(count, limit); -199 } -200 assertEquals(count, results.size()); -201 IntStream.range(0, count).forEach(i -> assertResultEquals(results.get(i), actualStart - i)); -202 } -203 -204 @Test -205 public void testScanWithStartKeyAndStopKey() throws Exception { -206 testScan(1, true, 998, false, -1); // from first region to last region -207 testScan(123, true, 345, true, -1); -208 testScan(234, true, 456, false, -1); -209 testScan(345, false, 567, true, -1); -210 testScan(456, false, 678, false, -1); -211 } -212 -213 @Test -214 public void testReversedScanWithStartKeyAndStopKey() throws Exception { -215 testReversedScan(998, true, 1, false, -1); // from last region to first region -216 testReversedScan(543, true, 321, true, -1); -217 testReversedScan(654, true, 432, false, -1); -218 testReversedScan(765, false, 543, true, -1); -219 testReversedScan(876, false, 654, false, -1); -220 } -221 -222 @Test -223 public void testScanAtRegionBoundary() throws Exception { -224 testScan(222, true, 333, true, -1); -225 testScan(333, true, 444, false, -1); -226 testScan(444, false, 555, true, -1); -227 testScan(555, false, 666, false, -1); -228 } -229 -230 @Test -231 public void testReversedScanAtRegionBoundary() throws Exception { -232 testReversedScan(333, true, 222, true, -1); -233 testReversedScan(444, true, 333, false, -1); -234 testReversedScan(555, false, 444, true, -1); -235 testReversedScan(666, false, 555, false, -1); -236 } -237 -238 @Test -239 public void testScanWithLimit() throws Exception { -240 testScan(1, true, 998, false, 900); // from first region to last region -241 testScan(123, true, 234, true, 100); -242 testScan(234, true, 456, false, 100); -243 testScan(345, false, 567, true, 100); -244 testScan(456, false, 678, false, 100); -245 } -246 -247 @Test -248 public void testScanWithLimitGreaterThanActualCount() throws Exception { -249 testScan(1, true, 998, false, 1000); // from first region to last region -250 testScan(123, true, 345, true, 200); -251 testScan(234, true, 456, false, 200); -252 testScan(345, false, 567, true, 200); -253 testScan(456, false, 678, false, 200); -254 } -255 -256 @Test -257 public void testReversedScanWithLimit() throws Exception { -258 testReversedScan(998, true, 1, false, 900); // from last region to first region -259 testReversedScan(543, true, 321, true, 100); -260 testReversedScan(654, true, 432, false, 100); -261 testReversedScan(765, false, 543, true, 100); -262 testReversedScan(876, false, 654, false, 100); -263 } -264 -265 @Test -266 public void testReversedScanWithLimitGreaterThanActualCount() throws Exception { -267 testReversedScan(998, true, 1, false, 1000); // from last region to first region -268 testReversedScan(543, true, 321, true, 200); -269 testReversedScan(654, true, 432, false, 200); -270 testReversedScan(765, false, 543, true, 200); -271 testReversedScan(876, false, 654, false, 200); -272 } -273} +033import org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException; +034import org.apache.hadoop.hbase.util.Bytes; +035import org.apache.hadoop.hbase.util.Pair; +036import org.junit.AfterClass; +037import org.junit.BeforeClass; +038import org.junit.Test; +039 +040public abstract class AbstractTestAsyncTableScan { +041 +042 protected static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); +043 +044 protected static TableName TABLE_NAME = TableName.valueOf("async"); +045 +046 protected static byte[] FAMILY = Bytes.toBytes("cf"); +047 +048 protected static byte[] CQ1 = Bytes.toBytes("cq1"); +049 +050 protected static byte[] CQ2 = Bytes.toBytes("cq2"); +051 +052 protected static int COUNT = 1000; +053 +054 protected static AsyncConnection ASYNC_CONN; +055 +056 @BeforeClass +057 public static void setUp() throws Exception { +058 TEST_UTIL.startMiniCluster(3); +059 byte[][] splitKeys = new byte[8][]; +060 for (int i = 111; i < 999; i += 111) { +061 splitKeys[i / 111 - 1] = Bytes.toBytes(String.format("%03d", i)); +062 } +063 TEST_UTIL.createTable(TABLE_NAME, FAMILY, splitKeys); +064 TEST_UTIL.waitTableAvailable(TABLE_NAME); +065 ASYNC_CONN = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get(); +066 ASYNC_CONN.getRawTable(TABLE_NAME).putAll(IntStream.range(0, COUNT) +067 .mapToObj(i -> new Put(Bytes.toBytes(String.format("%03d", i))) +068 .addColumn(FAMILY, CQ1, Bytes.toBytes(i)).addColumn(FAMILY, CQ2, Bytes.toBytes(i * i))) +069 .collect(Collectors.toList())).get(); +070 } +071 +072 @AfterClass +073 public static void tearDown() throws Exception { +074 ASYNC_CONN.close(); +075 TEST_UTIL.shutdownMiniCluster(); +076 } +077 +078 protected static Scan createNormalScan() { +079 return new Scan(); +080 } +081 +082 protected static Scan createBatchScan() { +083 return new Scan().setBatch(1); +084 } +085 +086 // set a small result size for testing flow control +087 protected static Scan createSmallResultSizeScan() { +088 return new Scan().setMaxResultSize(1); +089 } +090 +091 protected static Scan createBatchSmallResultSizeScan() { +092 return new Scan().setBatch(1).setMaxResultSize(1); +093 } +094 +095 protected static List<Pair<String, Supplier<Scan>>> getScanCreater() { +096 return Arrays.asList(Pair.newPair("normal", AbstractTestAsyncTableScan::createNormalScan), +097 Pair.newPair("batch", AbstractTestAsyncTableScan::createBatchScan), +098 Pair.newPair("smallResultSize", AbstractTestAsyncTableScan::createSmallResultSizeScan), +099 Pair.newPair("batchSmallResultSize", +100 AbstractTestAsyncTableScan::createBatchSmallResultSizeScan)); +101 } +102 +103 protected abstract Scan createScan(); +104 +105 protected abstract List<Result> doScan(Scan scan) throws Exception; +106 +107 protected final List<Result> convertFromBatchResult(List<Result> results) { +108 assertTrue(results.size() % 2 == 0); +109 return IntStream.range(0, results.size() / 2).mapToObj(i -> { +110 try { +111 return Result +112 .createCompleteResult(Arrays.asList(results.get(2 * i), results.get(2 * i + 1))); +113 } catch (IOException e) { +114 throw new UncheckedIOException(e); +115 } +116 }).collect(Collectors.toList()); +117 } +118 +119 @Test +120 public void testScanAll() throws Exception { +121 List<Result> results = doScan(createScan()); +122 // make sure all scanners are closed at RS side +123 TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer()) +124 .forEach(rs -> assertEquals( +125 "The scanner count of " + rs.getServerName() + " is " + +126 rs.getRSRpcServices().getScannersCount(), +127 0, rs.getRSRpcServices().getScannersCount())); +128 assertEquals(COUNT, results.size()); +129 IntStream.range(0, COUNT).forEach(i -> { +130 Result result = results.get(i); +131 assertEquals(String.format("%03d", i), Bytes.toString(result.getRow())); +132 assertEquals(i, Bytes.toInt(result.getValue(FAMILY, CQ1))); +133 }); +134 } +135 +136 private void assertResultEquals(Result result, int i) { +137 assertEquals(String.format("%03d", i), Bytes.toString(result.getRow())); +138 assertEquals(i, Bytes.toInt(result.getValue(FAMILY, CQ1))); +139 assertEquals(i * i, Bytes.toInt(result.getValue(FAMILY, CQ2))); +140 } +141 +142 @Test +143 public void testReversedScanAll() throws Exception { +144 List<Result> results = doScan(createScan().setReversed(true)); +145 assertEquals(COUNT, results.size()); +146 IntStream.range(0, COUNT).forEach(i -> assertResultEquals(results.get(i), COUNT - i - 1)); +147 } +148 +149 @Test +150 public void testScanNoStopKey() throws Exception { +151 int start = 345; +152 List<Result> results = +153 doScan(createScan().withStartRow(Bytes.toBytes(String.format("%03d", start)))); +154 assertEquals(COUNT - start, results.size()); +155 IntStream.range(0, COUNT - start).forEach(i -> assertResultEquals(results.get(i), start + i)); +156 } +157 +158 @Test +159 public void testReverseScanNoStopKey() throws Exception { +160 int start = 765; +161 List<Result> results = doScan( +162 createScan().withStartRow(Bytes.toBytes(String.format("%03d", start))).setReversed(true)); +163 assertEquals(start + 1, results.size()); +164 IntStream.range(0, start + 1).forEach(i -> assertResultEquals(results.get(i), start - i)); +165 } +166 +167 @Test +168 public void testScanWrongColumnFamily() throws Exception { +169 try { +170 doScan(createScan().addFamily(Bytes.toBytes("WrongColumnFamily"))); +171 } catch (Exception e) { +172 assertTrue(e instanceof NoSuchColumnFamilyException +173 || e.getCause() instanceof NoSuchColumnFamilyException); +174 } +175 } +176 +177 private void testScan(int start, boolean startInclusive, int stop, boolean stopInclusive, +178 int limit) throws Exception { +179 Scan scan = +180 createScan().withStartRow(Bytes.toBytes(String.format("%03d", start)), startInclusive) +181 .withStopRow(Bytes.toBytes(String.format("%03d", stop)), stopInclusive); +182 if (limit > 0) { +183 scan.setLimit(limit); +184 } +185 List<Result> results = doScan(scan); +186 int actualStart = startInclusive ? start : start + 1; +187 int actualStop = stopInclusive ? stop + 1 : stop; +188 int count = actualStop - actualStart; +189 if (limit > 0) { +190 count = Math.min(count, limit); +191 } +192 assertEquals(count, results.size()); +193 IntStream.range(0, count).forEach(i -> assertResultEquals(results.get(i), actualStart + i)); +194 } +195 +196 private void testReversedScan(int start, boolean startInclusive, int stop, boolean stopInclusive, +197 int limit) throws Exception { +198 Scan scan = createScan() +199 .withStartRow(Bytes.toBytes(String.format("%03d", start)), startInclusive) +200 .withStopRow(Bytes.toBytes(String.format("%03d", stop)), stopInclusive).setReversed(true); +201 if (limit > 0) { +202 scan.setLimit(limit); +203 } +204 List<Result> results = doScan(scan); +205 int actualStart = startInclusive ? start : start - 1; +206 int actualStop = stopInclusive ? stop - 1 : stop; +207 int count = actualStart - actualStop; +208 if (limit > 0) { +209 count = Math.min(count, limit); +210 } +211 assertEquals(count, results.size()); +212 IntStream.range(0, count).forEach(i -> assertResultEquals(results.get(i), actualStart - i)); +213 } +214 +215 @Test +216 public void testScanWithStartKeyAndStopKey() throws Exception { +217 testScan(1, true, 998, false, -1); // from first region to last region +218 testScan(123, true, 345, true, -1); +219 testScan(234, true, 456, false, -1); +220 testScan(345, false, 567, true, -1); +221 testScan(456, false, 678, false, -1); +222 } +223 +224 @Test +225 public void testReversedScanWithStartKeyAndStopKey() throws Exception { +226 testReversedScan(998, true, 1, false, -1); // from last region to first region +227 testReversedScan(543, true, 321, true, -1); +228 testReversedScan(654, true, 432, false, -1); +229 testReversedScan(765, false, 543, true, -1); +230 testReversedScan(876, false, 654, false, -1); +231 } +232 +233 @Test +234 public void testScanAtRegionBoundary() throws Exception { +235 testScan(222, true, 333, true, -1); +236 testScan(333, true, 444, false, -1); +237 testScan(444, false, 555, true, -1); +238 testScan(555, false, 666, false, -1); +239 } +240 +241 @Test +242 public void testReversedScanAtRegionBoundary() throws Exception { +243 testReversedScan(333, true, 222, true, -1); +244 testReversedScan(444, true, 333, false, -1); +245 testReversedScan(555, false, 444, true, -1); +246 testReversedScan(666, false, 555, false, -1); +247 } +248 +249 @Test +250 public void testScanWithLimit() throws Exception { +251 testScan(1, true, 998, false, 900); // from first region to last region +252 testScan(123, true, 234, true, 100); +253 testScan(234, true, 456, false, 100); +254 testScan(345, false, 567, true, 100); +255 testScan(456, false, 678, false, 100); +256 } +257 +258 @Test +259 public void testScanWithLimitGreaterThanActualCount() throws Exception { +260 testScan(1, true, 998, false, 1000); // from first region to last region +261 testScan(123, true, 345, true, 200); +262 testScan(234, true, 456, false, 200); +263 testScan(345, false, 567, true, 200); +264 testScan(456, false, 678, false, 200); +265 } +266 +267 @Test +268 public void testReversedScanWithLimit() throws Exception { +269 testReversedScan(998, true, 1, false, 900); // from last region to first region +270 testReversedScan(543, true, 321, true, 100); +271 testReversedScan(654, true, 432, false, 100); +272 testReversedScan(765, false, 543, true, 100); +273 testReversedScan(876, false, 654, false, 100); +274 } +275 +276 @Test +277 public void testReversedScanWithLimitGreaterThanActualCount() throws Exception { +278 testReversedScan(998, true, 1, false, 1000); // from last region to first region +279 testReversedScan(543, true, 321, true, 200); +280 testReversedScan(654, true, 432, false, 200); +281 testReversedScan(765, false, 543, true, 200); +282 testReversedScan(876, false, 654, false, 200); +283 } +284} http://git-wip-us.apache.org/repos/asf/hbase-site/blob/986c93ca/testdevapidocs/src-html/org/apache/hadoop/hbase/procedure2/TestStateMachineProcedure.SimpleChildProcedure.html ---------------------------------------------------------------------- diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/procedure2/TestStateMachineProcedure.SimpleChildProcedure.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/procedure2/TestStateMachineProcedure.SimpleChildProcedure.html index 9e2d08d..60a7ac6 100644 --- a/testdevapidocs/src-html/org/apache/hadoop/hbase/procedure2/TestStateMachineProcedure.SimpleChildProcedure.html +++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/procedure2/TestStateMachineProcedure.SimpleChildProcedure.html @@ -101,105 +101,123 @@ 093 } 094 095 @Test -096 public void testChildOnLastStep() { -097 long procId = procExecutor.submitProcedure(new TestSMProcedure()); -098 ProcedureTestingUtility.waitProcedure(procExecutor, procId); -099 assertEquals(3, procExecutor.getEnvironment().execCount.get()); -100 assertEquals(0, procExecutor.getEnvironment().rollbackCount.get()); -101 ProcedureTestingUtility.assertProcNotFailed(procExecutor, procId); -102 } -103 -104 @Test -105 public void testChildOnLastStepDoubleExecution() throws Exception { -106 ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExecutor, true); -107 long procId = procExecutor.submitProcedure(new TestSMProcedure()); -108 ProcedureTestingUtility.testRecoveryAndDoubleExecution(procExecutor, procId); -109 assertEquals(6, procExecutor.getEnvironment().execCount.get()); -110 assertEquals(0, procExecutor.getEnvironment().rollbackCount.get()); -111 ProcedureTestingUtility.assertProcNotFailed(procExecutor, procId); -112 } -113 -114 @Test -115 public void testChildOnLastStepWithRollback() { -116 procExecutor.getEnvironment().triggerChildRollback = true; -117 long procId = procExecutor.submitProcedure(new TestSMProcedure()); -118 ProcedureTestingUtility.waitProcedure(procExecutor, procId); -119 assertEquals(3, procExecutor.getEnvironment().execCount.get()); -120 assertEquals(3, procExecutor.getEnvironment().rollbackCount.get()); -121 Throwable cause = ProcedureTestingUtility.assertProcFailed(procExecutor, procId); -122 assertEquals(TEST_FAILURE_EXCEPTION, cause); -123 } -124 -125 @Test -126 public void testChildOnLastStepWithRollbackDoubleExecution() throws Exception { -127 procExecutor.getEnvironment().triggerChildRollback = true; -128 ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExecutor, true); -129 long procId = procExecutor.submitProcedure(new TestSMProcedure()); -130 ProcedureTestingUtility.testRecoveryAndDoubleExecution(procExecutor, procId, true); -131 assertEquals(6, procExecutor.getEnvironment().execCount.get()); -132 assertEquals(6, procExecutor.getEnvironment().rollbackCount.get()); -133 Throwable cause = ProcedureTestingUtility.assertProcFailed(procExecutor, procId); -134 assertEquals(TEST_FAILURE_EXCEPTION, cause); -135 } -136 -137 public enum TestSMProcedureState { STEP_1, STEP_2 }; -138 public static class TestSMProcedure -139 extends StateMachineProcedure<TestProcEnv, TestSMProcedureState> { -140 protected Flow executeFromState(TestProcEnv env, TestSMProcedureState state) { -141 LOG.info("EXEC " + state + " " + this); -142 env.execCount.incrementAndGet(); -143 switch (state) { -144 case STEP_1: -145 setNextState(TestSMProcedureState.STEP_2); -146 break; -147 case STEP_2: -148 addChildProcedure(new SimpleChildProcedure()); -149 return Flow.NO_MORE_STATE; -150 } -151 return Flow.HAS_MORE_STATE; -152 } -153 -154 protected void rollbackState(TestProcEnv env, TestSMProcedureState state) { -155 LOG.info("ROLLBACK " + state + " " + this); -156 env.rollbackCount.incrementAndGet(); -157 } -158 -159 protected TestSMProcedureState getState(int stateId) { -160 return TestSMProcedureState.values()[stateId]; -161 } -162 -163 protected int getStateId(TestSMProcedureState state) { -164 return state.ordinal(); -165 } -166 -167 protected TestSMProcedureState getInitialState() { -168 return TestSMProcedureState.STEP_1; +096 public void testAbortStuckProcedure() throws InterruptedException { +097 try { +098 procExecutor.getEnvironment().loop = true; +099 TestSMProcedure proc = new TestSMProcedure(); +100 long procId = procExecutor.submitProcedure(proc); +101 Thread.sleep(1000 + (int) (Math.random() * 4001)); +102 proc.abort(procExecutor.getEnvironment()); +103 ProcedureTestingUtility.waitProcedure(procExecutor, procId); +104 assertEquals(true, proc.isFailed()); +105 } finally { +106 procExecutor.getEnvironment().loop = false; +107 } +108 } +109 +110 @Test +111 public void testChildOnLastStep() { +112 long procId = procExecutor.submitProcedure(new TestSMProcedure()); +113 ProcedureTestingUtility.waitProcedure(procExecutor, procId); +114 assertEquals(3, procExecutor.getEnvironment().execCount.get()); +115 assertEquals(0, procExecutor.getEnvironment().rollbackCount.get()); +116 ProcedureTestingUtility.assertProcNotFailed(procExecutor, procId); +117 } +118 +119 @Test +120 public void testChildOnLastStepDoubleExecution() throws Exception { +121 ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExecutor, true); +122 long procId = procExecutor.submitProcedure(new TestSMProcedure()); +123 ProcedureTestingUtility.testRecoveryAndDoubleExecution(procExecutor, procId); +124 assertEquals(6, procExecutor.getEnvironment().execCount.get()); +125 assertEquals(0, procExecutor.getEnvironment().rollbackCount.get()); +126 ProcedureTestingUtility.assertProcNotFailed(procExecutor, procId); +127 } +128 +129 @Test +130 public void testChildOnLastStepWithRollback() { +131 procExecutor.getEnvironment().triggerChildRollback = true; +132 long procId = procExecutor.submitProcedure(new TestSMProcedure()); +133 ProcedureTestingUtility.waitProcedure(procExecutor, procId); +134 assertEquals(3, procExecutor.getEnvironment().execCount.get()); +135 assertEquals(3, procExecutor.getEnvironment().rollbackCount.get()); +136 Throwable cause = ProcedureTestingUtility.assertProcFailed(procExecutor, procId); +137 assertEquals(TEST_FAILURE_EXCEPTION, cause); +138 } +139 +140 @Test +141 public void testChildOnLastStepWithRollbackDoubleExecution() throws Exception { +142 procExecutor.getEnvironment().triggerChildRollback = true; +143 ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExecutor, true); +144 long procId = procExecutor.submitProcedure(new TestSMProcedure()); +145 ProcedureTestingUtility.testRecoveryAndDoubleExecution(procExecutor, procId, true); +146 assertEquals(6, procExecutor.getEnvironment().execCount.get()); +147 assertEquals(6, procExecutor.getEnvironment().rollbackCount.get()); +148 Throwable cause = ProcedureTestingUtility.assertProcFailed(procExecutor, procId); +149 assertEquals(TEST_FAILURE_EXCEPTION, cause); +150 } +151 +152 public enum TestSMProcedureState { STEP_1, STEP_2 }; +153 public static class TestSMProcedure +154 extends StateMachineProcedure<TestProcEnv, TestSMProcedureState> { +155 protected Flow executeFromState(TestProcEnv env, TestSMProcedureState state) { +156 LOG.info("EXEC " + state + " " + this); +157 env.execCount.incrementAndGet(); +158 switch (state) { +159 case STEP_1: +160 if (!env.loop) { +161 setNextState(TestSMProcedureState.STEP_2); +162 } +163 break; +164 case STEP_2: +165 addChildProcedure(new SimpleChildProcedure()); +166 return Flow.NO_MORE_STATE; +167 } +168 return Flow.HAS_MORE_STATE; 169 } -170 } -171 -172 public static class SimpleChildProcedure extends NoopProcedure<TestProcEnv> { -173 protected Procedure[] execute(TestProcEnv env) { -174 LOG.info("EXEC " + this); -175 env.execCount.incrementAndGet(); -176 if (env.triggerChildRollback) { -177 setFailure("test-failure", TEST_FAILURE_EXCEPTION); -178 } -179 return null; -180 } -181 -182 @Override -183 protected void rollback(TestProcEnv env) { -184 LOG.info("ROLLBACK " + this); -185 env.rollbackCount.incrementAndGet(); +170 +171 protected void rollbackState(TestProcEnv env, TestSMProcedureState state) { +172 LOG.info("ROLLBACK " + state + " " + this); +173 env.rollbackCount.incrementAndGet(); +174 } +175 +176 protected TestSMProcedureState getState(int stateId) { +177 return TestSMProcedureState.values()[stateId]; +178 } +179 +180 protected int getStateId(TestSMProcedureState state) { +181 return state.ordinal(); +182 } +183 +184 protected TestSMProcedureState getInitialState() { +185 return TestSMProcedureState.STEP_1; 186 } 187 } 188 -189 public class TestProcEnv { -190 AtomicInteger execCount = new AtomicInteger(0); -191 AtomicInteger rollbackCount = new AtomicInteger(0); -192 boolean triggerChildRollback = false; -193 } -194} +189 public static class SimpleChildProcedure extends NoopProcedure<TestProcEnv> { +190 protected Procedure[] execute(TestProcEnv env) { +191 LOG.info("EXEC " + this); +192 env.execCount.incrementAndGet(); +193 if (env.triggerChildRollback) { +194 setFailure("test-failure", TEST_FAILURE_EXCEPTION); +195 } +196 return null; +197 } +198 +199 @Override +200 protected void rollback(TestProcEnv env) { +201 LOG.info("ROLLBACK " + this); +202 env.rollbackCount.incrementAndGet(); +203 } +204 } +205 +206 public class TestProcEnv { +207 AtomicInteger execCount = new AtomicInteger(0); +208 AtomicInteger rollbackCount = new AtomicInteger(0); +209 boolean triggerChildRollback = false; +210 boolean loop = false; +211 } +212}