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.regionserver.wal; 019 020import static org.junit.jupiter.api.Assertions.assertEquals; 021 022import java.util.ArrayList; 023import java.util.List; 024import org.apache.hadoop.hbase.CellBuilderType; 025import org.apache.hadoop.hbase.ExtendedCell; 026import org.apache.hadoop.hbase.ExtendedCellBuilderFactory; 027import org.apache.hadoop.hbase.HConstants; 028import org.apache.hadoop.hbase.KeyValue; 029import org.apache.hadoop.hbase.testclassification.RegionServerTests; 030import org.apache.hadoop.hbase.testclassification.SmallTests; 031import org.apache.hadoop.hbase.util.Bytes; 032import org.apache.hadoop.hbase.wal.WALEdit; 033import org.junit.jupiter.api.Tag; 034import org.junit.jupiter.api.Test; 035 036@Tag(RegionServerTests.TAG) 037@Tag(SmallTests.TAG) 038public class TestFSWALEntry { 039 040 @Test 041 public void testCollectFamilies() { 042 byte[] family0 = Bytes.toBytes("family0"); 043 byte[] family1 = Bytes.toBytes("family1"); 044 byte[] family2 = Bytes.toBytes("family2"); 045 046 List<ExtendedCell> cells = new ArrayList<>(); 047 assertEquals(0, FSWALEntry.collectFamilies(cells).size()); 048 049 cells.add(ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(family0) 050 .setFamily(family0).setQualifier(family0).setTimestamp(HConstants.LATEST_TIMESTAMP) 051 .setType(KeyValue.Type.Maximum.getCode()).setValue(HConstants.EMPTY_BYTE_ARRAY).build()); 052 assertEquals(1, FSWALEntry.collectFamilies(cells).size()); 053 054 cells.add(ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(family1) 055 .setFamily(family1).setQualifier(family1).setTimestamp(HConstants.LATEST_TIMESTAMP) 056 .setType(KeyValue.Type.Maximum.getCode()).setValue(HConstants.EMPTY_BYTE_ARRAY).build()); 057 assertEquals(2, FSWALEntry.collectFamilies(cells).size()); 058 059 cells.add(ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(family0) 060 .setFamily(family0).setQualifier(family0).setTimestamp(HConstants.LATEST_TIMESTAMP) 061 .setType(KeyValue.Type.Maximum.getCode()).setValue(HConstants.EMPTY_BYTE_ARRAY).build()); 062 cells.add(ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(family1) 063 .setFamily(family1).setQualifier(family1).setTimestamp(HConstants.LATEST_TIMESTAMP) 064 .setType(KeyValue.Type.Maximum.getCode()).setValue(HConstants.EMPTY_BYTE_ARRAY).build()); 065 assertEquals(2, FSWALEntry.collectFamilies(cells).size()); 066 067 cells.add(ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(family2) 068 .setFamily(family2).setQualifier(family2).setTimestamp(HConstants.LATEST_TIMESTAMP) 069 .setType(KeyValue.Type.Maximum.getCode()).setValue(HConstants.EMPTY_BYTE_ARRAY).build()); 070 assertEquals(3, FSWALEntry.collectFamilies(cells).size()); 071 072 cells.add(ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY) 073 .setRow(WALEdit.METAFAMILY).setFamily(WALEdit.METAFAMILY).setQualifier(WALEdit.METAFAMILY) 074 .setTimestamp(HConstants.LATEST_TIMESTAMP).setType(KeyValue.Type.Maximum.getCode()) 075 .setValue(HConstants.EMPTY_BYTE_ARRAY).build()); 076 assertEquals(3, FSWALEntry.collectFamilies(cells).size()); 077 } 078}