Skip to content

Commit

Permalink
#43 managed to reproduce the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
baubakg committed Sep 12, 2023
1 parent 7d41cbd commit 63add73
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 18 deletions.
12 changes: 12 additions & 0 deletions bridgeService-data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@
<properties>
<sonar.skip>true</sonar.skip>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.20.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.20.0</version>
</dependency>
</dependencies>
<parent>
<groupId>com.adobe.campaign.tests.bridge</groupId>
<artifactId>parent</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2022 Adobe
* All Rights Reserved.
*
* NOTICE: Adobe permits you to use, modify, and distribute this file in
* accordance with the terms of the Adobe license agreement accompanying
* it.
*/
package com.adobe.campaign.tests.bridge.testdata.one;


import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Arrays;
import java.util.List;
import java.util.Random;

public class ClassWithLogger {
protected static Logger log = LogManager.getLogger();



private static final List<String> countries = Arrays.asList("AT", "AU",
"CA", "CH", "DE");

private static Random randomGen = new Random();

/**
* A getter for the Language Encodings
* @return
*
public static LanguageEncodings getLanguageEncoding(){
return languageEncoding;
}
*/
public static List<String> getCountries() {
return countries;
}



public static Random getRandomGen() {
return randomGen;
}


/**
* This method returns a random country ISOA2 code.
*
* @return ISOA2 country code
*
* @author lepolles
*/
public static String fetchRandomCountry() {
int l_countryNr = countries.size();

return countries.get(getRandomGen().nextInt(l_countryNr));
}

}
1 change: 1 addition & 0 deletions integroBridgeService/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public enum ConfigValueHandlerIBS {
"IBS.CLASSLOADER.INTEGRITY.MODE","semi-manual", false,
"This value defined the injection mode of packages and classes. We have three modes: automatic, manual, semi-automatic"),*/
INTEGRITY_PACKAGE_INJECTION_MODE(
"IBS.CLASSLOADER.INTEGRITY.MODE","semi-manual", false,
"IBS.CLASSLOADER.INTEGRITY.MODE","automatic", false,
"This value defined the injection mode of packages and classes. We have three modes: automatic, manual, semi-automatic") {
public void activate(String in_value) {
//Use default if value is not in range
if (Arrays.asList("manual","semi-manual").contains(in_value.toLowerCase())) {
if (Arrays.asList("manual","semi-manual","automatic").contains(in_value.toLowerCase())) {
System.setProperty(this.systemName, in_value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ private synchronized Class getClass(String in_classPath) throws ClassNotFoundEx
// is this class already loaded?
Class cls = super.findLoadedClass(in_classPath);
if (cls != null) {
log.debug("Class {} has already been loaded.",in_classPath);
log.trace("Class {} has already been loaded.",in_classPath);
return cls;
} else {
log.debug("Class {} has not been loaded. Loading now.", in_classPath);
log.trace("Class {} has not been loaded. Loading now.", in_classPath);
}


Expand Down Expand Up @@ -90,18 +90,18 @@ private synchronized Class getClass(String in_classPath) throws ClassNotFoundEx
*/
@Override
public Class loadClass(String in_classFullPath) throws ClassNotFoundException {
log.debug("Preparing class {}", in_classFullPath);
log.trace("Preparing class {}", in_classFullPath);

if (ConfigValueHandlerIBS.INTEGRITY_PACKAGE_INJECTION_MODE.is("manual", "semi-manual")) {
if (isClassAmongPackagePaths(in_classFullPath)) {
return getClass(in_classFullPath);
}
}
/* Removing until issue ##5 is resolved
/* Removing until issue #45 is resolved*/
else if (!in_classFullPath.startsWith("java")) {
return getClass(in_classFullPath);
}
*/

return super.loadClass(in_classFullPath);

}
Expand Down
2 changes: 1 addition & 1 deletion integroBridgeService/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<Loggers>
<Root level="DEBUG">
<AppenderRef ref="FILE" level="DEBUG"/>
<AppenderRef ref="STDOUT" level="TRANCE"/>
<AppenderRef ref="STDOUT" level="INFO"/>
<!--You can set ref="STDOUT" level ="DEBUG" to allow all the logs in the console locally-->
</Root>
</Loggers>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
public class E2ETests {
public static final String EndPointURL = "http://localhost:8080/";
private static final int port1 = 1111;
protected static final boolean AUTOMATIC_FLAG = false;
ServerSocket serverSocket1 = null;

@BeforeGroups(groups = "E2E")
Expand Down Expand Up @@ -466,7 +465,7 @@ public void testIssue34Manual() {

}

@Test(groups = "E2E", enabled = AUTOMATIC_FLAG)
@Test(groups = "E2E")
public void testIssue34Automatic() {
//long before = MemoryTools.fetchMemory();
ConfigValueHandlerIBS.INTEGRITY_PACKAGE_INJECTION_MODE.activate("automatic");
Expand Down Expand Up @@ -552,15 +551,23 @@ public void testIntegroIssue() {
JavaCalls l_myJavaCalls = new JavaCalls();

CallContent l_cc = new CallContent();
l_cc.setClassName("com.adobe.campaign.tests.integro.tools.RandomManager");

l_cc.setClassName("com.adobe.campaign.tests.bridge.testdata.one.ClassWithLogger");
l_cc.setMethodName("fetchRandomCountry");

l_myJavaCalls.getCallContent().put("countries", l_cc);


System.out.println(given().body(l_myJavaCalls).post(EndPointURL + "call").then().extract().asPrettyString());

given().body(l_myJavaCalls).post(EndPointURL + "call").then().assertThat().statusCode(500).body("originalException", Matchers.equalTo(
"java.lang.IllegalAccessError")).body("originalMessage", Matchers.equalTo("class jdk.internal.reflect.ConstructorAccessorImpl loaded by com.adobe.campaign.tests.bridge.service.IntegroBridgeClassLoader @2a8337ef cannot access jdk/internal/reflect superclass jdk.internal.reflect.MagicAccessorImpl"));

given().body(l_myJavaCalls).post(EndPointURL + "call").then().assertThat().statusCode(200).body("returnValues.countries", Matchers.in(
new String[] { "AT", "AU", "CA" , "CH", "DE"}));
}


@AfterGroups(groups = "E2E", alwaysRun = true)
public void tearDown() throws IOException {
ConfigValueHandlerIBS.resetAllValues();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
import com.adobe.campaign.tests.bridge.service.data.MyPropertiesHandler;
import com.adobe.campaign.tests.bridge.service.exceptions.ClassLoaderConflictException;
import com.adobe.campaign.tests.bridge.service.exceptions.IBSConfigurationException;
import com.adobe.campaign.tests.bridge.testdata.issue34.pckg1.CalledClass1;
import com.adobe.campaign.tests.bridge.testdata.issue34.pckg1.CalledClass2;
import com.adobe.campaign.tests.bridge.testdata.one.EnvironmentVariableHandler;
import org.hamcrest.Matchers;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -131,7 +128,7 @@ public void testsearchClass_negativeNonexistantClassManual2_usingJavaClass() thr
}


@Test(enabled = E2ETests.AUTOMATIC_FLAG)
@Test
public void testIssue34AutomaticLoading() {
ConfigValueHandlerIBS.INTEGRITY_PACKAGE_INJECTION_MODE.activate("automatic");
JavaCalls l_myJavaCalls = new JavaCalls();
Expand Down Expand Up @@ -174,12 +171,14 @@ public void testIssue34AutomaticLoading_negativeDefaultBehavior() {
l_cc2.setMethodName("calledMethod");
l_myJavaCalls.getCallContent().put("call2", l_cc2);

Assert.assertThrows(IBSConfigurationException.class, () -> l_myJavaCalls.submitCalls());
/* Related to issue #55
//Assert.assertThrows(IBSConfigurationException.class, () -> l_myJavaCalls.submitCalls());
//#43
l_myJavaCalls.submitCalls();

assertThat("The called class should be loaded.", l_myJavaCalls.getLocalClassLoader().isClassLoaded("com.adobe.campaign.tests.bridge.testdata.issue34.pckg1.CalledClass1"));
assertThat("The MiddleMan class should be loaded.", l_myJavaCalls.getLocalClassLoader().isClassLoaded("com.adobe.campaign.tests.bridge.testdata.issue34.pckg1.MiddleMan"));
assertThat("The MiddleManFactory class should be loaded.", l_myJavaCalls.getLocalClassLoader().isClassLoaded("com.adobe.campaign.tests.bridge.testdata.issue34.pckg2.MiddleManClassFactory"));
*/

}

@Test
Expand Down

0 comments on commit 63add73

Please sign in to comment.