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.junit.jupiter.api.Assertions.assertFalse; 021import static org.junit.jupiter.api.Assertions.assertTrue; 022 023import java.util.ArrayList; 024import java.util.List; 025import org.apache.hadoop.hbase.util.Bytes; 026import org.junit.jupiter.api.TestTemplate; 027import org.slf4j.Logger; 028import org.slf4j.LoggerFactory; 029 030public class FromClientSideTestHTableExistsMethodMultipleRegionsMultipleGets 031 extends FromClientSideTestBase { 032 033 private static final Logger LOG = 034 LoggerFactory.getLogger(FromClientSideTestHTableExistsMethodMultipleRegionsMultipleGets.class); 035 036 private static byte[] ANOTHERROW = Bytes.toBytes("anotherrow"); 037 038 protected FromClientSideTestHTableExistsMethodMultipleRegionsMultipleGets( 039 Class<? extends ConnectionRegistry> registryImpl, int numHedgedReqs) { 040 super(registryImpl, numHedgedReqs); 041 } 042 043 @TestTemplate 044 public void testHTableExistsMethodMultipleRegionsMultipleGets() throws Exception { 045 TEST_UTIL.createTable(tableName, new byte[][] { FAMILY }, 1, new byte[] { 0x00 }, 046 new byte[] { (byte) 0xff }, 255); 047 TEST_UTIL.waitTableAvailable(tableName, 10_000); 048 try (Connection conn = getConnection(); Table table = conn.getTable(tableName)) { 049 Put put = new Put(ROW); 050 put.addColumn(FAMILY, QUALIFIER, VALUE); 051 table.put(put); 052 053 List<Get> gets = new ArrayList<>(); 054 gets.add(new Get(ANOTHERROW)); 055 gets.add(new Get(Bytes.add(ROW, new byte[] { 0x00 }))); 056 gets.add(new Get(ROW)); 057 gets.add(new Get(Bytes.add(ANOTHERROW, new byte[] { 0x00 }))); 058 059 LOG.info("Calling exists"); 060 boolean[] results = table.exists(gets); 061 assertFalse(results[0]); 062 assertFalse(results[1]); 063 assertTrue(results[2]); 064 assertFalse(results[3]); 065 066 // Test with the first region. 067 put = new Put(new byte[] { 0x00 }); 068 put.addColumn(FAMILY, QUALIFIER, VALUE); 069 table.put(put); 070 071 gets = new ArrayList<>(); 072 gets.add(new Get(new byte[] { 0x00 })); 073 gets.add(new Get(new byte[] { 0x00, 0x00 })); 074 results = table.exists(gets); 075 assertTrue(results[0]); 076 assertFalse(results[1]); 077 078 // Test with the last region 079 put = new Put(new byte[] { (byte) 0xff, (byte) 0xff }); 080 put.addColumn(FAMILY, QUALIFIER, VALUE); 081 table.put(put); 082 083 gets = new ArrayList<>(); 084 gets.add(new Get(new byte[] { (byte) 0xff })); 085 gets.add(new Get(new byte[] { (byte) 0xff, (byte) 0xff })); 086 gets.add(new Get(new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff })); 087 results = table.exists(gets); 088 assertFalse(results[0]); 089 assertTrue(results[1]); 090 assertFalse(results[2]); 091 } 092 } 093}