[rfc][icedtea-web] fixing CacheReproducerTest and improving VersionedJarTest

Jiri Vanek jvanek at redhat.com
Tue Mar 3 15:49:28 UTC 2015


On 03/03/2015 04:25 PM, Jie Kang wrote:
>
>
> ----- Original Message -----
>> snip
>>> However. Later I noted that recently_used file is not handled via
>>> PahsAndFiles.
>>>
>>> I moved it here, which needed some more changes - like make it properly
>>> testable and so get rid of
>>> this untestable ENUM and replace it by getter singleton with possibility to
>>> make testable instance.
>>>
>>> I agree that this patch was written in rush, and needs  proper review.
>>> J.
>
> Hello,
>
> Nits below:
>
> +    public final PropertiesFile cacheOrder;
> +    public final File cacheOrderParent;
> +    public final File cacheOrderFile;
>
> The name 'cacheOrder' isn't very descriptive. Can you change it to recentlyUsedFile or something similar?
>
> Can you use getters instead of public variables? Then you can reduce it to just one variable.
>

Done. Now the patch is a bit dirty, but it was good change.

> e.g.
>
> private final PropertiesFile recentlyUsed;
>
> public PropertiesFile getProperties() { ... }
> public File getParentFile() { ... }
> public File getFile() { ... }
>
> Names of function are up to you.
>
> +    private static final CacheLRUWrapper clw = new CacheLRUWrapper(new File(System.getProperty("java.io.tmpdir"),cacheIndexFileName));
>
> Space after the comma: ("java.io.tmpdir"),cacheIndexFileName
done
>
> Also, this will set the cache to the tmp directory. Can you create a tempcache directory inside tmp and then use that instead?

I hate how this is done in java... anyweay done.
>
> It's a little bit cleaner. And please make sure the tests clean themselves up afterwards using file.deleteOnExit(), etc.
done
>
> +    private static final int PERNAMENT_FILES = 1;
>
> s/PERNAMENT/PERMANENT

Thanx!
>
>
> Side note:
>
> I don't see how this is more testable than before. enum singleton and class singleton are equally testable to me. Can you provide any examples?
>

To beable to create fake testable instance.
>
> Regards,
>
>>
>> ping
>>
>

-------------- next part --------------
diff -r d0e2beda96ca ChangeLog
--- a/ChangeLog	Tue Mar 03 15:33:27 2015 +0100
+++ b/ChangeLog	Tue Mar 03 16:48:10 2015 +0100
@@ -1,4 +1,9 @@
-2015-02-27  Jiri Vanek  <jvanek at redhat.com>
+2015-03-03  Jiri Vanek  <jvanek at redhat.com>
+
+	Changing enum CacheLRUWrapper singleton to instantiatible one
+	* netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java
+
+2015-03-03  Jiri Vanek  <jvanek at redhat.com>
 
 	Fixed CacheReproducerTest and VersionedJarTest tests
 	* tests/reproducers/signed/CacheReproducer/testcases/CacheReproducerTest.java:
diff -r d0e2beda96ca netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java
--- a/netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java	Tue Mar 03 15:33:27 2015 +0100
+++ b/netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java	Tue Mar 03 16:48:10 2015 +0100
@@ -49,8 +49,7 @@
 import java.util.Map.Entry;
 import java.util.Set;
 
-import net.sourceforge.jnlp.config.DeploymentConfiguration;
-import net.sourceforge.jnlp.runtime.JNLPRuntime;
+import net.sourceforge.jnlp.config.PathsAndFiles;
 import net.sourceforge.jnlp.util.FileUtils;
 import net.sourceforge.jnlp.util.PropertiesFile;
 import net.sourceforge.jnlp.util.logging.OutputController;
@@ -59,33 +58,44 @@
  * This class helps maintain the ordering of most recently use items across
  * multiple jvm instances.
  * 
