From 68ae73a84d8cb20785d5076dfc3819ea9abe51ca Mon Sep 17 00:00:00 2001 From: Benjamin Confino Date: Wed, 4 Dec 2024 21:34:17 +0000 Subject: [PATCH] add special mode for unittests where we cannot use OSGi --- .../classsource/internal/ClassSourceImpl_Aggregate.java | 8 ++++++-- .../ws/annocache/test/info/InfoStore_Internals_Test.java | 4 ++++ .../ibm/ws/annocache/test/info/InfoStore_TestBase.java | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/classsource/internal/ClassSourceImpl_Aggregate.java b/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/classsource/internal/ClassSourceImpl_Aggregate.java index 7faa260b371..1cb1bd80ff0 100644 --- a/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/classsource/internal/ClassSourceImpl_Aggregate.java +++ b/dev/com.ibm.ws.anno/src/com/ibm/ws/annocache/classsource/internal/ClassSourceImpl_Aggregate.java @@ -16,6 +16,8 @@ import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.ref.Reference; +import java.lang.ref.SoftReference; import java.lang.ref.WeakReference; import java.text.MessageFormat; import java.util.ArrayList; @@ -111,7 +113,9 @@ public ClassSourceImpl_Aggregate( Properties props = System.getProperties(); String inUnitTest = props.getProperty("running.unit.test"); - if (applicationName != ClassSource_Factory.UNNAMED_APP) { + if (inUnitTest != null && inUnitTest.equals("true")) { + this.applicationKey = new SoftReference(new AppKey(applicationName)); + } else if (applicationName != ClassSource_Factory.UNNAMED_APP) { AppKey appKey = keyServiceServiceCaller.run((AnnotationService_KeyService ks) -> ks.getKeyForApp(applicationName)).get(); this.applicationKey = new WeakReference(appKey); } else { @@ -198,7 +202,7 @@ protected String internClassName(String className, boolean doForce) { protected final String applicationName; protected final String moduleName; protected final String moduleCategoryName; - protected final WeakReference applicationKey; + protected final Reference applicationKey; /** *

Answer the name of the application of this class source.

diff --git a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/info/InfoStore_Internals_Test.java b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/info/InfoStore_Internals_Test.java index dbe150cafd0..f678719506f 100644 --- a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/info/InfoStore_Internals_Test.java +++ b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/info/InfoStore_Internals_Test.java @@ -15,6 +15,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.Map; +import java.util.Properties; import java.util.Set; import java.util.logging.Logger; @@ -70,6 +71,9 @@ public class InfoStore_Internals_Test { public static void setup() throws ClassSource_Exception, InfoStoreException { UtilImpl_Factory utilImplFactory = new UtilImpl_Factory(); ClassSourceImpl_Factory factory = new ClassSourceImpl_Factory(utilImplFactory); + + Properties props = System.getProperties(); + props.setProperty("running.unit.test", "true"); ClassSourceImpl_Aggregate useRootClassSource = factory.createAggregateClassSource("TestEar", "TestMod", ClassSource_Factory.UNSET_CATEGORY_NAME, factory.createOptions() ); diff --git a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/info/InfoStore_TestBase.java b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/info/InfoStore_TestBase.java index cbf548ced34..1dba39c07ad 100644 --- a/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/info/InfoStore_TestBase.java +++ b/dev/com.ibm.ws.anno/test/com/ibm/ws/annocache/test/info/InfoStore_TestBase.java @@ -17,6 +17,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.Properties; import org.junit.AfterClass; import org.junit.Assert; @@ -99,6 +100,9 @@ private static void setUpClassSource() throws Exception { protected static ClassSourceImpl_Aggregate createClassSource() throws Exception { ClassSourceImpl_Factory factory = getClassSourceFactory(); + + Properties props = System.getProperties(); + props.setProperty("running.unit.test", "true"); ClassSourceImpl_Aggregate useRootClassSource = factory.createAggregateClassSource(