[jboss-cvs] JBossAS SVN: r87410 - in projects/vfs/trunk/src: test/java/org/jboss/test/virtual/test and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 16 08:05:17 EDT 2009


Author: alesj
Date: 2009-04-16 08:05:17 -0400 (Thu, 16 Apr 2009)
New Revision: 87410

Modified:
   projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java
   projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JarOverrideTestCase.java
Log:
[JBAS-6715]; fix map entry override.

Modified: projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java	2009-04-16 11:05:27 UTC (rev 87409)
+++ projects/vfs/trunk/src/main/java/org/jboss/virtual/plugins/context/AbstractVFSContext.java	2009-04-16 12:05:17 UTC (rev 87410)
@@ -27,11 +27,13 @@
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
-import java.util.concurrent.ConcurrentHashMap;
+import java.util.HashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.jboss.logging.Logger;
 import org.jboss.virtual.VFS;
@@ -72,7 +74,7 @@
    private VirtualFileHandler rootPeer;
 
    /** The temp handlers */
-   private Map<String, TempInfo> tempInfos = new ConcurrentHashMap<String, TempInfo>();
+   private final Map<String, List<TempInfo>> tempInfos = Collections.synchronizedMap(new HashMap<String, List<TempInfo>>());
 
    /**
     * Create a new AbstractVFSContext.
@@ -378,39 +380,72 @@
 
    public void addTempInfo(TempInfo tempInfo)
    {
-      tempInfos.put(tempInfo.getPath(), tempInfo);
+      String key = tempInfo.getPath();
+      List<TempInfo> list;
+      synchronized (tempInfos)
+      {
+         list = tempInfos.get(key);
+         if (list == null)
+         {
+            list = new CopyOnWriteArrayList<TempInfo>();
+            tempInfos.put(key, list);
+         }
+      }
+      list.add(tempInfo);
    }
 
    public TempInfo getTempInfo(String path)
    {
-      TempInfo tempInfo = tempInfos.get(path);
-      if (tempInfo == null)
+      TempInfo result = null;
+      List<TempInfo> list = tempInfos.get(path);
+      if (list != null && list.isEmpty())
       {
-         return null;
+         Iterator<TempInfo> iter = list.iterator();
+         while(iter.hasNext())
+         {
+            TempInfo ti = iter.next();
+            if (ti.isValid() == false)
+            {
+               iter.remove();
+            }
+            else if (result == null)
+            {
+               result = ti;
+            }
+         }
       }
-      else if (tempInfo.isValid() == false)
-      {
-         tempInfos.remove(path);
-         return null;
-      }
-      else
-      {
-         return tempInfo;
-      }
+      return result;
    }
 
    public Iterable<TempInfo> getTempInfos()
    {
       Map<String, TempInfo> result = new TreeMap<String, TempInfo>();
-      Iterator<Map.Entry<String, TempInfo>> iter = tempInfos.entrySet().iterator();
+      Iterator<Map.Entry<String, List<TempInfo>>> iter = tempInfos.entrySet().iterator();
       while(iter.hasNext())
       {
-         Map.Entry<String, TempInfo> entry = iter.next();
-         if (entry.getValue().isValid())
+         Map.Entry<String, List<TempInfo>> entry = iter.next();
+         List<TempInfo> list = entry.getValue();
+         if (list != null && list.isEmpty() == false)
          {
-            result.put(entry.getKey(), entry.getValue());
+            Iterator<TempInfo> listIter = list.iterator();
+            while(listIter.hasNext())
+            {
+               TempInfo ti = listIter.next();
+               if (ti.isValid())
+               {
+                  String path = ti.getPath();
+                  if (result.containsKey(path) == false)
+                  {
+                     result.put(path, ti);
+                  }
+               }
+               else
+               {
+                  listIter.remove();
+               }
+            }
          }
-         else
+         if (list == null || list.isEmpty())
          {
             iter.remove();
          }
@@ -423,27 +458,33 @@
       boolean trace = log.isTraceEnabled();
       List<String> info = null;
 
-      Iterator<Map.Entry<String, TempInfo>> iter = tempInfos.entrySet().iterator();
+      Iterator<Map.Entry<String, List<TempInfo>>> iter = tempInfos.entrySet().iterator();
       while (iter.hasNext())
       {
-         Map.Entry<String, TempInfo> entry = iter.next();
+         Map.Entry<String, List<TempInfo>> entry = iter.next();
          if (entry.getKey().startsWith(path))
          {
+            List<TempInfo> list = entry.getValue();
+
             if (trace)
             {
                if (info == null)
                   info = new ArrayList<String>();
-               
-               info.add(entry.getValue().toString());
+
+               if (list != null && list.isEmpty() == false)
+                  info.add(list.toString());
             }
-            
-            try
+
+            for (TempInfo ti : list)
             {
-               entry.getValue().cleanup();
+               try
+               {
+                  ti.cleanup();                  
+               }
+               catch (Throwable ignored)
+               {
+               }
             }
-            catch (Throwable ignored)
-            {
-            }
             iter.remove();
          }
       }

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JarOverrideTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JarOverrideTestCase.java	2009-04-16 11:05:27 UTC (rev 87409)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/virtual/test/JarOverrideTestCase.java	2009-04-16 12:05:17 UTC (rev 87410)
@@ -21,7 +21,16 @@
  */
 package org.jboss.test.virtual.test;
 
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileInputStream;
+import java.net.URI;
+import java.net.URL;
+
 import junit.framework.Test;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
 
 /**
  * Test jar file override.
@@ -32,21 +41,56 @@
 {
    public JarOverrideTestCase(String name)
    {
-      super(name, false, false);
+      super(name, true, false);
    }
 
-   protected JarOverrideTestCase(String name, boolean forceCopy)
-   {
-      super(name, forceCopy, false);
-   }
-
    public static Test suite()
    {
       return suite(JarOverrideTestCase.class);
    }
 
+   @SuppressWarnings("deprecation")
    public void testOverride() throws Exception
    {
-      // TODO - cleanup, override code
+      URL topURL = getResource("/vfs/test/nested/nested.jar");
+      URI topURI = topURL.toURI();
+      File source = new File(topURI);
+
+      // create temp so we can override it, not worrying about other tests
+      File tempDest = File.createTempFile("nested", "-temp.jar");
+      tempDest.deleteOnExit();
+      copy(source, tempDest);
+      long ts1 = tempDest.lastModified();
+
+      VirtualFile nested = VFS.createNewRoot(tempDest.toURI());
+      VirtualFile complex = nested.findChild("complex.jar");
+      // mock war unjaring
+      VirtualFile unjared = VFSUtils.unjar(complex);
+      assertNotSame(complex, unjared);
+
+      // override
+      copy(source, tempDest);
+      long ts2 = tempDest.lastModified();
+      // was it really overridden
+      assertFalse(ts1 == ts2);
+
+      // undeploy
+      nested.cleanup();
+      complex.cleanup();
+      // check we really deleted unjared temp
+      URL url = VFSUtils.getRealURL(unjared);
+      File unjaredTemp = new File(url.toURI());
+      assertFalse(unjaredTemp.exists());
+
+      // 2nd pass to mock
+      complex = nested.findChild("complex.jar");
+      // this is where JBAS-6715 fails
+      unjared = VFSUtils.unjar(complex);
+      assertNotSame(complex, unjared);
    }
+
+   protected void copy(File source, File dest) throws Exception
+   {
+      VFSUtils.copyStreamAndClose(new FileInputStream(source), new FileOutputStream(dest));
+   }
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list