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.Arrays; 022import java.util.List; 023import org.apache.hadoop.conf.Configuration; 024import org.apache.hadoop.hbase.HBaseClassTestRule; 025import org.apache.hadoop.hbase.codec.Codec; 026import org.apache.hadoop.hbase.testclassification.MediumTests; 027import org.apache.hadoop.hbase.testclassification.RPCTests; 028import org.junit.ClassRule; 029import org.junit.experimental.categories.Category; 030import org.junit.runner.RunWith; 031import org.junit.runners.Parameterized; 032import org.junit.runners.Parameterized.Parameters; 033 034@RunWith(Parameterized.class) 035@Category({ RPCTests.class, MediumTests.class }) 036public class TestBlockingIPC extends AbstractTestIPC { 037 038 @ClassRule 039 public static final HBaseClassTestRule CLASS_RULE = 040 HBaseClassTestRule.forClass(TestBlockingIPC.class); 041 042 @Parameters(name = "{index}: rpcServerImpl={0}") 043 public static List<Object[]> data() { 044 return Arrays.asList(new Object[] { SimpleRpcServer.class }, 045 new Object[] { NettyRpcServer.class }); 046 } 047 048 @Override 049 protected BlockingRpcClient createRpcClientNoCodec(Configuration conf) { 050 return new BlockingRpcClient(conf) { 051 @Override 052 protected Codec getCodec() { 053 return null; 054 } 055 }; 056 } 057 058 @Override 059 protected BlockingRpcClient createRpcClient(Configuration conf) { 060 return new BlockingRpcClient(conf); 061 } 062 063 @Override 064 protected BlockingRpcClient createRpcClientRTEDuringConnectionSetup(Configuration conf) 065 throws IOException { 066 return new BlockingRpcClient(conf) { 067 068 @Override 069 protected boolean isTcpNoDelay() { 070 throw new RuntimeException("Injected fault"); 071 } 072 }; 073 } 074 075 @Override 076 protected AbstractRpcClient<?> createBadAuthRpcClient(Configuration conf) { 077 return new BlockingRpcClient(conf) { 078 079 @Override 080 protected BlockingRpcConnection createConnection(ConnectionId remoteId) throws IOException { 081 return new BlockingRpcConnection(this, remoteId) { 082 @Override 083 protected byte[] getConnectionHeaderPreamble() { 084 byte[] header = super.getConnectionHeaderPreamble(); 085 // set an invalid auth code 086 header[header.length - 1] = -10; 087 return header; 088 } 089 }; 090 } 091 }; 092 } 093}