[jboss-cvs] JBossAS SVN: r89974 - in projects/jboss-deployers/trunk: deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jun 8 13:26:10 EDT 2009
Author: alesj
Date: 2009-06-08 13:26:10 -0400 (Mon, 08 Jun 2009)
New Revision: 89974
Added:
projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractStructureCacheTest.java
projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/DefaultStructureCacheTestCase.java
projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/TreeStructureCacheTestCase.java
Modified:
projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/TreeStructureCache.java
Log:
[JBDEPLOY-190]; fix tree structure cache.
Add cache tests.
TODO; why just null check in TSC::getChildrenNames doesn't work in Demos?
Added: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractStructureCacheTest.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractStructureCacheTest.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/AbstractStructureCacheTest.java 2009-06-08 17:26:10 UTC (rev 89974)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.deployers.vfs.structure.modified.test;
+
+import java.util.Set;
+
+import org.jboss.deployers.vfs.spi.structure.modified.StructureCache;
+import org.jboss.test.deployers.BootstrapDeployersTest;
+
+/**
+ * AbstractStructureCache tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractStructureCacheTest extends BootstrapDeployersTest
+{
+ protected AbstractStructureCacheTest(String name)
+ {
+ super(name);
+ }
+
+ protected abstract StructureCache<Long> createStructureCache();
+
+ public void testCacheBehavior() throws Throwable
+ {
+ StructureCache<Long> cache = createStructureCache();
+
+ cache.initializeCache("acme1.jar");
+
+ Set<String> leaves = cache.getLeaves("acme1.jar/META-INF");
+ assertNull(leaves);
+
+ cache.putCacheValue("acme1.jar/META-INF/a.xml", 1l);
+ cache.putCacheValue("acme1.jar/META-INF/b.xml", 2l);
+
+ cache.putCacheValue("acme1.jar/META-INF", 1l);
+
+ leaves = cache.getLeaves("acme1.jar/META-INF");
+ assertEquals(2, leaves.size());
+
+ assertNotNull(cache.getCacheValue("acme1.jar/META-INF/a.xml"));
+ assertNotNull(cache.getCacheValue("acme1.jar/META-INF/b.xml"));
+ assertNotNull(cache.getCacheValue("acme1.jar/META-INF"));
+
+ leaves = cache.getLeaves("acme1.jar/META-INF");
+ assertEquals(2, leaves.size());
+
+ cache.invalidateCache("acme1.jar");
+ }
+}
\ No newline at end of file
Added: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/DefaultStructureCacheTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/DefaultStructureCacheTestCase.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/DefaultStructureCacheTestCase.java 2009-06-08 17:26:10 UTC (rev 89974)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.deployers.vfs.structure.modified.test;
+
+import org.jboss.deployers.vfs.spi.structure.modified.DefaultStructureCache;
+import org.jboss.deployers.vfs.spi.structure.modified.StructureCache;
+
+/**
+ * DefaultStructureCache tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class DefaultStructureCacheTestCase extends AbstractStructureCacheTest
+{
+ public DefaultStructureCacheTestCase(String name)
+ {
+ super(name);
+ }
+
+ protected StructureCache<Long> createStructureCache()
+ {
+ return new DefaultStructureCache<Long>();
+ }
+}
\ No newline at end of file
Added: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/TreeStructureCacheTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/TreeStructureCacheTestCase.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/structure/modified/test/TreeStructureCacheTestCase.java 2009-06-08 17:26:10 UTC (rev 89974)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.deployers.vfs.structure.modified.test;
+
+import org.jboss.deployers.vfs.spi.structure.modified.StructureCache;
+import org.jboss.deployers.vfs.spi.structure.modified.TreeStructureCache;
+
+/**
+ * TreeStructureCache tests.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class TreeStructureCacheTestCase extends AbstractStructureCacheTest
+{
+ public TreeStructureCacheTestCase(String name)
+ {
+ super(name);
+ }
+
+ protected StructureCache<Long> createStructureCache()
+ {
+ return new TreeStructureCache<Long>();
+ }
+}
Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/TreeStructureCache.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/TreeStructureCache.java 2009-06-08 16:03:02 UTC (rev 89973)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/java/org/jboss/deployers/vfs/spi/structure/modified/TreeStructureCache.java 2009-06-08 17:26:10 UTC (rev 89974)
@@ -24,10 +24,12 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.HashSet;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.jboss.virtual.plugins.vfs.helpers.PathTokenizer;
@@ -69,10 +71,8 @@
public T putCacheValue(String pathName, T value)
{
- Node<T> node = getNode(pathName);
- if (node == null)
- node = initializeNode(pathName);
-
+ // we try to initialize it if it doesn't exist
+ Node<T> node = initializeNode(pathName);
T previous = node.getValue();
node.setValue(value);
return previous;
@@ -180,6 +180,8 @@
*/
private class Node<U>
{
+ private ReadWriteLock lock = new ReentrantReadWriteLock();
+
private String name;
private String fullName;
private Node<U> parent;
@@ -266,13 +268,21 @@
*/
private void addChild(Node<U> node)
{
- if (children == null)
- children = new HashMap<String, Node<U>>();
+ lock.writeLock().lock();
+ try
+ {
+ if (children == null)
+ children = new HashMap<String, Node<U>>();
- children.put(node.getName(), node);
+ children.put(node.getName(), node);
- if (names != null)
- names.add(node.getFullName());
+ if (names != null)
+ names.add(node.getFullName());
+ }
+ finally
+ {
+ lock.writeLock().unlock();
+ }
}
/**
@@ -280,20 +290,28 @@
*
* @param node the child node
*/
- public synchronized void removeChild(Node<U> node)
+ public void removeChild(Node<U> node)
{
- if (children == null)
- return;
-
- children.remove(node.getName());
+ lock.writeLock().lock();
+ try
+ {
+ if (children == null)
+ return;
- if (names != null)
- names.remove(node.getFullName());
+ children.remove(node.getName());
- if (children.isEmpty())
- children = null;
- if (names != null && names.isEmpty())
- names = null;
+ if (names != null)
+ names.remove(node.getFullName());
+
+ if (children.isEmpty())
+ children = null;
+ if (names != null && names.isEmpty())
+ names = null;
+ }
+ finally
+ {
+ lock.writeLock().unlock();
+ }
}
/**
@@ -301,9 +319,17 @@
*/
void clear()
{
- value = null;
- children = null;
- names = null;
+ lock.writeLock().lock();
+ try
+ {
+ value = null;
+ children = null;
+ names = null;
+ }
+ finally
+ {
+ lock.writeLock().unlock();
+ }
}
/**
@@ -314,7 +340,15 @@
*/
public Node<U> getChild(String name)
{
- return (children != null) ? children.get(name) : null;
+ lock.readLock().lock();
+ try
+ {
+ return (children != null) ? children.get(name) : null;
+ }
+ finally
+ {
+ lock.readLock().unlock();
+ }
}
/**
@@ -322,20 +356,29 @@
*
* @return the children names
*/
- public synchronized Set<String> getChildrenNames()
+ public Set<String> getChildrenNames()
{
- if (children == null)
- return Collections.emptySet();
+ lock.writeLock().lock();
+ try
+ {
+ if (children == null)
+ return Collections.emptySet();
- if (names == null)
- {
- names = new HashSet<String>();
- for (Node<U> child : children.values())
+ // TODO; I don't understand how can I get non-null names, but not equal to children
+ if (names == null || (names.size() != children.size()))
{
- names.add(child.getFullName());
+ names = new HashSet<String>();
+ for (Node<U> child : children.values())
+ {
+ names.add(child.getFullName());
+ }
}
+ return names;
}
- return names;
+ finally
+ {
+ lock.writeLock().unlock();
+ }
}
/**
@@ -345,7 +388,21 @@
*/
public Collection<Node<U>> getChildren()
{
- return (children != null) ? children.values() : Collections.<Node<U>>emptySet();
+ lock.readLock().lock();
+ try
+ {
+ return (children != null) ? children.values() : Collections.<Node<U>>emptySet();
+ }
+ finally
+ {
+ lock.readLock().unlock();
+ }
}
+
+ @Override
+ public String toString()
+ {
+ return getFullName();
+ }
}
}
More information about the jboss-cvs-commits
mailing list