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.client;
019
020import static org.junit.Assert.assertEquals;
021import static org.junit.Assert.assertNotEquals;
022
023import java.io.IOException;
024import org.apache.hadoop.conf.Configuration;
025import org.apache.hadoop.hbase.CellUtil;
026import org.apache.hadoop.hbase.HBaseClassTestRule;
027import org.apache.hadoop.hbase.HBaseTestingUtility;
028import org.apache.hadoop.hbase.KeyValue;
029import org.apache.hadoop.hbase.TableName;
030import org.apache.hadoop.hbase.testclassification.LargeTests;
031import org.apache.hadoop.hbase.util.Bytes;
032import org.junit.AfterClass;
033import org.junit.BeforeClass;
034import org.junit.ClassRule;
035import org.junit.Rule;
036import org.junit.Test;
037import org.junit.experimental.categories.Category;
038import org.junit.rules.TestName;
039
040/**
041 * Run Append tests that use the HBase clients;
042 */
043@Category(LargeTests.class)
044public class TestAppendFromClientSide {
045
046  @ClassRule
047  public static final HBaseClassTestRule CLASS_RULE =
048      HBaseClassTestRule.forClass(TestAppendFromClientSide.class);
049
050  protected final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
051  private static byte [] ROW = Bytes.toBytes("testRow");
052  private static byte [] FAMILY = Bytes.toBytes("testFamily");
053  private static byte [] QUALIFIER = Bytes.toBytes("testQualifier");
054  @Rule
055  public TestName name = new TestName();
056  @BeforeClass
057  public static void beforeClass() throws Exception {
058    Configuration conf = TEST_UTIL.getConfiguration();
059    TEST_UTIL.startMiniCluster(3);
060  }
061
062  /**
063   * @throws java.lang.Exception
064   */
065  @AfterClass
066  public static void afterClass() throws Exception {
067    TEST_UTIL.shutdownMiniCluster();
068  }
069
070  @Test
071  public void testAppendWithCustomTimestamp() throws IOException {
072    TableName TABLENAME = TableName.valueOf(name.getMethodName());
073    Table table = TEST_UTIL.createTable(TABLENAME, FAMILY);
074    long timestamp = 999;
075    Append append = new Append(ROW);
076    append.add(CellUtil.createCell(ROW, FAMILY, QUALIFIER, timestamp, KeyValue.Type.Put.getCode(), Bytes.toBytes(100L)));
077    Result r = table.append(append);
078    assertEquals(1, r.size());
079    assertEquals(timestamp, r.rawCells()[0].getTimestamp());
080    r = table.get(new Get(ROW));
081    assertEquals(1, r.size());
082    assertEquals(timestamp, r.rawCells()[0].getTimestamp());
083    r = table.append(append);
084    assertEquals(1, r.size());
085    assertNotEquals(timestamp, r.rawCells()[0].getTimestamp());
086    r = table.get(new Get(ROW));
087    assertEquals(1, r.size());
088    assertNotEquals(timestamp, r.rawCells()[0].getTimestamp());
089  }
090}