HBASE-26416 Implement a new method for region replication instead of using replay...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / util / TestIdReadWriteLockStrongRef.java
blob8768efb7e49e1fc7bc31119b4fe16f93c592a4a1
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.util;
20 import java.util.concurrent.locks.ReentrantReadWriteLock;
22 import org.apache.hadoop.hbase.HBaseClassTestRule;
23 import org.apache.hadoop.hbase.testclassification.SmallTests;
24 import org.junit.Assert;
25 import org.junit.ClassRule;
26 import org.junit.Test;
27 import org.junit.experimental.categories.Category;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 @Category({ SmallTests.class })
33 public class TestIdReadWriteLockStrongRef {
35 @ClassRule
36 public static final HBaseClassTestRule CLASS_RULE =
37 HBaseClassTestRule.forClass(TestIdReadWriteLockStrongRef.class);
39 private static final Logger LOG = LoggerFactory.getLogger(TestIdReadWriteLockStrongRef.class);
41 private IdReadWriteLockStrongRef<Long> idLock = new IdReadWriteLockStrongRef<>();
43 @Test
44 public void testGetLock() throws Exception {
45 Long offset_1 = 1L;
46 Long offset_2 = 2L;
47 ReentrantReadWriteLock offsetLock_1 = idLock.getLock(offset_1);
48 ReentrantReadWriteLock offsetLock_2 = idLock.getLock(offset_1);
49 Assert.assertEquals(offsetLock_1,offsetLock_2);
50 ReentrantReadWriteLock offsetLock_3 = idLock.getLock(offset_2);
51 Assert.assertNotEquals(offsetLock_1,offsetLock_3);