View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.mob.compactions;
20  
21  import org.apache.hadoop.fs.FileStatus;
22  import org.apache.hadoop.fs.Path;
23  import org.apache.hadoop.hbase.testclassification.SmallTests;
24  import org.apache.hadoop.hbase.mob.compactions.PartitionedMobCompactionRequest.CompactionPartition;
25  import org.apache.hadoop.hbase.mob.compactions.PartitionedMobCompactionRequest.CompactionPartitionId;
26  import org.junit.Assert;
27  import org.junit.Test;
28  import org.junit.experimental.categories.Category;
29  
30  @Category(SmallTests.class)
31  public class TestPartitionedMobCompactionRequest {
32  
33    @Test
34    public void testCompactedPartitionId() {
35      String startKey1 = "startKey1";
36      String startKey2 = "startKey2";
37      String date1 = "date1";
38      String date2 = "date2";
39      CompactionPartitionId partitionId1 = new CompactionPartitionId(startKey1, date1);
40      CompactionPartitionId partitionId2 = new CompactionPartitionId(startKey2, date2);
41      CompactionPartitionId partitionId3 = new CompactionPartitionId(startKey1, date2);
42  
43      Assert.assertTrue(partitionId1.equals(partitionId1));
44      Assert.assertFalse(partitionId1.equals(partitionId2));
45      Assert.assertFalse(partitionId1.equals(partitionId3));
46      Assert.assertFalse(partitionId2.equals(partitionId3));
47  
48      Assert.assertEquals(startKey1, partitionId1.getStartKey());
49      Assert.assertEquals(date1, partitionId1.getDate());
50    }
51  
52    @Test
53    public void testCompactedPartition() {
54      CompactionPartitionId partitionId = new CompactionPartitionId("startKey1", "date1");
55      CompactionPartition partition = new CompactionPartition(partitionId);
56      FileStatus file = new FileStatus(1, false, 1, 1024, 1, new Path("/test"));
57      partition.addFile(file);
58      Assert.assertEquals(file, partition.listFiles().get(0));
59    }
60  }