HBASE-19862 Fix TestTokenAuthentication - mock RegionCoprocessorEnvironment should be of type HasRegionServerServices also.

This commit is contained in:
Apekshit Sharma 2018-01-25 14:01:42 -08:00
parent 72f4e98ed1
commit dbe5cbf5ae
1 changed files with 42 additions and 100 deletions

View File

@ -22,6 +22,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.IOException; import java.io.IOException;
import java.io.InterruptedIOException; import java.io.InterruptedIOException;
@ -45,6 +47,7 @@ import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.client.ClusterConnection; import org.apache.hadoop.hbase.client.ClusterConnection;
import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.coprocessor.HasRegionServerServices;
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessor; import org.apache.hadoop.hbase.coprocessor.RegionCoprocessor;
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
import org.apache.hadoop.hbase.ipc.FifoRpcScheduler; import org.apache.hadoop.hbase.ipc.FifoRpcScheduler;
@ -88,6 +91,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters; import org.junit.runners.Parameterized.Parameters;
import org.mockito.Mockito;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -160,41 +164,37 @@ public class TestTokenAuthentication {
AuthenticationProtos.AuthenticationService.newReflectiveBlockingService(this); AuthenticationProtos.AuthenticationService.newReflectiveBlockingService(this);
final org.apache.hbase.thirdparty.com.google.protobuf.BlockingService proxy = final org.apache.hbase.thirdparty.com.google.protobuf.BlockingService proxy =
new org.apache.hbase.thirdparty.com.google.protobuf.BlockingService() { new org.apache.hbase.thirdparty.com.google.protobuf.BlockingService() {
@Override @Override public Message callBlockingMethod(MethodDescriptor md,
public Message callBlockingMethod(MethodDescriptor md, org.apache.hbase.thirdparty.com.google.protobuf.RpcController controller,
org.apache.hbase.thirdparty.com.google.protobuf.RpcController controller, Message param)
Message param)
throws org.apache.hbase.thirdparty.com.google.protobuf.ServiceException { throws org.apache.hbase.thirdparty.com.google.protobuf.ServiceException {
com.google.protobuf.Descriptors.MethodDescriptor methodDescriptor = com.google.protobuf.Descriptors.MethodDescriptor methodDescriptor =
service.getDescriptorForType().findMethodByName(md.getName()); service.getDescriptorForType().findMethodByName(md.getName());
com.google.protobuf.Message request = service.getRequestPrototype(methodDescriptor); com.google.protobuf.Message request = service.getRequestPrototype(methodDescriptor);
// TODO: Convert rpcController // TODO: Convert rpcController
com.google.protobuf.Message response = null; com.google.protobuf.Message response = null;
try { try {
response = service.callBlockingMethod(methodDescriptor, null, request); response = service.callBlockingMethod(methodDescriptor, null, request);
} catch (ServiceException e) { } catch (ServiceException e) {
throw new org.apache.hbase.thirdparty.com.google.protobuf.ServiceException(e); throw new org.apache.hbase.thirdparty.com.google.protobuf.ServiceException(e);
} }
return null;// Convert 'response'. return null;// Convert 'response'.
} }
@Override @Override public ServiceDescriptor getDescriptorForType() {
public ServiceDescriptor getDescriptorForType() { return null;
return null; }
}
@Override @Override public Message getRequestPrototype(MethodDescriptor arg0) {
public Message getRequestPrototype(MethodDescriptor arg0) { // TODO Auto-generated method stub
// TODO Auto-generated method stub return null;
return null; }
}
@Override @Override public Message getResponsePrototype(MethodDescriptor arg0) {
public Message getResponsePrototype(MethodDescriptor arg0) { // TODO Auto-generated method stub
// TODO Auto-generated method stub return null;
return null; }
} };
};
sai.add(new BlockingServiceAndInterface(proxy, sai.add(new BlockingServiceAndInterface(proxy,
AuthenticationProtos.AuthenticationService.BlockingInterface.class)); AuthenticationProtos.AuthenticationService.BlockingInterface.class));
this.rpcServer = RpcServerFactory.createRpcServer(this, "tokenServer", sai, this.rpcServer = RpcServerFactory.createRpcServer(this, "tokenServer", sai,
@ -268,76 +268,18 @@ public class TestTokenAuthentication {
this, true); this, true);
this.rpcServer.start(); this.rpcServer.start();
// mock RegionServerServices to provide to coprocessor environment // Mock up region coprocessor environment
final RegionServerServices mockServices = TEST_UTIL.createMockRegionServerService(rpcServer); RegionCoprocessorEnvironment mockRegionCpEnv = mock(RegionCoprocessorEnvironment.class,
Mockito.withSettings().extraInterfaces(HasRegionServerServices.class));
// mock up coprocessor environment when(mockRegionCpEnv.getConfiguration()).thenReturn(conf);
super.start( new RegionCoprocessorEnvironment() { when(mockRegionCpEnv.getClassLoader()).then(
@Override (var1) -> Thread.currentThread().getContextClassLoader());
public HRegion getRegion() { return null; } RegionServerServices mockRss = mock(RegionServerServices.class);
when(mockRss.getRpcServer()).thenReturn(rpcServer);
@Override when(((HasRegionServerServices) mockRegionCpEnv).getRegionServerServices())
public OnlineRegions getOnlineRegions() { .thenReturn(mockRss);
return null;
}
@Override
public ConcurrentMap<String, Object> getSharedData() { return null; }
@Override
public MetricRegistry getMetricRegistryForRegionServer() {
return null;
}
@Override
public int getVersion() { return 0; }
@Override
public String getHBaseVersion() { return null; }
@Override
public RegionCoprocessor getInstance() { return null; }
@Override
public int getPriority() { return 0; }
@Override
public int getLoadSequence() { return 0; }
@Override
public Configuration getConfiguration() { return conf; }
@Override
public ClassLoader getClassLoader() {
return Thread.currentThread().getContextClassLoader();
}
@Override
public HRegionInfo getRegionInfo() {
return null;
}
@Override
public ServerName getServerName() {
return null;
}
@Override
public Connection getConnection() {
return null;
}
@Override
public Connection createConnection(Configuration conf) throws IOException {
return null;
}
@Override
public RawCellBuilder getCellBuilder() {
return null;
}
});
super.start(mockRegionCpEnv);
started = true; started = true;
} }