RpcTimeoutConnection(Configuration conf, ExecutorService pool, User user) throws IOException { super(conf, pool, user); // Mock up my stub so an exists call -- which turns into a get -- throws an exception this.stub = Mockito.mock(ClientService.BlockingInterface.class); try { Mockito.when(stub.get((RpcController)Mockito.any(), (ClientProtos.GetRequest)Mockito.any())). thenThrow(new ServiceException(new RegionServerStoppedException("From Mockito"))); } catch (ServiceException e) { throw new IOException(e); } }
@Override // TODO: Very like the super class implemenation. Can we shrink this down? protected Result rpcCall() throws Exception { if (getRpcController().isCanceled()) return null; if (Thread.interrupted()) { throw new InterruptedIOException(); } byte[] reg = location.getRegionInfo().getRegionName(); ClientProtos.GetRequest request = RequestConverter.buildGetRequest(reg, get); HBaseRpcController hrc = (HBaseRpcController)getRpcController(); hrc.reset(); hrc.setCallTimeout(rpcTimeout); hrc.setPriority(tableName); ClientProtos.GetResponse response = getStub().get(hrc, request); if (response == null) { return null; } return ProtobufUtil.toResult(response.getResult(), hrc.cellScanner()); } }
/** * Test normal operations */ @Test public void testMetaLookup() throws IOException, InterruptedException, ServiceException, KeeperException { final ClientProtos.ClientService.BlockingInterface client = Mockito.mock(ClientProtos.ClientService.BlockingInterface.class); Mockito.when(client.get((RpcController) Mockito.any(), (GetRequest) Mockito.any())) .thenReturn(GetResponse.newBuilder().build()); assertNull(MetaTableLocator.getMetaRegionLocation(this.watcher)); for (RegionState.State state : RegionState.State.values()) { if (state.equals(RegionState.State.OPEN)) { continue; } MetaTableLocator.setMetaLocation(this.watcher, SN, state); assertNull(MetaTableLocator.getMetaRegionLocation(this.watcher)); assertEquals(state, MetaTableLocator.getMetaRegionState(this.watcher).getState()); } MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPEN); assertEquals(SN, MetaTableLocator.getMetaRegionLocation(this.watcher)); assertEquals(RegionState.State.OPEN, MetaTableLocator.getMetaRegionState(this.watcher).getState()); MetaTableLocator.deleteMetaLocation(this.watcher); assertNull(MetaTableLocator.getMetaRegionState(this.watcher).getServerName()); assertEquals(RegionState.State.OFFLINE, MetaTableLocator.getMetaRegionState(this.watcher).getState()); assertNull(MetaTableLocator.getMetaRegionLocation(this.watcher)); }
Mockito.mock(ClientProtos.ClientService.BlockingInterface.class); Mockito.when(client.get((RpcController)Mockito.any(), (GetRequest)Mockito.any())). thenReturn(GetResponse.newBuilder().build());
/** * Test normal operations */ @Test public void testMetaLookup() throws IOException, InterruptedException, ServiceException, KeeperException { final ClientProtos.ClientService.BlockingInterface client = Mockito.mock(ClientProtos.ClientService.BlockingInterface.class); Mockito.when(client.get((RpcController)Mockito.any(), (GetRequest)Mockito.any())). thenReturn(GetResponse.newBuilder().build()); final MetaTableLocator mtl = new MetaTableLocator(); assertNull(mtl.getMetaRegionLocation(this.watcher)); for (RegionState.State state : RegionState.State.values()) { if (state.equals(RegionState.State.OPEN)) continue; MetaTableLocator.setMetaLocation(this.watcher, SN, state); assertNull(mtl.getMetaRegionLocation(this.watcher)); assertEquals(state, MetaTableLocator.getMetaRegionState(this.watcher).getState()); } MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPEN); assertEquals(SN, mtl.getMetaRegionLocation(this.watcher)); assertEquals(RegionState.State.OPEN, MetaTableLocator.getMetaRegionState(this.watcher).getState()); mtl.deleteMetaLocation(this.watcher); assertNull(MetaTableLocator.getMetaRegionState(this.watcher).getServerName()); assertEquals(RegionState.State.OFFLINE, MetaTableLocator.getMetaRegionState(this.watcher).getState()); assertNull(mtl.getMetaRegionLocation(this.watcher)); }
@Override // TODO: Very like the super class implemenation. Can we shrink this down? protected Result rpcCall() throws Exception { if (getRpcController().isCanceled()) return null; if (Thread.interrupted()) { throw new InterruptedIOException(); } byte[] reg = location.getRegionInfo().getRegionName(); ClientProtos.GetRequest request = RequestConverter.buildGetRequest(reg, get); HBaseRpcController hrc = (HBaseRpcController)getRpcController(); hrc.reset(); hrc.setCallTimeout(rpcTimeout); hrc.setPriority(tableName); ClientProtos.GetResponse response = getStub().get(hrc, request); if (response == null) { return null; } return ProtobufUtil.toResult(response.getResult(), hrc.cellScanner()); } }
private void testVerifyMetaRegionLocationWithException(Exception ex) throws IOException, InterruptedException, KeeperException, ServiceException { // Mock an ClientProtocol. final ClientProtos.ClientService.BlockingInterface implementation = Mockito.mock(ClientProtos.ClientService.BlockingInterface.class); ClusterConnection connection = mockConnection(null, implementation); // If a 'get' is called on mocked interface, throw connection refused. Mockito.when(implementation.get((RpcController) Mockito.any(), (GetRequest) Mockito.any())). thenThrow(new ServiceException(ex)); long timeout = UTIL.getConfiguration(). getLong("hbase.catalog.verification.timeout", 1000); MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPENING); assertFalse(new MetaTableLocator().verifyMetaRegionLocation( connection, watcher, timeout)); MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPEN); assertFalse(new MetaTableLocator().verifyMetaRegionLocation( connection, watcher, timeout)); }
protected ClientProtos.GetResponse doGet(ClientProtos.GetRequest request) throws org.apache.hbase.thirdparty.com.google.protobuf.ServiceException { return getStub().get(getRpcController(), request); }
@Override // TODO: Very like the super class implemenation. Can we shrink this down? protected Result rpcCall() throws Exception { if (getRpcController().isCanceled()) return null; if (Thread.interrupted()) { throw new InterruptedIOException(); } byte[] reg = location.getRegionInfo().getRegionName(); ClientProtos.GetRequest request = RequestConverter.buildGetRequest(reg, get); HBaseRpcController hrc = (HBaseRpcController)getRpcController(); hrc.reset(); hrc.setCallTimeout(rpcTimeout); hrc.setPriority(tableName); ClientProtos.GetResponse response = getStub().get(hrc, request); if (response == null) { return null; } return ProtobufUtil.toResult(response.getResult(), hrc.cellScanner()); } }
RpcTimeoutConnection(Configuration conf, ExecutorService pool, User user) throws IOException { super(conf, pool, user); // Mock up my stub so an exists call -- which turns into a get -- throws an exception this.stub = Mockito.mock(ClientService.BlockingInterface.class); try { Mockito.when(stub.get((RpcController)Mockito.any(), (ClientProtos.GetRequest)Mockito.any())). thenThrow(new ServiceException(new RegionServerStoppedException("From Mockito"))); } catch (ServiceException e) { throw new IOException(e); } }
protected ClientProtos.GetResponse doGet(ClientProtos.GetRequest request) throws org.apache.hbase.thirdparty.com.google.protobuf.ServiceException { return getStub().get(getRpcController(), request); }
protected ClientProtos.GetResponse doGet(ClientProtos.GetRequest request) throws org.apache.hbase.thirdparty.com.google.protobuf.ServiceException { return getStub().get(getRpcController(), request); }