Skip to content

Commit

Permalink
Merge pull request #43406 from warunalakshitha/java21_jbal_tests
Browse files Browse the repository at this point in the history
[Java 21] Fix testerina tests
  • Loading branch information
warunalakshitha authored Sep 26, 2024
2 parents 3b7111f + fea2118 commit a78c679
Show file tree
Hide file tree
Showing 108 changed files with 1,296 additions and 393 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/pull_request_full_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ jobs:
do git clone https://github.com/ballerina-platform/${module_name}.git; \
done
# - name: Checkout non-default branch
# run: |
# for module_name in $(jq -r '.standard_library| .[] | select(.level==${{ matrix.level }}) | .name' extensions.json); do \
# cd $module_name && git fetch origin && git checkout -t origin/java_21_migration && cd ..; \
# done
- name: Checkout non-default branch
run: |
for module_name in $(jq -r '.standard_library| .[] | select(.level==${{ matrix.level }}) | .name' extensions.json); do \
cd $module_name && git fetch origin && git checkout -t origin/java21 && cd ..; \
done
- name: Update Lang Version in Module
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull_request_ubuntu_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
run: |
export DISPLAY=':99.0'
/usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
./gradlew build -Pnative.test --max-workers=2 --scan --no-daemon
./gradlew build -x jballerina-debugger-integration-test:test -Pnative.test --max-workers=2 --scan --no-daemon
- name: Generate Jacoco report
if: github.event_name == 'pull_request'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull_request_windows_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ jobs:
env:
packageUser: ${{ github.actor }}
packagePAT: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew.bat build --continue -x :ballerina-lang:test -x :jballerina-integration-test:test -x javadoc --stacktrace -scan --console=plain --no-daemon --no-parallel
run: ./gradlew.bat build --continue -x :ballerina-lang:test -x :jballerina-integration-test:test -x jballerina-debugger-integration-test:test -x javadoc --stacktrace -scan --console=plain --no-daemon --no-parallel

Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import io.ballerina.runtime.api.values.BError;
import io.ballerina.runtime.internal.BalRuntime;
import io.ballerina.runtime.internal.ClassloaderRuntime;
import io.ballerina.runtime.internal.scheduling.Scheduler;
import io.ballerina.runtime.internal.scheduling.Strand;
import io.ballerina.shell.DiagnosticReporter;
import io.ballerina.shell.exceptions.InvokerException;
import io.ballerina.shell.exceptions.InvokerPanicException;
Expand All @@ -52,8 +50,6 @@
import java.io.IOException;
import java.io.PrintStream;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -356,30 +352,19 @@ protected void executeProject(ClassLoadContext context, String templateName) thr
* @param jBallerinaBackend Backed to use.
* @param module Module to execute.
*/
protected void executeProject(JBallerinaBackend jBallerinaBackend, io.ballerina.runtime.api.Module module) {
protected void executeProject(JBallerinaBackend jBallerinaBackend, io.ballerina.runtime.api.Module module)
throws InvokerPanicException {
if (bufferFile == null) {
throw new UnsupportedOperationException("Buffer file must be set before execution");
}

PrintStream errorStream = getErrorStream();
try {
// Main method class name is file name without extension
String fileName = bufferFile.getName();
String mainMethodClassName = fileName.substring(0, fileName.length() - TEMP_FILE_SUFFIX.length());

JarResolver jarResolver = jBallerinaBackend.jarResolver();
ClassLoader classLoader = jarResolver.getClassLoaderWithRequiredJarFilesForExecution();
BalRuntime runtime = new ClassloaderRuntime(module, classLoader);
// Initialize the module
runtime.init();
// Start the module
runtime.start();
// Then call run method
try {
runtime.call(module, MODULE_RUN_METHOD_NAME);
runtime.stop();
} catch (BError e) {
errorStream.println("fail: " + e.getMessage());
Object failErrorMessage = this.callRun(classLoader, module);
if (failErrorMessage != null) {
errorStream.println("fail: " + failErrorMessage);
}
} catch (Throwable panicError) {
List<String> stacktrace = Arrays.stream(panicError.getCause().getStackTrace())
Expand All @@ -397,73 +382,40 @@ protected void executeProject(JBallerinaBackend jBallerinaBackend, io.ballerina.
/* Invocation methods */

/**
* Invokes a method that is in the given class.
* The method must be a static method accepting only one parameter, a {@link Strand}.
* Invokes a run function.
*
* @param classLoader Class loader to find the class.
* @param className Class name with the method.
* @param methodName Method name to invoke.
* @return The result of the invocation.
* @throws InvokerException If invocation failed.
*/
protected Object invokeScheduledMethod(ClassLoader classLoader, String className, String methodName)
throws InvokerException {
protected Object callRun(ClassLoader classLoader, io.ballerina.runtime.api.Module module)
throws InvokerPanicException {
BalRuntime runtime = new ClassloaderRuntime(module, classLoader);
Object result;
try {
addDebugDiagnostic(String.format("Running %s.%s on schedule", className, methodName));

// Get class and method references
Class<?> clazz = classLoader.loadClass(className);
Method method = clazz.getDeclaredMethod(methodName, Strand.class);
// Initialize the module
result = runtime.init();
if (result instanceof Throwable throwable) {
throw new InvokerPanicException(throwable);
}
// Start the module
result = runtime.start();
if (result instanceof Throwable throwable) {
throw new InvokerPanicException(throwable);
}
// Then call run method
result = runtime.call(module, MODULE_RUN_METHOD_NAME);
if (result instanceof Throwable throwable) {
throw new InvokerPanicException(throwable);
}
} catch (Throwable throwable) {
throw new InvokerPanicException(throwable);
} finally {
try {
return method.invoke(null, Scheduler.getStrand());
} catch (InvocationTargetException e) {
return e.getTargetException();
} catch (IllegalAccessException e) {
throw new RuntimeException("Error while invoking function.", e);
runtime.stop();
} catch (BError ignored) {
// stop errors are ignored
}
} catch (ClassNotFoundException e) {
addErrorDiagnostic(className + " class not found: " + e.getMessage());
throw new InvokerException(e);
} catch (NoSuchMethodException e) {
addErrorDiagnostic(methodName + " method not found: " + e.getMessage());
throw new InvokerException(e);
}
}

/**
* Invokes a method that is in the given class.
* This is directly invoked without scheduling.
* The method must be a static method accepting the given parameters.
*
* @param classLoader Class loader to find the class.
* @param className Class name with the method.
* @param methodName Method name to invoke.
* @param argTypes Types of arguments.
* @param args Arguments to provide.
* @return The result of the invocation.
* @throws InvokerException If invocation failed.
*/
protected Object invokeMethodDirectly(ClassLoader classLoader, String className, String methodName,
Class<?>[] argTypes, Object[] args) throws InvokerException {
try {
// Get class and method references
addDebugDiagnostic(String.format("Running %s.%s directly", className, methodName));
Class<?> clazz = classLoader.loadClass(className);
Method method = clazz.getDeclaredMethod(methodName, argTypes);
return method.invoke(null, args);
} catch (ClassNotFoundException e) {
addErrorDiagnostic(className + " class not found: " + e.getMessage());
throw new InvokerException(e);
} catch (NoSuchMethodException e) {
addErrorDiagnostic(methodName + " method not found: " + e.getMessage());
throw new InvokerException(e);
} catch (IllegalAccessException e) {
addErrorDiagnostic(methodName + " illegal access: " + e.getMessage());
throw new InvokerException(e);
} catch (InvocationTargetException e) {
addErrorDiagnostic(methodName + " exception at target: " + e.getTargetException());
throw new InvokerException(e);
}
return result;
}

/* Util methods */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

package io.ballerina.shell.test.evaluator.base;

import io.ballerina.shell.exceptions.InvokerException;
import io.ballerina.runtime.api.Module;
import io.ballerina.shell.exceptions.InvokerPanicException;
import io.ballerina.shell.invoker.classload.ClassLoadInvoker;

import java.io.ByteArrayOutputStream;
Expand All @@ -40,12 +41,11 @@ public TestInvoker() {
}

@Override
protected Object invokeScheduledMethod(ClassLoader classLoader, String className, String methodName)
throws InvokerException {
protected Object callRun(ClassLoader classLoader, Module module) throws InvokerPanicException {
PrintStream stdOut = System.out;
try {
System.setOut(stdOutMock);
return super.invokeScheduledMethod(classLoader, className, methodName);
return super.callRun(classLoader, module);
} finally {
System.setOut(stdOut);
}
Expand Down
2 changes: 2 additions & 0 deletions bvm/ballerina-rt/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ dependencies {
//// metrics
dist project(':metrics-extensions:ballerina-metrics-extension')

dist "com.google.code.gson:gson:${project.gsonVersion}"

// Transaction related third party jars
dist "com.atomikos:transactions-jta:${project.atomikosTransactionsJtaVersion}"
dist "com.atomikos:atomikos-util:${project.atomikosUtilVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public static Runtime from(Module module) {
/**
* Performs the module initialization.
*/
public abstract void init();
public abstract Object init();

/**
* Starts the listening phase.
*/
public abstract void start();
public abstract Object start();

/**
* Gracefully shuts down the Ballerina runtime.
Expand Down
Loading

0 comments on commit a78c679

Please sign in to comment.