Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EJBCLIENT-254 client fails on Xbootclasspath #317

Merged
merged 1 commit into from
Sep 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<!-- 2.1.x also work on JDK9-->
<version.org.jboss.logging.jboss-logging-tools>2.1.0.Final</version.org.jboss.logging.jboss-logging-tools>
<version.org.jboss.logmanager>2.0.7.Final</version.org.jboss.logmanager>
<version.org.jboss.marshalling>2.0.0.Final</version.org.jboss.marshalling>
<version.org.jboss.marshalling>2.0.1.Final</version.org.jboss.marshalling>
<version.org.jboss.modules>1.6.0.Final</version.org.jboss.modules>
<version.org.jboss.remoting>5.0.0.Final</version.org.jboss.remoting>
<version.org.jboss.spec.javax.ejb>1.0.0.Final</version.org.jboss.spec.javax.ejb>
Expand Down Expand Up @@ -278,4 +278,37 @@
<developerConnection>scm:git:[email protected]:jbossas/jboss-ejb-client.git</developerConnection>
<url>https://github.com/jbossas/jboss-ejb-client</url>
</scm>
<profiles>
<profile>
<id>test-bootclasspath</id>
<activation>
<property>
<name>test-bootclasspath</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<longClasspath>false</longClasspath>
<classpathScope>test</classpathScope>
<commandlineArgs>-Xbootclasspath/a:%classpath org.jboss.ejb.client.test.ManualTestRunner "Boot ClassPath Testing"</commandlineArgs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ public static <T, U> JBossEJBProperties fromResource(final String fileName, fina
if (stream == null) {
return null;
}
return fromResource(fileName, stream);
}

private static JBossEJBProperties fromResource(String fileName, InputStream stream) throws IOException {
try (InputStream inputStream = stream) {
try (BufferedInputStream bis = new BufferedInputStream(inputStream)) {
try (InputStreamReader reader = new InputStreamReader(bis, StandardCharsets.UTF_8)) {
Expand Down Expand Up @@ -444,6 +448,9 @@ public static JBossEJBProperties fromPath(final Path propertiesFile) throws IOEx
}

public static JBossEJBProperties fromClassPath(final ClassLoader classLoader, final String pathName) throws IOException {
if (classLoader == null) {
return fromResource(pathName, ClassLoader.getSystemResourceAsStream(pathName));
}
return fromResource(pathName, ClassLoader::getResourceAsStream, classLoader, pathName);
}

Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/jboss/ejb/client/test/ClassCallback.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.jboss.ejb.client.test;

public class ClassCallback {
private static volatile Runnable beforeClassCallback;

public static void beforeClassCallback() {
if (beforeClassCallback != null) {
beforeClassCallback.run();
}
}

public static void setBeforeClassCallback(Runnable beforeClassCallback) {
ClassCallback.beforeClassCallback = beforeClassCallback;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.wildfly.common.context.ContextManager;
import org.wildfly.common.context.Contextual;

import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;

Expand Down Expand Up @@ -83,6 +87,9 @@ public static void beforeClass() throws Exception {
// trigger the static init of the correct properties file - this also depends on running in forkMode=always
JBossEJBProperties ejbProperties = JBossEJBProperties.fromClassPath(SimpleInvocationTestCase.class.getClassLoader(), PROPERTIES_FILE);
JBossEJBProperties.getContextManager().setGlobalDefault(ejbProperties);

// Launch callback if needed
ClassCallback.beforeClassCallback();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,9 @@ public void afterTest() {
public static void afterClass() {
}

public static void main(String[] args) throws Exception {
JBossEJBPropertiesTestCase props = new JBossEJBPropertiesTestCase();
props.testLegacyProperties();
}

}
57 changes: 57 additions & 0 deletions src/test/java/org/jboss/ejb/client/test/ManualTestRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.jboss.ejb.client.test;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

import org.jboss.ejb.client.serialization.ProxySerializationTestCase;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;

// Manually launches EJB tests (e.g. for Xbootclasspath testing)
public class ManualTestRunner {
public static void main(String[] args) throws Exception {
String summary = args.length > 0 ? args[0] : null;
if (summary == null || summary.length() == 0) {
summary = "Manual Test Run";
}
System.out.println("===========================");
System.out.printf(" %s \n", summary);
System.out.println("===========================");

ClassCallback.setBeforeClassCallback(ManualTestRunner::reloadConfiguration);

Result result = JUnitCore.runClasses(JBossEJBPropertiesTestCase.class, ClusteredInvocationTestCase.class, SimpleInvocationTestCase.class, ProxySerializationTestCase.class, WildflyClientXMLTestCase.class);

System.out.println("Failed: " + result.getFailureCount() + " Ignored: " + result.getIgnoreCount() +
" Succeeded: " + (result.getRunCount() - result.getFailureCount() - result.getIgnoreCount()));
for (Failure failure: result.getFailures()) {
System.out.println(failure.getDescription());
System.out.println(failure.getTrace());
}

System.exit(result.wasSuccessful() ? 0 : 1);
}

private static void reloadConfiguration() {
try {
// Force reconfiguration so that one test class doesn't pollute the other
// (since we are running them all in one JVM)
Class<?> clazz = Class.forName("org.jboss.ejb.client.ConfigurationBasedEJBClientContextSelector");
Method init = clazz.getDeclaredMethod("loadConfiguration");
init.setAccessible(true);
Object o = init.invoke(null);
Field field = clazz.getDeclaredField("configuredContext");
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);

field.setAccessible(true);
field.set(null, o);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.wildfly.common.context.ContextManager;
import org.wildfly.common.context.Contextual;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
Expand All @@ -58,6 +63,7 @@ public class SimpleInvocationTestCase {

private static final String SERVER_NAME = "test-server";


/**
* Do any general setup here
* @throws Exception
Expand All @@ -67,6 +73,9 @@ public static void beforeClass() throws Exception {
// trigger the static init of the correct proeprties file - this also depends on running in forkMode=always
JBossEJBProperties ejbProperties = JBossEJBProperties.fromClassPath(SimpleInvocationTestCase.class.getClassLoader(), PROPERTIES_FILE);
JBossEJBProperties.getContextManager().setGlobalDefault(ejbProperties);

// Launch callback if needed
ClassCallback.beforeClassCallback();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.junit.Test;

import java.io.File;
import java.net.URL;

/**
* Tests some basic features of wildfly-client.xml processing
Expand All @@ -45,8 +46,10 @@ public class WildflyClientXMLTestCase {
public static void beforeClass() throws Exception {
// make sure the desired configuration file is picked up
ClassLoader cl = WildflyClientXMLTestCase.class.getClassLoader();
File file = new File(cl.getResource(CONFIGURATION_FILE).getFile());
URL resource = cl != null ? cl.getResource(CONFIGURATION_FILE) : ClassLoader.getSystemResource(CONFIGURATION_FILE);
File file = new File(resource.getFile());
System.setProperty(CONFIGURATION_FILE_SYSTEM_PROPERTY_NAME,file.getAbsolutePath());
ClassCallback.beforeClassCallback();
}

@Test
Expand Down