Author: cdouglas
Date: Mon Jun 2 14:20:09 2008
New Revision: 662569
URL: http://svn.apache.org/viewvc?rev=662569&view=rev
Log:
HADOOP-3471. Fix spurious errors from TestIndexedSort and add additional
logging to let failures be reproducible.
Modified:
hadoop/core/trunk/CHANGES.txt
hadoop/core/trunk/src/test/org/apache/hadoop/util/TestIndexedSort.java
Modified: hadoop/core/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=662569&r1=662568&r2=662569&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Mon Jun 2 14:20:09 2008
@@ -385,6 +385,9 @@
/bin/bash and fix the test patch to require bash instead of sh.
(Brice Arnould via omalley)
+ HADOOP-3471. Fix spurious errors from TestIndexedSort and add additional
+ logging to let failures be reproducible. (cdouglas)
+
Release 0.17.0 - 2008-05-18
INCOMPATIBLE CHANGES
Modified: hadoop/core/trunk/src/test/org/apache/hadoop/util/TestIndexedSort.java
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/util/TestIndexedSort.java?rev=662569&r1=662568&r2=662569&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/util/TestIndexedSort.java
(original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/util/TestIndexedSort.java Mon
Jun 2 14:20:09 2008
@@ -35,6 +35,7 @@
private int[] valindex;
private int[] valindirect;
private int[] values;
+ private final long seed;
public SampleSortable() {
this(50);
@@ -42,6 +43,8 @@
public SampleSortable(int j) {
Random r = new Random();
+ seed = r.nextLong();
+ r.setSeed(seed);
values = new int[j];
valindex = new int[j];
valindirect = new int[j];
@@ -58,6 +61,11 @@
for (int i = 0; i < values.length; ++i) {
valindex[i] = valindirect[i] = i;
}
+ seed = 0;
+ }
+
+ public long getSeed() {
+ return seed;
}
public int compare(int i, int j) {
@@ -97,12 +105,15 @@
private final byte[] bytes;
private final WritableComparator comparator;
private final String[] check;
+ private final long seed;
public WritableSortable() throws IOException {
this(100);
}
public WritableSortable(int j) throws IOException {
+ seed = r.nextLong();
+ r.setSeed(seed);
Text t = new Text();
StringBuffer sb = new StringBuffer();
indices = new int[j];
@@ -121,6 +132,10 @@
comparator = WritableComparator.get(Text.class);
}
+ public long getSeed() {
+ return seed;
+ }
+
private static void genRandom(Text t, int len, StringBuffer sb) {
sb.setLength(0);
for (int i = 0; i < len; ++i) {
@@ -174,10 +189,13 @@
int[] check = s.getSorted();
assertTrue(Arrays.toString(values) + "\ndoesn't match\n" +
Arrays.toString(check), Arrays.equals(values, check));
+ // Set random min/max, re-sort.
Random r = new Random();
- int diff = r.nextInt(SAMPLE);
- values[diff] = 9;
- values[(diff + r.nextInt(SAMPLE >>> 1)) % SAMPLE] = 11;
+ int min = r.nextInt(SAMPLE);
+ int max = (min + 1 + r.nextInt(SAMPLE - 2)) % SAMPLE;
+ values[min] = 9;
+ values[max] = 11;
+ System.out.println("testAllEqual setting min/max at " + min + "/" + max);
s = new SampleSortable(values);
sorter.sort(s, 0, SAMPLE);
check = s.getSorted();
@@ -192,6 +210,9 @@
final int SAMPLE = 500;
int[] values = new int[SAMPLE];
Random r = new Random();
+ long seed = r.nextLong();
+ r.setSeed(seed);
+ System.out.println("testSorted seed: " + seed);
for (int i = 0; i < SAMPLE; ++i) {
values[i] = r.nextInt(100);
}
@@ -222,7 +243,6 @@
final int SAMPLE = 1;
SampleSortable s = new SampleSortable(SAMPLE);
int[] values = s.getValues();
- Arrays.sort(values);
IndexedSorter sorter = new QuickSort();
sorter.sort(s, 0, SAMPLE);
int[] check = s.getSorted();
@@ -233,6 +253,7 @@
public void testQuickSort() throws Exception {
final int SAMPLE = 100000;
SampleSortable s = new SampleSortable(SAMPLE);
+ System.out.println("testQuickSort seed: " + s.getSeed());
int[] values = s.getValues();
Arrays.sort(values);
IndexedSorter sorter = new QuickSort();
@@ -245,6 +266,7 @@
public void testWritable() throws Exception {
final int SAMPLE = 1000;
WritableSortable s = new WritableSortable(SAMPLE);
+ System.out.println("testWritable seed: " + s.getSeed());
String[] values = s.getValues();
Arrays.sort(values);
IndexedSorter sorter = new QuickSort();