HBASE-26567 Remove IndexType from ChunkCreator (#3947)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / regionserver / TestHRegionTracing.java
blob62f8a150bcf4c777abb470281ccdd8fa30725e2c
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.regionserver;
20 import static org.junit.Assert.assertTrue;
22 import io.opentelemetry.sdk.testing.junit4.OpenTelemetryRule;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.List;
26 import org.apache.hadoop.fs.Path;
27 import org.apache.hadoop.hbase.HBaseClassTestRule;
28 import org.apache.hadoop.hbase.HBaseTestingUtil;
29 import org.apache.hadoop.hbase.TableName;
30 import org.apache.hadoop.hbase.TableNameTestRule;
31 import org.apache.hadoop.hbase.client.Append;
32 import org.apache.hadoop.hbase.client.CheckAndMutate;
33 import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
34 import org.apache.hadoop.hbase.client.Delete;
35 import org.apache.hadoop.hbase.client.Get;
36 import org.apache.hadoop.hbase.client.Increment;
37 import org.apache.hadoop.hbase.client.Mutation;
38 import org.apache.hadoop.hbase.client.Put;
39 import org.apache.hadoop.hbase.client.RegionInfo;
40 import org.apache.hadoop.hbase.client.RegionInfoBuilder;
41 import org.apache.hadoop.hbase.client.Scan;
42 import org.apache.hadoop.hbase.client.TableDescriptor;
43 import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
44 import org.apache.hadoop.hbase.testclassification.MediumTests;
45 import org.apache.hadoop.hbase.testclassification.RegionServerTests;
46 import org.apache.hadoop.hbase.trace.HBaseSemanticAttributes;
47 import org.apache.hadoop.hbase.util.Bytes;
48 import org.apache.hadoop.hbase.wal.WAL;
49 import org.junit.After;
50 import org.junit.AfterClass;
51 import org.junit.Before;
52 import org.junit.ClassRule;
53 import org.junit.Rule;
54 import org.junit.Test;
55 import org.junit.experimental.categories.Category;
57 import org.apache.hbase.thirdparty.com.google.common.io.Closeables;
59 @Category({ RegionServerTests.class, MediumTests.class })
60 public class TestHRegionTracing {
62 @ClassRule
63 public static final HBaseClassTestRule CLASS_RULE =
64 HBaseClassTestRule.forClass(TestHRegionTracing.class);
66 private static HBaseTestingUtil UTIL = new HBaseTestingUtil();
68 private static byte[] FAMILY = Bytes.toBytes("family");
70 private static byte[] QUALIFIER = Bytes.toBytes("qual");
72 private static byte[] ROW = Bytes.toBytes("row");
74 private static byte[] VALUE = Bytes.toBytes("value");
76 @Rule
77 public final OpenTelemetryRule traceRule = OpenTelemetryRule.create();
79 @Rule
80 public final TableNameTestRule tableNameRule = new TableNameTestRule();
82 private WAL wal;
84 private HRegion region;
86 @AfterClass
87 public static void tearDownAfterClass() throws IOException {
88 UTIL.cleanupTestDir();
91 @Before
92 public void setUp() throws IOException {
93 TableName tableName = tableNameRule.getTableName();
94 TableDescriptor desc = TableDescriptorBuilder.newBuilder(tableName)
95 .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)).build();
96 RegionInfo info = RegionInfoBuilder.newBuilder(tableName).build();
97 ChunkCreator.initialize(MemStoreLAB.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null,
98 MemStoreLAB.INDEX_CHUNK_SIZE_PERCENTAGE_DEFAULT);
99 wal = HBaseTestingUtil.createWal(UTIL.getConfiguration(),
100 new Path(UTIL.getDataTestDir(), tableName.getNameAsString()), null);
101 region = HRegion.createHRegion(info, UTIL.getDataTestDir(), UTIL.getConfiguration(), desc, wal);
102 region = UTIL.createLocalHRegion(info, desc);
105 @After
106 public void tearDown() throws IOException {
107 if (region != null) {
108 region.close();
110 Closeables.close(wal, true);
113 private void assertSpan(String spanName) {
114 assertTrue(traceRule.getSpans().stream().anyMatch(span -> {
115 if (!span.getName().equals(spanName)) {
116 return false;
118 List<String> regionNames = span.getAttributes().get(HBaseSemanticAttributes.REGION_NAMES_KEY);
119 return regionNames != null && regionNames.size() == 1 &&
120 regionNames.get(0).equals(region.getRegionInfo().getRegionNameAsString());
121 }));
124 @Test
125 public void testGet() throws IOException {
126 region.get(new Get(ROW));
127 assertSpan("Region.get");
130 @Test
131 public void testPut() throws IOException {
132 region.put(new Put(ROW).addColumn(FAMILY, QUALIFIER, VALUE));
133 assertSpan("Region.put");
134 assertSpan("Region.getRowLock");
137 @Test
138 public void testDelete() throws IOException {
139 region.delete(new Delete(ROW).addColumn(FAMILY, QUALIFIER));
140 assertSpan("Region.delete");
141 assertSpan("Region.getRowLock");
144 @Test
145 public void testAppend() throws IOException {
146 region.append(new Append(ROW).addColumn(FAMILY, QUALIFIER, VALUE));
147 assertSpan("Region.append");
148 assertSpan("Region.getRowLock");
151 @Test
152 public void testIncrement() throws IOException {
153 region.increment(new Increment(ROW).addColumn(FAMILY, QUALIFIER, 1));
154 assertSpan("Region.increment");
155 assertSpan("Region.getRowLock");
158 @Test
159 public void testBatchMutate() throws IOException {
160 region.batchMutate(new Mutation[] { new Put(ROW).addColumn(FAMILY, QUALIFIER, VALUE) });
161 assertSpan("Region.batchMutate");
162 assertSpan("Region.getRowLock");
165 @Test
166 public void testCheckAndMutate() throws IOException {
167 region.checkAndMutate(CheckAndMutate.newBuilder(ROW).ifNotExists(FAMILY, QUALIFIER)
168 .build(new Put(ROW).addColumn(FAMILY, QUALIFIER, VALUE)));
169 assertSpan("Region.checkAndMutate");
170 assertSpan("Region.getRowLock");
173 @Test
174 public void testScanner() throws IOException {
175 try (RegionScanner scanner = region.getScanner(new Scan())) {
176 scanner.reseek(ROW);
177 scanner.next(new ArrayList<>());
179 assertSpan("Region.getScanner");
180 assertSpan("RegionScanner.reseek");
181 assertSpan("RegionScanner.close");