HDFS-6497. Make TestAvailableSpaceVolumeChoosingPolicy deterministic (cmccabe)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1601035 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Colin McCabe 2014-06-06 23:40:39 +00:00
parent 14394eed00
commit 9528ed939d
3 changed files with 18 additions and 6 deletions

View File

@ -648,6 +648,9 @@ Release 2.5.0 - UNRELEASED
HDFS-6424. blockReport doesn't need to invalidate blocks on SBN. (Ming Ma
via jing9)
HDFS-6497. Make TestAvailableSpaceVolumeChoosingPolicy deterministic
(cmccabe)
Release 2.4.1 - UNRELEASED
INCOMPATIBLE CHANGES

View File

@ -45,11 +45,19 @@ public class AvailableSpaceVolumeChoosingPolicy<V extends FsVolumeSpi>
private static final Log LOG = LogFactory.getLog(AvailableSpaceVolumeChoosingPolicy.class);
private static final Random RAND = new Random();
private final Random random;
private long balancedSpaceThreshold = DFS_DATANODE_AVAILABLE_SPACE_VOLUME_CHOOSING_POLICY_BALANCED_SPACE_THRESHOLD_DEFAULT;
private float balancedPreferencePercent = DFS_DATANODE_AVAILABLE_SPACE_VOLUME_CHOOSING_POLICY_BALANCED_SPACE_PREFERENCE_FRACTION_DEFAULT;
AvailableSpaceVolumeChoosingPolicy(Random random) {
this.random = random;
}
public AvailableSpaceVolumeChoosingPolicy() {
this(new Random());
}
@Override
public synchronized void setConf(Configuration conf) {
balancedSpaceThreshold = conf.getLong(
@ -128,7 +136,7 @@ public synchronized V chooseVolume(List<V> volumes,
(highAvailableVolumes.size() * balancedPreferencePercent) /
preferencePercentScaler;
if (mostAvailableAmongLowVolumes < replicaSize ||
RAND.nextFloat() < scaledPreferencePercent) {
random.nextFloat() < scaledPreferencePercent) {
volume = roundRobinPolicyHighAvailable.chooseVolume(
highAvailableVolumes,
replicaSize);

View File

@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.conf.Configuration;
@ -251,10 +252,10 @@ public void randomizedTest4() throws Exception {
*/
public void doRandomizedTest(float preferencePercent, int lowSpaceVolumes,
int highSpaceVolumes) throws Exception {
@SuppressWarnings("unchecked")
final AvailableSpaceVolumeChoosingPolicy<FsVolumeSpi> policy =
ReflectionUtils.newInstance(AvailableSpaceVolumeChoosingPolicy.class, null);
Random random = new Random(123L);
final AvailableSpaceVolumeChoosingPolicy<FsVolumeSpi> policy =
new AvailableSpaceVolumeChoosingPolicy<FsVolumeSpi>(random);
List<FsVolumeSpi> volumes = new ArrayList<FsVolumeSpi>();
// Volumes with 1MB free space