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.junit.jupiter.api.Assertions.assertEquals; 021import static org.mockito.ArgumentMatchers.any; 022import static org.mockito.Mockito.mock; 023import static org.mockito.Mockito.mockStatic; 024import static org.mockito.Mockito.when; 025 026import java.net.URI; 027import java.util.concurrent.CompletableFuture; 028import org.apache.hadoop.conf.Configuration; 029import org.apache.hadoop.hbase.HBaseConfiguration; 030import org.apache.hadoop.hbase.testclassification.ClientTests; 031import org.apache.hadoop.hbase.testclassification.SmallTests; 032import org.junit.jupiter.api.AfterEach; 033import org.junit.jupiter.api.BeforeEach; 034import org.junit.jupiter.api.Tag; 035import org.junit.jupiter.api.Test; 036import org.mockito.ArgumentCaptor; 037import org.mockito.MockedStatic; 038 039@Tag(ClientTests.TAG) 040@Tag(SmallTests.TAG) 041public class TestConnectionFactoryApplyURIQueries { 042 043 private Configuration conf; 044 045 private MockedStatic<ConnectionRegistryFactory> mockedConnectionRegistryFactory; 046 047 private ConnectionRegistry registry; 048 049 @BeforeEach 050 public void setUp() { 051 conf = HBaseConfiguration.create(); 052 mockedConnectionRegistryFactory = mockStatic(ConnectionRegistryFactory.class); 053 registry = mock(ConnectionRegistry.class); 054 mockedConnectionRegistryFactory 055 .when(() -> ConnectionRegistryFactory.create(any(), any(), any())).thenReturn(registry); 056 when(registry.getClusterId()).thenReturn(CompletableFuture.completedFuture("cluster")); 057 } 058 059 @AfterEach 060 public void tearDown() { 061 mockedConnectionRegistryFactory.closeOnDemand(); 062 } 063 064 @Test 065 public void testApplyURIQueries() throws Exception { 066 ConnectionFactory.createConnection(new URI("hbase+rpc://server:16010?a=1&b=2&c"), conf); 067 ArgumentCaptor<Configuration> captor = ArgumentCaptor.forClass(Configuration.class); 068 mockedConnectionRegistryFactory 069 .verify(() -> ConnectionRegistryFactory.create(any(), captor.capture(), any())); 070 Configuration c = captor.getValue(); 071 assertEquals("1", c.get("a")); 072 assertEquals("2", c.get("b")); 073 assertEquals("", c.get("c")); 074 } 075}