2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.client
;
20 import static org
.junit
.Assert
.assertEquals
;
21 import static org
.junit
.Assert
.assertTrue
;
22 import static org
.junit
.Assert
.fail
;
24 import java
.io
.IOException
;
25 import java
.util
.ArrayList
;
26 import java
.util
.List
;
27 import java
.util
.concurrent
.CompletableFuture
;
28 import java
.util
.concurrent
.ExecutionException
;
29 import org
.apache
.hadoop
.conf
.Configuration
;
30 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
31 import org
.apache
.hadoop
.hbase
.HBaseConfiguration
;
32 import org
.apache
.hadoop
.hbase
.HConstants
;
33 import org
.apache
.hadoop
.hbase
.testclassification
.ClientTests
;
34 import org
.apache
.hadoop
.hbase
.testclassification
.SmallTests
;
35 import org
.apache
.hadoop
.hbase
.util
.FutureUtils
;
36 import org
.junit
.BeforeClass
;
37 import org
.junit
.ClassRule
;
38 import org
.junit
.Test
;
39 import org
.junit
.experimental
.categories
.Category
;
41 @Category({ ClientTests
.class, SmallTests
.class })
42 public class TestConnectionRegistryLeak
{
45 public static final HBaseClassTestRule CLASS_RULE
=
46 HBaseClassTestRule
.forClass(TestConnectionRegistryLeak
.class);
48 public static final class ConnectionRegistryForTest
extends DoNothingConnectionRegistry
{
50 private boolean closed
= false;
52 public ConnectionRegistryForTest(Configuration conf
) {
58 public CompletableFuture
<String
> getClusterId() {
59 return FutureUtils
.failedFuture(new IOException("inject error"));
68 private static final List
<ConnectionRegistryForTest
> CREATED
= new ArrayList
<>();
70 private static Configuration CONF
= HBaseConfiguration
.create();
73 public static void setUp() {
74 CONF
.setClass(HConstants
.CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY
,
75 ConnectionRegistryForTest
.class, ConnectionRegistry
.class);
79 public void test() throws InterruptedException
{
80 for (int i
= 0; i
< 10; i
++) {
82 ConnectionFactory
.createAsyncConnection(CONF
).get();
84 } catch (ExecutionException e
) {
88 assertEquals(10, CREATED
.size());
89 CREATED
.forEach(r
-> assertTrue(r
.closed
));