HBASE-19862 Fix TestTokenAuthentication - mock RegionCoprocessorEnvironment should be of type HasRegionServerServices also.
This commit is contained in:
parent
72f4e98ed1
commit
dbe5cbf5ae
|
@ -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,8 +164,7 @@ 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 {
|
||||||
|
@ -178,19 +181,16 @@ public class TestTokenAuthentication {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue