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