1 19 20 package org.openide.util.lookup; 21 22 import org.netbeans.junit.NbTestCase; 23 import org.netbeans.junit.NbTestSuite; 24 25 import org.openide.util.Lookup; 26 27 28 32 public class SimpleProxyLookupSpeedIssue42244Test extends NbTestCase { 33 34 public SimpleProxyLookupSpeedIssue42244Test (String name) { 35 super (name); 36 } 37 38 41 public static void main(String [] args) { 42 junit.textui.TestRunner.run(new NbTestSuite (SimpleProxyLookupSpeedIssue42244Test.class)); 43 } 44 45 public void testCompareTheSpeed () { 46 String content1 = "String1"; 47 String content2 = "String2"; 48 49 Lookup fixed1 = Lookups.singleton(content1); 50 Lookup fixed2 = Lookups.singleton(content2); 51 52 53 Lookup.Template template = new Lookup.Template(String .class); 54 55 MyProvider provider = new MyProvider(); 56 provider.setLookup(fixed1); 57 58 Lookup top = Lookups.proxy(provider); 59 60 Lookup.Result r0 = top.lookup(template); 61 r0.allInstances(); 62 63 long time = System.currentTimeMillis(); 64 top.lookup(template).allInstances(); 65 long withOneResult = System.currentTimeMillis() - time; 66 67 68 java.util.HashSet results = new java.util.HashSet (); 69 for (int i=0; i<10000; i++) { 70 Lookup.Result res = top.lookup (template); 71 results.add (res); 72 res.allInstances(); 73 } 74 75 provider.setLookup(fixed2); 76 77 time = System.currentTimeMillis(); 78 top.lookup(template).allInstances(); 79 long withManyResults = System.currentTimeMillis() - time; 80 81 if (withManyResults < 10) { 83 withManyResults = 10; 84 } 85 if (withOneResult < 10) { 86 withOneResult = 10; 87 } 88 89 if (withManyResults >= 10 * withOneResult) { 90 fail ("With many results the test runs too long.\n With many: " + withManyResults + "\n With one : " + withOneResult); 91 } 92 } 93 94 private static class MyProvider implements Lookup.Provider { 95 private Lookup lookup; 96 public Lookup getLookup() { 97 return lookup; 98 } 99 100 void setLookup(Lookup lookup) { 101 this.lookup = lookup; 102 } 103 } 104 105 } 106 | Popular Tags |