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;
019
020import static org.junit.Assert.assertEquals;
021import static org.mockito.Mockito.doReturn;
022import static org.mockito.Mockito.mock;
023import org.apache.hadoop.hbase.HBaseClassTestRule;
024import org.apache.hadoop.hbase.TableName;
025import org.apache.hadoop.hbase.client.RegionInfo;
026import org.apache.hadoop.hbase.client.RegionInfoBuilder;
027import org.apache.hadoop.hbase.regionserver.MemStoreFlusher.FlushRegionEntry;
028import org.apache.hadoop.hbase.testclassification.RegionServerTests;
029import org.apache.hadoop.hbase.testclassification.SmallTests;
030import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
031import org.apache.hadoop.hbase.util.ManualEnvironmentEdge;
032import org.junit.AfterClass;
033import org.junit.BeforeClass;
034import org.junit.ClassRule;
035import org.junit.Rule;
036import org.junit.Test;
037import org.junit.experimental.categories.Category;
038import org.junit.rules.TestName;
039
040@Category({ RegionServerTests.class, SmallTests.class })
041public class TestFlushRegionEntry {
042
043  @ClassRule
044  public static final HBaseClassTestRule CLASS_RULE =
045      HBaseClassTestRule.forClass(TestFlushRegionEntry.class);
046
047  @Rule
048  public TestName name = new TestName();
049
050  @BeforeClass
051  public static void setUp() throws Exception {
052    ManualEnvironmentEdge edge = new ManualEnvironmentEdge();
053    edge.setValue(12345);
054    EnvironmentEdgeManager.injectEdge(edge);
055  }
056
057  @AfterClass
058  public static void teardown() {
059    EnvironmentEdgeManager.reset();
060  }
061
062  @Test
063  public void testFlushRegionEntryEquality() {
064    RegionInfo hri = RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName()))
065        .setRegionId(1).setReplicaId(0).build();
066    HRegion r = mock(HRegion.class);
067    doReturn(hri).when(r).getRegionInfo();
068
069    FlushRegionEntry entry = new FlushRegionEntry(r, true, FlushLifeCycleTracker.DUMMY);
070    FlushRegionEntry other = new FlushRegionEntry(r, true, FlushLifeCycleTracker.DUMMY);
071
072    assertEquals(entry.hashCode(), other.hashCode());
073    assertEquals(entry, other);
074  }
075}