|
Lines 8-14
Link Here
|
| 8 |
package org.eclipse.mylyn.jira.tests; |
8 |
package org.eclipse.mylyn.jira.tests; |
| 9 |
|
9 |
|
| 10 |
import java.io.IOException; |
10 |
import java.io.IOException; |
|
|
11 |
import java.io.Reader; |
| 11 |
import java.io.StringReader; |
12 |
import java.io.StringReader; |
|
|
13 |
import java.util.concurrent.Callable; |
| 14 |
import java.util.concurrent.ExecutionException; |
| 15 |
import java.util.concurrent.ExecutorService; |
| 16 |
import java.util.concurrent.Executors; |
| 17 |
import java.util.concurrent.FutureTask; |
| 18 |
import java.util.concurrent.TimeUnit; |
| 19 |
import java.util.concurrent.TimeoutException; |
| 12 |
|
20 |
|
| 13 |
import junit.framework.TestCase; |
21 |
import junit.framework.TestCase; |
| 14 |
|
22 |
|
|
Lines 49-52
Link Here
|
| 49 |
assertEquals(" ", new String(chars, 0, len)); |
57 |
assertEquals(" ", new String(chars, 0, len)); |
| 50 |
} |
58 |
} |
| 51 |
|
59 |
|
|
|
60 |
public void testHeadCpuLoop() { |
| 61 |
assertTrue(testCpuLoop("b <head> a ")); |
| 62 |
} |
| 63 |
|
| 64 |
public void testPreCpuLoop() { |
| 65 |
assertTrue(testCpuLoop("b <pre> b ")); |
| 66 |
} |
| 67 |
|
| 68 |
private boolean testCpuLoop(final String text) { |
| 69 |
ExecutorService executor = Executors.newFixedThreadPool(1); |
| 70 |
FutureTask<Boolean> future = new FutureTask<Boolean>(new Callable<Boolean>() { |
| 71 |
public Boolean call() { |
| 72 |
Reader stringReader = new StringReader(text); |
| 73 |
|
| 74 |
HTML2TextReader html2TextReader = new HTML2TextReader(stringReader, null); |
| 75 |
try { |
| 76 |
char[] chars = new char[text.length()]; |
| 77 |
int len = html2TextReader.read(chars, 0, chars.length); |
| 78 |
return true; |
| 79 |
} catch (Throwable e) { |
| 80 |
return false; |
| 81 |
} |
| 82 |
} |
| 83 |
}); |
| 84 |
try { |
| 85 |
executor.execute(future); |
| 86 |
|
| 87 |
return future.get(2, TimeUnit.SECONDS); |
| 88 |
|
| 89 |
} catch (Throwable e) { |
| 90 |
future.cancel(true); |
| 91 |
} |
| 92 |
return false; |
| 93 |
} |
| 94 |
|
| 52 |
} |
95 |
} |