HDFS-15792. Addendum: ClasscastException while loading FSImage. Contributed by Renukaprasad C.

This commit is contained in:
He Xiaoqiao 2021-02-02 13:50:48 +08:00
parent 58a9640f8e
commit f97709beaa
No known key found for this signature in database
GPG Key ID: A80CC124E9A0FA63

View File

@ -23,18 +23,17 @@
import org.junit.Test; import org.junit.Test;
/** /**
* Verify ReferenceCount map in concurrent scenarios * Verify ReferenceCount map in concurrent scenarios.
*
*/ */
public class TestReferenceCountMap { public class TestReferenceCountMap {
//Add these number of references in loop //Add these number of references in loop
public static final int LOOP_COUNTER = 10000; public static final int LOOP_COUNTER = 10000;
//Use 2 global features //Use 2 global features
AclFeature aclFeature1 = new AclFeature(new int[]{1}); private AclFeature aclFeature1 = new AclFeature(new int[]{1});
AclFeature aclFeature2 = new AclFeature(new int[]{2}); private AclFeature aclFeature2 = new AclFeature(new int[]{2});
@Test @Test
public void testReferenceCountMap() throws Exception{ public void testReferenceCountMap() throws Exception {
ReferenceCountMap<AclFeature> countMap = new ReferenceCountMap<>(); ReferenceCountMap<AclFeature> countMap = new ReferenceCountMap<>();
countMap.put(aclFeature1); countMap.put(aclFeature1);
countMap.put(aclFeature2); countMap.put(aclFeature2);
@ -63,7 +62,7 @@ public void testReferenceCountMap() throws Exception{
} }
@Test @Test
public void testRefCountMapConcurrently() throws Exception{ public void testRefCountMapConcurrently() throws Exception {
ReferenceCountMap<AclFeature> countMap = new ReferenceCountMap<>(); ReferenceCountMap<AclFeature> countMap = new ReferenceCountMap<>();
PutThread putThread1 = new PutThread(countMap); PutThread putThread1 = new PutThread(countMap);
@ -74,8 +73,10 @@ public void testRefCountMapConcurrently() throws Exception{
putThread1.join(); putThread1.join();
putThread2.join(); putThread2.join();
Assert.assertEquals(2 * LOOP_COUNTER, countMap.getReferenceCount(aclFeature1)); Assert.assertEquals(2 * LOOP_COUNTER,
Assert.assertEquals(2 * LOOP_COUNTER, countMap.getReferenceCount(aclFeature2)); countMap.getReferenceCount(aclFeature1));
Assert.assertEquals(2 * LOOP_COUNTER,
countMap.getReferenceCount(aclFeature2));
removeThread1.start(); removeThread1.start();
removeThread1.join(); removeThread1.join();
@ -83,9 +84,9 @@ public void testRefCountMapConcurrently() throws Exception{
Assert.assertEquals(LOOP_COUNTER, countMap.getReferenceCount(aclFeature2)); Assert.assertEquals(LOOP_COUNTER, countMap.getReferenceCount(aclFeature2));
} }
class PutThread extends Thread{ class PutThread extends Thread {
ReferenceCountMap<AclFeature> referenceCountMap; private ReferenceCountMap<AclFeature> referenceCountMap;
public PutThread(ReferenceCountMap<AclFeature> referenceCountMap){ PutThread(ReferenceCountMap<AclFeature> referenceCountMap) {
this.referenceCountMap = referenceCountMap; this.referenceCountMap = referenceCountMap;
} }
@Override @Override
@ -97,9 +98,9 @@ public void run() {
} }
}; };
class RemoveThread extends Thread{ class RemoveThread extends Thread {
ReferenceCountMap<AclFeature> referenceCountMap; private ReferenceCountMap<AclFeature> referenceCountMap;
public RemoveThread(ReferenceCountMap<AclFeature> referenceCountMap){ RemoveThread(ReferenceCountMap<AclFeature> referenceCountMap) {
this.referenceCountMap = referenceCountMap; this.referenceCountMap = referenceCountMap;
} }
@Override @Override