Hi,

The attached patch fixes a previous contribution of mine to
transparently get resources either from the filesystem or from a jar
file. When accessing a file from a jar that files gets decompressed in a
temporary location which name was generated at random for each call.
This however did not work with all the tests - NavTest.testCache(), for
example, expected a file name not to change between calls. The proposed
implementation will stick to the same temporary file name as long as the
requested file name (and path) stays the same, thereby fixing NavTest
when run from a jar.

Regards,
-- 
Silvio Moioli
SUSE LINUX Products GmbH
Maxfeldstraße 5, 90409 Nürnberg Germany


>From cc7e859551be0997f7d45ff6ad3257d91a15d4a6 Mon Sep 17 00:00:00 2001
From: Silvio Moioli <smoi...@suse.de>
Date: Wed, 11 Sep 2013 15:48:57 +0200
Subject: [PATCH 21/22] TestUtils: use the same temporary filename when the
 same file is requested

Fixes NavTest.testCache() when running from a jar.
---
 java/code/src/com/redhat/rhn/testing/TestUtils.java | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/java/code/src/com/redhat/rhn/testing/TestUtils.java b/java/code/src/com/redhat/rhn/testing/TestUtils.java
index 24a8250..0d83f40 100644
--- a/java/code/src/com/redhat/rhn/testing/TestUtils.java
+++ b/java/code/src/com/redhat/rhn/testing/TestUtils.java
@@ -68,6 +68,9 @@ import java.util.Map;
 
 public class TestUtils {
 
+    /** Prefix for temporary file names created by this class. */
+    private static String filePrefix = TestUtils.randomString();
+
     // static class
     private TestUtils() { }
 
@@ -93,8 +96,7 @@ public class TestUtils {
         URL ret = clazz.getResource(path);
 
         if (ret.toString().contains("!")) { // file is from an archive
-            String tempPath =
-                    "/tmp/" + System.currentTimeMillis() + TestUtils.randomString();
+            String tempPath = "/tmp/" + filePrefix + ret.hashCode();
             InputStream input = clazz.getResourceAsStream(path);
 
             OutputStream output = new FileOutputStream(tempPath);
-- 
1.8.1.4



_______________________________________________
Spacewalk-devel mailing list
Spacewalk-devel@redhat.com
https://www.redhat.com/mailman/listinfo/spacewalk-devel

Reply via email to