1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.regionserver;
20
21 import java.io.IOException;
22 import java.util.concurrent.atomic.AtomicBoolean;
23
24 import org.apache.hadoop.hbase.MediumTests;
25 import org.apache.hadoop.hbase.RegionTooBusyException;
26 import org.apache.hadoop.hbase.client.Get;
27 import org.apache.hadoop.hbase.util.Bytes;
28 import org.junit.Test;
29 import org.junit.experimental.categories.Category;
30
31
32
33
34
35 @Category(MediumTests.class)
36 @SuppressWarnings("deprecation")
37 public class TestHRegionBusyWait extends TestHRegion {
38 public TestHRegionBusyWait() {
39 conf.set("hbase.busy.wait.duration", "1000");
40 }
41
42
43
44
45 @Test (timeout=2000)
46 public void testRegionTooBusy() throws IOException {
47 String method = "testRegionTooBusy";
48 byte[] tableName = Bytes.toBytes(method);
49 byte[] family = Bytes.toBytes("family");
50 region = initHRegion(tableName, method, conf, family);
51 final AtomicBoolean stopped = new AtomicBoolean(true);
52 Thread t = new Thread(new Runnable() {
53 @Override
54 public void run() {
55 try {
56 region.lock.writeLock().lock();
57 stopped.set(false);
58 while (!stopped.get()) {
59 Thread.sleep(100);
60 }
61 } catch (InterruptedException ie) {
62 } finally {
63 region.lock.writeLock().unlock();
64 }
65 }
66 });
67 t.start();
68 Get get = new Get(row);
69 try {
70 while (stopped.get()) {
71 Thread.sleep(100);
72 }
73 region.get(get, null);
74 fail("Should throw RegionTooBusyException");
75 } catch (InterruptedException ie) {
76 fail("test interrupted");
77 } catch (RegionTooBusyException e) {
78
79 } finally {
80 stopped.set(true);
81 try {
82 t.join();
83 } catch (Throwable e) {
84 }
85
86 HRegion.closeHRegion(region);
87 region = null;
88 }
89 }
90 }