Skip to content

Commit

Permalink
add special mode for unittests where we cannot use OSGi
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-confino committed Dec 3, 2024
1 parent 6a34cff commit 889df79
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
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;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -31,7 +35,6 @@
import com.ibm.websphere.ras.TraceComponent;
import com.ibm.websphere.ras.annotation.Trivial;
import com.ibm.ws.annocache.service.internal.AnnotationCacheServiceImpl_Logging;
import com.ibm.ws.annocache.targets.cache.internal.TargetCacheImpl_DataApps;
import com.ibm.ws.kernel.service.util.ServiceCaller;
import com.ibm.wsspi.anno.classsource.ClassSource_ScanCounts;
import com.ibm.wsspi.anno.classsource.ClassSource_ScanCounts.ResultField;
Expand Down Expand Up @@ -105,7 +108,15 @@ public ClassSourceImpl_Aggregate(
this.applicationName = applicationName;
this.moduleName = moduleName;
this.moduleCategoryName = moduleCategoryName;
this.applicationKey = keyServiceServiceCaller.run((AnnotationService_KeyService ks) -> ks.getKeyForApp(applicationName)).get();

Properties props = System.getProperties();
String inUnitTest = props.getProperty("running.unit.test");
if (inUnitTest != null && inUnitTest.equals("true")) {
this.applicationKey = new SoftReference<AppKey>(new AppKey(applicationName));
} else {
AppKey appKey = keyServiceServiceCaller.run((AnnotationService_KeyService ks) -> ks.getKeyForApp(applicationName)).get();
this.applicationKey = new WeakReference<AppKey>(appKey);
}

//

Expand Down Expand Up @@ -187,7 +198,7 @@ protected String internClassName(String className, boolean doForce) {
protected final String applicationName;
protected final String moduleName;
protected final String moduleCategoryName;
protected final AppKey applicationKey;
protected final Reference<AppKey> applicationKey;

/**
* <p>Answer the name of the application of this class source.</p>
Expand All @@ -208,7 +219,7 @@ public String getApplicationName() {
@Override
@Trivial
public AppKey getApplicationKey() {
return applicationKey;
return applicationKey.get();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 889df79

Please sign in to comment.