001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.client;
019
020import static org.apache.hadoop.hbase.HConstants.CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY;
021
022import java.io.Closeable;
023import java.io.IOException;
024import java.util.concurrent.ExecutionException;
025import org.apache.hadoop.hbase.HBaseClassTestRule;
026import org.apache.hadoop.hbase.security.User;
027import org.apache.hadoop.hbase.security.UserProvider;
028import org.apache.hadoop.hbase.testclassification.ClientTests;
029import org.apache.hadoop.hbase.testclassification.SmallTests;
030import org.junit.After;
031import org.junit.Before;
032import org.junit.ClassRule;
033import org.junit.Test;
034import org.junit.experimental.categories.Category;
035
036import org.apache.hbase.thirdparty.com.google.common.io.Closeables;
037
038@Category({ ClientTests.class, SmallTests.class })
039public class TestConnectionFactoryTracing extends TestTracingBase {
040
041  @ClassRule
042  public static final HBaseClassTestRule CLASS_RULE =
043    HBaseClassTestRule.forClass(TestConnectionFactoryTracing.class);
044
045  private User currentUser;
046  private Object connection;
047
048  @Override
049  @Before
050  public void setUp() throws Exception {
051    super.setUp();
052    currentUser = UserProvider.instantiate(conf).getCurrent();
053    conf.set(CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY, RegistryForTracingTest.class.getName());
054  }
055
056  @After
057  public void tearDown() throws IOException {
058    Closeables.close((Closeable) connection, true);
059  }
060
061  @Test
062  public void testConnectionTracing() throws IOException {
063    connection = ConnectionFactory.createConnection(conf, currentUser);
064    assertTrace(ConnectionFactory.class.getSimpleName(), "createConnection", null, null);
065  }
066
067  @Test
068  public void testAsyncConnectionTracing()
069    throws IOException, ExecutionException, InterruptedException {
070    connection = ConnectionFactory.createAsyncConnection(conf, currentUser).get();
071    assertTrace(ConnectionFactory.class.getSimpleName(), "createAsyncConnection", null, null);
072  }
073
074}