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