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.mob.compactions;
019
020import org.apache.hadoop.fs.FileStatus;
021import org.apache.hadoop.fs.Path;
022import org.apache.hadoop.hbase.HBaseClassTestRule;
023import org.apache.hadoop.hbase.mob.compactions.PartitionedMobCompactionRequest.CompactionPartition;
024import org.apache.hadoop.hbase.mob.compactions.PartitionedMobCompactionRequest.CompactionPartitionId;
025import org.apache.hadoop.hbase.testclassification.SmallTests;
026import org.junit.Assert;
027import org.junit.ClassRule;
028import org.junit.Test;
029import org.junit.experimental.categories.Category;
030
031@Category(SmallTests.class)
032public class TestPartitionedMobCompactionRequest {
033
034  @ClassRule
035  public static final HBaseClassTestRule CLASS_RULE =
036      HBaseClassTestRule.forClass(TestPartitionedMobCompactionRequest.class);
037
038  @Test
039  public void testCompactedPartitionId() {
040    String startKey1 = "startKey1";
041    String startKey2 = "startKey2";
042    String date1 = "date1";
043    String date2 = "date2";
044    CompactionPartitionId partitionId1 = new CompactionPartitionId(startKey1, date1);
045    CompactionPartitionId partitionId2 = new CompactionPartitionId(startKey2, date2);
046    CompactionPartitionId partitionId3 = new CompactionPartitionId(startKey1, date2);
047
048    Assert.assertTrue(partitionId1.equals(partitionId1));
049    Assert.assertFalse(partitionId1.equals(partitionId2));
050    Assert.assertFalse(partitionId1.equals(partitionId3));
051    Assert.assertFalse(partitionId2.equals(partitionId3));
052
053    Assert.assertEquals(startKey1, partitionId1.getStartKey());
054    Assert.assertEquals(date1, partitionId1.getDate());
055  }
056
057  @Test
058  public void testCompactedPartition() {
059    CompactionPartitionId partitionId = new CompactionPartitionId("startKey1", "date1");
060    CompactionPartition partition = new CompactionPartition(partitionId);
061    FileStatus file = new FileStatus(1, false, 1, 1024, 1, new Path("/test"));
062    partition.addFile(file);
063    Assert.assertEquals(file, partition.listFiles().get(0));
064  }
065}