@Test
public void testLocalServerLookup() throws Exception {
Configuration conf = UTIL.getConfiguration();
// get a real rs
HRegionServer server =
UTIL.getMiniHBaseCluster().getLiveRegionServerThreads().get(0).getRegionServer();
// fake the connection to look like we are living on that server
CoprocessorHConnection connection = new CoprocessorHConnection(conf, server);
// create a table that exists
byte[] tableName = Bytes.toBytes("testLocalServerLookup");
byte[] family = Bytes.toBytes("family");
UTIL.createTable(tableName, family);
// if we can write to the table correctly, then our connection is doing the right thing
HTable table = new HTable(tableName, connection);
Put p = new Put(Bytes.toBytes("row"));
p.add(family, null, null);
table.put(p);
table.flushCommits();
//make sure we get the actual server when doing a direct lookup
ServerName name = server.getServerName();
assertEquals("Didn't get the expected server from the connection", server,
connection.getHRegionConnection(name.getHostname(), name.getPort()));
// cleanup
table.close();