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