HBASE-19887 Do not overwrite the surefire junit listener property in the pom of sub modules
This commit is contained in:
parent
afdfa54cd3
commit
28d13c54a9
|
@ -40,19 +40,6 @@
|
|||
<surefire.version>2.19</surefire.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- Dependency for hbase-testing-util must precede compile-scoped dependencies. -->
|
||||
<dependency>
|
||||
|
|
|
@ -40,19 +40,6 @@
|
|||
<surefire.version>2.19</surefire.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- Dependency for hbase-testing-util must precede compile-scoped dependencies. -->
|
||||
<dependency>
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
package org.apache.hadoop.hbase.util;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import org.apache.hadoop.hbase.util.PoolMap.PoolType;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
public abstract class PoolMapTestBase {
|
||||
|
||||
protected PoolMap<String, String> poolMap;
|
||||
|
||||
protected static final int POOL_SIZE = 3;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
this.poolMap = new PoolMap<>(getPoolType(), POOL_SIZE);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
this.poolMap.clear();
|
||||
}
|
||||
|
||||
protected abstract PoolType getPoolType();
|
||||
|
||||
protected void runThread(final String randomKey, final String randomValue,
|
||||
final String expectedValue) throws InterruptedException {
|
||||
final AtomicBoolean matchFound = new AtomicBoolean(false);
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
poolMap.put(randomKey, randomValue);
|
||||
String actualValue = poolMap.get(randomKey);
|
||||
matchFound
|
||||
.set(expectedValue == null ? actualValue == null : expectedValue.equals(actualValue));
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
thread.join();
|
||||
assertTrue(matchFound.get());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
package org.apache.hadoop.hbase.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||
import org.apache.hadoop.hbase.testclassification.MiscTests;
|
||||
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||
import org.apache.hadoop.hbase.util.PoolMap.PoolType;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
@Category({ MiscTests.class, SmallTests.class })
|
||||
public class TestReusablePoolMap extends PoolMapTestBase {
|
||||
|
||||
@ClassRule
|
||||
public static final HBaseClassTestRule CLASS_RULE =
|
||||
HBaseClassTestRule.forClass(TestReusablePoolMap.class);
|
||||
|
||||
@Override
|
||||
protected PoolType getPoolType() {
|
||||
return PoolType.Reusable;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleThreadedClient() throws InterruptedException, ExecutionException {
|
||||
Random rand = ThreadLocalRandom.current();
|
||||
String randomKey = String.valueOf(rand.nextInt());
|
||||
String randomValue = String.valueOf(rand.nextInt());
|
||||
// As long as we poll values we put, the pool size should remain zero
|
||||
runThread(randomKey, randomValue, randomValue);
|
||||
assertEquals(0, poolMap.size(randomKey));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiThreadedClients() throws InterruptedException, ExecutionException {
|
||||
Random rand = ThreadLocalRandom.current();
|
||||
// As long as we poll values we put, the pool size should remain zero
|
||||
for (int i = 0; i < POOL_SIZE; i++) {
|
||||
String randomKey = String.valueOf(rand.nextInt());
|
||||
String randomValue = String.valueOf(rand.nextInt());
|
||||
runThread(randomKey, randomValue, randomValue);
|
||||
assertEquals(0, poolMap.size(randomKey));
|
||||
}
|
||||
poolMap.clear();
|
||||
String randomKey = String.valueOf(rand.nextInt());
|
||||
for (int i = 0; i < POOL_SIZE - 1; i++) {
|
||||
String randomValue = String.valueOf(rand.nextInt());
|
||||
runThread(randomKey, randomValue, randomValue);
|
||||
assertEquals(0, poolMap.size(randomKey));
|
||||
}
|
||||
assertEquals(0, poolMap.size(randomKey));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPoolCap() throws InterruptedException, ExecutionException {
|
||||
Random rand = ThreadLocalRandom.current();
|
||||
// As long as we poll values we put, the pool size should remain zero
|
||||
String randomKey = String.valueOf(rand.nextInt());
|
||||
List<String> randomValues = new ArrayList<>();
|
||||
for (int i = 0; i < POOL_SIZE * 2; i++) {
|
||||
String randomValue = String.valueOf(rand.nextInt());
|
||||
randomValues.add(randomValue);
|
||||
runThread(randomKey, randomValue, randomValue);
|
||||
}
|
||||
assertEquals(0, poolMap.size(randomKey));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
package org.apache.hadoop.hbase.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||
import org.apache.hadoop.hbase.testclassification.MiscTests;
|
||||
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||
import org.apache.hadoop.hbase.util.PoolMap.PoolType;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
@Category({ MiscTests.class, SmallTests.class })
|
||||
public class TestRoundRobinPoolMap extends PoolMapTestBase {
|
||||
|
||||
@ClassRule
|
||||
public static final HBaseClassTestRule CLASS_RULE =
|
||||
HBaseClassTestRule.forClass(TestRoundRobinPoolMap.class);
|
||||
|
||||
@Override
|
||||
protected PoolType getPoolType() {
|
||||
return PoolType.RoundRobin;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleThreadedClient() throws InterruptedException, ExecutionException {
|
||||
Random rand = ThreadLocalRandom.current();
|
||||
String randomKey = String.valueOf(rand.nextInt());
|
||||
String randomValue = String.valueOf(rand.nextInt());
|
||||
// As long as the pool is not full, we'll get null back.
|
||||
// This forces the user to create new values that can be used to populate
|
||||
// the pool.
|
||||
runThread(randomKey, randomValue, null);
|
||||
assertEquals(1, poolMap.size(randomKey));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiThreadedClients() throws InterruptedException, ExecutionException {
|
||||
Random rand = ThreadLocalRandom.current();
|
||||
for (int i = 0; i < POOL_SIZE; i++) {
|
||||
String randomKey = String.valueOf(rand.nextInt());
|
||||
String randomValue = String.valueOf(rand.nextInt());
|
||||
// As long as the pool is not full, we'll get null back
|
||||
runThread(randomKey, randomValue, null);
|
||||
// As long as we use distinct keys, each pool will have one value
|
||||
assertEquals(1, poolMap.size(randomKey));
|
||||
}
|
||||
poolMap.clear();
|
||||
String randomKey = String.valueOf(rand.nextInt());
|
||||
for (int i = 0; i < POOL_SIZE - 1; i++) {
|
||||
String randomValue = String.valueOf(rand.nextInt());
|
||||
// As long as the pool is not full, we'll get null back
|
||||
runThread(randomKey, randomValue, null);
|
||||
// since we use the same key, the pool size should grow
|
||||
assertEquals(i + 1, poolMap.size(randomKey));
|
||||
}
|
||||
// at the end of the day, there should be as many values as we put
|
||||
assertEquals(POOL_SIZE - 1, poolMap.size(randomKey));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPoolCap() throws InterruptedException, ExecutionException {
|
||||
Random rand = ThreadLocalRandom.current();
|
||||
String randomKey = String.valueOf(rand.nextInt());
|
||||
List<String> randomValues = new ArrayList<>();
|
||||
for (int i = 0; i < POOL_SIZE * 2; i++) {
|
||||
String randomValue = String.valueOf(rand.nextInt());
|
||||
randomValues.add(randomValue);
|
||||
if (i < POOL_SIZE - 1) {
|
||||
// As long as the pool is not full, we'll get null back
|
||||
runThread(randomKey, randomValue, null);
|
||||
} else {
|
||||
// when the pool becomes full, we expect the value we get back to be
|
||||
// what we put earlier, in round-robin order
|
||||
runThread(randomKey, randomValue, randomValues.get((i - POOL_SIZE + 1) % POOL_SIZE));
|
||||
}
|
||||
}
|
||||
assertEquals(POOL_SIZE, poolMap.size(randomKey));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
package org.apache.hadoop.hbase.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||
import org.apache.hadoop.hbase.testclassification.MiscTests;
|
||||
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||
import org.apache.hadoop.hbase.util.PoolMap.PoolType;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
@Category({ MiscTests.class, SmallTests.class })
|
||||
public class TestThreadLocalPoolMap extends PoolMapTestBase {
|
||||
|
||||
@ClassRule
|
||||
public static final HBaseClassTestRule CLASS_RULE =
|
||||
HBaseClassTestRule.forClass(TestThreadLocalPoolMap.class);
|
||||
|
||||
@Override
|
||||
protected PoolType getPoolType() {
|
||||
return PoolType.ThreadLocal;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleThreadedClient() throws InterruptedException, ExecutionException {
|
||||
Random rand = ThreadLocalRandom.current();
|
||||
String randomKey = String.valueOf(rand.nextInt());
|
||||
String randomValue = String.valueOf(rand.nextInt());
|
||||
// As long as the pool is not full, we should get back what we put
|
||||
runThread(randomKey, randomValue, randomValue);
|
||||
assertEquals(1, poolMap.size(randomKey));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiThreadedClients() throws InterruptedException, ExecutionException {
|
||||
Random rand = ThreadLocalRandom.current();
|
||||
// As long as the pool is not full, we should get back what we put
|
||||
for (int i = 0; i < POOL_SIZE; i++) {
|
||||
String randomKey = String.valueOf(rand.nextInt());
|
||||
String randomValue = String.valueOf(rand.nextInt());
|
||||
runThread(randomKey, randomValue, randomValue);
|
||||
assertEquals(1, poolMap.size(randomKey));
|
||||
}
|
||||
String randomKey = String.valueOf(rand.nextInt());
|
||||
for (int i = 0; i < POOL_SIZE; i++) {
|
||||
String randomValue = String.valueOf(rand.nextInt());
|
||||
runThread(randomKey, randomValue, randomValue);
|
||||
assertEquals(i + 1, poolMap.size(randomKey));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPoolCap() throws InterruptedException, ExecutionException {
|
||||
Random rand = ThreadLocalRandom.current();
|
||||
String randomKey = String.valueOf(rand.nextInt());
|
||||
for (int i = 0; i < POOL_SIZE * 2; i++) {
|
||||
String randomValue = String.valueOf(rand.nextInt());
|
||||
// as of HBASE-4150, pool limit is no longer used with ThreadLocalPool
|
||||
runThread(randomKey, randomValue, randomValue);
|
||||
}
|
||||
assertEquals(POOL_SIZE * 2, poolMap.size(randomKey));
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
/*
|
||||
*
|
||||
/**
|
||||
* 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
|
||||
|
@ -19,25 +18,24 @@
|
|||
|
||||
package org.apache.hadoop.hbase;
|
||||
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.hadoop.hbase.ResourceChecker.Phase;
|
||||
import org.apache.hadoop.hbase.util.JVM;
|
||||
import org.junit.runner.notification.RunListener;
|
||||
|
||||
/**
|
||||
* Listen to the test progress and check the usage of:
|
||||
* - threads
|
||||
* - open file descriptor
|
||||
* - max open file descriptor
|
||||
* <p/>
|
||||
* <ul>
|
||||
* <li>threads</li>
|
||||
* <li>open file descriptor</li>
|
||||
* <li>max open file descriptor</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* When surefire forkMode=once/always/perthread, this code is executed on the forked process.
|
||||
*/
|
||||
public class ResourceCheckerJUnitListener extends RunListener {
|
||||
|
@ -91,7 +89,7 @@ public class ResourceCheckerJUnitListener extends RunListener {
|
|||
return 0;
|
||||
}
|
||||
JVM jvm = new JVM();
|
||||
return (int)jvm.getOpenFileDescriptorCount();
|
||||
return (int) jvm.getOpenFileDescriptorCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -107,7 +105,7 @@ public class ResourceCheckerJUnitListener extends RunListener {
|
|||
return 0;
|
||||
}
|
||||
JVM jvm = new JVM();
|
||||
return (int)jvm.getMaxFileDescriptorCount();
|
||||
return (int) jvm.getMaxFileDescriptorCount();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,7 +115,7 @@ public class ResourceCheckerJUnitListener extends RunListener {
|
|||
if (!JVM.isUnix()) {
|
||||
return 0;
|
||||
}
|
||||
return (int)(new JVM().getSystemLoadAverage()*100);
|
||||
return (int) (new JVM().getSystemLoadAverage() * 100);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,4 +191,3 @@ public class ResourceCheckerJUnitListener extends RunListener {
|
|||
end(descriptionToShortTestName(description));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -79,17 +79,6 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<properties>
|
||||
<property>
|
||||
<name>listener</name>
|
||||
<value>org.apache.hadoop.hbase.ResourceCheckerJUnitListener</value>
|
||||
</property>
|
||||
</properties>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- Make a jar and put the sources in the jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
|
|
@ -122,12 +122,6 @@
|
|||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<properties>
|
||||
<property>
|
||||
<name>listener</name>
|
||||
<value>org.apache.hadoop.hbase.ResourceCheckerJUnitListener</value>
|
||||
</property>
|
||||
</properties>
|
||||
<systemPropertyVariables>
|
||||
<test.build.webapps>target/test-classes/webapps</test.build.webapps>
|
||||
</systemPropertyVariables>
|
||||
|
|
|
@ -66,18 +66,6 @@
|
|||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- Testing plugins -->
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<properties>
|
||||
<property>
|
||||
<name>listener</name>
|
||||
<value>org.apache.hadoop.hbase.ServerResourceCheckerJUnitListener</value>
|
||||
</property>
|
||||
</properties>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- Make a jar and put the sources in the jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
|
|
@ -47,23 +47,6 @@
|
|||
<skipAssembly>true</skipAssembly>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<!-- Always skip the second part executions, since we only run
|
||||
simple unit tests in this module -->
|
||||
<executions>
|
||||
<execution>
|
||||
<id>secondPartTestsExecution</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- Make a jar and put the sources in the jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
|
|
@ -125,12 +125,6 @@
|
|||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<properties>
|
||||
<property>
|
||||
<name>listener</name>
|
||||
<value>org.apache.hadoop.hbase.ServerResourceCheckerJUnitListener</value>
|
||||
</property>
|
||||
</properties>
|
||||
<systemPropertyVariables>
|
||||
<test.build.webapps>target/test-classes/webapps</test.build.webapps>
|
||||
</systemPropertyVariables>
|
||||
|
|
|
@ -237,12 +237,6 @@
|
|||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<properties>
|
||||
<property>
|
||||
<name>listener</name>
|
||||
<value>org.apache.hadoop.hbase.ServerResourceCheckerJUnitListener</value>
|
||||
</property>
|
||||
</properties>
|
||||
<systemPropertyVariables>
|
||||
<test.build.webapps>target/test-classes/webapps</test.build.webapps>
|
||||
</systemPropertyVariables>
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.apache.hadoop.hbase;
|
||||
|
||||
/**
|
||||
* Monitor the resources. use by the tests All resources in {@link ResourceCheckerJUnitListener}
|
||||
* plus the number of connection.
|
||||
*/
|
||||
public class ServerResourceCheckerJUnitListener extends ResourceCheckerJUnitListener {
|
||||
}
|
|
@ -1,238 +0,0 @@
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
package org.apache.hadoop.hbase.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||
import org.apache.hadoop.hbase.testclassification.MiscTests;
|
||||
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||
import org.apache.hadoop.hbase.util.PoolMap.PoolType;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({TestPoolMap.TestRoundRobinPoolType.class, TestPoolMap.TestThreadLocalPoolType.class,
|
||||
TestPoolMap.TestReusablePoolType.class})
|
||||
@Category({MiscTests.class, SmallTests.class})
|
||||
public class TestPoolMap {
|
||||
|
||||
@ClassRule
|
||||
public static final HBaseClassTestRule CLASS_RULE =
|
||||
HBaseClassTestRule.forClass(TestPoolMap.class);
|
||||
|
||||
public abstract static class TestPoolType extends TestCase {
|
||||
protected PoolMap<String, String> poolMap;
|
||||
protected Random random = new Random();
|
||||
|
||||
protected static final int POOL_SIZE = 3;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
this.poolMap = new PoolMap<>(getPoolType(), POOL_SIZE);
|
||||
}
|
||||
|
||||
protected abstract PoolType getPoolType();
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
this.poolMap.clear();
|
||||
}
|
||||
|
||||
protected void runThread(final String randomKey, final String randomValue,
|
||||
final String expectedValue) throws InterruptedException {
|
||||
final AtomicBoolean matchFound = new AtomicBoolean(false);
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
poolMap.put(randomKey, randomValue);
|
||||
String actualValue = poolMap.get(randomKey);
|
||||
matchFound.set(expectedValue == null ? actualValue == null
|
||||
: expectedValue.equals(actualValue));
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
thread.join();
|
||||
assertTrue(matchFound.get());
|
||||
}
|
||||
}
|
||||
|
||||
@Category({MiscTests.class, SmallTests.class})
|
||||
public static class TestRoundRobinPoolType extends TestPoolType {
|
||||
@Override
|
||||
protected PoolType getPoolType() {
|
||||
return PoolType.RoundRobin;
|
||||
}
|
||||
|
||||
public void testSingleThreadedClient() throws InterruptedException,
|
||||
ExecutionException {
|
||||
String randomKey = String.valueOf(random.nextInt());
|
||||
String randomValue = String.valueOf(random.nextInt());
|
||||
// As long as the pool is not full, we'll get null back.
|
||||
// This forces the user to create new values that can be used to populate
|
||||
// the pool.
|
||||
runThread(randomKey, randomValue, null);
|
||||
assertEquals(1, poolMap.size(randomKey));
|
||||
}
|
||||
|
||||
public void testMultiThreadedClients() throws InterruptedException,
|
||||
ExecutionException {
|
||||
for (int i = 0; i < POOL_SIZE; i++) {
|
||||
String randomKey = String.valueOf(random.nextInt());
|
||||
String randomValue = String.valueOf(random.nextInt());
|
||||
// As long as the pool is not full, we'll get null back
|
||||
runThread(randomKey, randomValue, null);
|
||||
// As long as we use distinct keys, each pool will have one value
|
||||
assertEquals(1, poolMap.size(randomKey));
|
||||
}
|
||||
poolMap.clear();
|
||||
String randomKey = String.valueOf(random.nextInt());
|
||||
for (int i = 0; i < POOL_SIZE - 1; i++) {
|
||||
String randomValue = String.valueOf(random.nextInt());
|
||||
// As long as the pool is not full, we'll get null back
|
||||
runThread(randomKey, randomValue, null);
|
||||
// since we use the same key, the pool size should grow
|
||||
assertEquals(i + 1, poolMap.size(randomKey));
|
||||
}
|
||||
// at the end of the day, there should be as many values as we put
|
||||
assertEquals(POOL_SIZE - 1, poolMap.size(randomKey));
|
||||
}
|
||||
|
||||
public void testPoolCap() throws InterruptedException, ExecutionException {
|
||||
String randomKey = String.valueOf(random.nextInt());
|
||||
List<String> randomValues = new ArrayList<>();
|
||||
for (int i = 0; i < POOL_SIZE * 2; i++) {
|
||||
String randomValue = String.valueOf(random.nextInt());
|
||||
randomValues.add(randomValue);
|
||||
if (i < POOL_SIZE - 1) {
|
||||
// As long as the pool is not full, we'll get null back
|
||||
runThread(randomKey, randomValue, null);
|
||||
} else {
|
||||
// when the pool becomes full, we expect the value we get back to be
|
||||
// what we put earlier, in round-robin order
|
||||
runThread(randomKey, randomValue,
|
||||
randomValues.get((i - POOL_SIZE + 1) % POOL_SIZE));
|
||||
}
|
||||
}
|
||||
assertEquals(POOL_SIZE, poolMap.size(randomKey));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Category({MiscTests.class, SmallTests.class})
|
||||
public static class TestThreadLocalPoolType extends TestPoolType {
|
||||
@Override
|
||||
protected PoolType getPoolType() {
|
||||
return PoolType.ThreadLocal;
|
||||
}
|
||||
|
||||
public void testSingleThreadedClient() throws InterruptedException,
|
||||
ExecutionException {
|
||||
String randomKey = String.valueOf(random.nextInt());
|
||||
String randomValue = String.valueOf(random.nextInt());
|
||||
// As long as the pool is not full, we should get back what we put
|
||||
runThread(randomKey, randomValue, randomValue);
|
||||
assertEquals(1, poolMap.size(randomKey));
|
||||
}
|
||||
|
||||
public void testMultiThreadedClients() throws InterruptedException,
|
||||
ExecutionException {
|
||||
// As long as the pool is not full, we should get back what we put
|
||||
for (int i = 0; i < POOL_SIZE; i++) {
|
||||
String randomKey = String.valueOf(random.nextInt());
|
||||
String randomValue = String.valueOf(random.nextInt());
|
||||
runThread(randomKey, randomValue, randomValue);
|
||||
assertEquals(1, poolMap.size(randomKey));
|
||||
}
|
||||
String randomKey = String.valueOf(random.nextInt());
|
||||
for (int i = 0; i < POOL_SIZE; i++) {
|
||||
String randomValue = String.valueOf(random.nextInt());
|
||||
runThread(randomKey, randomValue, randomValue);
|
||||
assertEquals(i + 1, poolMap.size(randomKey));
|
||||
}
|
||||
}
|
||||
|
||||
public void testPoolCap() throws InterruptedException, ExecutionException {
|
||||
String randomKey = String.valueOf(random.nextInt());
|
||||
for (int i = 0; i < POOL_SIZE * 2; i++) {
|
||||
String randomValue = String.valueOf(random.nextInt());
|
||||
// as of HBASE-4150, pool limit is no longer used with ThreadLocalPool
|
||||
runThread(randomKey, randomValue, randomValue);
|
||||
}
|
||||
assertEquals(POOL_SIZE * 2, poolMap.size(randomKey));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Category({MiscTests.class, SmallTests.class})
|
||||
public static class TestReusablePoolType extends TestPoolType {
|
||||
@Override
|
||||
protected PoolType getPoolType() {
|
||||
return PoolType.Reusable;
|
||||
}
|
||||
|
||||
public void testSingleThreadedClient() throws InterruptedException,
|
||||
ExecutionException {
|
||||
String randomKey = String.valueOf(random.nextInt());
|
||||
String randomValue = String.valueOf(random.nextInt());
|
||||
// As long as we poll values we put, the pool size should remain zero
|
||||
runThread(randomKey, randomValue, randomValue);
|
||||
assertEquals(0, poolMap.size(randomKey));
|
||||
}
|
||||
|
||||
public void testMultiThreadedClients() throws InterruptedException,
|
||||
ExecutionException {
|
||||
// As long as we poll values we put, the pool size should remain zero
|
||||
for (int i = 0; i < POOL_SIZE; i++) {
|
||||
String randomKey = String.valueOf(random.nextInt());
|
||||
String randomValue = String.valueOf(random.nextInt());
|
||||
runThread(randomKey, randomValue, randomValue);
|
||||
assertEquals(0, poolMap.size(randomKey));
|
||||
}
|
||||
poolMap.clear();
|
||||
String randomKey = String.valueOf(random.nextInt());
|
||||
for (int i = 0; i < POOL_SIZE - 1; i++) {
|
||||
String randomValue = String.valueOf(random.nextInt());
|
||||
runThread(randomKey, randomValue, randomValue);
|
||||
assertEquals(0, poolMap.size(randomKey));
|
||||
}
|
||||
assertEquals(0, poolMap.size(randomKey));
|
||||
}
|
||||
|
||||
public void testPoolCap() throws InterruptedException, ExecutionException {
|
||||
// As long as we poll values we put, the pool size should remain zero
|
||||
String randomKey = String.valueOf(random.nextInt());
|
||||
List<String> randomValues = new ArrayList<>();
|
||||
for (int i = 0; i < POOL_SIZE * 2; i++) {
|
||||
String randomValue = String.valueOf(random.nextInt());
|
||||
randomValues.add(randomValue);
|
||||
runThread(randomKey, randomValue, randomValue);
|
||||
}
|
||||
assertEquals(0, poolMap.size(randomKey));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -123,18 +123,6 @@
|
|||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>findbugs-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<!-- Testing plugins -->
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<properties>
|
||||
<property>
|
||||
<name>listener</name>
|
||||
<value>org.apache.hadoop.hbase.ServerResourceCheckerJUnitListener</value>
|
||||
</property>
|
||||
</properties>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<!-- General Resources -->
|
||||
<pluginManagement>
|
||||
|
|
|
@ -98,18 +98,6 @@
|
|||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>findbugs-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<!-- Testing plugins -->
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<properties>
|
||||
<property>
|
||||
<name>listener</name>
|
||||
<value>org.apache.hadoop.hbase.ResourceCheckerJUnitListener</value>
|
||||
</property>
|
||||
</properties>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<!-- General Resources -->
|
||||
<pluginManagement>
|
||||
|
|
Loading…
Reference in New Issue