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.ipc.RpcServer.MAX_REQUEST_SIZE; 021import static org.junit.Assert.assertThrows; 022 023import org.apache.hadoop.hbase.HBaseClassTestRule; 024import org.apache.hadoop.hbase.HBaseTestingUtil; 025import org.apache.hadoop.hbase.TableName; 026import org.apache.hadoop.hbase.exceptions.RequestTooBigException; 027import org.apache.hadoop.hbase.testclassification.ClientTests; 028import org.apache.hadoop.hbase.testclassification.MediumTests; 029import org.apache.hadoop.hbase.util.Bytes; 030import org.junit.AfterClass; 031import org.junit.BeforeClass; 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({ MediumTests.class, ClientTests.class }) 039public class TestRequestTooBigException { 040 041 @ClassRule 042 public static final HBaseClassTestRule CLASS_RULE = 043 HBaseClassTestRule.forClass(TestRequestTooBigException.class); 044 045 private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 046 047 private static final TableName NAME = TableName.valueOf("request_too_big"); 048 049 private static final byte[] FAMILY = Bytes.toBytes("family"); 050 051 private static Table TABLE; 052 053 @BeforeClass 054 public static void setUpBeforeClass() throws Exception { 055 TEST_UTIL.getConfiguration().setInt(MAX_REQUEST_SIZE, 10 * 1024); 056 TEST_UTIL.startMiniCluster(1); 057 TABLE = TEST_UTIL.createTable(NAME, FAMILY); 058 TEST_UTIL.waitTableAvailable(NAME); 059 } 060 061 @AfterClass 062 public static void tearDownAfterClass() throws Exception { 063 Closeables.close(TABLE, true); 064 TEST_UTIL.shutdownMiniCluster(); 065 } 066 067 @Test 068 public void testHbasePutDeleteCell() throws Exception { 069 byte[] value = new byte[1024]; 070 Bytes.random(value); 071 for (int m = 0; m < 100; m++) { 072 Put p = new Put(Bytes.toBytes("bigrow-" + m)); 073 // max request is 10K, big request = 100 * 1K 074 for (int i = 0; i < 100; i++) { 075 p.addColumn(FAMILY, Bytes.toBytes("someQualifier" + i), value); 076 } 077 final Put finalPut = p; 078 assertThrows(RequestTooBigException.class, () -> TABLE.put(finalPut)); 079 } 080 } 081}