[jboss-cvs] JBossAS SVN: r67244 - in projects/microcontainer/trunk/container/src: tests/org/jboss/test/metadata/retrieval/support and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Nov 19 08:13:10 EST 2007
Author: alesj
Date: 2007-11-19 08:13:10 -0500 (Mon, 19 Nov 2007)
New Revision: 67244
Added:
projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/retrieval/support/TestAnnotated.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/retrieval/support/TestAnnotation.java
Modified:
projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/context/CachingMetaDataContext.java
projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/retrieval/test/EmptyTestCase.java
Log:
JBMICROCONT-218 tests.
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/context/CachingMetaDataContext.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/context/CachingMetaDataContext.java 2007-11-19 10:37:14 UTC (rev 67243)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/context/CachingMetaDataContext.java 2007-11-19 13:13:10 UTC (rev 67244)
@@ -25,6 +25,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import org.jboss.metadata.spi.context.MetaDataContext;
@@ -66,12 +67,9 @@
/** Is empty */
private volatile Boolean empty;
- /** The scoped context */
- private volatile MetaDataRetrieval scopedContext;
+ /** Scoped contexs */
+ private volatile Map<ScopeLevel, MetaDataRetrieval> cachedScopedRetrievals;
- /** Was scoped context check done */
- private volatile boolean scopedRetrievalExecuted;
-
/**
* Create a new CachingMetaDataContext.
*
@@ -241,6 +239,7 @@
super.append(retrieval);
cachedComponents = null;
empty = null;
+ cachedScopedRetrievals = null;
}
public void prepend(MetaDataRetrieval retrieval)
@@ -248,6 +247,7 @@
super.prepend(retrieval);
cachedComponents = null;
empty = null;
+ cachedScopedRetrievals = null;
}
public void remove(MetaDataRetrieval retrieval)
@@ -255,6 +255,7 @@
super.remove(retrieval);
cachedComponents = null;
empty = null;
+ cachedScopedRetrievals = null;
}
public MetaDataRetrieval getComponentMetaDataRetrieval(Signature signature)
@@ -290,11 +291,29 @@
public MetaDataRetrieval getScopedRetrieval(ScopeLevel level)
{
- if (cachedComponents == null || scopedRetrievalExecuted == false)
+ boolean update = cachedScopedRetrievals == null || cachedScopedRetrievals.keySet().contains(level) == false;
+ return getCachedScopedRetrieval(level, update);
+ }
+
+ /**
+ * Get the cached scoped retireval.
+ *
+ * @param level the scope level
+ * @param update update current cache
+ * @return cached retrieval or null
+ */
+ protected MetaDataRetrieval getCachedScopedRetrieval(ScopeLevel level, boolean update)
+ {
+ if (cachedScopedRetrievals == null)
{
- scopedRetrievalExecuted = true;
- scopedContext = super.getScopedRetrieval(level);
+ cachedScopedRetrievals = new HashMap<ScopeLevel, MetaDataRetrieval>();
}
- return scopedContext;
+ MetaDataRetrieval retrieval = cachedScopedRetrievals.get(level);
+ if (update)
+ {
+ retrieval = super.getScopedRetrieval(level);
+ cachedScopedRetrievals.put(level, retrieval);
+ }
+ return retrieval;
}
}
Added: projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/retrieval/support/TestAnnotated.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/retrieval/support/TestAnnotated.java (rev 0)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/retrieval/support/TestAnnotated.java 2007-11-19 13:13:10 UTC (rev 67244)
@@ -0,0 +1,30 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.metadata.retrieval.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at TestAnnotation
+public class TestAnnotated
+{
+}
Added: projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/retrieval/support/TestAnnotation.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/retrieval/support/TestAnnotation.java (rev 0)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/retrieval/support/TestAnnotation.java 2007-11-19 13:13:10 UTC (rev 67244)
@@ -0,0 +1,36 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.metadata.retrieval.support;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({ElementType.TYPE, ElementType.METHOD})
+public @interface TestAnnotation
+{
+}
Modified: projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/retrieval/test/EmptyTestCase.java
===================================================================
--- projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/retrieval/test/EmptyTestCase.java 2007-11-19 10:37:14 UTC (rev 67243)
+++ projects/microcontainer/trunk/container/src/tests/org/jboss/test/metadata/retrieval/test/EmptyTestCase.java 2007-11-19 13:13:10 UTC (rev 67244)
@@ -21,7 +21,23 @@
*/
package org.jboss.test.metadata.retrieval.test;
+import java.lang.annotation.Annotation;
+import java.util.Arrays;
+
+import org.jboss.metadata.plugins.context.AbstractMetaDataContext;
+import org.jboss.metadata.plugins.context.CachingMetaDataContext;
+import org.jboss.metadata.plugins.loader.SimpleMetaDataLoader;
+import org.jboss.metadata.plugins.loader.memory.MemoryMetaDataLoader;
+import org.jboss.metadata.plugins.loader.reflection.AnnotatedElementMetaDataLoader;
+import org.jboss.metadata.plugins.loader.thread.ThreadLocalMetaDataLoader;
+import org.jboss.metadata.spi.context.MetaDataContext;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.ScopeLevel;
+import org.jboss.metadata.spi.scope.ScopeKey;
import org.jboss.test.metadata.AbstractMetaDataTest;
+import org.jboss.test.metadata.retrieval.support.TestAnnotated;
+import org.jboss.test.metadata.retrieval.support.TestAnnotation;
/**
* EmptyTestCase.
@@ -36,13 +52,182 @@
super(name);
}
+ protected MetaDataRetrieval[] getSimpleMetaDataRetrievals()
+ {
+ MetaDataRetrieval[] retrievals = new MetaDataRetrieval[4];
+ retrievals[0] = new AnnotatedElementMetaDataLoader(getClass());
+ retrievals[1] = new MemoryMetaDataLoader();
+ retrievals[2] = new SimpleMetaDataLoader(new Annotation[]{});
+ retrievals[3] = ThreadLocalMetaDataLoader.INSTANCE;
+ return retrievals;
+ }
+
+ protected MetaDataContext[] getMetaDataContexts(
+ MetaDataRetrieval[] retrievals,
+ MetaDataContext emptyContext,
+ MetaDataRetrieval emptyRetrieval)
+ {
+ boolean mix = emptyContext != null && emptyRetrieval != null;
+ int size = mix ? 10 : 6;
+ MetaDataContext[] contexts = new MetaDataContext[size];
+ contexts[0] = new AbstractMetaDataContext(retrievals[0]);
+ contexts[1] = new AbstractMetaDataContext(contexts[0], retrievals[1]);
+ contexts[2] = new AbstractMetaDataContext(contexts[0], Arrays.asList(retrievals));
+ contexts[3] = new CachingMetaDataContext(contexts[0]);
+ contexts[4] = new CachingMetaDataContext(contexts[0], retrievals[1]);
+ contexts[5] = new CachingMetaDataContext(contexts[0], Arrays.asList(retrievals));
+ if (mix)
+ {
+ contexts[6] = new AbstractMetaDataContext(emptyContext, retrievals[0]);
+ contexts[7] = new AbstractMetaDataContext(contexts[0], emptyRetrieval);
+ contexts[8] = new CachingMetaDataContext(emptyContext, retrievals[0]);
+ contexts[9] = new CachingMetaDataContext(contexts[0], emptyRetrieval);
+ }
+ return contexts;
+ }
+
+ protected TestAnnotation getAnnotation()
+ {
+ return new TestAnnotation()
+ {
+ public Class<? extends Annotation> annotationType()
+ {
+ return TestAnnotation.class;
+ }
+ };
+ }
+
public void testEmpty() throws Exception
{
- // todo
+ MetaDataRetrieval[] retrievals = getSimpleMetaDataRetrievals();
+ for(MetaDataRetrieval rdr : retrievals)
+ assertTrue(rdr.toString(), rdr.isEmpty());
+
+ MetaDataContext[] contexts = getMetaDataContexts(retrievals, null, null);
+ for(MetaDataRetrieval rdr : contexts)
+ assertTrue(rdr.toString(), rdr.isEmpty());
+
+ retrievals[0] = new AnnotatedElementMetaDataLoader(TestAnnotated.class);
+ MemoryMetaDataLoader mmdl = new MemoryMetaDataLoader();
+ TestAnnotation annotation = getAnnotation();
+ mmdl.addMetaData(annotation, TestAnnotation.class);
+ retrievals[1] = mmdl;
+ retrievals[2] = new SimpleMetaDataLoader(new Annotation[]{annotation});
+ ThreadLocalMetaDataLoader tlmdl = ThreadLocalMetaDataLoader.INSTANCE;
+ tlmdl.addAnnotation(annotation);
+ retrievals[3] = tlmdl;
+ for(MetaDataRetrieval rdr : retrievals)
+ assertFalse(rdr.toString(), rdr.isEmpty());
+
+ mmdl.removeMetaData(TestAnnotation.class);
+ assertTrue(mmdl.toString(), mmdl.isEmpty());
+ tlmdl.removeAnnotation(TestAnnotation.class);
+ assertTrue(tlmdl.toString(), tlmdl.isEmpty());
+
+ MetaDataRetrieval emptyRetrieval = new MemoryMetaDataLoader();
+ MetaDataContext emptyContext = new AbstractMetaDataContext(emptyRetrieval);
+
+ contexts = getMetaDataContexts(retrievals, emptyContext, emptyRetrieval);
+ for(MetaDataRetrieval rdr : contexts)
+ assertFalse(rdr.toString(), rdr.isEmpty());
}
public void testScopedRetrieval() throws Exception
{
- // todo
+ ScopeLevel[] commonLevels = new ScopeLevel[]
+ {
+ CommonLevels.DOMAIN,
+ CommonLevels.CLUSTER,
+ CommonLevels.MACHINE,
+ CommonLevels.NODE,
+ CommonLevels.JVM,
+ CommonLevels.SERVER,
+ CommonLevels.SUBSYSTEM,
+ CommonLevels.APPLICATION,
+ CommonLevels.DEPLOYMENT,
+ CommonLevels.CLASS,
+ CommonLevels.INSTANCE,
+ CommonLevels.JOINPOINT,
+ CommonLevels.JOINPOINT_OVERRIDE,
+ CommonLevels.THREAD,
+ CommonLevels.WORK,
+ CommonLevels.REQUEST,
+ };
+
+ MetaDataRetrieval[] retrievals = getSimpleMetaDataRetrievals();
+ for(ScopeLevel level : commonLevels)
+ {
+ for(MetaDataRetrieval rdr : retrievals)
+ {
+ MetaDataRetrieval sr = rdr.getScopedRetrieval(level);
+ if (sr != null)
+ assertSame(sr, rdr);
+ }
+ }
+
+ MetaDataRetrieval aemdl = new AnnotatedElementMetaDataLoader(TestAnnotated.class);
+ assertNotNull(aemdl.getScopedRetrieval(CommonLevels.CLASS));
+ assertNull(aemdl.getScopedRetrieval(CommonLevels.INSTANCE));
+
+ for(ScopeLevel level : commonLevels)
+ {
+ MemoryMetaDataLoader mmdl = new MemoryMetaDataLoader(new ScopeKey(level, "123"));
+ for(ScopeLevel sl : commonLevels)
+ {
+ if (sl != level)
+ {
+ assertNull(mmdl.getScopedRetrieval(sl));
+ }
+ }
+ }
+
+ MetaDataContext parent = new AbstractMetaDataContext(retrievals[0]);
+ MetaDataContext context = new AbstractMetaDataContext(parent, aemdl);
+ assertSame(aemdl, context.getScopedRetrieval(CommonLevels.CLASS));
+
+ MetaDataRetrieval mmdl = new MemoryMetaDataLoader(new ScopeKey(CommonLevels.INSTANCE, "123"));
+
+ context = new AbstractMetaDataContext(parent, mmdl);
+ assertSame(mmdl, context.getScopedRetrieval(CommonLevels.INSTANCE));
+
+ context = new AbstractMetaDataContext(parent, Arrays.asList(aemdl, mmdl));
+ assertNotNull(context.getScopedRetrieval(CommonLevels.CLASS));
+ assertNotNull(context.getScopedRetrieval(CommonLevels.INSTANCE));
+
+ context = new CachingMetaDataContext(parent, Arrays.asList(aemdl, mmdl, aemdl, mmdl));
+ assertNotNull(context.getScopedRetrieval(CommonLevels.CLASS));
+ assertNotNull(context.getScopedRetrieval(CommonLevels.INSTANCE));
+
+ MetaDataRetrieval expected1 = context.getScopedRetrieval(CommonLevels.CLASS);
+ assertSame(expected1, context.getScopedRetrieval(CommonLevels.CLASS));
+ MetaDataRetrieval expected2 = context.getScopedRetrieval(CommonLevels.INSTANCE);
+ assertSame(expected2, context.getScopedRetrieval(CommonLevels.INSTANCE));
+
+ context.append(ThreadLocalMetaDataLoader.INSTANCE);
+ context.remove(ThreadLocalMetaDataLoader.INSTANCE);
+
+ assertNotNull(context.getScopedRetrieval(CommonLevels.CLASS));
+ assertNotNull(context.getScopedRetrieval(CommonLevels.INSTANCE));
+ assertNotSame(expected1, context.getScopedRetrieval(CommonLevels.CLASS));
+ assertNotSame(expected2, context.getScopedRetrieval(CommonLevels.INSTANCE));
+
+ context = new AbstractMetaDataContext(parent, Arrays.asList(mmdl, mmdl));
+ assertNull(context.getScopedRetrieval(CommonLevels.CLASS));
+ context = new AbstractMetaDataContext(parent, Arrays.asList(aemdl, aemdl));
+ assertNull(context.getScopedRetrieval(CommonLevels.INSTANCE));
+
+ parent = new AbstractMetaDataContext(new MemoryMetaDataLoader(new ScopeKey(CommonLevels.INSTANCE, "0123")));
+ context = new CachingMetaDataContext(parent, Arrays.asList(mmdl, mmdl));
+ assertNull(context.getScopedRetrieval(CommonLevels.CLASS));
+ MetaDataRetrieval scr1 = context.getScopedRetrieval(CommonLevels.INSTANCE);
+ assertNotNull(scr1);
+ assertTrue(scr1.isEmpty());
+
+ parent = new AbstractMetaDataContext(new MemoryMetaDataLoader(new ScopeKey(CommonLevels.CLASS, "0123")));
+ context = new CachingMetaDataContext(parent, Arrays.asList(aemdl, aemdl));
+ assertNull(context.getScopedRetrieval(CommonLevels.INSTANCE));
+ MetaDataRetrieval scr2 = context.getScopedRetrieval(CommonLevels.CLASS);
+ assertNotNull(scr2);
+ assertFalse(scr2.isEmpty());
}
}
More information about the jboss-cvs-commits
mailing list