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  
19  package org.apache.hadoop.hbase.client;
20  
21  import java.io.IOException;
22  
23  import org.apache.hadoop.hbase.HBaseClusterTestCase;
24  import org.apache.hadoop.hbase.HColumnDescriptor;
25  import org.apache.hadoop.hbase.HTableDescriptor;
26  import org.apache.hadoop.hbase.TimestampTestBase;
27  
28  /**
29   * Tests user specifiable time stamps putting, getting and scanning.  Also
30   * tests same in presence of deletes.  Test cores are written so can be
31   * run against an HRegion and against an HTable: i.e. both local and remote.
32   */
33  public class TestTimestamp extends HBaseClusterTestCase {
34    public static String COLUMN_NAME = "colfamily1";
35  
36    /** constructor */
37    public TestTimestamp() {
38      super();
39    }
40  
41    /**
42     * Basic test of timestamps.
43     * Do the above tests from client side.
44     * @throws IOException
45     */
46    public void testTimestamps() throws IOException {
47      HTable t = createTable();
48      Incommon incommon = new HTableIncommon(t);
49      TimestampTestBase.doTestDelete(incommon, new FlushCache() {
50        public void flushcache() throws IOException {
51          cluster.flushcache();
52        }
53       });
54  
55      // Perhaps drop and readd the table between tests so the former does
56      // not pollute this latter?  Or put into separate tests.
57      TimestampTestBase.doTestTimestampScanning(incommon, new FlushCache() {
58        public void flushcache() throws IOException {
59          cluster.flushcache();
60        }
61      });
62    }
63  
64    /*
65     * Create a table named TABLE_NAME.
66     * @return An instance of an HTable connected to the created table.
67     * @throws IOException
68     */
69    private HTable createTable() throws IOException {
70      HTableDescriptor desc = new HTableDescriptor(getName());
71      desc.addFamily(new HColumnDescriptor(COLUMN_NAME));
72      HBaseAdmin admin = new HBaseAdmin(conf);
73      admin.createTable(desc);
74      return new HTable(conf, getName());
75    }
76  }