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.jupiter.api.Assertions.assertEquals; 021import static org.junit.jupiter.api.Assertions.assertNotEquals; 022 023import java.io.IOException; 024import org.apache.hadoop.hbase.CellBuilderType; 025import org.apache.hadoop.hbase.ExtendedCellBuilderFactory; 026import org.apache.hadoop.hbase.HBaseTestingUtil; 027import org.apache.hadoop.hbase.KeyValue; 028import org.apache.hadoop.hbase.TableName; 029import org.apache.hadoop.hbase.testclassification.ClientTests; 030import org.apache.hadoop.hbase.testclassification.MediumTests; 031import org.apache.hadoop.hbase.util.Bytes; 032import org.junit.jupiter.api.AfterAll; 033import org.junit.jupiter.api.BeforeAll; 034import org.junit.jupiter.api.Tag; 035import org.junit.jupiter.api.Test; 036import org.junit.jupiter.api.TestInfo; 037 038/** 039 * Run Append tests that use the HBase clients; 040 */ 041@Tag(MediumTests.TAG) 042@Tag(ClientTests.TAG) 043public class TestAppendFromClientSide { 044 045 protected final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 046 private static byte[] ROW = Bytes.toBytes("testRow"); 047 private static byte[] FAMILY = Bytes.toBytes("testFamily"); 048 private static byte[] QUALIFIER = Bytes.toBytes("testQualifier"); 049 050 @BeforeAll 051 public static void beforeClass() throws Exception { 052 TEST_UTIL.startMiniCluster(3); 053 } 054 055 @AfterAll 056 public static void afterClass() throws Exception { 057 TEST_UTIL.shutdownMiniCluster(); 058 } 059 060 @Test 061 public void testAppendWithCustomTimestamp(TestInfo testInfo) throws IOException { 062 TableName TABLENAME = TableName.valueOf(testInfo.getTestMethod().get().getName()); 063 Table table = TEST_UTIL.createTable(TABLENAME, FAMILY); 064 long timestamp = 999; 065 Append append = new Append(ROW); 066 append.add(ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(ROW) 067 .setFamily(FAMILY).setQualifier(QUALIFIER).setTimestamp(timestamp) 068 .setType(KeyValue.Type.Put.getCode()).setValue(Bytes.toBytes(100L)).build()); 069 Result r = table.append(append); 070 assertEquals(1, r.size()); 071 assertEquals(timestamp, r.rawCells()[0].getTimestamp()); 072 r = table.get(new Get(ROW)); 073 assertEquals(1, r.size()); 074 assertEquals(timestamp, r.rawCells()[0].getTimestamp()); 075 r = table.append(append); 076 assertEquals(1, r.size()); 077 assertNotEquals(timestamp, r.rawCells()[0].getTimestamp()); 078 r = table.get(new Get(ROW)); 079 assertEquals(1, r.size()); 080 assertNotEquals(timestamp, r.rawCells()[0].getTimestamp()); 081 } 082}