1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.migration;
19  
20  
21  import java.io.IOException;
22  
23  import junit.framework.Assert;
24  
25  import org.apache.hadoop.hbase.HColumnDescriptor;
26  import org.apache.hadoop.hbase.HConstants;
27  import org.apache.hadoop.hbase.HRegionInfo;
28  import org.apache.hadoop.hbase.HTableDescriptor;
29  import org.apache.hadoop.hbase.catalog.MetaMigrationRemovingHTD;
30  import org.apache.hadoop.hbase.util.Writables;
31  import org.junit.Test;
32  
33  /**
34   * Migration tests that do not need spin up of a cluster.
35   * @deprecated Remove after we release 0.92
36   */
37  public class TestMigrationFrom090To092 {
38    @Test
39    public void testMigrateHRegionInfoFromVersion0toVersion1()
40    throws IOException {
41      HTableDescriptor htd =
42        getHTableDescriptor("testMigrateHRegionInfoFromVersion0toVersion1");
43      HRegionInfo090x ninety =
44        new HRegionInfo090x(htd, HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW);
45      byte [] bytes = Writables.getBytes(ninety);
46      // Now deserialize into an HRegionInfo
47      HRegionInfo hri = Writables.getHRegionInfo(bytes);
48      Assert.assertEquals(hri.getTableNameAsString(),
49        ninety.getTableDesc().getNameAsString());
50      Assert.assertEquals(HRegionInfo.VERSION, hri.getVersion());
51    }
52  
53    private HTableDescriptor getHTableDescriptor(final String name) {
54      HTableDescriptor htd = new HTableDescriptor(name);
55      htd.addFamily(new HColumnDescriptor("family"));
56      return htd;
57    }
58  }