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 static org.mockito.Matchers.*;
22 import static org.mockito.Mockito.*;
23
24 import org.apache.hadoop.hbase.regionserver.compactions.CompactionContext;
25 import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequest;
26 import org.apache.hadoop.hbase.security.User;
27 import org.mockito.invocation.InvocationOnMock;
28 import org.mockito.stubbing.Answer;
29
30
31
32
33
34 public class StatefulStoreMockMaker {
35
36 public CompactionContext selectCompaction() { return null; }
37 public void cancelCompaction(Object originalContext) {}
38 public int getPriority() { return 0; }
39
40 private class SelectAnswer implements Answer<CompactionContext> {
41 public CompactionContext answer(InvocationOnMock invocation) throws Throwable {
42 return selectCompaction();
43 }
44 }
45 private class PriorityAnswer implements Answer<Integer> {
46 public Integer answer(InvocationOnMock invocation) throws Throwable {
47 return getPriority();
48 }
49 }
50 private class CancelAnswer implements Answer<Object> {
51 public CompactionContext answer(InvocationOnMock invocation) throws Throwable {
52 cancelCompaction(invocation.getArguments()[0]); return null;
53 }
54 }
55
56 public Store createStoreMock(String name) throws Exception {
57 Store store = mock(Store.class, name);
58 when(store.requestCompaction(
59 anyInt(), isNull(CompactionRequest.class))).then(new SelectAnswer());
60 when(store.requestCompaction(
61 anyInt(), isNull(CompactionRequest.class), any(User.class))).then(new SelectAnswer());
62 when(store.getCompactPriority()).then(new PriorityAnswer());
63 doAnswer(new CancelAnswer()).when(
64 store).cancelRequestedCompaction(any(CompactionContext.class));
65 return store;
66 }
67 }