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.assertTrue; 021 022import org.apache.hadoop.hbase.KeyValue; 023import org.apache.hadoop.hbase.testclassification.FilterTests; 024import org.apache.hadoop.hbase.testclassification.SmallTests; 025import org.apache.hadoop.hbase.util.Bytes; 026import org.junit.jupiter.api.BeforeEach; 027import org.junit.jupiter.api.Tag; 028import org.junit.jupiter.api.Test; 029 030import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; 031import org.apache.hadoop.hbase.shaded.protobuf.generated.FilterProtos; 032 033/** 034 * Test for the ColumnPaginationFilter, used mainly to test the successful serialization of the 035 * filter. More test functionality can be found within 036 * {@link org.apache.hadoop.hbase.filter.TestFilter#testColumnPaginationFilter()} 037 */ 038@Tag(FilterTests.TAG) 039@Tag(SmallTests.TAG) 040public class TestColumnPaginationFilter { 041 042 private static final byte[] ROW = Bytes.toBytes("row_1_test"); 043 private static final byte[] COLUMN_FAMILY = Bytes.toBytes("test"); 044 private static final byte[] VAL_1 = Bytes.toBytes("a"); 045 private static final byte[] COLUMN_QUALIFIER = Bytes.toBytes("foo"); 046 047 private Filter columnPaginationFilterOffset; 048 private Filter columnPaginationFilter; 049 050 @BeforeEach 051 public void setUp() throws Exception { 052 columnPaginationFilter = getColumnPaginationFilter(); 053 columnPaginationFilterOffset = getColumnPaginationFilterOffset(); 054 } 055 056 private Filter getColumnPaginationFilter() { 057 return new ColumnPaginationFilter(1, 0); 058 } 059 060 private Filter getColumnPaginationFilterOffset() { 061 return new ColumnPaginationFilter(1, COLUMN_QUALIFIER); 062 } 063 064 private Filter serializationTest(Filter filter) throws Exception { 065 FilterProtos.Filter filterProto = ProtobufUtil.toFilter(filter); 066 Filter newFilter = ProtobufUtil.toFilter(filterProto); 067 068 return newFilter; 069 } 070 071 /** 072 * The more specific functionality tests are contained within the TestFilters class. This class is 073 * mainly for testing serialization 074 */ 075 private void basicFilterTests(ColumnPaginationFilter filter) throws Exception { 076 KeyValue c = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_1); 077 assertTrue(filter.filterCell(c) == Filter.ReturnCode.INCLUDE_AND_NEXT_COL, "basicFilter1"); 078 } 079 080 /** 081 * Tests serialization 082 */ 083 @Test 084 public void testSerialization() throws Exception { 085 Filter newFilter = serializationTest(columnPaginationFilter); 086 basicFilterTests((ColumnPaginationFilter) newFilter); 087 088 Filter newFilterOffset = serializationTest(columnPaginationFilterOffset); 089 basicFilterTests((ColumnPaginationFilter) newFilterOffset); 090 } 091 092}