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.ipc; 019 020import java.io.IOException; 021import java.util.stream.Stream; 022import org.apache.hadoop.conf.Configuration; 023import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate; 024import org.apache.hadoop.hbase.codec.Codec; 025import org.apache.hadoop.hbase.testclassification.MediumTests; 026import org.apache.hadoop.hbase.testclassification.RPCTests; 027import org.junit.jupiter.api.Tag; 028import org.junit.jupiter.params.provider.Arguments; 029 030@Tag(RPCTests.TAG) 031@Tag(MediumTests.TAG) 032@HBaseParameterizedTestTemplate(name = "{index}: rpcServerImpl={0}") 033public class TestBlockingIPC extends AbstractTestIPC { 034 035 public TestBlockingIPC(Class<? extends RpcServer> rpcServerImpl) { 036 super(rpcServerImpl); 037 } 038 039 public static Stream<Arguments> parameters() { 040 return Stream.of(Arguments.of(SimpleRpcServer.class), Arguments.of(NettyRpcServer.class)); 041 } 042 043 @Override 044 protected BlockingRpcClient createRpcClientNoCodec(Configuration conf) { 045 return new BlockingRpcClient(conf) { 046 @Override 047 protected Codec getCodec() { 048 return null; 049 } 050 }; 051 } 052 053 @Override 054 protected BlockingRpcClient createRpcClient(Configuration conf) { 055 return new BlockingRpcClient(conf); 056 } 057 058 @Override 059 protected BlockingRpcClient createRpcClientRTEDuringConnectionSetup(Configuration conf) 060 throws IOException { 061 return new BlockingRpcClient(conf) { 062 063 @Override 064 protected boolean isTcpNoDelay() { 065 throw new RuntimeException("Injected fault"); 066 } 067 }; 068 } 069 070 @Override 071 protected AbstractRpcClient<?> createBadAuthRpcClient(Configuration conf) { 072 return new BlockingRpcClient(conf) { 073 074 @Override 075 protected BlockingRpcConnection createConnection(ConnectionId remoteId) throws IOException { 076 return new BlockingRpcConnection(this, remoteId) { 077 @Override 078 protected byte[] getConnectionHeaderPreamble() { 079 byte[] header = super.getConnectionHeaderPreamble(); 080 // set an invalid auth code 081 header[header.length - 1] = -10; 082 return header; 083 } 084 }; 085 } 086 }; 087 } 088}