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; 019 020import static org.junit.jupiter.api.Assertions.assertEquals; 021 022import org.apache.hadoop.hbase.testclassification.MiscTests; 023import org.apache.hadoop.hbase.testclassification.SmallTests; 024import org.junit.jupiter.api.Tag; 025import org.junit.jupiter.api.Test; 026import org.junit.jupiter.api.extension.ExtendWith; 027 028@Tag(MiscTests.TAG) 029@Tag(SmallTests.TAG) 030@ExtendWith(HBaseJupiterExtension.class) 031public class TestCellBuilder { 032 033 private static final byte OLD_DATA = 87; 034 private static final byte NEW_DATA = 100; 035 036 @Test 037 public void testCellBuilderWithDeepCopy() { 038 byte[] row = new byte[] { OLD_DATA }; 039 byte[] family = new byte[] { OLD_DATA }; 040 byte[] qualifier = new byte[] { OLD_DATA }; 041 byte[] value = new byte[] { OLD_DATA }; 042 Cell cell = CellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(row).setFamily(family) 043 .setQualifier(qualifier).setType(Cell.Type.Put).setValue(value).build(); 044 row[0] = NEW_DATA; 045 family[0] = NEW_DATA; 046 qualifier[0] = NEW_DATA; 047 value[0] = NEW_DATA; 048 assertEquals(OLD_DATA, cell.getRowArray()[cell.getRowOffset()]); 049 assertEquals(OLD_DATA, cell.getFamilyArray()[cell.getFamilyOffset()]); 050 assertEquals(OLD_DATA, cell.getQualifierArray()[cell.getQualifierOffset()]); 051 assertEquals(OLD_DATA, cell.getValueArray()[cell.getValueOffset()]); 052 } 053 054 @Test 055 public void testCellBuilderWithShallowCopy() { 056 byte[] row = new byte[] { OLD_DATA }; 057 byte[] family = new byte[] { OLD_DATA }; 058 byte[] qualifier = new byte[] { OLD_DATA }; 059 byte[] value = new byte[] { OLD_DATA }; 060 Cell cell = CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY).setRow(row) 061 .setFamily(family).setQualifier(qualifier).setType(Cell.Type.Put).setValue(value).build(); 062 row[0] = NEW_DATA; 063 family[0] = NEW_DATA; 064 qualifier[0] = NEW_DATA; 065 value[0] = NEW_DATA; 066 assertEquals(NEW_DATA, cell.getRowArray()[cell.getRowOffset()]); 067 assertEquals(NEW_DATA, cell.getFamilyArray()[cell.getFamilyOffset()]); 068 assertEquals(NEW_DATA, cell.getQualifierArray()[cell.getQualifierOffset()]); 069 assertEquals(NEW_DATA, cell.getValueArray()[cell.getValueOffset()]); 070 } 071 072 @Test 073 public void testExtendedCellBuilderWithShallowCopy() { 074 byte[] row = new byte[] { OLD_DATA }; 075 byte[] family = new byte[] { OLD_DATA }; 076 byte[] qualifier = new byte[] { OLD_DATA }; 077 byte[] value = new byte[] { OLD_DATA }; 078 byte[] tags = new byte[] { OLD_DATA }; 079 long seqId = 999; 080 ExtendedCell cell = ExtendedCellBuilderFactory.create(CellBuilderType.SHALLOW_COPY).setRow(row) 081 .setFamily(family).setQualifier(qualifier).setType(KeyValue.Type.Put.getCode()) 082 .setValue(value).setTags(tags).setSequenceId(seqId).build(); 083 row[0] = NEW_DATA; 084 family[0] = NEW_DATA; 085 qualifier[0] = NEW_DATA; 086 value[0] = NEW_DATA; 087 tags[0] = NEW_DATA; 088 assertEquals(NEW_DATA, cell.getRowArray()[cell.getRowOffset()]); 089 assertEquals(NEW_DATA, cell.getFamilyArray()[cell.getFamilyOffset()]); 090 assertEquals(NEW_DATA, cell.getQualifierArray()[cell.getQualifierOffset()]); 091 assertEquals(NEW_DATA, cell.getValueArray()[cell.getValueOffset()]); 092 assertEquals(NEW_DATA, cell.getTagsArray()[cell.getTagsOffset()]); 093 assertEquals(seqId, cell.getSequenceId()); 094 } 095 096 @Test 097 public void testExtendedCellBuilderWithDeepCopy() { 098 byte[] row = new byte[] { OLD_DATA }; 099 byte[] family = new byte[] { OLD_DATA }; 100 byte[] qualifier = new byte[] { OLD_DATA }; 101 byte[] value = new byte[] { OLD_DATA }; 102 byte[] tags = new byte[] { OLD_DATA }; 103 long seqId = 999; 104 ExtendedCell cell = ExtendedCellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(row) 105 .setFamily(family).setQualifier(qualifier).setType(KeyValue.Type.Put.getCode()) 106 .setValue(value).setTags(tags).setSequenceId(seqId).build(); 107 row[0] = NEW_DATA; 108 family[0] = NEW_DATA; 109 qualifier[0] = NEW_DATA; 110 value[0] = NEW_DATA; 111 tags[0] = NEW_DATA; 112 assertEquals(OLD_DATA, cell.getRowArray()[cell.getRowOffset()]); 113 assertEquals(OLD_DATA, cell.getFamilyArray()[cell.getFamilyOffset()]); 114 assertEquals(OLD_DATA, cell.getQualifierArray()[cell.getQualifierOffset()]); 115 assertEquals(OLD_DATA, cell.getValueArray()[cell.getValueOffset()]); 116 assertEquals(OLD_DATA, cell.getTagsArray()[cell.getTagsOffset()]); 117 assertEquals(seqId, cell.getSequenceId()); 118 } 119}