MCPcopy Create free account
hub / github.com/OpenTSDB/asynchbase / before

Method before

test/BaseTestHBaseClient.java:130–188  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

128 protected FakeTimer timer;
129
130 @Before
131 public void before() throws Exception {
132 region_clients.clear();
133 rootclient = mock(RegionClient.class);
134 when(rootclient.toString()).thenReturn(MOCK_ROOT_CLIENT_NAME);
135 metaclient = mock(RegionClient.class);
136 when(metaclient.toString()).thenReturn(MOCK_META_CLIENT_NAME);
137 regionclient = mock(RegionClient.class);
138 when(regionclient.toString()).thenReturn(MOCK_RS_CLIENT_NAME);
139 zkclient = mock(ZKClient.class);
140 channel_factory = mock(NioClientSocketChannelFactory.class);
141 chan = mock(SocketChannel.class);
142 timer = new FakeTimer();
143
144 when(zkclient.getDeferredRoot()).thenReturn(new Deferred<Object>());
145 PowerMockito.mockStatic(Executors.class);
146 PowerMockito.when(Executors.defaultThreadFactory())
147 .thenReturn(mock(ThreadFactory.class));
148 PowerMockito.when(Executors.newCachedThreadPool())
149 .thenReturn(mock(ExecutorService.class));
150 PowerMockito.whenNew(NioClientSocketChannelFactory.class).withAnyArguments()
151 .thenReturn(channel_factory);
152
153 PowerMockito.whenNew(HashedWheelTimer.class).withAnyArguments()
154 .thenReturn(timer);
155 PowerMockito.whenNew(NioClientBossPool.class).withAnyArguments()
156 .thenReturn(mock(NioClientBossPool.class));
157 PowerMockito.whenNew(NioWorkerPool.class).withAnyArguments()
158 .thenReturn(mock(NioWorkerPool.class));
159
160 client = PowerMockito.spy(new HBaseClient("test-quorum-spec"));
161 Whitebox.setInternalState(client, "zkclient", zkclient);
162 Whitebox.setInternalState(client, "rootregion", rootclient);
163 regions_cache = Whitebox.getInternalState(client, "regions_cache");
164 region2client = Whitebox.getInternalState(client, "region2client");
165 client2regions = Whitebox.getInternalState(client, "client2regions");
166 got_nsre = Whitebox.getInternalState(client, "got_nsre");
167 ip2client = Whitebox.getInternalState(client, "ip2client");
168 injectRegionInCache(meta, metaclient, META_IP + ":" + RS_PORT);
169 injectRegionInCache(region, regionclient, REGION_CLIENT_IP + ":" + RS_PORT);
170
171 when(channel_factory.newChannel(any(ChannelPipeline.class)))
172 .thenReturn(chan);
173 when(chan.getConfig()).thenReturn(mock(SocketChannelConfig.class));
174 when(rootclient.toString()).thenReturn("Mock RootClient");
175
176 PowerMockito.doAnswer(new Answer<RegionClient>(){
177 @Override
178 public RegionClient answer(InvocationOnMock invocation) throws Throwable {
179 final Object[] args = invocation.getArguments();
180 final String endpoint = (String)args[0] + ":" + (Integer)args[1];
181 final RegionClient rc = mock(RegionClient.class);
182 when(rc.getRemoteAddress()).thenReturn(endpoint);
183 client2regions.put(rc, new ArrayList<RegionInfo>());
184 region_clients.add(rc);
185 return rc;
186 }
187 }).when(client, "newClient", anyString(), anyInt());

Callers

nothing calls this directly

Calls 5

injectRegionInCacheMethod · 0.95
clearMethod · 0.80
getConfigMethod · 0.80
toStringMethod · 0.45
getDeferredRootMethod · 0.45

Tested by

no test coverage detected