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