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