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