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