32
32
import static org .mockito .Mockito .mock ;
33
33
import static org .mockito .Mockito .times ;
34
34
import static org .mockito .Mockito .verify ;
35
-
36
35
import java .io .IOException ;
37
36
import java .util .Arrays ;
38
37
import java .util .Optional ;
39
38
import java .util .concurrent .ExecutorService ;
40
39
import java .util .concurrent .Executors ;
41
40
import java .util .concurrent .atomic .AtomicInteger ;
42
-
43
41
import org .apache .hadoop .conf .Configuration ;
44
42
import org .apache .hadoop .hbase .Cell ;
45
43
import org .apache .hadoop .hbase .CellBuilderFactory ;
74
72
*/
75
73
@ Category ({ ClientTests .class , MediumTests .class })
76
74
public class TestTableRpcPriority {
75
+
77
76
@ ClassRule
78
77
public static final HBaseClassTestRule CLASS_RULE =
79
78
HBaseClassTestRule .forClass (TestTableRpcPriority .class );
@@ -89,6 +88,7 @@ public void setUp() throws IOException, ServiceException {
89
88
stub = mock (ClientProtos .ClientService .BlockingInterface .class );
90
89
91
90
Configuration conf = HBaseConfiguration .create ();
91
+
92
92
ExecutorService executorService = Executors .newCachedThreadPool ();
93
93
conn = new ConnectionImplementation (conf , executorService ,
94
94
UserProvider .instantiate (conf ).getCurrent (), new DoNothingConnectionRegistry (conf )) {
@@ -122,6 +122,16 @@ public void testScan() throws Exception {
122
122
testForTable (TableName .valueOf (name .getMethodName ()), Optional .of (19 ));
123
123
}
124
124
125
+ /**
126
+ * This test verifies that our closeScanner request honors the original
127
+ * priority of the scan if it's greater than our expected HIGH_QOS for close calls.
128
+ */
129
+ @ Test
130
+ public void testScanSuperHighPriority () throws Exception {
131
+ mockScan (1000 );
132
+ testForTable (TableName .valueOf (name .getMethodName ()), Optional .of (1000 ));
133
+ }
134
+
125
135
@ Test
126
136
public void testScanNormalTable () throws Exception {
127
137
mockScan (NORMAL_QOS );
@@ -153,11 +163,22 @@ private void testForTable(TableName tableName, Optional<Integer> priority) throw
153
163
// just verify that the calls happened. verification of priority occurred in the mocking
154
164
// open, next, then several renew lease
155
165
verify (stub , atLeast (3 )).scan (any (), any (ClientProtos .ScanRequest .class ));
156
- verify (stub , times (1 )).scan (any (), assertScannerCloseRequest ());
166
+ verify (stub , times (1 )).scan (
167
+ assertControllerArgs (Math .max (priority .orElse (0 ), HIGH_QOS )), assertScannerCloseRequest ());
157
168
}
158
169
159
170
private void mockScan (int scanPriority ) throws ServiceException {
160
171
int scannerId = 1 ;
172
+
173
+ doAnswer (new Answer <ClientProtos .ScanResponse >() {
174
+ @ Override public ClientProtos .ScanResponse answer (InvocationOnMock invocation )
175
+ throws Throwable {
176
+ throw new IllegalArgumentException (
177
+ "Call not covered by explicit mock for arguments controller="
178
+ + invocation .getArgument (0 ) + ", request=" + invocation .getArgument (1 ));
179
+ }
180
+ }).when (stub ).scan (any (), any ());
181
+
161
182
AtomicInteger scanNextCalled = new AtomicInteger (0 );
162
183
doAnswer (new Answer <ClientProtos .ScanResponse >() {
163
184
@@ -182,7 +203,7 @@ public ClientProtos.ScanResponse answer(InvocationOnMock invocation)
182
203
return builder .setTtl (800 ).setMoreResultsInRegion (true ).setMoreResults (true )
183
204
.addResults (ProtobufUtil .toResult (result )).build ();
184
205
}
185
- }).when (stub ).scan (assertPriority (scanPriority ), any (ClientProtos . ScanRequest . class ));
206
+ }).when (stub ).scan (assertControllerArgs (scanPriority ), any ());
186
207
187
208
doAnswer (new Answer <ClientProtos .ScanResponse >() {
188
209
@@ -197,15 +218,19 @@ public ClientProtos.ScanResponse answer(InvocationOnMock invocation)
197
218
198
219
return ClientProtos .ScanResponse .getDefaultInstance ();
199
220
}
200
- }).when (stub ).scan (assertPriority (HIGH_QOS ), assertScannerCloseRequest ());
221
+ }).when (stub ).scan (assertControllerArgs (Math .max (scanPriority , HIGH_QOS )),
222
+ assertScannerCloseRequest ());
201
223
}
202
224
203
- private HBaseRpcController assertPriority (int priority ) {
225
+ private HBaseRpcController assertControllerArgs (int priority ) {
204
226
return argThat (new ArgumentMatcher <HBaseRpcController >() {
205
227
206
228
@ Override
207
229
public boolean matches (HBaseRpcController controller ) {
208
- return controller .getPriority () == priority ;
230
+ // check specified priority, but also check that it has a timeout
231
+ // this ensures that our conversion from the base controller to the close-specific
232
+ // controller honored the original arguments.
233
+ return controller .getPriority () == priority && controller .hasCallTimeout ();
209
234
}
210
235
});
211
236
}
0 commit comments