View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional information regarding
4    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with the License. You may obtain a
6    * copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable
7    * law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
8    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
9    * for the specific language governing permissions and limitations under the License.
10   */
11  package org.apache.hadoop.hbase.regionserver;
12  
13  import static org.junit.Assert.assertEquals;
14  import static org.mockito.Mockito.*;
15  
16  import org.apache.hadoop.hbase.HRegionInfo;
17  import org.apache.hadoop.hbase.TableName;
18  import org.apache.hadoop.hbase.testclassification.MediumTests;
19  import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
20  import org.apache.hadoop.hbase.util.ManualEnvironmentEdge;
21  import org.apache.hadoop.hbase.regionserver.MemStoreFlusher.FlushRegionEntry;
22  import org.junit.AfterClass;
23  import org.junit.BeforeClass;
24  import org.junit.Test;
25  import org.junit.experimental.categories.Category;
26  
27  @Category(MediumTests.class)
28  public class TestFlushRegionEntry {
29  
30    @BeforeClass
31    public static void setUp() throws Exception {
32      ManualEnvironmentEdge edge = new ManualEnvironmentEdge();
33      edge.setValue(12345);
34      EnvironmentEdgeManager.injectEdge(edge);
35    }
36  
37    @AfterClass
38    public static void teardown() {
39      EnvironmentEdgeManager.reset();
40    }
41  
42    @Test
43    public void testFlushRegionEntryEquality() {
44      HRegionInfo hri = new HRegionInfo(1, TableName.valueOf("TestTable"), 0);
45      HRegion r = mock(HRegion.class);
46      doReturn(hri).when(r).getRegionInfo();
47  
48      FlushRegionEntry entry = new FlushRegionEntry(r, true);
49      FlushRegionEntry other = new FlushRegionEntry(r, true);
50  
51      assertEquals(entry.hashCode(), other.hashCode());
52      assertEquals(entry, other);
53    }
54  
55  }