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
.master
;
20 import static org
.junit
.Assert
.assertEquals
;
21 import static org
.junit
.Assert
.assertNotNull
;
22 import static org
.junit
.Assert
.assertTrue
;
24 import java
.io
.IOException
;
25 import java
.util
.List
;
26 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
27 import org
.apache
.hadoop
.hbase
.HBaseTestingUtil
;
28 import org
.apache
.hadoop
.hbase
.HConstants
;
29 import org
.apache
.hadoop
.hbase
.NamespaceDescriptor
;
30 import org
.apache
.hadoop
.hbase
.SingleProcessHBaseCluster
;
31 import org
.apache
.hadoop
.hbase
.TableName
;
32 import org
.apache
.hadoop
.hbase
.client
.Put
;
33 import org
.apache
.hadoop
.hbase
.client
.Table
;
34 import org
.apache
.hadoop
.hbase
.regionserver
.HRegionServer
;
35 import org
.apache
.hadoop
.hbase
.regionserver
.Region
;
36 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
37 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
38 import org
.apache
.hadoop
.hbase
.util
.JVMClusterUtil
;
39 import org
.junit
.After
;
40 import org
.junit
.Before
;
41 import org
.junit
.ClassRule
;
42 import org
.junit
.Test
;
43 import org
.junit
.experimental
.categories
.Category
;
45 import org
.apache
.hadoop
.hbase
.shaded
.protobuf
.generated
.ClusterStatusProtos
.RegionStoreSequenceIds
;
48 * Trivial test to confirm that we can get last flushed sequence id by encodedRegionName. See
51 @Category(MediumTests
.class)
52 public class TestGetLastFlushedSequenceId
{
55 public static final HBaseClassTestRule CLASS_RULE
=
56 HBaseClassTestRule
.forClass(TestGetLastFlushedSequenceId
.class);
58 private final HBaseTestingUtil testUtil
= new HBaseTestingUtil();
60 private final TableName tableName
= TableName
.valueOf(getClass().getSimpleName(), "test");
62 private final byte[] family
= Bytes
.toBytes("f1");
64 private final byte[][] families
= new byte[][] { family
};
67 public void setUp() throws Exception
{
68 testUtil
.getConfiguration().setInt("hbase.regionserver.msginterval", 1000);
69 testUtil
.startMiniCluster();
73 public void tearDown() throws Exception
{
74 testUtil
.shutdownMiniCluster();
78 public void test() throws IOException
, InterruptedException
{
79 testUtil
.getAdmin().createNamespace(
80 NamespaceDescriptor
.create(tableName
.getNamespaceAsString()).build());
81 Table table
= testUtil
.createTable(tableName
, families
);
82 table
.put(new Put(Bytes
.toBytes("k"))
83 .addColumn(family
, Bytes
.toBytes("q"), Bytes
.toBytes("v")));
84 SingleProcessHBaseCluster cluster
= testUtil
.getMiniHBaseCluster();
85 List
<JVMClusterUtil
.RegionServerThread
> rsts
= cluster
.getRegionServerThreads();
87 for (int i
= 0; i
< cluster
.getRegionServerThreads().size(); i
++) {
88 HRegionServer hrs
= rsts
.get(i
).getRegionServer();
89 for (Region r
: hrs
.getRegions(tableName
)) {
94 assertNotNull(region
);
96 RegionStoreSequenceIds ids
= testUtil
.getHBaseCluster().getMaster().getServerManager()
97 .getLastFlushedSequenceId(region
.getRegionInfo().getEncodedNameAsBytes());
98 assertEquals(HConstants
.NO_SEQNUM
, ids
.getLastFlushedSequenceId());
99 // This will be the sequenceid just before that of the earliest edit in memstore.
100 long storeSequenceId
= ids
.getStoreSequenceId(0).getSequenceId();
101 assertTrue(storeSequenceId
> 0);
102 testUtil
.getAdmin().flush(tableName
);
104 ids
= testUtil
.getHBaseCluster().getMaster().getServerManager()
105 .getLastFlushedSequenceId(region
.getRegionInfo().getEncodedNameAsBytes());
106 assertTrue(ids
.getLastFlushedSequenceId() + " > " + storeSequenceId
,
107 ids
.getLastFlushedSequenceId() > storeSequenceId
);
108 assertEquals(ids
.getLastFlushedSequenceId(), ids
.getStoreSequenceId(0).getSequenceId());