- * @author <a href="mailto:Andrew%20Su%20<asu at redhat.com>">Andrew Su (asu at redhat.com</a>, <a href="mailto:Andrew%20Su%20<andrew.su at utoronto.ca>">andrew.su at utoronto.ca)</a>
- * 
  */
-public enum CacheLRUWrapper {
-    INSTANCE;
-
-    /* location of cache directory */
-    private final String setCachePath = JNLPRuntime.getConfiguration().getProperty(DeploymentConfiguration.KEY_USER_CACHE_DIR);
-    String cacheDir = new File(setCachePath != null ? setCachePath : System.getProperty("java.io.tmpdir")).getPath();
-
+public class CacheLRUWrapper {
+    
     /*
      * back-end of how LRU is implemented This file is to keep track of the most
      * recently used items. The items are to be kept with key = (current time
      * accessed) followed by folder of item. value = path to file.
      */
+    
+    private final PropertiesFile recentlyUsedPropertiesFile;
+    private final File cacheDir;
+    private final File recentlyUsedFile;
 
-    public static final String CACHE_INDEX_FILE_NAME = "recently_used";
-
-    PropertiesFile cacheOrder = new PropertiesFile(
-            new File(cacheDir + File.separator + CACHE_INDEX_FILE_NAME));
-
-    private CacheLRUWrapper() {
-        File f = cacheOrder.getStoreFile();
-        if (!f.exists()) {
+    public CacheLRUWrapper() {
+     this(PathsAndFiles.RECENTLY_USED_FILE.getFile());
+    }
+    
+    /**
+     * testing constructor
+     * @param recentlyUsed file to be used as recently_used file. its parent will be used as cache dir
+     */
+    public CacheLRUWrapper(final File recentlyUsed) {
+        this(recentlyUsed, recentlyUsed.getParentFile());
+    }
+    
+    /**
+     * testing constructor
+     * @param recentlyUsed file to be used as recently_used file
+     * @param cacheDir dir with cache
+     */
+    public CacheLRUWrapper(final File recentlyUsed, final File cacheDir) {
+        recentlyUsedPropertiesFile = new PropertiesFile(recentlyUsed);
+        recentlyUsedFile = recentlyUsed;
+        this.cacheDir = cacheDir;
+        if (!recentlyUsed.exists()) {
             try {
-                FileUtils.createParentDir(f);
-                FileUtils.createRestrictedFile(f, true);
+                FileUtils.createParentDir(recentlyUsed);
+                FileUtils.createRestrictedFile(recentlyUsed, true);
             } catch (IOException e) {
                 OutputController.getLogger().log(OutputController.Level.ERROR_ALL, e);
             }
@@ -98,14 +108,39 @@
      * @return an instance of the policy
      */
     public static CacheLRUWrapper getInstance() {
-        return INSTANCE;
+        return  CacheLRUWrapperHolder.INSTANCE;
     }
 
     /**
+     * @return the recentlyUsedPropertiesFile
+     */
+    public PropertiesFile getRecentlyUsedPropertiesFile() {
+        return recentlyUsedPropertiesFile;
+    }
+
+    /**
+     * @return the cacheDir
+     */
+    public File getCacheDir() {
+        return cacheDir;
+    }
+
+    /**
+     * @return the recentlyUsedFile
+     */
+    public File getRecentlyUsedFile() {
+        return recentlyUsedFile;
+    }
+    
+   private static class CacheLRUWrapperHolder{
+       private static final CacheLRUWrapper INSTANCE = new CacheLRUWrapper();
+   }
+
+    /**
      * Update map for keeping track of recently used items.
      */
     public synchronized void load() {
-        boolean loaded = cacheOrder.load();
+        boolean loaded = getRecentlyUsedPropertiesFile().load();
         /* 
          * clean up possibly corrupted entries
          */
@@ -118,13 +153,13 @@
     }
 
     /**
-     * check content of cacheOrder and remove invalid/corrupt entries
+     * check content of recentlyUsedPropertiesFile and remove invalid/corrupt entries
      *
      * @return true, if cache was corrupted and affected entry removed
      */
     private boolean checkData () {
         boolean modified = false;
-        Set<Entry<Object, Object>> q = cacheOrder.entrySet();
+        Set<Entry<Object, Object>> q = getRecentlyUsedPropertiesFile().entrySet();
         for (Iterator<Entry<Object, Object>> it = q.iterator(); it.hasNext();) {
             Entry<Object, Object> currentEntry = it.next();
 
@@ -144,7 +179,7 @@
 
             // 2. check path format - does the path look correct?
             if (path != null) {
-                if (path.indexOf(cacheDir) < 0) {
+                if (!path.contains(cacheDir.getAbsolutePath())) {
                     it.remove();
                     modified = true;
                 }
@@ -161,8 +196,8 @@
      * Write file to disk.
      */
     public synchronized boolean store() {
-        if (cacheOrder.isHeldByCurrentThread()) {
-            cacheOrder.store();
+        if (getRecentlyUsedPropertiesFile().isHeldByCurrentThread()) {
+            getRecentlyUsedPropertiesFile().store();
             return true;
         }
         return false;
@@ -176,10 +211,10 @@
      * @return true if we successfully added to map, false otherwise.
      */
     public synchronized boolean addEntry(String key, String path) {
-        if (cacheOrder.containsKey(key)) {
+        if (getRecentlyUsedPropertiesFile().containsKey(key)) {
             return false;
         }
-        cacheOrder.setProperty(key, path);
+        getRecentlyUsedPropertiesFile().setProperty(key, path);
         return true;
     }
 
@@ -190,15 +225,15 @@
      * @return true if we successfully removed key from map, false otherwise.
      */
     public synchronized boolean removeEntry(String key) {
-        if (!cacheOrder.containsKey(key)) {
+        if (!recentlyUsedPropertiesFile.containsKey(key)) {
             return false;
         }
-        cacheOrder.remove(key);
+        getRecentlyUsedPropertiesFile().remove(key);
         return true;
     }
 
     private String getIdForCacheFolder(String folder) {
-        int len = cacheDir.length();
+        int len = getCacheDir().getAbsolutePath().length();
         int index = folder.indexOf(File.separatorChar, len + 1);
         return folder.substring(len + 1, index);
     }
@@ -210,12 +245,12 @@
      * @return true if we successfully updated value, false otherwise.
      */
     public synchronized boolean updateEntry(String oldKey) {
-        if (!cacheOrder.containsKey(oldKey)) return false;
-        String value = cacheOrder.getProperty(oldKey);
+        if (!recentlyUsedPropertiesFile.containsKey(oldKey)) return false;
+        String value = getRecentlyUsedPropertiesFile().getProperty(oldKey);
         String folder = getIdForCacheFolder(value);
 
-        cacheOrder.remove(oldKey);
-        cacheOrder.setProperty(Long.toString(System.currentTimeMillis()) + "," + folder, value);
+        getRecentlyUsedPropertiesFile().remove(oldKey);
+        getRecentlyUsedPropertiesFile().setProperty(Long.toString(System.currentTimeMillis()) + "," + folder, value);
         return true;
     }
 
@@ -230,7 +265,7 @@
     public synchronized List<Entry<String, String>> getLRUSortedEntries() {
         List<Entry<String, String>> entries = new ArrayList<>();
 
-        for (Entry e : cacheOrder.entrySet()) {
+        for (Entry e : getRecentlyUsedPropertiesFile().entrySet()) {
             entries.add(new AbstractMap.SimpleImmutableEntry<String, String>(e));
         }
 
@@ -252,14 +287,14 @@
      * Lock the file to have exclusive access.
      */
     public synchronized void lock() {
-        cacheOrder.lock();
+        getRecentlyUsedPropertiesFile().lock();
     }
 
     /**
      * Unlock the file.
      */
     public synchronized void unlock() {
-        cacheOrder.unlock();
+        getRecentlyUsedPropertiesFile().unlock();
     }
 
     /**
@@ -269,15 +304,15 @@
      * @return value of given key, null otherwise.
      */
     public synchronized String getValue(String key) {
-        return cacheOrder.getProperty(key);
+        return getRecentlyUsedPropertiesFile().getProperty(key);
     }
 
     public synchronized boolean containsKey(String key) {
-        return cacheOrder.containsKey(key);
+        return getRecentlyUsedPropertiesFile().containsKey(key);
     }
 
     public synchronized boolean containsValue(String value) {
-        return cacheOrder.containsValue(value);
+        return getRecentlyUsedPropertiesFile().containsValue(value);
     }
 
     /**
@@ -292,6 +327,6 @@
     }
 
     void clearLRUSortedEntries() {
-        cacheOrder.clear();
+        getRecentlyUsedPropertiesFile().clear();
     }
 }
diff -r d0e2beda96ca netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java
--- a/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java	Tue Mar 03 15:33:27 2015 +0100
+++ b/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java	Tue Mar 03 16:48:10 2015 +0100
@@ -43,7 +43,6 @@
 import javax.naming.ConfigurationException;
 import javax.swing.JOptionPane;
 
-import net.sourceforge.jnlp.cache.CacheLRUWrapper;
 import net.sourceforge.jnlp.runtime.JNLPRuntime;
 import net.sourceforge.jnlp.util.FileUtils;
 import net.sourceforge.jnlp.util.logging.OutputController;
@@ -757,12 +756,12 @@
             errors += moveLegacyToCurrent(legacySecurity, currentSecurity);
 
             String legacyCache = LEGACY_USER_HOME + File.separator + "cache";
-            String currentCache = Defaults.getDefaults().get(DeploymentConfiguration.KEY_USER_CACHE_DIR).getDefaultValue();
+            String currentCache = PathsAndFiles.CACHE_DIR.getFullPath();
             errors += moveLegacyToCurrent(legacyCache, currentCache);
-            OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, "Adapting " + CacheLRUWrapper.CACHE_INDEX_FILE_NAME + " to new destination");
+            OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, "Adapting " + PathsAndFiles.CACHE_INDEX_FILE_NAME + " to new destination");
             //replace all legacyCache by currentCache in new recently_used
             try {
-                File f = new File(currentCache, CacheLRUWrapper.CACHE_INDEX_FILE_NAME);
+                File f = PathsAndFiles.RECENTLY_USED_FILE.getFile();
                 String s = FileUtils.loadFileAsString(f);
                 s = s.replace(legacyCache, currentCache);
                 FileUtils.saveFile(s, f);
diff -r d0e2beda96ca netx/net/sourceforge/jnlp/config/PathsAndFiles.java
--- a/netx/net/sourceforge/jnlp/config/PathsAndFiles.java	Tue Mar 03 15:33:27 2015 +0100
+++ b/netx/net/sourceforge/jnlp/config/PathsAndFiles.java	Tue Mar 03 16:48:10 2015 +0100
@@ -68,6 +68,7 @@
     private static final String USER_PROP = "user.name";
     private static final String VARIABLE = JNLPRuntime.isWindows() ? "%" : "$";
     public static final String ICEDTEA_SO = "IcedTeaPlugin.so";
+    public static final String CACHE_INDEX_FILE_NAME = "recently_used";
 
     static {
         String configHome = System.getProperty(HOME_PROP) + File.separator + ".config";
@@ -115,6 +116,7 @@
     public static final InfrastructureFileDescriptor OPERA_32 = new InfrastructureFileDescriptor(ICEDTEA_SO, "/usr/lib/opera/plugins/", "",  "FILEopera32", Target.PLUGIN);
     
     public static final InfrastructureFileDescriptor CACHE_DIR = new ItwCacheFileDescriptor("cache", "FILEcache", Target.JAVAWS, Target.ITWEB_SETTINGS);
+    public static final InfrastructureFileDescriptor RECENTLY_USED_FILE = new ItwCacheFileDescriptor(CACHE_INDEX_FILE_NAME, CACHE_DIR.getFile().getName(), "FILErecentlyUsed", Target.JAVAWS, Target.ITWEB_SETTINGS);
     public static final InfrastructureFileDescriptor PCACHE_DIR = new ItwCacheFileDescriptor("pcache", "FILEappdata", Target.JAVAWS, Target.ITWEB_SETTINGS);
     public static final InfrastructureFileDescriptor LOG_DIR = new ItwConfigFileDescriptor("log", "FILElogs", Target.JAVAWS, Target.ITWEB_SETTINGS);
     //javaws is saving here, itweb-settings may modify them
diff -r d0e2beda96ca netx/net/sourceforge/jnlp/controlpanel/CachePane.java
--- a/netx/net/sourceforge/jnlp/controlpanel/CachePane.java	Tue Mar 03 15:33:27 2015 +0100
+++ b/netx/net/sourceforge/jnlp/controlpanel/CachePane.java	Tue Mar 03 16:48:10 2015 +0100
@@ -58,10 +58,10 @@
 import javax.swing.table.TableRowSorter;
 
 import net.sourceforge.jnlp.cache.CacheDirectory;
-import net.sourceforge.jnlp.cache.CacheLRUWrapper;
 import net.sourceforge.jnlp.cache.CacheUtil;
 import net.sourceforge.jnlp.cache.DirectoryNode;
 import net.sourceforge.jnlp.config.DeploymentConfiguration;
+import net.sourceforge.jnlp.config.PathsAndFiles;
 import net.sourceforge.jnlp.runtime.Translator;
 import net.sourceforge.jnlp.util.FileUtils;
 import net.sourceforge.jnlp.util.PropertiesFile;
@@ -71,7 +71,7 @@
 public class CachePane extends JPanel {
     JDialog parent;
     DeploymentConfiguration config;
-    private String location;
+    private final String location;
     private JComponent defaultFocusComponent;
     DirectoryNode root;
     String[] columns = {
@@ -323,7 +323,7 @@
             }
 
             private void updateRecentlyUsed(File f) {
-                File recentlyUsedFile = new File(location + File.separator + CacheLRUWrapper.CACHE_INDEX_FILE_NAME);
+                File recentlyUsedFile = PathsAndFiles.RECENTLY_USED_FILE.getFile();
                 PropertiesFile pf = new PropertiesFile(recentlyUsedFile);
                 pf.load();
                 Enumeration<Object> en = pf.keys();
diff -r d0e2beda96ca netx/net/sourceforge/jnlp/resources/Messages.properties
--- a/netx/net/sourceforge/jnlp/resources/Messages.properties	Tue Mar 03 15:33:27 2015 +0100
+++ b/netx/net/sourceforge/jnlp/resources/Messages.properties	Tue Mar 03 16:48:10 2015 +0100
@@ -1034,6 +1034,7 @@
 FILEopera32=Location of plugin library for global purposes  on opera compliant browser, 32b systems.
     
 FILEcache=Contains cached runtime entries (and my be changed by you).
+FILErecentlyUsed=Additional information about items in cache
 FILEappdata=Contains saved application data.
 FILElogs=(may be set to different location by you) contains file log files (if enabled).  itw-cplugin-date_time.log for native part of plugin, itw-javantx-date_time.log for everything else.
 FILEicons=Location where icons of javaws applications desktp/menu launchers icons are stored
diff -r d0e2beda96ca tests/netx/unit/net/sourceforge/jnlp/cache/CacheLRUWrapperTest.java
--- a/tests/netx/unit/net/sourceforge/jnlp/cache/CacheLRUWrapperTest.java	Tue Mar 03 15:33:27 2015 +0100
+++ b/tests/netx/unit/net/sourceforge/jnlp/cache/CacheLRUWrapperTest.java	Tue Mar 03 16:48:10 2015 +0100
@@ -46,42 +46,43 @@
 import java.io.PrintStream;
 import java.util.concurrent.CountDownLatch;
 
-import org.junit.AfterClass;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 
 import net.sourceforge.jnlp.ServerAccess;
+import net.sourceforge.jnlp.config.PathsAndFiles;
 import net.sourceforge.jnlp.util.CacheTestUtils;
-import net.sourceforge.jnlp.util.PropertiesFile;
 
 public class CacheLRUWrapperTest {
 
-    private static final CacheLRUWrapper clw = CacheLRUWrapper.getInstance();
-    private static String cacheDirBackup;
-    private static PropertiesFile cacheOrderBackup;
     // does no DeploymentConfiguration exist for this file name? 
-    private static  final String cacheIndexFileName = CacheLRUWrapper.CACHE_INDEX_FILE_NAME + "_testing";
+    private static final String cacheIndexFileName = PathsAndFiles.CACHE_INDEX_FILE_NAME + "_testing";
+    private static final File javaTmp = new File(System.getProperty("java.io.tmpdir"));
+    private static final File tmpCache;
+
+    static {
+        try {
+            tmpCache = File.createTempFile("itw", "CacheLRUWrapperTest", javaTmp);
+            tmpCache.delete();
+            tmpCache.mkdir();
+            tmpCache.deleteOnExit();
+            if (!tmpCache.isDirectory()) {
+                throw new IOException("Unsuccess to create tmpfile, remove it and createsame directory");
+            }
+
+        } catch (IOException ex) {
+            throw new RuntimeException(ex);
+        }
+
+    }
+    private static final CacheLRUWrapper clw = new CacheLRUWrapper(new File(tmpCache, cacheIndexFileName));
 
     private final int noEntriesCacheFile = 1000;
 
     private ByteArrayOutputStream baos;
     private PrintStream out;
 
-    @BeforeClass
-    static public void setupJNLPRuntimeConfig() {
-        cacheDirBackup = clw.cacheDir;
-        cacheOrderBackup = clw.cacheOrder;
-        clw.cacheDir=System.getProperty("java.io.tmpdir");
-        clw.cacheOrder = new PropertiesFile( new File(clw.cacheDir + File.separator + cacheIndexFileName));
-        
-    }
-    
-    @AfterClass
-    static public void restoreJNLPRuntimeConfig() {
-        clw.cacheDir = cacheDirBackup;
-        clw.cacheOrder = cacheOrderBackup;
-    }
+
 
     @Before
     public void setup() {
@@ -92,7 +93,7 @@
     @Test
     public void testLoadStoreTiming() throws InterruptedException {
 
-        final File cacheIndexFile = new File(clw.cacheDir + File.separator + cacheIndexFileName);
+        final File cacheIndexFile = clw.getRecentlyUsedFile();
         cacheIndexFile.delete();
         try {
             int noLoops = 1000;
@@ -133,7 +134,7 @@
 
         // fill cache index file
         for(int i = 0; i < noEntries; i++) {
-            String path = clw.cacheDir + File.separatorChar + i + File.separatorChar + "test" + i + ".jar";
+            String path = clw.getRecentlyUsedFile().getAbsolutePath() + File.separatorChar + i + File.separatorChar + "test" + i + ".jar";
             String key = clw.generateKey(path);
             clw.addEntry(key, path);
         }
@@ -142,7 +143,7 @@
     @Test
     public void testModTimestampAfterStore() throws InterruptedException {
 
-        final File cacheIndexFile = new File(clw.cacheDir + File.separator + cacheIndexFileName);
+        final File cacheIndexFile = clw.getRecentlyUsedFile();
         cacheIndexFile.delete();
         try{
         clw.lock();
@@ -214,7 +215,7 @@
     public void testLock() throws IOException {
         try {
             clw.lock();
-            assertTrue(clw.cacheOrder.isHeldByCurrentThread());
+            assertTrue(clw.getRecentlyUsedPropertiesFile().isHeldByCurrentThread());
         } finally {
             clw.unlock();
         }
@@ -227,7 +228,7 @@
         } finally {
             clw.unlock();
         }
-        assertTrue(!clw.cacheOrder.isHeldByCurrentThread());
+        assertTrue(!clw.getRecentlyUsedPropertiesFile().isHeldByCurrentThread());
     }
 
     @Test(timeout = 2000l)
@@ -280,7 +281,7 @@
         @Override
         public void run() {
             try {
-                clw.cacheOrder.tryLock();
+                clw.getRecentlyUsedPropertiesFile().tryLock();
                 boolean result = clw.store();
                 synchronized (out) {
                     out.println(String.valueOf(result));
diff -r d0e2beda96ca tests/reproducers/signed/CacheReproducer/testcases/CacheReproducerTest.java
--- a/tests/reproducers/signed/CacheReproducer/testcases/CacheReproducerTest.java	Tue Mar 03 15:33:27 2015 +0100
+++ b/tests/reproducers/signed/CacheReproducer/testcases/CacheReproducerTest.java	Tue Mar 03 16:48:10 2015 +0100
@@ -44,13 +44,11 @@
 import java.io.UnsupportedEncodingException;
 import java.util.Arrays;
 import java.util.List;
-import java.util.PropertyResourceBundle;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import net.sourceforge.jnlp.ServerAccess;
 import net.sourceforge.jnlp.ProcessResult;
 import net.sourceforge.jnlp.annotations.KnownToFail;
-import net.sourceforge.jnlp.config.Defaults;
 import net.sourceforge.jnlp.config.PathsAndFiles;
 import net.sourceforge.jnlp.tools.MessageProperties;
 import org.junit.AfterClass;
@@ -70,13 +68,12 @@
     private static final Pattern corruptPatern = Pattern.compile(corruptRegex);
     private static final String corruptString = "156dsf1562kd5";
 
-    private static final File icedteaCache = new File(PathsAndFiles.USER_CACHE_HOME, "cache");
-    private static final File icedteaCacheFile = new File(icedteaCache, "recently_used");
-    private static final File netxLock = new File(System.getProperty("java.io.tmpdir"),
-            System.getProperty("user.name") + File.separator +
-            "netx" + File.separator +
-            "locks" + File.separator +
-            "netx_running");
+    //recently.used is always here
+    private static final int PERMANENT_FILES = 1;
+    
+    private static final File icedteaCache = PathsAndFiles.CACHE_DIR.getFile();
+    private static final File icedteaCacheFile = PathsAndFiles.RECENTLY_USED_FILE.getFile();
+    private static final File netxLock = PathsAndFiles.MAIN_LOCK.getFile();
 
     String testS = "#netx file\n"
                + "#Mon Dec 12 16:20:46 CET 2011\n"
@@ -142,7 +139,7 @@
     private void assertCacheIsNotEmpty() {
         Assert.assertTrue("icedtea cache " + icedteaCache.getAbsolutePath() + " should exist some any run", icedteaCache.exists());
         Assert.assertTrue("icedtea cache file " + icedteaCacheFile.getAbsolutePath() + " should exist some any run", icedteaCacheFile.exists());
-        Assert.assertTrue("icedtea cache file " + icedteaCacheFile.getAbsolutePath() + " should not be empty", icedteaCacheFile.length() > 0);
+        Assert.assertTrue("icedtea cache file " + icedteaCacheFile.getAbsolutePath() + " should not be empty", icedteaCacheFile.length() > PERMANENT_FILES);
     }
 
     /**
@@ -346,7 +343,7 @@
 
         }
         tryToClearcache();
-        Assert.assertTrue("icedtea cache " + icedteaCache.getAbsolutePath() + " should be empty after clearing", icedteaCache.listFiles().length == 0);
+        Assert.assertTrue("icedtea cache " + icedteaCache.getAbsolutePath() + " should be empty after clearing", icedteaCache.listFiles().length == PERMANENT_FILES);
     }
 
     private static String loadFile(File f) throws FileNotFoundException, UnsupportedEncodingException, IOException {


More information about the distro-pkg-dev mailing list