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.filter; 019 020import static org.junit.jupiter.api.Assertions.assertFalse; 021import static org.junit.jupiter.api.Assertions.assertTrue; 022 023import org.apache.hadoop.hbase.KeyValueUtil; 024import org.apache.hadoop.hbase.testclassification.FilterTests; 025import org.apache.hadoop.hbase.testclassification.SmallTests; 026import org.apache.hadoop.hbase.util.Bytes; 027import org.junit.jupiter.api.BeforeEach; 028import org.junit.jupiter.api.Tag; 029import org.junit.jupiter.api.Test; 030 031/** 032 * Tests the inclusive stop row filter 033 */ 034@Tag(FilterTests.TAG) 035@Tag(SmallTests.TAG) 036public class TestInclusiveStopFilter { 037 038 private final byte[] STOP_ROW = Bytes.toBytes("stop_row"); 039 private final byte[] GOOD_ROW = Bytes.toBytes("good_row"); 040 private final byte[] PAST_STOP_ROW = Bytes.toBytes("zzzzzz"); 041 042 Filter mainFilter; 043 044 @BeforeEach 045 public void setUp() throws Exception { 046 mainFilter = new InclusiveStopFilter(STOP_ROW); 047 } 048 049 /** 050 * Tests identification of the stop row 051 */ 052 @Test 053 public void testStopRowIdentification() throws Exception { 054 stopRowTests(mainFilter); 055 } 056 057 /** 058 * Tests serialization 059 */ 060 @Test 061 public void testSerialization() throws Exception { 062 // Decompose mainFilter to bytes. 063 byte[] buffer = mainFilter.toByteArray(); 064 065 // Recompose mainFilter. 066 Filter newFilter = InclusiveStopFilter.parseFrom(buffer); 067 068 // Ensure the serialization preserved the filter by running a full test. 069 stopRowTests(newFilter); 070 } 071 072 private void stopRowTests(Filter filter) throws Exception { 073 assertFalse(filter.filterRowKey(KeyValueUtil.createFirstOnRow(GOOD_ROW)), 074 "Filtering on " + Bytes.toString(GOOD_ROW)); 075 assertFalse(filter.filterRowKey(KeyValueUtil.createFirstOnRow(STOP_ROW)), 076 "Filtering on " + Bytes.toString(STOP_ROW)); 077 assertTrue(filter.filterRowKey(KeyValueUtil.createFirstOnRow(PAST_STOP_ROW)), 078 "Filtering on " + Bytes.toString(PAST_STOP_ROW)); 079 080 assertTrue(filter.filterAllRemaining(), "FilterAllRemaining"); 081 assertFalse(filter.filterRow(), "FilterNotNull"); 082 } 083 084}