< prev index next >

src/com/sun/javatest/TestResult.java

Print this page
rev 145 : 7902237: Fixing raw use of parameterized class
Reviewed-by: jjg


 933         // avoid creating output (which will cause observer messages)
 934         // before the createdSection has been notified
 935         section.createOutput(TestResult.MESSAGE_OUTPUT_NAME);
 936 
 937         return section;
 938     }
 939 
 940 
 941     /**
 942      * Set the environment used by this test. When the test is run,
 943      * those entries in the environment that are referenced are noted;
 944      * those entries will be recorded here in the test result object.
 945      * @param environment the test environment used by this test.
 946      * @see #getEnvironment
 947      */
 948     public synchronized void setEnvironment(TestEnvironment environment) {
 949         if (!isMutable()) {
 950             throw new IllegalStateException(
 951                         "This TestResult is no longer mutable!");
 952         }
 953         for (Iterator i = environment.elementsUsed().iterator(); i.hasNext(); ) {
 954             TestEnvironment.Element elem = (TestEnvironment.Element) (i.next());
 955             // this is stunningly inefficient and should be fixed
 956             env = PropertyArray.put(env, elem.getKey(), elem.getValue());
 957         }
 958     }
 959 
 960     /**
 961      * Set the result of this test.  This action makes this object immutable.
 962      * If a result comparison is needed, it will be done in here.
 963      * @param stat A status object representing the outcome of the test
 964      * @see #getStatus
 965      */
 966     public synchronized void setStatus(Status stat) {
 967         if (!isMutable()) {
 968             throw new IllegalStateException(
 969                         "This TestResult is no longer mutable!");
 970         }
 971 
 972         if (stat == null) {
 973             throw new IllegalArgumentException(
 974                         "TestResult status cannot be set to null!");


1284             case '/':
1285                 break stripExtn;
1286             }
1287         }
1288 
1289         // add in uniquifying id if
1290         if (testId != null) {
1291             sb.append('_');
1292             sb.append(testId);
1293         }
1294 
1295         sb.append(EXTN);
1296 
1297         return sb.toString();
1298     }
1299 
1300     /**
1301      * Get the keys of the properties that this object has stored.
1302      * @return the keys of the properties that this object has stored
1303      */
1304     public synchronized Enumeration getPropertyNames() {
1305         return PropertyArray.enumerate(props);
1306     }
1307 
1308     /**
1309      * Get the value of a property of this test result.
1310      *
1311      * @param name The name of the property to be retrieved.
1312      * @return The value corresponding to the property name, null if not
1313      *          found.
1314      * @throws TestResult.Fault if there is a problem
1315      *          recreating data from the results file.
1316      */
1317     public synchronized String getProperty(String name)
1318             throws Fault {
1319         if (props == null) {
1320             // reconstitute properties
1321             // this may result in a Fault, which is okay
1322             reload();
1323         }
1324 
1325         return PropertyArray.get(props, name);
1326     }
1327 
1328     /**
1329      * Get a copy of the environment that this object has stored.
1330      * @return a copy of the environment that this object has stored
1331      * @throws TestResult.Fault if there is a problem
1332      *          recreating data from the results file.
1333      * @see #setEnvironment
1334      */
1335     public synchronized Map getEnvironment() throws Fault {
1336         if (env == null) {
1337             // reconstitute environment
1338             // this may result in a Fault, which is okay
1339             reload();
1340         }
1341         return PropertyArray.getProperties(env);
1342     }
1343 
1344     /**
1345      * Get the parent node in the test result table that
1346      * contains this test result object.
1347      * @return the parent node in the test result table that
1348      * contains this test result object.
1349      */
1350     public TestResultTable.TreeNode getParent() {
1351         return parent;
1352     }
1353 
1354 
1355     /**


1965 
1966     private long computeChecksum() {
1967         long cs = 0;
1968         cs = cs * 37 + computeChecksum(desc);
1969         // in JT2.1.1a, environment was not included in checksum,
1970         // so allow that for backward compatibility
1971         String jtv = PropertyArray.get(props, VERSION);
1972         if (env != null) {
1973             if (jtv == null || !jtv.equals("JT_2.1.1a"))
1974                 cs = cs * 37 + computeChecksum(env);
1975         }
1976         cs = cs * 37 + computeChecksum(props);
1977         if (sections != null)
1978             cs = cs * 37 + computeChecksum(sections);
1979         cs = cs * 37 + execStatus.getType() + computeChecksum(execStatus.getReason());
1980         return Math.abs(cs);  // ensure +ve, to avoid sign issues!
1981     }
1982 
1983     private static long computeChecksum(TestDescription td) {
1984         long cs = 0;
1985         for (Iterator i = td.getParameterKeys(); i.hasNext(); ) {
1986             // don't rely on enumeration in a particular order
1987             // so simply add the checksum products together
1988             String key = (String) (i.next());
1989             cs += computeChecksum(key) * computeChecksum(td.getParameter(key));
1990         }
1991         return cs;
1992     }
1993 
1994     private static long computeChecksum(Section[] sections) {
1995         long cs = sections.length;
1996         for (int i = 0; i < sections.length; i++) {
1997             cs = cs * 37 + computeChecksum(sections[i]);
1998         }
1999         return cs;
2000     }
2001 
2002     private static long computeChecksum(Section s) {
2003         long cs = computeChecksum(s.getTitle());
2004         String[] names = s.getOutputNames();
2005         for (int i = 0; i <names.length; i++) {
2006             cs = cs * 37 + computeChecksum(names[i]);
2007             cs = cs * 37 + computeChecksum(s.getOutput(names[i]));
2008         }


2540         for (location = 0; location < sections.length; location++) {
2541             if (sections[location].getTitle().equals(name)) {
2542                 // found
2543                 break;
2544             }
2545         }   // for
2546 
2547         // loop exited because of counter, not a hit
2548         if (location == sections.length) {
2549             location = -1;
2550         }
2551 
2552         return location;
2553     }
2554 
2555     private void addToShrinkList() {
2556         synchronized (shrinkList) {
2557             // if this object is in the list; remove it;
2558             // if there are dead weak refs, remove them
2559             for (Iterator<WeakReference<TestResult>> iter = shrinkList.iterator(); iter.hasNext(); ) {
2560                 WeakReference wref = iter.next();
2561                 Object o = wref.get();
2562                 if (o == null || o == this)
2563                     iter.remove();
2564             }
2565             while (shrinkList.size() >= maxShrinkListSize) {
2566                 WeakReference wref = shrinkList.removeFirst();
2567                 TestResult tr = (TestResult) (wref.get());
2568                 if (tr != null)
2569                     tr.shrink();
2570             }
2571             shrinkList.addLast(new WeakReference<>(this));
2572         }
2573     }
2574 
2575     /**
2576      * Tells the object that it can optimize itself for a small memory footprint.
2577      * Doing this may sacrifice performance when accessing object data.  This
2578      * only works on results that are immutable.
2579      */
2580     private synchronized void shrink() {
2581         if (isMutable()) {
2582             throw new IllegalStateException("Can't shrink a mutable test result!");
2583         }
2584 
2585         // Should ensure we have a resultsFile.
2586         sections = null;
2587 




 933         // avoid creating output (which will cause observer messages)
 934         // before the createdSection has been notified
 935         section.createOutput(TestResult.MESSAGE_OUTPUT_NAME);
 936 
 937         return section;
 938     }
 939 
 940 
 941     /**
 942      * Set the environment used by this test. When the test is run,
 943      * those entries in the environment that are referenced are noted;
 944      * those entries will be recorded here in the test result object.
 945      * @param environment the test environment used by this test.
 946      * @see #getEnvironment
 947      */
 948     public synchronized void setEnvironment(TestEnvironment environment) {
 949         if (!isMutable()) {
 950             throw new IllegalStateException(
 951                         "This TestResult is no longer mutable!");
 952         }
 953         for (Iterator<TestEnvironment.Element> i = environment.elementsUsed().iterator(); i.hasNext(); ) {
 954             TestEnvironment.Element elem = i.next();
 955             // this is stunningly inefficient and should be fixed
 956             env = PropertyArray.put(env, elem.getKey(), elem.getValue());
 957         }
 958     }
 959 
 960     /**
 961      * Set the result of this test.  This action makes this object immutable.
 962      * If a result comparison is needed, it will be done in here.
 963      * @param stat A status object representing the outcome of the test
 964      * @see #getStatus
 965      */
 966     public synchronized void setStatus(Status stat) {
 967         if (!isMutable()) {
 968             throw new IllegalStateException(
 969                         "This TestResult is no longer mutable!");
 970         }
 971 
 972         if (stat == null) {
 973             throw new IllegalArgumentException(
 974                         "TestResult status cannot be set to null!");


1284             case '/':
1285                 break stripExtn;
1286             }
1287         }
1288 
1289         // add in uniquifying id if
1290         if (testId != null) {
1291             sb.append('_');
1292             sb.append(testId);
1293         }
1294 
1295         sb.append(EXTN);
1296 
1297         return sb.toString();
1298     }
1299 
1300     /**
1301      * Get the keys of the properties that this object has stored.
1302      * @return the keys of the properties that this object has stored
1303      */
1304     public synchronized Enumeration<String> getPropertyNames() {
1305         return PropertyArray.enumerate(props);
1306     }
1307 
1308     /**
1309      * Get the value of a property of this test result.
1310      *
1311      * @param name The name of the property to be retrieved.
1312      * @return The value corresponding to the property name, null if not
1313      *          found.
1314      * @throws TestResult.Fault if there is a problem
1315      *          recreating data from the results file.
1316      */
1317     public synchronized String getProperty(String name)
1318             throws Fault {
1319         if (props == null) {
1320             // reconstitute properties
1321             // this may result in a Fault, which is okay
1322             reload();
1323         }
1324 
1325         return PropertyArray.get(props, name);
1326     }
1327 
1328     /**
1329      * Get a copy of the environment that this object has stored.
1330      * @return a copy of the environment that this object has stored
1331      * @throws TestResult.Fault if there is a problem
1332      *          recreating data from the results file.
1333      * @see #setEnvironment
1334      */
1335     public synchronized Map<String, String> getEnvironment() throws Fault {
1336         if (env == null) {
1337             // reconstitute environment
1338             // this may result in a Fault, which is okay
1339             reload();
1340         }
1341         return PropertyArray.getProperties(env);
1342     }
1343 
1344     /**
1345      * Get the parent node in the test result table that
1346      * contains this test result object.
1347      * @return the parent node in the test result table that
1348      * contains this test result object.
1349      */
1350     public TestResultTable.TreeNode getParent() {
1351         return parent;
1352     }
1353 
1354 
1355     /**


1965 
1966     private long computeChecksum() {
1967         long cs = 0;
1968         cs = cs * 37 + computeChecksum(desc);
1969         // in JT2.1.1a, environment was not included in checksum,
1970         // so allow that for backward compatibility
1971         String jtv = PropertyArray.get(props, VERSION);
1972         if (env != null) {
1973             if (jtv == null || !jtv.equals("JT_2.1.1a"))
1974                 cs = cs * 37 + computeChecksum(env);
1975         }
1976         cs = cs * 37 + computeChecksum(props);
1977         if (sections != null)
1978             cs = cs * 37 + computeChecksum(sections);
1979         cs = cs * 37 + execStatus.getType() + computeChecksum(execStatus.getReason());
1980         return Math.abs(cs);  // ensure +ve, to avoid sign issues!
1981     }
1982 
1983     private static long computeChecksum(TestDescription td) {
1984         long cs = 0;
1985         for (Iterator<String> i = td.getParameterKeys(); i.hasNext(); ) {
1986             // don't rely on enumeration in a particular order
1987             // so simply add the checksum products together
1988             String key = (i.next());
1989             cs += computeChecksum(key) * computeChecksum(td.getParameter(key));
1990         }
1991         return cs;
1992     }
1993 
1994     private static long computeChecksum(Section[] sections) {
1995         long cs = sections.length;
1996         for (int i = 0; i < sections.length; i++) {
1997             cs = cs * 37 + computeChecksum(sections[i]);
1998         }
1999         return cs;
2000     }
2001 
2002     private static long computeChecksum(Section s) {
2003         long cs = computeChecksum(s.getTitle());
2004         String[] names = s.getOutputNames();
2005         for (int i = 0; i <names.length; i++) {
2006             cs = cs * 37 + computeChecksum(names[i]);
2007             cs = cs * 37 + computeChecksum(s.getOutput(names[i]));
2008         }


2540         for (location = 0; location < sections.length; location++) {
2541             if (sections[location].getTitle().equals(name)) {
2542                 // found
2543                 break;
2544             }
2545         }   // for
2546 
2547         // loop exited because of counter, not a hit
2548         if (location == sections.length) {
2549             location = -1;
2550         }
2551 
2552         return location;
2553     }
2554 
2555     private void addToShrinkList() {
2556         synchronized (shrinkList) {
2557             // if this object is in the list; remove it;
2558             // if there are dead weak refs, remove them
2559             for (Iterator<WeakReference<TestResult>> iter = shrinkList.iterator(); iter.hasNext(); ) {
2560                 WeakReference<TestResult> wref = iter.next();
2561                 Object o = wref.get();
2562                 if (o == null || o == this)
2563                     iter.remove();
2564             }
2565             while (shrinkList.size() >= maxShrinkListSize) {
2566                 WeakReference<TestResult> wref = shrinkList.removeFirst();
2567                 TestResult tr = wref.get();
2568                 if (tr != null)
2569                     tr.shrink();
2570             }
2571             shrinkList.addLast(new WeakReference<>(this));
2572         }
2573     }
2574 
2575     /**
2576      * Tells the object that it can optimize itself for a small memory footprint.
2577      * Doing this may sacrifice performance when accessing object data.  This
2578      * only works on results that are immutable.
2579      */
2580     private synchronized void shrink() {
2581         if (isMutable()) {
2582             throw new IllegalStateException("Can't shrink a mutable test result!");
2583         }
2584 
2585         // Should ensure we have a resultsFile.
2586         sections = null;
2587 


< prev index next >