1   /**
2    * Copyright 2008 The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  package org.apache.hadoop.hbase.util;
21  
22  import org.apache.hadoop.hbase.HBaseClusterTestCase;
23  import org.apache.hadoop.hbase.HColumnDescriptor;
24  import org.apache.hadoop.hbase.HTableDescriptor;
25  import org.apache.hadoop.hbase.MiniHBaseCluster;
26  import org.apache.hadoop.hbase.client.HBaseAdmin;
27  import org.apache.hadoop.hbase.client.HTable;
28  import org.apache.hadoop.hbase.client.HConnectionManager;
29  
30  /**
31   * Test is flakey.  Needs work.  Fails too often on hudson.
32   */
33  public class DisabledTestMetaUtils extends HBaseClusterTestCase {
34    public void testColumnEdits() throws Exception {
35      HBaseAdmin admin = new HBaseAdmin(this.conf);
36      final String oldColumn = "oldcolumn:";
37      // Add three tables
38      for (int i = 0; i < 5; i++) {
39        HTableDescriptor htd = new HTableDescriptor(getName() + i);
40        htd.addFamily(new HColumnDescriptor(oldColumn));
41        admin.createTable(htd);
42      }
43      this.cluster.shutdown();
44      this.cluster = null;
45      MetaUtils utils = new MetaUtils(this.conf);
46      // Add a new column to the third table, getName() + '2', and remove the old.
47      final byte [] editTable = Bytes.toBytes(getName() + 2);
48      final byte [] newColumn = Bytes.toBytes("newcolumn:");
49      utils.addColumn(editTable, new HColumnDescriptor(newColumn));
50      utils.deleteColumn(editTable, Bytes.toBytes(oldColumn));
51      utils.shutdown();
52      // Delete again so we go get it all fresh.
53      HConnectionManager.deleteConnection(conf, false);
54      // Now assert columns were added and deleted.
55      this.cluster = new MiniHBaseCluster(this.conf, 1);
56      // Now assert columns were added and deleted.
57      HTable t = new HTable(conf, editTable);
58      HTableDescriptor htd = t.getTableDescriptor();
59      HColumnDescriptor hcd = htd.getFamily(newColumn);
60      assertTrue(hcd != null);
61      assertNull(htd.getFamily(Bytes.toBytes(oldColumn)));
62    }
63  }