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.util; 019 020import static org.junit.jupiter.api.Assertions.assertFalse; 021import static org.mockito.Mockito.mockStatic; 022 023import java.util.stream.Stream; 024import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate; 025import org.apache.hadoop.hbase.client.ConnectionRegistry; 026import org.apache.hadoop.hbase.client.FromClientSideTest3; 027import org.apache.hadoop.hbase.client.RpcConnectionRegistry; 028import org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint; 029import org.apache.hadoop.hbase.testclassification.ClientTests; 030import org.apache.hadoop.hbase.testclassification.LargeTests; 031import org.apache.hadoop.hbase.unsafe.HBasePlatformDependent; 032import org.junit.jupiter.api.BeforeAll; 033import org.junit.jupiter.api.Tag; 034import org.junit.jupiter.params.provider.Arguments; 035import org.mockito.MockedStatic; 036 037@Tag(LargeTests.TAG) 038@Tag(ClientTests.TAG) 039@HBaseParameterizedTestTemplate(name = "{index}: registryImpl={0}, numHedgedReqs={1}") 040public class TestFromClientSide3WoUnsafe extends FromClientSideTest3 { 041 042 public TestFromClientSide3WoUnsafe(Class<? extends ConnectionRegistry> registryImpl, 043 int numHedgedReqs) { 044 super(registryImpl, numHedgedReqs); 045 } 046 047 @BeforeAll 048 public static void setUpBeforeAll() throws Exception { 049 try (MockedStatic<HBasePlatformDependent> mocked = mockStatic(HBasePlatformDependent.class)) { 050 mocked.when(HBasePlatformDependent::isUnsafeAvailable).thenReturn(false); 051 mocked.when(HBasePlatformDependent::unaligned).thenReturn(false); 052 assertFalse(ByteBufferUtils.UNSAFE_AVAIL); 053 assertFalse(ByteBufferUtils.UNSAFE_UNALIGNED); 054 } 055 startCluster(MultiRowMutationEndpoint.class); 056 } 057 058 // Override the parameters in parent class as we will find the parameters method from the current 059 // class first in HBaseParameterizedTemplateProvider. 060 // Tests will run much slower without Unsafe, and since this test is just to confirm that our code 061 // is still OK without Unsafe, and ZKConnectionRegistry does not use our Unsafe classes, so just 062 // run with RpcConnectionRegistry to speed up the tests. 063 public static Stream<Arguments> parameters() { 064 return Stream.of(Arguments.of(RpcConnectionRegistry.class, 2)); 065 } 066}