<reponame>sho25/hbase
begin_unit|revision:0.9.5;language:Java;cregit-version:0.0.1
begin_comment
comment|/**  * Licensed to the Apache Software Foundation (ASF) under one  * or more contributor license agreements.  See the NOTICE file  * distributed with this work for additional information  * regarding copyright ownership.  The ASF licenses this file  * to you under the Apache License, Version 2.0 (the  * "License"); you may not use this file except in compliance  * with the License.  You may obtain a copy of the License at  *  *     http://www.apache.org/licenses/LICENSE-2.0  *  * Unless required by applicable law or agreed to in writing, software  * distributed under the License is distributed on an "AS IS" BASIS,  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  * See the License for the specific language governing permissions and  * limitations under the License.  */
end_comment

begin_package
package|package
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|regionserver
package|;
end_package

begin_import
import|import static
name|org
operator|.
name|junit
operator|.
name|Assert
operator|.
name|assertEquals
import|;
end_import

begin_import
import|import static
name|org
operator|.
name|junit
operator|.
name|Assert
operator|.
name|assertTrue
import|;
end_import

begin_import
import|import
name|java
operator|.
name|io
operator|.
name|IOException
import|;
end_import

begin_import
import|import
name|java
operator|.
name|util
operator|.
name|ArrayList
import|;
end_import

begin_import
import|import
name|java
operator|.
name|util
operator|.
name|List
import|;
end_import

begin_import
import|import
name|java
operator|.
name|util
operator|.
name|Optional
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|conf
operator|.
name|Configuration
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|ArrayBackedTag
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|Cell
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|CellScanner
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|CellUtil
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|HBaseClassTestRule
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|HBaseTestingUtility
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|HConstants
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|KeyValue
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|KeyValueUtil
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|PrivateCellUtil
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|TableName
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|Tag
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|client
operator|.
name|Admin
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|client
operator|.
name|Append
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|client
operator|.
name|ColumnFamilyDescriptorBuilder
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|client
operator|.
name|CompactionState
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|client
operator|.
name|Durability
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|client
operator|.
name|Increment
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|client
operator|.
name|Mutation
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|client
operator|.
name|Put
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|client
operator|.
name|Result
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|client
operator|.
name|ResultScanner
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|client
operator|.
name|Scan
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|client
operator|.
name|Table
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|client
operator|.
name|TableDescriptorBuilder
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|coprocessor
operator|.
name|CoprocessorHost
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|coprocessor
operator|.
name|ObserverContext
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|coprocessor
operator|.
name|RegionCoprocessor
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|coprocessor
operator|.
name|RegionCoprocessorEnvironment
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|coprocessor
operator|.
name|RegionObserver
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|io
operator|.
name|encoding
operator|.
name|DataBlockEncoding
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|testclassification
operator|.
name|MediumTests
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|testclassification
operator|.
name|RegionServerTests
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|util
operator|.
name|Bytes
import|;
end_import

begin_import
import|import
name|org
operator|.
name|apache
operator|.
name|hadoop
operator|.
name|hbase
operator|.
name|wal
operator|.
name|WALEdit
import|;
end_import

begin_import
import|import
name|org
operator|.
name|junit
operator|.
name|After
import|;
end_import

begin_import
import|import
name|org
operator|.
name|junit
operator|.
name|AfterClass
import|;
end_import

begin_import
import|import
name|org
operator|.
name|junit
operator|.
name|BeforeClass
import|;
end_import

begin_import
import|import
name|org
operator|.
name|junit
operator|.
name|ClassRule
import|;
end_import

begin_import
import|import
name|org
operator|.
name|junit
operator|.
name|Rule
import|;
end_import

begin_import
import|import
name|org
operator|.
name|junit
operator|.
name|Test
import|;
end_import

begin_import
import|import
name|org
operator|.
name|junit
operator|.
name|experimental
operator|.
name|categories
operator|.
name|Category
import|;
end_import

begin_import
import|import
name|org
operator|.
name|junit
operator|.
name|rules
operator|.
name|TestName
import|;
end_import

begin_comment
comment|/**  * Class that test tags  */
end_comment

