[rfc] icedtea-web minor fix for two unittests
Jiri Vanek
jvanek at redhat.com
Tue Dec 18 06:34:40 PST 2012
On 12/17/2012 05:59 PM, Adam Domurad wrote:
> On 12/17/2012 10:14 AM, Jiri Vanek wrote:
>> This tests were wrongly adapted for lates ITW. And so they were incorrectly failing. This should fix them.
>>
>> J.
>
> Thanks for looking into it!
>
>>
>> diff -r 1fe2a4f7981f tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java
>> --- a/tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java Tue Dec 11 20:32:26 2012 +0100
>> +++ b/tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java Mon Dec 17 16:09:22 2012 +0100
>> @@ -68,6 +68,24 @@
>> throw new RuntimeException(ex);
>> }
>> }
>> +
>> + private class DummyJNLPFile extends JNLPFile{
>> +
>> + @Override
>> + public ResourcesDesc getResources() {
>> + return new ResourcesDesc(null, new Locale[0], new String[0], new String[0]);
>> + }
>> +
>> + @Override
>> + public URL getCodeBase() {
>> + return CODEBASE_URL;
>> + }
>> +
>> + @Override
>> + public SecurityDesc getSecurity() {
>> + return new SecurityDesc(this, SecurityDesc.SANDBOX_PERMISSIONS, null);
>> + }
>> + };
>
> +1
>
>> private static final String isWSA = "isWebstartApplication";
>>
>> static void setStaticField(Field field, Object newValue) throws Exception {
>> @@ -97,47 +115,73 @@
>> public void testResourceLoadSuccessCachingApplication() throws Exception {
>> setWSA();
>> //we are testing new resource not in cache
>> - testResourceLoadSuccessCaching("Main.class");
>> + testResourceLoadSuccessCaching2("Main.class");
>
> Just a nitpick,
>
> testResourceLoadSuccessCachingApplication calls testResourceLoadSuccessCaching2
> but testResourceLoadSuccessCachingApplication2 calls testResourceLoadSuccessCaching1, the mismatch is a little confusing
>
>
>> }
>>
>> @Test
>> public void testResourceLoadSuccessCachingApplet() throws Exception {
>> setApplet();
>> //so new resource again not in cache
>> - testResourceLoadSuccessCaching("HTMLPanel.java");
>> + testResourceLoadSuccessCaching2("Main.class");
>> + }
>> +
>> + @Test
>> + public void testResourceLoadSuccessCachingApplication2() throws Exception {
>> + setWSA();
>> + //we are testing new resource not in cache
>> + testResourceLoadSuccessCaching1("HTMLPanel.java");
>> }
>>
>> - public void testResourceLoadSuccessCaching(String r) throws Exception {
>> - JNLPFile dummyJnlpFile = new JNLPFile() {
>> + @Test
>> + public void testResourceLoadSuccessCachingApplet2() throws Exception {
>> + setApplet();
>> + //so new resource again not in cache
>> + testResourceLoadSuccessCaching1("HTMLPanel.java");
>> + }
>>
>> - @Override
>> - public ResourcesDesc getResources() {
>> - return new ResourcesDesc(null, new Locale[0], new String[0], new String[0]);
>> - }
>> + public void testResourceLoadSuccessCaching1(String r) throws Exception {
>> + JNLPFile dummyJnlpFile = new DummyJNLPFile();
>>
>> - @Override
>> - public URL getCodeBase() {
>> - return CODEBASE_URL;
>> - }
>> -
>> - @Override
>> - public SecurityDesc getSecurity() {
>> - return new SecurityDesc(this, SecurityDesc.SANDBOX_PERMISSIONS, null);
>> - }
>> - };
>> JNLPClassLoader parent = new JNLPClassLoader(dummyJnlpFile, null);
>> CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[] { JAR_URL, CODEBASE_URL }, parent);
>>
>> long startTime, stopTime;
>>
>> startTime = System.nanoTime();
>> - classLoader.findResource("net/sourceforge/jnlp/about/"+r);
>> + URL u1 = classLoader.findResource("net/sourceforge/jnlp/about/"+r);
>> + Assert.assertNull(u1);
>> stopTime = System.nanoTime();
>> long timeOnFirstTry = stopTime - startTime;
>> ServerAccess.logErrorReprint("" + timeOnFirstTry);
>>
>> startTime = System.nanoTime();
>> - classLoader.findResource("net/sourceforge/jnlp/about/"+r);
>> + URL u2 = classLoader.findResource("net/sourceforge/jnlp/about/"+r);
>> + Assert.assertNull(u2);
>> + stopTime = System.nanoTime();
>> + long timeOnSecondTry = stopTime - startTime;
>> + ServerAccess.logErrorReprint("" + timeOnSecondTry);
>> +
>> + assertTrue(timeOnSecondTry< (timeOnFirstTry / 10));
>> + }
>> +
>> + public void testResourceLoadSuccessCaching2(String r) throws Exception {
>
> I dislike numerically distinguished names strongly :-)
> I had to do a diff to be sure of the difference here. It seems there should just be one function (equivalent to testResourceLoadSuccessCaching2), and the "net/sourceforge/jnlp/about/" be added to the parameter upon usage.
>
>> + JNLPFile dummyJnlpFile = new DummyJNLPFile();
>> +
>> + JNLPClassLoader parent = new JNLPClassLoader(dummyJnlpFile, null);
>> + CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[] { JAR_URL, CODEBASE_URL }, parent);
>> +
>> + long startTime, stopTime;
>> +
>> + startTime = System.nanoTime();
>> + URL u1 = classLoader.findResource(r);
>> + Assert.assertNull(u1);
>> + stopTime = System.nanoTime();
>> + long timeOnFirstTry = stopTime - startTime;
>> + ServerAccess.logErrorReprint("" + timeOnFirstTry);
>> +
>> + startTime = System.nanoTime();
>> + URL u2 = classLoader.findResource(r);
>> + Assert.assertNull(u2);
>> stopTime = System.nanoTime();
>> long timeOnSecondTry = stopTime - startTime;
>> ServerAccess.logErrorReprint("" + timeOnSecondTry);
>> @@ -161,23 +205,7 @@
>> }
>>
>> public void testResourceLoadFailureCaching() throws Exception {
>> - JNLPFile dummyJnlpFile = new JNLPFile() {
>> -
>> - @Override
>> - public ResourcesDesc getResources() {
>> - return new ResourcesDesc(null, new Locale[0], new String[0], new String[0]);
>> - }
>> -
>> - @Override
>> - public URL getCodeBase() {
>> - return CODEBASE_URL;
>> - }
>> -
>> - @Override
>> - public SecurityDesc getSecurity() {
>> - return new SecurityDesc(this, SecurityDesc.SANDBOX_PERMISSIONS, null);
>> - }
>> - };
>> + JNLPFile dummyJnlpFile = new DummyJNLPFile();
>>
>> JNLPClassLoader parent = new JNLPClassLoader(dummyJnlpFile, null);
>> CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[] { JAR_URL, CODEBASE_URL }, parent);
>> @@ -212,24 +240,8 @@
>> }
>>
>> public void testParentClassLoaderIsAskedForClasses() throws Exception {
>> - JNLPFile dummyJnlpFile = new JNLPFile() {
>> -
>> - @Override
>> - public ResourcesDesc getResources() {
>> - return new ResourcesDesc(null, new Locale[0], new String[0], new String[0]);
>> - }
>> -
>> - @Override
>> - public URL getCodeBase() {
>> - return CODEBASE_URL;
>> - }
>> -
>> - @Override
>> - public SecurityDesc getSecurity() {
>> - return new SecurityDesc(this, SecurityDesc.SANDBOX_PERMISSIONS, null);
>> - }
>> - };
>> -
>> + JNLPFile dummyJnlpFile = new DummyJNLPFile();
>> +
>> final boolean[] parentWasInvoked = new boolean[1];
>>
>> JNLPClassLoader parent = new JNLPClassLoader(dummyJnlpFile, null) {
>
> Please also rid of the duplicated dummy in testNullFileSecurityDesc.
Atatched even more fixed and cleaned version
>
> -Adam
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fixedUnittest2.patch
Type: text/x-patch
Size: 10714 bytes
Desc: not available
Url : http://mail.openjdk.java.net/pipermail/distro-pkg-dev/attachments/20121218/a21a6344/fixedUnittest2.patch
More information about the distro-pkg-dev
mailing list