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.jupiter.api.Assertions.assertEquals;
021import static org.mockito.Mockito.doReturn;
022import static org.mockito.Mockito.mock;
023
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.jupiter.api.AfterAll;
033import org.junit.jupiter.api.BeforeAll;
034import org.junit.jupiter.api.BeforeEach;
035import org.junit.jupiter.api.Tag;
036import org.junit.jupiter.api.Test;
037import org.junit.jupiter.api.TestInfo;
038
039@Tag(RegionServerTests.TAG)
040@Tag(SmallTests.TAG)
041public class TestFlushRegionEntry {
042
043  private String name;
044
045  @BeforeEach
046  public void setTestName(TestInfo testInfo) {
047    this.name = testInfo.getTestMethod().get().getName();
048  }
049
050  @BeforeAll
051  public static void setUp() throws Exception {
052    ManualEnvironmentEdge edge = new ManualEnvironmentEdge();
053    edge.setValue(12345);
054    EnvironmentEdgeManager.injectEdge(edge);
055  }
056
057  @AfterAll
058  public static void teardown() {
059    EnvironmentEdgeManager.reset();
060  }
061
062  @Test
063  public void testFlushRegionEntryEquality() {
064    RegionInfo hri =
065      RegionInfoBuilder.newBuilder(TableName.valueOf(name)).setRegionId(1).setReplicaId(0).build();
066    HRegion r = mock(HRegion.class);
067    doReturn(hri).when(r).getRegionInfo();
068
069    FlushRegionEntry entry = new FlushRegionEntry(r, null, FlushLifeCycleTracker.DUMMY);
070    FlushRegionEntry other = new FlushRegionEntry(r, null, FlushLifeCycleTracker.DUMMY);
071
072    assertEquals(entry.hashCode(), other.hashCode());
073    assertEquals(entry, other);
074  }
075}