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.Assert.assertEquals;
021
022import java.util.ArrayList;
023import java.util.List;
024import org.apache.hadoop.hbase.Cell;
025import org.apache.hadoop.hbase.CellUtil;
026import org.apache.hadoop.hbase.HBaseClassTestRule;
027import org.apache.hadoop.hbase.testclassification.RegionServerTests;
028import org.apache.hadoop.hbase.testclassification.SmallTests;
029import org.apache.hadoop.hbase.util.Bytes;
030import org.apache.hadoop.hbase.wal.WALEdit;
031import org.junit.ClassRule;
032import org.junit.Test;
033import org.junit.experimental.categories.Category;
034
035@Category({ RegionServerTests.class, SmallTests.class })
036public class TestFSWALEntry {
037
038  @ClassRule
039  public static final HBaseClassTestRule CLASS_RULE =
040    HBaseClassTestRule.forClass(TestFSWALEntry.class);
041
042  @Test
043  public void testCollectFamilies() {
044    byte[] family0 = Bytes.toBytes("family0");
045    byte[] family1 = Bytes.toBytes("family1");
046    byte[] family2 = Bytes.toBytes("family2");
047
048    List<Cell> cells = new ArrayList<>();
049    assertEquals(0, FSWALEntry.collectFamilies(cells).size());
050
051    cells.add(CellUtil.createCell(family0, family0, family0));
052    assertEquals(1, FSWALEntry.collectFamilies(cells).size());
053
054    cells.add(CellUtil.createCell(family1, family1, family1));
055    assertEquals(2, FSWALEntry.collectFamilies(cells).size());
056
057    cells.add(CellUtil.createCell(family0, family0, family0));
058    cells.add(CellUtil.createCell(family1, family1, family1));
059    assertEquals(2, FSWALEntry.collectFamilies(cells).size());
060
061    cells.add(CellUtil.createCell(family2, family2, family2));
062    assertEquals(3, FSWALEntry.collectFamilies(cells).size());
063
064    cells.add(CellUtil.createCell(WALEdit.METAFAMILY, WALEdit.METAFAMILY, WALEdit.METAFAMILY));
065    assertEquals(3, FSWALEntry.collectFamilies(cells).size());
066  }
067}