begin_class
annotation|@
name|Category
argument_list|(
block|{
name|RegionServerTests
operator|.
name|class
block|,
name|MediumTests
operator|.
name|class
block|}
argument_list|)
specifier|public
class|class
name|TestTags
block|{
annotation|@
name|ClassRule
specifier|public
specifier|static
specifier|final
name|HBaseClassTestRule
name|CLASS_RULE
init|=
name|HBaseClassTestRule
operator|.
name|forClass
argument_list|(
name|TestTags
operator|.
name|class
argument_list|)
decl_stmt|;
specifier|static
name|boolean
name|useFilter
init|=
literal|false
decl_stmt|;
specifier|private
specifier|final
specifier|static
name|HBaseTestingUtility
name|TEST_UTIL
init|=
operator|new
name|HBaseTestingUtility
argument_list|()
decl_stmt|;
annotation|@
name|Rule
specifier|public
specifier|final
name|TestName
name|TEST_NAME
init|=
operator|new
name|TestName
argument_list|()
decl_stmt|;
annotation|@
name|BeforeClass
specifier|public
specifier|static
name|void
name|setUpBeforeClass
parameter_list|()
throws|throws
name|Exception
block|{
name|Configuration
name|conf
init|=
name|TEST_UTIL
operator|.
name|getConfiguration
argument_list|()
decl_stmt|;
name|conf
operator|.
name|setInt
argument_list|(
literal|"hfile.format.version"
argument_list|,
literal|3
argument_list|)
expr_stmt|;
name|conf
operator|.
name|setStrings
argument_list|(
name|CoprocessorHost
operator|.
name|USER_REGION_COPROCESSOR_CONF_KEY
argument_list|,
name|TestCoprocessorForTags
operator|.
name|class
operator|.
name|getName
argument_list|()
argument_list|)
expr_stmt|;
name|TEST_UTIL
operator|.
name|startMiniCluster
argument_list|(
literal|2
argument_list|)
expr_stmt|;
block|}
annotation|@
name|AfterClass
specifier|public
specifier|static
name|void
name|tearDownAfterClass
parameter_list|()
throws|throws
name|Exception
block|{
name|TEST_UTIL
operator|.
name|shutdownMiniCluster
argument_list|()
expr_stmt|;
block|}
annotation|@
name|After
specifier|public
name|void
name|tearDown
parameter_list|()
block|{
name|useFilter
operator|=
literal|false
expr_stmt|;
block|}
annotation|@
name|Test
specifier|public
name|void
name|testTags
parameter_list|()
throws|throws
name|Exception
block|{
name|Table
name|table
init|=
literal|null
decl_stmt|;
try|try
block|{
name|TableName
name|tableName
init|=
name|TableName
operator|.
name|valueOf
argument_list|(
name|TEST_NAME
operator|.
name|getMethodName
argument_list|()
argument_list|)
decl_stmt|;
name|byte
index|[]
name|fam
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"info"
argument_list|)
decl_stmt|;
name|byte
index|[]
name|row
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"rowa"
argument_list|)
decl_stmt|;
comment|// column names
name|byte
index|[]
name|qual
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"qual"
argument_list|)
decl_stmt|;
name|byte
index|[]
name|row1
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"rowb"
argument_list|)
decl_stmt|;
name|byte
index|[]
name|row2
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"rowc"
argument_list|)
decl_stmt|;
name|TableDescriptorBuilder
operator|.
name|ModifyableTableDescriptor
name|tableDescriptor
init|=
operator|new
name|TableDescriptorBuilder
operator|.
name|ModifyableTableDescriptor
argument_list|(
name|tableName
argument_list|)
decl_stmt|;
name|ColumnFamilyDescriptorBuilder
operator|.
name|ModifyableColumnFamilyDescriptor
name|familyDescriptor
init|=
operator|new
name|ColumnFamilyDescriptorBuilder
operator|.
name|ModifyableColumnFamilyDescriptor
argument_list|(
name|fam
argument_list|)
decl_stmt|;
name|familyDescriptor
operator|.
name|setBlockCacheEnabled
argument_list|(
literal|true
argument_list|)
expr_stmt|;
name|familyDescriptor
operator|.
name|setDataBlockEncoding
argument_list|(
name|DataBlockEncoding
operator|.
name|NONE
argument_list|)
expr_stmt|;
name|tableDescriptor
operator|.
name|setColumnFamily
argument_list|(
name|familyDescriptor
argument_list|)
expr_stmt|;
name|Admin
name|admin
init|=
name|TEST_UTIL
operator|.
name|getAdmin
argument_list|()
decl_stmt|;
name|admin
operator|.
name|createTable
argument_list|(
name|tableDescriptor
argument_list|)
expr_stmt|;
name|byte
index|[]
name|value
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"value"
argument_list|)
decl_stmt|;
name|table
operator|=
name|TEST_UTIL
operator|.
name|getConnection
argument_list|()
operator|.
name|getTable
argument_list|(
name|tableName
argument_list|)
expr_stmt|;
name|Put
name|put
init|=
operator|new
name|Put
argument_list|(
name|row
argument_list|)
decl_stmt|;
name|put
operator|.
name|addColumn
argument_list|(
name|fam
argument_list|,
name|qual
argument_list|,
name|HConstants
operator|.
name|LATEST_TIMESTAMP
argument_list|,
name|value
argument_list|)
expr_stmt|;
name|put
operator|.
name|setAttribute
argument_list|(
literal|"visibility"
argument_list|,
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"myTag"
argument_list|)
argument_list|)
expr_stmt|;
name|table
operator|.
name|put
argument_list|(
name|put
argument_list|)
expr_stmt|;
name|admin
operator|.
name|flush
argument_list|(
name|tableName
argument_list|)
expr_stmt|;
comment|// We are lacking an API for confirming flush request compaction.
comment|// Just sleep for a short time. We won't be able to confirm flush
comment|// completion but the test won't hang now or in the future if
comment|// default compaction policy causes compaction between flush and
comment|// when we go to confirm it.
name|Thread
operator|.
name|sleep
argument_list|(
literal|1000
argument_list|)
expr_stmt|;
name|Put
name|put1
init|=
operator|new
name|Put
argument_list|(
name|row1
argument_list|)
decl_stmt|;
name|byte
index|[]
name|value1
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"1000dfsdf"
argument_list|)
decl_stmt|;
name|put1
operator|.
name|addColumn
argument_list|(
name|fam
argument_list|,
name|qual
argument_list|,
name|HConstants
operator|.
name|LATEST_TIMESTAMP
argument_list|,
name|value1
argument_list|)
expr_stmt|;
comment|// put1.setAttribute("visibility", Bytes.toBytes("myTag3"));
name|table
operator|.
name|put
argument_list|(
name|put1
argument_list|)
expr_stmt|;
name|admin
operator|.
name|flush
argument_list|(
name|tableName
argument_list|)
expr_stmt|;
name|Thread
operator|.
name|sleep
argument_list|(
literal|1000
argument_list|)
expr_stmt|;
name|Put
name|put2
init|=
operator|new
name|Put
argument_list|(
name|row2
argument_list|)
decl_stmt|;
name|byte
index|[]
name|value2
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"1000dfsdf"
argument_list|)
decl_stmt|;
name|put2
operator|.
name|addColumn
argument_list|(
name|fam
argument_list|,
name|qual
argument_list|,
name|HConstants
operator|.
name|LATEST_TIMESTAMP
argument_list|,
name|value2
argument_list|)
expr_stmt|;
name|put2
operator|.
name|setAttribute
argument_list|(
literal|"visibility"
argument_list|,
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"myTag3"
argument_list|)
argument_list|)
expr_stmt|;
name|table
operator|.
name|put
argument_list|(
name|put2
argument_list|)
expr_stmt|;
name|admin
operator|.
name|flush
argument_list|(
name|tableName
argument_list|)
expr_stmt|;
name|Thread
operator|.
name|sleep
argument_list|(
literal|1000
argument_list|)
expr_stmt|;
name|result
argument_list|(
name|fam
argument_list|,
name|row
argument_list|,
name|qual
argument_list|,
name|row2
argument_list|,
name|table
argument_list|,
name|value
argument_list|,
name|value2
argument_list|,
name|row1
argument_list|,
name|value1
argument_list|)
expr_stmt|;
name|admin
operator|.
name|compact
argument_list|(
name|tableName
argument_list|)
expr_stmt|;
while|while
condition|(
name|admin
operator|.
name|getCompactionState
argument_list|(
name|tableName
argument_list|)
operator|!=
name|CompactionState
operator|.
name|NONE
condition|)
block|{
name|Thread
operator|.
name|sleep
argument_list|(
literal|10
argument_list|)
expr_stmt|;
block|}
name|result
argument_list|(
name|fam
argument_list|,
name|row
argument_list|,
name|qual
argument_list|,
name|row2
argument_list|,
name|table
argument_list|,
name|value
argument_list|,
name|value2
argument_list|,
name|row1
argument_list|,
name|value1
argument_list|)
expr_stmt|;
block|}
finally|finally
block|{
if|if
condition|(
name|table
operator|!=
literal|null
condition|)
block|{
name|table
operator|.
name|close
argument_list|()
expr_stmt|;
block|}
block|}
block|}
annotation|@
name|Test
specifier|public
name|void
name|testFlushAndCompactionWithoutTags
parameter_list|()
throws|throws
name|Exception
block|{
name|Table
name|table
init|=
literal|null
decl_stmt|;
try|try
block|{
name|TableName
name|tableName
init|=
name|TableName
operator|.
name|valueOf
argument_list|(
name|TEST_NAME
operator|.
name|getMethodName
argument_list|()
argument_list|)
decl_stmt|;
name|byte
index|[]
name|fam
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"info"
argument_list|)
decl_stmt|;
name|byte
index|[]
name|row
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"rowa"
argument_list|)
decl_stmt|;
comment|// column names
name|byte
index|[]
name|qual
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"qual"
argument_list|)
decl_stmt|;
name|byte
index|[]
name|row1
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"rowb"
argument_list|)
decl_stmt|;
name|byte
index|[]
name|row2
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"rowc"
argument_list|)
decl_stmt|;
name|TableDescriptorBuilder
operator|.
name|ModifyableTableDescriptor
name|tableDescriptor
init|=
operator|new
name|TableDescriptorBuilder
operator|.
name|ModifyableTableDescriptor
argument_list|(
name|tableName
argument_list|)
decl_stmt|;
name|ColumnFamilyDescriptorBuilder
operator|.
name|ModifyableColumnFamilyDescriptor
name|familyDescriptor
init|=
operator|new
name|ColumnFamilyDescriptorBuilder
operator|.
name|ModifyableColumnFamilyDescriptor
argument_list|(
name|fam
argument_list|)
decl_stmt|;
name|familyDescriptor
operator|.
name|setBlockCacheEnabled
argument_list|(
literal|true
argument_list|)
expr_stmt|;
name|tableDescriptor
operator|.
name|setColumnFamily
argument_list|(
name|familyDescriptor
argument_list|)
expr_stmt|;
name|Admin
name|admin
init|=
name|TEST_UTIL
operator|.
name|getAdmin
argument_list|()
decl_stmt|;
name|admin
operator|.
name|createTable
argument_list|(
name|tableDescriptor
argument_list|)
expr_stmt|;
name|table
operator|=
name|TEST_UTIL
operator|.
name|getConnection
argument_list|()
operator|.
name|getTable
argument_list|(
name|tableName
argument_list|)
expr_stmt|;
name|Put
name|put
init|=
operator|new
name|Put
argument_list|(
name|row
argument_list|)
decl_stmt|;
name|byte
index|[]
name|value
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"value"
argument_list|)
decl_stmt|;
name|put
operator|.
name|addColumn
argument_list|(
name|fam
argument_list|,
name|qual
argument_list|,
name|HConstants
operator|.
name|LATEST_TIMESTAMP
argument_list|,
name|value
argument_list|)
expr_stmt|;
name|table
operator|.
name|put
argument_list|(
name|put
argument_list|)
expr_stmt|;
name|admin
operator|.
name|flush
argument_list|(
name|tableName
argument_list|)
expr_stmt|;
comment|// We are lacking an API for confirming flush request compaction.
comment|// Just sleep for a short time. We won't be able to confirm flush
comment|// completion but the test won't hang now or in the future if
comment|// default compaction policy causes compaction between flush and
comment|// when we go to confirm it.
name|Thread
operator|.
name|sleep
argument_list|(
literal|1000
argument_list|)
expr_stmt|;
name|Put
name|put1
init|=
operator|new
name|Put
argument_list|(
name|row1
argument_list|)
decl_stmt|;
name|byte
index|[]
name|value1
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"1000dfsdf"
argument_list|)
decl_stmt|;
name|put1
operator|.
name|addColumn
argument_list|(
name|fam
argument_list|,
name|qual
argument_list|,
name|HConstants
operator|.
name|LATEST_TIMESTAMP
argument_list|,
name|value1
argument_list|)
expr_stmt|;
name|table
operator|.
name|put
argument_list|(
name|put1
argument_list|)
expr_stmt|;
name|admin
operator|.
name|flush
argument_list|(
name|tableName
argument_list|)
expr_stmt|;
name|Thread
operator|.
name|sleep
argument_list|(
literal|1000
argument_list|)
expr_stmt|;
name|Put
name|put2
init|=
operator|new
name|Put
argument_list|(
name|row2
argument_list|)
decl_stmt|;
name|byte
index|[]
name|value2
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"1000dfsdf"
argument_list|)
decl_stmt|;
name|put2
operator|.
name|addColumn
argument_list|(
name|fam
argument_list|,
name|qual
argument_list|,
name|HConstants
operator|.
name|LATEST_TIMESTAMP
argument_list|,
name|value2
argument_list|)
expr_stmt|;
name|table
operator|.
name|put
argument_list|(
name|put2
argument_list|)
expr_stmt|;
name|admin
operator|.
name|flush
argument_list|(
name|tableName
argument_list|)
expr_stmt|;
name|Thread
operator|.
name|sleep
argument_list|(
literal|1000
argument_list|)
expr_stmt|;
name|Scan
name|s
init|=
operator|new
name|Scan
argument_list|(
name|row
argument_list|)
decl_stmt|;
name|ResultScanner
name|scanner
init|=
name|table
operator|.
name|getScanner
argument_list|(
name|s
argument_list|)
decl_stmt|;
try|try
block|{
name|Result
index|[]
name|next
init|=
name|scanner
operator|.
name|next
argument_list|(
literal|3
argument_list|)
decl_stmt|;
for|for
control|(
name|Result
name|result
range|:
name|next
control|)
block|{
name|CellScanner
name|cellScanner
init|=
name|result
operator|.
name|cellScanner
argument_list|()
decl_stmt|;
name|cellScanner
operator|.
name|advance
argument_list|()
expr_stmt|;
name|Cell
name|current
init|=
name|cellScanner
operator|.
name|current
argument_list|()
decl_stmt|;
name|assertEquals
argument_list|(
literal|0
argument_list|,
name|current
operator|.
name|getTagsLength
argument_list|()
argument_list|)
expr_stmt|;
block|}
block|}
finally|finally
block|{
if|if
condition|(
name|scanner
operator|!=
literal|null
condition|)
name|scanner
operator|.
name|close
argument_list|()
expr_stmt|;
block|}
name|admin
operator|.
name|compact
argument_list|(
name|tableName
argument_list|)
expr_stmt|;
while|while
condition|(
name|admin
operator|.
name|getCompactionState
argument_list|(
name|tableName
argument_list|)
operator|!=
name|CompactionState
operator|.
name|NONE
condition|)
block|{
name|Thread
operator|.
name|sleep
argument_list|(
literal|10
argument_list|)
expr_stmt|;
block|}
name|s
operator|=
operator|new
name|Scan
argument_list|(
name|row
argument_list|)
expr_stmt|;
name|scanner
operator|=
name|table
operator|.
name|getScanner
argument_list|(
name|s
argument_list|)
expr_stmt|;
try|try
block|{
name|Result
index|[]
name|next
init|=
name|scanner
operator|.
name|next
argument_list|(
literal|3
argument_list|)
decl_stmt|;
for|for
control|(
name|Result
name|result
range|:
name|next
control|)
block|{
name|CellScanner
name|cellScanner
init|=
name|result
operator|.
name|cellScanner
argument_list|()
decl_stmt|;
name|cellScanner
operator|.
name|advance
argument_list|()
expr_stmt|;
name|Cell
name|current
init|=
name|cellScanner
operator|.
name|current
argument_list|()
decl_stmt|;
name|assertEquals
argument_list|(
literal|0
argument_list|,
name|current
operator|.
name|getTagsLength
argument_list|()
argument_list|)
expr_stmt|;
block|}
block|}
finally|finally
block|{
if|if
condition|(
name|scanner
operator|!=
literal|null
condition|)
block|{
name|scanner
operator|.
name|close
argument_list|()
expr_stmt|;
block|}
block|}
block|}
finally|finally
block|{
if|if
condition|(
name|table
operator|!=
literal|null
condition|)
block|{
name|table
operator|.
name|close
argument_list|()
expr_stmt|;
block|}
block|}
block|}
annotation|@
name|Test
specifier|public
name|void
name|testFlushAndCompactionwithCombinations
parameter_list|()
throws|throws
name|Exception
block|{
name|TableName
name|tableName
init|=
name|TableName
operator|.
name|valueOf
argument_list|(
name|TEST_NAME
operator|.
name|getMethodName
argument_list|()
argument_list|)
decl_stmt|;
name|byte
index|[]
name|fam
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"info"
argument_list|)
decl_stmt|;
name|byte
index|[]
name|row
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"rowa"
argument_list|)
decl_stmt|;
comment|// column names
name|byte
index|[]
name|qual
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"qual"
argument_list|)
decl_stmt|;
name|byte
index|[]
name|row1
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"rowb"
argument_list|)
decl_stmt|;
name|byte
index|[]
name|row2
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"rowc"
argument_list|)
decl_stmt|;
name|byte
index|[]
name|rowd
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"rowd"
argument_list|)
decl_stmt|;
name|byte
index|[]
name|rowe
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"rowe"
argument_list|)
decl_stmt|;
name|Table
name|table
init|=
literal|null
decl_stmt|;
for|for
control|(
name|DataBlockEncoding
name|encoding
range|:
name|DataBlockEncoding
operator|.
name|values
argument_list|()
control|)
block|{
name|TableDescriptorBuilder
operator|.
name|ModifyableTableDescriptor
name|tableDescriptor
init|=
operator|new
name|TableDescriptorBuilder
operator|.
name|ModifyableTableDescriptor
argument_list|(
name|tableName
argument_list|)
decl_stmt|;
name|ColumnFamilyDescriptorBuilder
operator|.
name|ModifyableColumnFamilyDescriptor
name|familyDescriptor
init|=
operator|new
name|ColumnFamilyDescriptorBuilder
operator|.
name|ModifyableColumnFamilyDescriptor
argument_list|(
name|fam
argument_list|)
decl_stmt|;
name|familyDescriptor
operator|.
name|setBlockCacheEnabled
argument_list|(
literal|true
argument_list|)
expr_stmt|;
name|familyDescriptor
operator|.
name|setDataBlockEncoding
argument_list|(
name|encoding
argument_list|)
expr_stmt|;
name|tableDescriptor
operator|.
name|setColumnFamily
argument_list|(
name|familyDescriptor
argument_list|)
expr_stmt|;
name|Admin
name|admin
init|=
name|TEST_UTIL
operator|.
name|getAdmin
argument_list|()
decl_stmt|;
name|admin
operator|.
name|createTable
argument_list|(
name|tableDescriptor
argument_list|)
expr_stmt|;
try|try
block|{
name|table
operator|=
name|TEST_UTIL
operator|.
name|getConnection
argument_list|()
operator|.
name|getTable
argument_list|(
name|tableName
argument_list|)
expr_stmt|;
name|Put
name|put
init|=
operator|new
name|Put
argument_list|(
name|row
argument_list|)
decl_stmt|;
name|byte
index|[]
name|value
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"value"
argument_list|)
decl_stmt|;
name|put
operator|.
name|addColumn
argument_list|(
name|fam
argument_list|,
name|qual
argument_list|,
name|HConstants
operator|.
name|LATEST_TIMESTAMP
argument_list|,
name|value
argument_list|)
expr_stmt|;
name|int
name|bigTagLen
init|=
name|Short
operator|.
name|MAX_VALUE
operator|-
literal|5
decl_stmt|;
name|put
operator|.
name|setAttribute
argument_list|(
literal|"visibility"
argument_list|,
operator|new
name|byte
index|[
name|bigTagLen
index|]
argument_list|)
expr_stmt|;
name|table
operator|.
name|put
argument_list|(
name|put
argument_list|)
expr_stmt|;
name|Put
name|put1
init|=
operator|new
name|Put
argument_list|(
name|row1
argument_list|)
decl_stmt|;
name|byte
index|[]
name|value1
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"1000dfsdf"
argument_list|)
decl_stmt|;
name|put1
operator|.
name|addColumn
argument_list|(
name|fam
argument_list|,
name|qual
argument_list|,
name|HConstants
operator|.
name|LATEST_TIMESTAMP
argument_list|,
name|value1
argument_list|)
expr_stmt|;
name|table
operator|.
name|put
argument_list|(
name|put1
argument_list|)
expr_stmt|;
name|admin
operator|.
name|flush
argument_list|(
name|tableName
argument_list|)
expr_stmt|;
comment|// We are lacking an API for confirming flush request compaction.
comment|// Just sleep for a short time. We won't be able to confirm flush
comment|// completion but the test won't hang now or in the future if
comment|// default compaction policy causes compaction between flush and
comment|// when we go to confirm it.
name|Thread
operator|.
name|sleep
argument_list|(
literal|1000
argument_list|)
expr_stmt|;
name|put1
operator|=
operator|new
name|Put
argument_list|(
name|row2
argument_list|)
expr_stmt|;
name|value1
operator|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"1000dfsdf"
argument_list|)
expr_stmt|;
name|put1
operator|.
name|addColumn
argument_list|(
name|fam
argument_list|,
name|qual
argument_list|,
name|HConstants
operator|.
name|LATEST_TIMESTAMP
argument_list|,
name|value1
argument_list|)
expr_stmt|;
name|table
operator|.
name|put
argument_list|(
name|put1
argument_list|)
expr_stmt|;
name|admin
operator|.
name|flush
argument_list|(
name|tableName
argument_list|)
expr_stmt|;
name|Thread
operator|.
name|sleep
argument_list|(
literal|1000
argument_list|)
expr_stmt|;
name|Put
name|put2
init|=
operator|new
name|Put
argument_list|(
name|rowd
argument_list|)
decl_stmt|;
name|byte
index|[]
name|value2
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"1000dfsdf"
argument_list|)
decl_stmt|;
name|put2
operator|.
name|addColumn
argument_list|(
name|fam
argument_list|,
name|qual
argument_list|,
name|HConstants
operator|.
name|LATEST_TIMESTAMP
argument_list|,
name|value2
argument_list|)
expr_stmt|;
name|table
operator|.
name|put
argument_list|(
name|put2
argument_list|)
expr_stmt|;
name|put2
operator|=
operator|new
name|Put
argument_list|(
name|rowe
argument_list|)
expr_stmt|;
name|value2
operator|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"1000dfsddfdf"
argument_list|)
expr_stmt|;
name|put2
operator|.
name|addColumn
argument_list|(
name|fam
argument_list|,
name|qual
argument_list|,
name|HConstants
operator|.
name|LATEST_TIMESTAMP
argument_list|,
name|value2
argument_list|)
expr_stmt|;
name|put
operator|.
name|setAttribute
argument_list|(
literal|"visibility"
argument_list|,
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"ram"
argument_list|)
argument_list|)
expr_stmt|;
name|table
operator|.
name|put
argument_list|(
name|put2
argument_list|)
expr_stmt|;
name|admin
operator|.
name|flush
argument_list|(
name|tableName
argument_list|)
expr_stmt|;
name|Thread
operator|.
name|sleep
argument_list|(
literal|1000
argument_list|)
expr_stmt|;
name|TestCoprocessorForTags
operator|.
name|checkTagPresence
operator|=
literal|true
expr_stmt|;
name|Scan
name|s
init|=
operator|new
name|Scan
argument_list|(
name|row
argument_list|)
decl_stmt|;
name|s
operator|.
name|setCaching
argument_list|(
literal|1
argument_list|)
expr_stmt|;
name|ResultScanner
name|scanner
init|=
name|table
operator|.
name|getScanner
argument_list|(
name|s
argument_list|)
decl_stmt|;
try|try
block|{
name|Result
name|next
init|=
literal|null
decl_stmt|;
while|while
condition|(
operator|(
name|next
operator|=
name|scanner
operator|.
name|next
argument_list|()
operator|)
operator|!=
literal|null
condition|)
block|{
name|CellScanner
name|cellScanner
init|=
name|next
operator|.
name|cellScanner
argument_list|()
decl_stmt|;
name|cellScanner
operator|.
name|advance
argument_list|()
expr_stmt|;
name|Cell
name|current
init|=
name|cellScanner
operator|.
name|current
argument_list|()
decl_stmt|;
if|if
condition|(
name|CellUtil
operator|.
name|matchingRows
argument_list|(
name|current
argument_list|,
name|row
argument_list|)
condition|)
block|{
name|assertEquals
argument_list|(
literal|1
argument_list|,
name|TestCoprocessorForTags
operator|.
name|tags
operator|.
name|size
argument_list|()
argument_list|)
expr_stmt|;
name|Tag
name|tag
init|=
name|TestCoprocessorForTags
operator|.
name|tags
operator|.
name|get
argument_list|(
literal|0
argument_list|)
decl_stmt|;
name|assertEquals
argument_list|(
name|bigTagLen
argument_list|,
name|tag
operator|.
name|getValueLength
argument_list|()
argument_list|)
expr_stmt|;
block|}
else|else
block|{
name|assertEquals
argument_list|(
literal|0
argument_list|,
name|TestCoprocessorForTags
operator|.
name|tags
operator|.
name|size
argument_list|()
argument_list|)
expr_stmt|;
block|}
block|}
block|}
finally|finally
block|{
if|if
condition|(
name|scanner
operator|!=
literal|null
condition|)
block|{
name|scanner
operator|.
name|close
argument_list|()
expr_stmt|;
block|}
name|TestCoprocessorForTags
operator|.
name|checkTagPresence
operator|=
literal|false
expr_stmt|;
block|}
while|while
condition|(
name|admin
operator|.
name|getCompactionState
argument_list|(
name|tableName
argument_list|)
operator|!=
name|CompactionState
operator|.
name|NONE
condition|)
block|{
name|Thread
operator|.
name|sleep
argument_list|(
literal|10
argument_list|)
expr_stmt|;
block|}
name|TestCoprocessorForTags
operator|.
name|checkTagPresence
operator|=
literal|true
expr_stmt|;
name|scanner
operator|=
name|table
operator|.
name|getScanner
argument_list|(
name|s
argument_list|)
expr_stmt|;
try|try
block|{
name|Result
name|next
init|=
literal|null
decl_stmt|;
while|while
condition|(
operator|(
name|next
operator|=
name|scanner
operator|.
name|next
argument_list|()
operator|)
operator|!=
literal|null
condition|)
block|{
name|CellScanner
name|cellScanner
init|=
name|next
operator|.
name|cellScanner
argument_list|()
decl_stmt|;
name|cellScanner
operator|.
name|advance
argument_list|()
expr_stmt|;
name|Cell
name|current
init|=
name|cellScanner
operator|.
name|current
argument_list|()
decl_stmt|;
if|if
condition|(
name|CellUtil
operator|.
name|matchingRows
argument_list|(
name|current
argument_list|,
name|row
argument_list|)
condition|)
block|{
name|assertEquals
argument_list|(
literal|1
argument_list|,
name|TestCoprocessorForTags
operator|.
name|tags
operator|.
name|size
argument_list|()
argument_list|)
expr_stmt|;
name|Tag
name|tag
init|=
name|TestCoprocessorForTags
operator|.
name|tags
operator|.
name|get
argument_list|(
literal|0
argument_list|)
decl_stmt|;
name|assertEquals
argument_list|(
name|bigTagLen
argument_list|,
name|tag
operator|.
name|getValueLength
argument_list|()
argument_list|)
expr_stmt|;
block|}
else|else
block|{
name|assertEquals
argument_list|(
literal|0
argument_list|,
name|TestCoprocessorForTags
operator|.
name|tags
operator|.
name|size
argument_list|()
argument_list|)
expr_stmt|;
block|}
block|}
block|}
finally|finally
block|{
if|if
condition|(
name|scanner
operator|!=
literal|null
condition|)
block|{
name|scanner
operator|.
name|close
argument_list|()
expr_stmt|;
block|}
name|TestCoprocessorForTags
operator|.
name|checkTagPresence
operator|=
literal|false
expr_stmt|;
block|}
block|}
finally|finally
block|{
if|if
condition|(
name|table
operator|!=
literal|null
condition|)
block|{
name|table
operator|.
name|close
argument_list|()
expr_stmt|;
block|}
comment|// delete the table
name|admin
operator|.
name|disableTable
argument_list|(
name|tableName
argument_list|)
expr_stmt|;
name|admin
operator|.
name|deleteTable
argument_list|(
name|tableName
argument_list|)
expr_stmt|;
block|}
block|}
block|}
annotation|@
name|Test
specifier|public
name|void
name|testTagsWithAppendAndIncrement
parameter_list|()
throws|throws
name|Exception
block|{
name|TableName
name|tableName
init|=
name|TableName
operator|.
name|valueOf
argument_list|(
name|TEST_NAME
operator|.
name|getMethodName
argument_list|()
argument_list|)
decl_stmt|;
name|byte
index|[]
name|f
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"f"
argument_list|)
decl_stmt|;
name|byte
index|[]
name|q
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"q"
argument_list|)
decl_stmt|;
name|byte
index|[]
name|row1
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"r1"
argument_list|)
decl_stmt|;
name|byte
index|[]
name|row2
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"r2"
argument_list|)
decl_stmt|;
name|TableDescriptorBuilder
operator|.
name|ModifyableTableDescriptor
name|tableDescriptor
init|=
operator|new
name|TableDescriptorBuilder
operator|.
name|ModifyableTableDescriptor
argument_list|(
name|tableName
argument_list|)
decl_stmt|;
name|ColumnFamilyDescriptorBuilder
operator|.
name|ModifyableColumnFamilyDescriptor
name|colDesc
init|=
operator|new
name|ColumnFamilyDescriptorBuilder
operator|.
name|ModifyableColumnFamilyDescriptor
argument_list|(
name|f
argument_list|)
decl_stmt|;
name|tableDescriptor
operator|.
name|setColumnFamily
argument_list|(
name|colDesc
argument_list|)
expr_stmt|;
name|TEST_UTIL
operator|.
name|getAdmin
argument_list|()
operator|.
name|createTable
argument_list|(
name|tableDescriptor
argument_list|)
expr_stmt|;
name|Table
name|table
init|=
literal|null
decl_stmt|;
try|try
block|{
name|table
operator|=
name|TEST_UTIL
operator|.
name|getConnection
argument_list|()
operator|.
name|getTable
argument_list|(
name|tableName
argument_list|)
expr_stmt|;
name|Put
name|put
init|=
operator|new
name|Put
argument_list|(
name|row1
argument_list|)
decl_stmt|;
name|byte
index|[]
name|v
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|2L
argument_list|)
decl_stmt|;
name|put
operator|.
name|addColumn
argument_list|(
name|f
argument_list|,
name|q
argument_list|,
name|v
argument_list|)
expr_stmt|;
name|put
operator|.
name|setAttribute
argument_list|(
literal|"visibility"
argument_list|,
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"tag1"
argument_list|)
argument_list|)
expr_stmt|;
name|table
operator|.
name|put
argument_list|(
name|put
argument_list|)
expr_stmt|;
name|Increment
name|increment
init|=
operator|new
name|Increment
argument_list|(
name|row1
argument_list|)
decl_stmt|;
name|increment
operator|.
name|addColumn
argument_list|(
name|f
argument_list|,
name|q
argument_list|,
literal|1L
argument_list|)
expr_stmt|;
name|table
operator|.
name|increment
argument_list|(
name|increment
argument_list|)
expr_stmt|;
name|TestCoprocessorForTags
operator|.
name|checkTagPresence
operator|=
literal|true
expr_stmt|;
name|ResultScanner
name|scanner
init|=
name|table
operator|.
name|getScanner
argument_list|(
operator|new
name|Scan
argument_list|()
argument_list|)
decl_stmt|;
name|Result
name|result
init|=
name|scanner
operator|.
name|next
argument_list|()
decl_stmt|;
name|KeyValue
name|kv
init|=
name|KeyValueUtil
operator|.
name|ensureKeyValue
argument_list|(
name|result
operator|.
name|getColumnLatestCell
argument_list|(
name|f
argument_list|,
name|q
argument_list|)
argument_list|)
decl_stmt|;
name|List
argument_list|<
name|Tag
argument_list|>
name|tags
init|=
name|TestCoprocessorForTags
operator|.
name|tags
decl_stmt|;
name|assertEquals
argument_list|(
literal|3L
argument_list|,
name|Bytes
operator|.
name|toLong
argument_list|(
name|kv
operator|.
name|getValueArray
argument_list|()
argument_list|,
name|kv
operator|.
name|getValueOffset
argument_list|()
argument_list|,
name|kv
operator|.
name|getValueLength
argument_list|()
argument_list|)
argument_list|)
expr_stmt|;
name|assertEquals
argument_list|(
literal|1
argument_list|,
name|tags
operator|.
name|size
argument_list|()
argument_list|)
expr_stmt|;
name|assertEquals
argument_list|(
literal|"tag1"
argument_list|,
name|Bytes
operator|.
name|toString
argument_list|(
name|Tag
operator|.
name|cloneValue
argument_list|(
name|tags
operator|.
name|get
argument_list|(
literal|0
argument_list|)
argument_list|)
argument_list|)
argument_list|)
expr_stmt|;
name|TestCoprocessorForTags
operator|.
name|checkTagPresence
operator|=
literal|false
expr_stmt|;
name|TestCoprocessorForTags
operator|.
name|tags
operator|=
literal|null
expr_stmt|;
name|increment
operator|=
operator|new
name|Increment
argument_list|(
name|row1
argument_list|)
expr_stmt|;
name|increment
operator|.
name|add
argument_list|(
operator|new
name|KeyValue
argument_list|(
name|row1
argument_list|,
name|f
argument_list|,
name|q
argument_list|,
literal|1234L
argument_list|,
name|v
argument_list|)
argument_list|)
expr_stmt|;
name|increment
operator|.
name|setAttribute
argument_list|(
literal|"visibility"
argument_list|,
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"tag2"
argument_list|)
argument_list|)
expr_stmt|;
name|table
operator|.
name|increment
argument_list|(
name|increment
argument_list|)
expr_stmt|;
name|TestCoprocessorForTags
operator|.
name|checkTagPresence
operator|=
literal|true
expr_stmt|;
name|scanner
operator|=
name|table
operator|.
name|getScanner
argument_list|(
operator|new
name|Scan
argument_list|()
argument_list|)
expr_stmt|;
name|result
operator|=
name|scanner
operator|.
name|next
argument_list|()
expr_stmt|;
name|kv
operator|=
name|KeyValueUtil
operator|.
name|ensureKeyValue
argument_list|(
name|result
operator|.
name|getColumnLatestCell
argument_list|(
name|f
argument_list|,
name|q
argument_list|)
argument_list|)
expr_stmt|;
name|tags
operator|=
name|TestCoprocessorForTags
operator|.
name|tags
expr_stmt|;
name|assertEquals
argument_list|(
literal|5L
argument_list|,
name|Bytes
operator|.
name|toLong
argument_list|(
name|kv
operator|.
name|getValueArray
argument_list|()
argument_list|,
name|kv
operator|.
name|getValueOffset
argument_list|()
argument_list|,
name|kv
operator|.
name|getValueLength
argument_list|()
argument_list|)
argument_list|)
expr_stmt|;
name|assertEquals
argument_list|(
literal|2
argument_list|,
name|tags
operator|.
name|size
argument_list|()
argument_list|)
expr_stmt|;
comment|// We cannot assume the ordering of tags
name|List
argument_list|<
name|String
argument_list|>
name|tagValues
init|=
operator|new
name|ArrayList
argument_list|<>
argument_list|()
decl_stmt|;
for|for
control|(
name|Tag
name|tag
range|:
name|tags
control|)
block|{
name|tagValues
operator|.
name|add
argument_list|(
name|Bytes
operator|.
name|toString
argument_list|(
name|Tag
operator|.
name|cloneValue
argument_list|(
name|tag
argument_list|)
argument_list|)
argument_list|)
expr_stmt|;
block|}
name|assertTrue
argument_list|(
name|tagValues
operator|.
name|contains
argument_list|(
literal|"tag1"
argument_list|)
argument_list|)
expr_stmt|;
name|assertTrue
argument_list|(
name|tagValues
operator|.
name|contains
argument_list|(
literal|"tag2"
argument_list|)
argument_list|)
expr_stmt|;
name|TestCoprocessorForTags
operator|.
name|checkTagPresence
operator|=
literal|false
expr_stmt|;
name|TestCoprocessorForTags
operator|.
name|tags
operator|=
literal|null
expr_stmt|;
name|put
operator|=
operator|new
name|Put
argument_list|(
name|row2
argument_list|)
expr_stmt|;
name|v
operator|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|2L
argument_list|)
expr_stmt|;
name|put
operator|.
name|addColumn
argument_list|(
name|f
argument_list|,
name|q
argument_list|,
name|v
argument_list|)
expr_stmt|;
name|table
operator|.
name|put
argument_list|(
name|put
argument_list|)
expr_stmt|;
name|increment
operator|=
operator|new
name|Increment
argument_list|(
name|row2
argument_list|)
expr_stmt|;
name|increment
operator|.
name|add
argument_list|(
operator|new
name|KeyValue
argument_list|(
name|row2
argument_list|,
name|f
argument_list|,
name|q
argument_list|,
literal|1234L
argument_list|,
name|v
argument_list|)
argument_list|)
expr_stmt|;
name|increment
operator|.
name|setAttribute
argument_list|(
literal|"visibility"
argument_list|,
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"tag2"
argument_list|)
argument_list|)
expr_stmt|;
name|table
operator|.
name|increment
argument_list|(
name|increment
argument_list|)
expr_stmt|;
name|TestCoprocessorForTags
operator|.
name|checkTagPresence
operator|=
literal|true
expr_stmt|;
name|scanner
operator|=
name|table
operator|.
name|getScanner
argument_list|(
operator|new
name|Scan
argument_list|()
operator|.
name|withStartRow
argument_list|(
name|row2
argument_list|)
argument_list|)
expr_stmt|;
name|result
operator|=
name|scanner
operator|.
name|next
argument_list|()
expr_stmt|;
name|kv
operator|=
name|KeyValueUtil
operator|.
name|ensureKeyValue
argument_list|(
name|result
operator|.
name|getColumnLatestCell
argument_list|(
name|f
argument_list|,
name|q
argument_list|)
argument_list|)
expr_stmt|;
name|tags
operator|=
name|TestCoprocessorForTags
operator|.
name|tags
expr_stmt|;
name|assertEquals
argument_list|(
literal|4L
argument_list|,
name|Bytes
operator|.
name|toLong
argument_list|(
name|kv
operator|.
name|getValueArray
argument_list|()
argument_list|,
name|kv
operator|.
name|getValueOffset
argument_list|()
argument_list|,
name|kv
operator|.
name|getValueLength
argument_list|()
argument_list|)
argument_list|)
expr_stmt|;
name|assertEquals
argument_list|(
literal|1
argument_list|,
name|tags
operator|.
name|size
argument_list|()
argument_list|)
expr_stmt|;
name|assertEquals
argument_list|(
literal|"tag2"
argument_list|,
name|Bytes
operator|.
name|toString
argument_list|(
name|Tag
operator|.
name|cloneValue
argument_list|(
name|tags
operator|.
name|get
argument_list|(
literal|0
argument_list|)
argument_list|)
argument_list|)
argument_list|)
expr_stmt|;
name|TestCoprocessorForTags
operator|.
name|checkTagPresence
operator|=
literal|false
expr_stmt|;
name|TestCoprocessorForTags
operator|.
name|tags
operator|=
literal|null
expr_stmt|;
comment|// Test Append
name|byte
index|[]
name|row3
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"r3"
argument_list|)
decl_stmt|;
name|put
operator|=
operator|new
name|Put
argument_list|(
name|row3
argument_list|)
expr_stmt|;
name|put
operator|.
name|addColumn
argument_list|(
name|f
argument_list|,
name|q
argument_list|,
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"a"
argument_list|)
argument_list|)
expr_stmt|;
name|put
operator|.
name|setAttribute
argument_list|(
literal|"visibility"
argument_list|,
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"tag1"
argument_list|)
argument_list|)
expr_stmt|;
name|table
operator|.
name|put
argument_list|(
name|put
argument_list|)
expr_stmt|;
name|Append
name|append
init|=
operator|new
name|Append
argument_list|(
name|row3
argument_list|)
decl_stmt|;
name|append
operator|.
name|addColumn
argument_list|(
name|f
argument_list|,
name|q
argument_list|,
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"b"
argument_list|)
argument_list|)
expr_stmt|;
name|table
operator|.
name|append
argument_list|(
name|append
argument_list|)
expr_stmt|;
name|TestCoprocessorForTags
operator|.
name|checkTagPresence
operator|=
literal|true
expr_stmt|;
name|scanner
operator|=
name|table
operator|.
name|getScanner
argument_list|(
operator|new
name|Scan
argument_list|()
operator|.
name|withStartRow
argument_list|(
name|row3
argument_list|)
argument_list|)
expr_stmt|;
name|result
operator|=
name|scanner
operator|.
name|next
argument_list|()
expr_stmt|;
name|kv
operator|=
name|KeyValueUtil
operator|.
name|ensureKeyValue
argument_list|(
name|result
operator|.
name|getColumnLatestCell
argument_list|(
name|f
argument_list|,
name|q
argument_list|)
argument_list|)
expr_stmt|;
name|tags
operator|=
name|TestCoprocessorForTags
operator|.
name|tags
expr_stmt|;
name|assertEquals
argument_list|(
literal|1
argument_list|,
name|tags
operator|.
name|size
argument_list|()
argument_list|)
expr_stmt|;
name|assertEquals
argument_list|(
literal|"tag1"
argument_list|,
name|Bytes
operator|.
name|toString
argument_list|(
name|Tag
operator|.
name|cloneValue
argument_list|(
name|tags
operator|.
name|get
argument_list|(
literal|0
argument_list|)
argument_list|)
argument_list|)
argument_list|)
expr_stmt|;
name|TestCoprocessorForTags
operator|.
name|checkTagPresence
operator|=
literal|false
expr_stmt|;
name|TestCoprocessorForTags
operator|.
name|tags
operator|=
literal|null
expr_stmt|;
name|append
operator|=
operator|new
name|Append
argument_list|(
name|row3
argument_list|)
expr_stmt|;
name|append
operator|.
name|add
argument_list|(
operator|new
name|KeyValue
argument_list|(
name|row3
argument_list|,
name|f
argument_list|,
name|q
argument_list|,
literal|1234L
argument_list|,
name|v
argument_list|)
argument_list|)
expr_stmt|;
name|append
operator|.
name|setAttribute
argument_list|(
literal|"visibility"
argument_list|,
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"tag2"
argument_list|)
argument_list|)
expr_stmt|;
name|table
operator|.
name|append
argument_list|(
name|append
argument_list|)
expr_stmt|;
name|TestCoprocessorForTags
operator|.
name|checkTagPresence
operator|=
literal|true
expr_stmt|;
name|scanner
operator|=
name|table
operator|.
name|getScanner
argument_list|(
operator|new
name|Scan
argument_list|()
operator|.
name|withStartRow
argument_list|(
name|row3
argument_list|)
argument_list|)
expr_stmt|;
name|result
operator|=
name|scanner
operator|.
name|next
argument_list|()
expr_stmt|;
name|kv
operator|=
name|KeyValueUtil
operator|.
name|ensureKeyValue
argument_list|(
name|result
operator|.
name|getColumnLatestCell
argument_list|(
name|f
argument_list|,
name|q
argument_list|)
argument_list|)
expr_stmt|;
name|tags
operator|=
name|TestCoprocessorForTags
operator|.
name|tags
expr_stmt|;
name|assertEquals
argument_list|(
literal|2
argument_list|,
name|tags
operator|.
name|size
argument_list|()
argument_list|)
expr_stmt|;
comment|// We cannot assume the ordering of tags
name|tagValues
operator|.
name|clear
argument_list|()
expr_stmt|;
for|for
control|(
name|Tag
name|tag
range|:
name|tags
control|)
block|{
name|tagValues
operator|.
name|add
argument_list|(
name|Bytes
operator|.
name|toString
argument_list|(
name|Tag
operator|.
name|cloneValue
argument_list|(
name|tag
argument_list|)
argument_list|)
argument_list|)
expr_stmt|;
block|}
name|assertTrue
argument_list|(
name|tagValues
operator|.
name|contains
argument_list|(
literal|"tag1"
argument_list|)
argument_list|)
expr_stmt|;
name|assertTrue
argument_list|(
name|tagValues
operator|.
name|contains
argument_list|(
literal|"tag2"
argument_list|)
argument_list|)
expr_stmt|;
name|TestCoprocessorForTags
operator|.
name|checkTagPresence
operator|=
literal|false
expr_stmt|;
name|TestCoprocessorForTags
operator|.
name|tags
operator|=
literal|null
expr_stmt|;
name|byte
index|[]
name|row4
init|=
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"r4"
argument_list|)
decl_stmt|;
name|put
operator|=
operator|new
name|Put
argument_list|(
name|row4
argument_list|)
expr_stmt|;
name|put
operator|.
name|addColumn
argument_list|(
name|f
argument_list|,
name|q
argument_list|,
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"a"
argument_list|)
argument_list|)
expr_stmt|;
name|table
operator|.
name|put
argument_list|(
name|put
argument_list|)
expr_stmt|;
name|append
operator|=
operator|new
name|Append
argument_list|(
name|row4
argument_list|)
expr_stmt|;
name|append
operator|.
name|add
argument_list|(
operator|new
name|KeyValue
argument_list|(
name|row4
argument_list|,
name|f
argument_list|,
name|q
argument_list|,
literal|1234L
argument_list|,
name|v
argument_list|)
argument_list|)
expr_stmt|;
name|append
operator|.
name|setAttribute
argument_list|(
literal|"visibility"
argument_list|,
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"tag2"
argument_list|)
argument_list|)
expr_stmt|;
name|table
operator|.
name|append
argument_list|(
name|append
argument_list|)
expr_stmt|;
name|TestCoprocessorForTags
operator|.
name|checkTagPresence
operator|=
literal|true
expr_stmt|;
name|scanner
operator|=
name|table
operator|.
name|getScanner
argument_list|(
operator|new
name|Scan
argument_list|()
operator|.
name|withStartRow
argument_list|(
name|row4
argument_list|)
argument_list|)
expr_stmt|;
name|result
operator|=
name|scanner
operator|.
name|next
argument_list|()
expr_stmt|;
name|kv
operator|=
name|KeyValueUtil
operator|.
name|ensureKeyValue
argument_list|(
name|result
operator|.
name|getColumnLatestCell
argument_list|(
name|f
argument_list|,
name|q
argument_list|)
argument_list|)
expr_stmt|;
name|tags
operator|=
name|TestCoprocessorForTags
operator|.
name|tags
expr_stmt|;
name|assertEquals
argument_list|(
literal|1
argument_list|,
name|tags
operator|.
name|size
argument_list|()
argument_list|)
expr_stmt|;
name|assertEquals
argument_list|(
literal|"tag2"
argument_list|,
name|Bytes
operator|.
name|toString
argument_list|(
name|Tag
operator|.
name|cloneValue
argument_list|(
name|tags
operator|.
name|get
argument_list|(
literal|0
argument_list|)
argument_list|)
argument_list|)
argument_list|)
expr_stmt|;
block|}
finally|finally
block|{
name|TestCoprocessorForTags
operator|.
name|checkTagPresence
operator|=
literal|false
expr_stmt|;
name|TestCoprocessorForTags
operator|.
name|tags
operator|=
literal|null
expr_stmt|;
if|if
condition|(
name|table
operator|!=
literal|null
condition|)
block|{
name|table
operator|.
name|close
argument_list|()
expr_stmt|;
block|}
block|}
block|}
specifier|private
name|void
name|result
parameter_list|(
name|byte
index|[]
name|fam
parameter_list|,
name|byte
index|[]
name|row
parameter_list|,
name|byte
index|[]
name|qual
parameter_list|,
name|byte
index|[]
name|row2
parameter_list|,
name|Table
name|table
parameter_list|,
name|byte
index|[]
name|value
parameter_list|,
name|byte
index|[]
name|value2
parameter_list|,
name|byte
index|[]
name|row1
parameter_list|,
name|byte
index|[]
name|value1
parameter_list|)
throws|throws
name|IOException
block|{
name|Scan
name|s
init|=
operator|new
name|Scan
argument_list|(
name|row
argument_list|)
decl_stmt|;
comment|// If filters are used this attribute can be specifically check for in
comment|// filterKV method and
comment|// kvs can be filtered out if the tags of interest is not found in that kv
name|s
operator|.
name|setAttribute
argument_list|(
literal|"visibility"
argument_list|,
name|Bytes
operator|.
name|toBytes
argument_list|(
literal|"myTag"
argument_list|)
argument_list|)
expr_stmt|;
name|ResultScanner
name|scanner
init|=
literal|null
decl_stmt|;
try|try
block|{
name|scanner
operator|=
name|table
operator|.
name|getScanner
argument_list|(
name|s
argument_list|)
expr_stmt|;
name|Result
name|next
init|=
name|scanner
operator|.
name|next
argument_list|()
decl_stmt|;
name|assertTrue
argument_list|(
name|Bytes
operator|.
name|equals
argument_list|(
name|next
operator|.
name|getRow
argument_list|()
argument_list|,
name|row
argument_list|)
argument_list|)
expr_stmt|;
name|assertTrue
argument_list|(
name|Bytes
operator|.
name|equals
argument_list|(
name|next
operator|.
name|getValue
argument_list|(
name|fam
argument_list|,
name|qual
argument_list|)
argument_list|,
name|value
argument_list|)
argument_list|)
expr_stmt|;
name|Result
name|next2
init|=
name|scanner
operator|.
name|next
argument_list|()
decl_stmt|;
name|assertTrue
argument_list|(
name|next2
operator|!=
literal|null
argument_list|)
expr_stmt|;
name|assertTrue
argument_list|(
name|Bytes
operator|.
name|equals
argument_list|(
name|next2
operator|.
name|getRow
argument_list|()
argument_list|,
name|row1
argument_list|)
argument_list|)
expr_stmt|;
name|assertTrue
argument_list|(
name|Bytes
operator|.
name|equals
argument_list|(
name|next2
operator|.
name|getValue
argument_list|(
name|fam
argument_list|,
name|qual
argument_list|)
argument_list|,
name|value1
argument_list|)
argument_list|)
expr_stmt|;
name|next2
operator|=
name|scanner
operator|.
name|next
argument_list|()
expr_stmt|;
name|assertTrue
argument_list|(
name|next2
operator|!=
literal|null
argument_list|)
expr_stmt|;
name|assertTrue
argument_list|(
name|Bytes
operator|.
name|equals
argument_list|(
name|next2
operator|.
name|getRow
argument_list|()
argument_list|,
name|row2
argument_list|)
argument_list|)
expr_stmt|;
name|assertTrue
argument_list|(
name|Bytes
operator|.
name|equals
argument_list|(
name|next2
operator|.
name|getValue
argument_list|(
name|fam
argument_list|,
name|qual
argument_list|)
argument_list|,
name|value2
argument_list|)
argument_list|)
expr_stmt|;
block|}
finally|finally
block|{
if|if
condition|(
name|scanner
operator|!=
literal|null
condition|)
name|scanner
operator|.
name|close
argument_list|()
expr_stmt|;
block|}
block|}
specifier|public
specifier|static
class|class
name|TestCoprocessorForTags
implements|implements
name|RegionCoprocessor
implements|,
name|RegionObserver
block|{
specifier|public
specifier|static
specifier|volatile
name|boolean
name|checkTagPresence
init|=
literal|false
decl_stmt|;
specifier|public
specifier|static
name|List
argument_list|<
name|Tag
argument_list|>
name|tags
init|=
literal|null
decl_stmt|;
annotation|@
name|Override
specifier|public
name|Optional
argument_list|<
name|RegionObserver
argument_list|>
name|getRegionObserver
parameter_list|()
block|{
return|return
name|Optional
operator|.
name|of
argument_list|(
name|this
argument_list|)
return|;
block|}
annotation|@
name|Override
specifier|public
name|void
name|prePut
parameter_list|(
specifier|final
name|ObserverContext
argument_list|<
name|RegionCoprocessorEnvironment
argument_list|>
name|e
parameter_list|,
specifier|final
name|Put
name|put
parameter_list|,
specifier|final
name|WALEdit
name|edit
parameter_list|,
specifier|final
name|Durability
name|durability
parameter_list|)
throws|throws
name|IOException
block|{
name|updateMutationAddingTags
argument_list|(
name|put
argument_list|)
expr_stmt|;
block|}
specifier|private
name|void
name|updateMutationAddingTags
parameter_list|(
specifier|final
name|Mutation
name|m
parameter_list|)
block|{
name|byte
index|[]
name|attribute
init|=
name|m
operator|.
name|getAttribute
argument_list|(
literal|"visibility"
argument_list|)
decl_stmt|;
name|byte
index|[]
name|cf
init|=
literal|null
decl_stmt|;
name|List
argument_list|<
name|Cell
argument_list|>
name|updatedCells
init|=
operator|new
name|ArrayList
argument_list|<>
argument_list|()
decl_stmt|;
if|if
condition|(
name|attribute
operator|!=
literal|null
condition|)
block|{
for|for
control|(
name|List
argument_list|<
name|?
extends|extends
name|Cell
argument_list|>
name|edits
range|:
name|m
operator|.
name|getFamilyCellMap
argument_list|()
operator|.
name|values
argument_list|()
control|)
block|{
for|for
control|(
name|Cell
name|cell
range|:
name|edits
control|)
block|{
name|KeyValue
name|kv
init|=
name|KeyValueUtil
operator|.
name|ensureKeyValue
argument_list|(
name|cell
argument_list|)
decl_stmt|;
if|if
condition|(
name|cf
operator|==
literal|null
condition|)
block|{
name|cf
operator|=
name|CellUtil
operator|.
name|cloneFamily
argument_list|(
name|kv
argument_list|)
expr_stmt|;
block|}
name|Tag
name|tag
init|=
operator|new
name|ArrayBackedTag
argument_list|(
operator|(
name|byte
operator|)
literal|1
argument_list|,
name|attribute
argument_list|)
decl_stmt|;
name|List
argument_list|<
name|Tag
argument_list|>
name|tagList
init|=
operator|new
name|ArrayList
argument_list|<>
argument_list|()
decl_stmt|;
name|tagList
operator|.
name|add
argument_list|(
name|tag
argument_list|)
expr_stmt|;
name|KeyValue
name|newKV
init|=
operator|new
name|KeyValue
argument_list|(
name|CellUtil
operator|.
name|cloneRow
argument_list|(
name|kv
argument_list|)
argument_list|,
literal|0
argument_list|,
name|kv
operator|.
name|getRowLength
argument_list|()
argument_list|,
name|CellUtil
operator|.
name|cloneFamily
argument_list|(
name|kv
argument_list|)
argument_list|,
literal|0
argument_list|,
name|kv
operator|.
name|getFamilyLength
argument_list|()
argument_list|,
name|CellUtil
operator|.
name|cloneQualifier
argument_list|(
name|kv
argument_list|)
argument_list|,
literal|0
argument_list|,
name|kv
operator|.
name|getQualifierLength
argument_list|()
argument_list|,
name|kv
operator|.
name|getTimestamp
argument_list|()
argument_list|,
name|KeyValue
operator|.
name|Type
operator|.
name|codeToType
argument_list|(
name|kv
operator|.
name|getTypeByte
argument_list|()
argument_list|)
argument_list|,
name|CellUtil
operator|.
name|cloneValue
argument_list|(
name|kv
argument_list|)
argument_list|,
literal|0
argument_list|,
name|kv
operator|.
name|getValueLength
argument_list|()
argument_list|,
name|tagList
argument_list|)
decl_stmt|;
operator|(
operator|(
name|List
argument_list|<
name|Cell
argument_list|>
operator|)
name|updatedCells
operator|)
operator|.
name|add
argument_list|(
name|newKV
argument_list|)
expr_stmt|;
block|}
block|}
name|m
operator|.
name|getFamilyCellMap
argument_list|()
operator|.
name|remove
argument_list|(
name|cf
argument_list|)
expr_stmt|;
comment|// Update the family map
name|m
operator|.
name|getFamilyCellMap
argument_list|()
operator|.
name|put
argument_list|(
name|cf
argument_list|,
name|updatedCells
argument_list|)
expr_stmt|;
block|}
block|}
annotation|@
name|Override
specifier|public
name|Result
name|preIncrement
parameter_list|(
name|ObserverContext
argument_list|<
name|RegionCoprocessorEnvironment
argument_list|>
name|e
parameter_list|,
name|Increment
name|increment
parameter_list|)
throws|throws
name|IOException
block|{
name|updateMutationAddingTags
argument_list|(
name|increment
argument_list|)
expr_stmt|;
return|return
literal|null
return|;
block|}
annotation|@
name|Override
specifier|public
name|Result
name|preAppend
parameter_list|(
name|ObserverContext
argument_list|<
name|RegionCoprocessorEnvironment
argument_list|>
name|e
parameter_list|,
name|Append
name|append
parameter_list|)
throws|throws
name|IOException
block|{
name|updateMutationAddingTags
argument_list|(
name|append
argument_list|)
expr_stmt|;
return|return
literal|null
return|;
block|}
annotation|@
name|Override
specifier|public
name|boolean
name|postScannerNext
parameter_list|(
name|ObserverContext
argument_list|<
name|RegionCoprocessorEnvironment
argument_list|>
name|e
parameter_list|,
name|InternalScanner
name|s
parameter_list|,
name|List
argument_list|<
name|Result
argument_list|>
name|results
parameter_list|,
name|int
name|limit
parameter_list|,
name|boolean
name|hasMore
parameter_list|)
throws|throws
name|IOException
block|{
if|if
condition|(
name|checkTagPresence
condition|)
block|{
if|if
condition|(
name|results
operator|.
name|size
argument_list|()
operator|>
literal|0
condition|)
block|{
comment|// Check tag presence in the 1st cell in 1st Result
name|Result
name|result
init|=
name|results
operator|.
name|get
argument_list|(
literal|0
argument_list|)
decl_stmt|;
name|CellScanner
name|cellScanner
init|=
name|result
operator|.
name|cellScanner
argument_list|()
decl_stmt|;
if|if
condition|(
name|cellScanner
operator|.
name|advance
argument_list|()
condition|)
block|{
name|Cell
name|cell
init|=
name|cellScanner
operator|.
name|current
argument_list|()
decl_stmt|;
name|tags
operator|=
name|PrivateCellUtil
operator|.
name|getTags
argument_list|(
name|cell
argument_list|)
expr_stmt|;
block|}
block|}
block|}
return|return
name|hasMore
return|;
block|}
block|}
block|}
end_class

end_unit

