HBASE-21929 The checks at the end of TestRpcClientLeaks are not executed
Signed-off-by: Xu Cang <xucang@apache.org>
This commit is contained in:
parent
51fb26209d
commit
3e2c75d2d7
|
@ -19,11 +19,13 @@ package org.apache.hadoop.hbase.ipc;
|
||||||
|
|
||||||
import static org.apache.hadoop.hbase.HBaseTestingUtility.fam1;
|
import static org.apache.hadoop.hbase.HBaseTestingUtility.fam1;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.util.List;
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||||
|
@ -43,26 +45,23 @@ import org.junit.ClassRule;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.junit.rules.TestName;
|
import org.junit.rules.TestName;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
|
|
||||||
|
|
||||||
@Category(MediumTests.class)
|
@Category(MediumTests.class)
|
||||||
public class TestRpcClientLeaks {
|
public class TestRpcClientLeaks {
|
||||||
|
|
||||||
@ClassRule
|
@ClassRule
|
||||||
public static final HBaseClassTestRule CLASS_RULE =
|
public static final HBaseClassTestRule CLASS_RULE =
|
||||||
HBaseClassTestRule.forClass(TestRpcClientLeaks.class);
|
HBaseClassTestRule.forClass(TestRpcClientLeaks.class);
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public TestName name = new TestName();
|
public TestName name = new TestName();
|
||||||
|
|
||||||
|
private static BlockingQueue<Socket> SAVED_SOCKETS = new LinkedBlockingQueue<>();
|
||||||
|
|
||||||
public static class MyRpcClientImpl extends BlockingRpcClient {
|
public static class MyRpcClientImpl extends BlockingRpcClient {
|
||||||
public static List<Socket> savedSockets = Lists.newArrayList();
|
|
||||||
@Rule public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
public MyRpcClientImpl(Configuration conf) {
|
public MyRpcClientImpl(Configuration conf) {
|
||||||
super(conf);
|
super(conf);
|
||||||
|
@ -79,11 +78,9 @@ public class TestRpcClientLeaks {
|
||||||
@Override
|
@Override
|
||||||
protected synchronized void setupConnection() throws IOException {
|
protected synchronized void setupConnection() throws IOException {
|
||||||
super.setupConnection();
|
super.setupConnection();
|
||||||
synchronized (savedSockets) {
|
SAVED_SOCKETS.add(socket);
|
||||||
savedSockets.add(socket);
|
throw new IOException(
|
||||||
}
|
"Sample exception for verifying socket closure in case of exceptions.");
|
||||||
throw new IOException("Sample exception for " +
|
|
||||||
"verifying socket closure in case of exceptions.");
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -103,21 +100,23 @@ public class TestRpcClientLeaks {
|
||||||
|
|
||||||
public static final Logger LOG = LoggerFactory.getLogger(TestRpcClientLeaks.class);
|
public static final Logger LOG = LoggerFactory.getLogger(TestRpcClientLeaks.class);
|
||||||
|
|
||||||
@Test(expected=RetriesExhaustedException.class)
|
@Test
|
||||||
public void testSocketClosed() throws IOException, InterruptedException {
|
public void testSocketClosed() throws IOException, InterruptedException {
|
||||||
TableName tableName = TableName.valueOf(name.getMethodName());
|
TableName tableName = TableName.valueOf(name.getMethodName());
|
||||||
UTIL.createTable(tableName, fam1).close();
|
UTIL.createTable(tableName, fam1).close();
|
||||||
|
|
||||||
Configuration conf = new Configuration(UTIL.getConfiguration());
|
Configuration conf = new Configuration(UTIL.getConfiguration());
|
||||||
conf.set(RpcClientFactory.CUSTOM_RPC_CLIENT_IMPL_CONF_KEY,
|
conf.set(RpcClientFactory.CUSTOM_RPC_CLIENT_IMPL_CONF_KEY, MyRpcClientImpl.class.getName());
|
||||||
MyRpcClientImpl.class.getName());
|
|
||||||
conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);
|
conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);
|
||||||
Connection connection = ConnectionFactory.createConnection(conf);
|
try (Connection connection = ConnectionFactory.createConnection(conf);
|
||||||
Table table = connection.getTable(TableName.valueOf(name.getMethodName()));
|
Table table = connection.getTable(TableName.valueOf(name.getMethodName()))) {
|
||||||
table.get(new Get(Bytes.toBytes("asd")));
|
table.get(new Get(Bytes.toBytes("asd")));
|
||||||
connection.close();
|
fail("Should fail because the injected error");
|
||||||
for (Socket socket : MyRpcClientImpl.savedSockets) {
|
} catch (RetriesExhaustedException e) {
|
||||||
assertTrue("Socket + " + socket + " is not closed", socket.isClosed());
|
// expected
|
||||||
|
}
|
||||||
|
for (Socket socket : SAVED_SOCKETS) {
|
||||||
|
assertTrue("Socket " + socket + " is not closed", socket.isClosed());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue