### Question:
RegionMergeTransaction { public boolean prepare(final RegionServerServices services) { if (!region_a.getTableDesc().getTableName() .equals(region_b.getTableDesc().getTableName())) { LOG.info("Can't merge regions " + region_a + "," + region_b + " because they do not belong to the same table"); return false; } if (region_a.getRegionInfo().equals(region_b.getRegionInfo())) { LOG.info("Can't merge the same region " + region_a); return false; } if (!forcible && !HRegionInfo.areAdjacent(region_a.getRegionInfo(), region_b.getRegionInfo())) { String msg = "Skip merging " + this.region_a.getRegionNameAsString() + " and " + this.region_b.getRegionNameAsString() + ", because they are not adjacent."; LOG.info(msg); return false; } if (!this.region_a.isMergeable() || !this.region_b.isMergeable()) { return false; } try { boolean regionAHasMergeQualifier = hasMergeQualifierInMeta(services, region_a.getRegionName()); if (regionAHasMergeQualifier || hasMergeQualifierInMeta(services, region_b.getRegionName())) { LOG.debug("Region " + (regionAHasMergeQualifier ? region_a.getRegionNameAsString() : region_b.getRegionNameAsString()) + " is not mergeable because it has merge qualifier in META"); return false; } } catch (IOException e) { LOG.warn("Failed judging whether merge transaction is available for " + region_a.getRegionNameAsString() + " and " + region_b.getRegionNameAsString(), e); return false; } this.mergedRegionInfo = getMergedRegionInfo(region_a.getRegionInfo(), region_b.getRegionInfo()); return true; } RegionMergeTransaction(final HRegion a, final HRegion b,
      final boolean forcible); boolean prepare(final RegionServerServices services); HRegion execute(final Server server,
      final RegionServerServices services); static HRegionInfo getMergedRegionInfo(final HRegionInfo a,
      final HRegionInfo b); @SuppressWarnings("deprecation") boolean rollback(final Server server,
      final RegionServerServices services); static void createNodeMerging(final ZooKeeperWatcher zkw, final HRegionInfo region,
      final ServerName serverName, final HRegionInfo a,
      final HRegionInfo b); static int transitionMergingNode(ZooKeeperWatcher zkw,
      HRegionInfo merged, HRegionInfo a, HRegionInfo b, ServerName serverName,
      final int znodeVersion, final EventType beginState,
      final EventType endState);  }### Answer:
@Test public void testPrepare() throws IOException { prepareOnGoodRegions(); }
@Test public void testPrepareWithSameRegion() throws IOException { RegionMergeTransaction mt = new RegionMergeTransaction(this.region_a, this.region_a, true); assertFalse("should not merge the same region even if it is forcible ", mt.prepare(null)); }
@Test public void testPrepareWithRegionsNotAdjacent() throws IOException { RegionMergeTransaction mt = new RegionMergeTransaction(this.region_a, this.region_c, false); assertFalse("should not merge two regions if they are adjacent except it is forcible", mt.prepare(null)); }
@Test public void testPrepareWithRegionsWithReference() throws IOException { HStore storeMock = Mockito.mock(HStore.class); when(storeMock.hasReferences()).thenReturn(true); when(storeMock.getFamily()).thenReturn(new HColumnDescriptor("cf")); when(storeMock.close()).thenReturn(ImmutableList.<StoreFile>of()); this.region_a.stores.put(Bytes.toBytes(""), storeMock); RegionMergeTransaction mt = new RegionMergeTransaction(this.region_a, this.region_b, false); assertFalse( "a region should not be mergeable if it has instances of store file references", mt.prepare(null)); }
@Test public void testPrepareWithClosedRegion() throws IOException { this.region_a.close(); RegionMergeTransaction mt = new RegionMergeTransaction(this.region_a, this.region_b, false); assertFalse(mt.prepare(null)); }