Skip to content

Commit

Permalink
Fix some jballerina integration tests on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadow-Devil committed Dec 2, 2024
1 parent eca0cf6 commit 68a3eb6
Show file tree
Hide file tree
Showing 20 changed files with 127 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,15 @@
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

/**
* The RouteTable class contains all URL routes in the WebServer.
*
* @since 0.982.0
*/
class RouteTable {
private final ArrayList<Route> routes;

RouteTable() {
this.routes = new ArrayList<Route>();
}
private final List<Route> routes = new ArrayList<>();

void addRoute(final Route route) {
this.routes.add(route);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,10 @@

import org.apache.commons.lang3.ArrayUtils;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;

import java.io.*;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

Expand All @@ -47,10 +32,9 @@
* @since 0.982.0
*/
public class BMainInstance implements BMain {
private static final Logger LOG = LoggerFactory.getLogger(BMainInstance.class);
private static final String JAVA_OPTS = "JAVA_OPTS";
private String agentArgs = "";
private BalServer balServer;
private final BalServer balServer;
public static final int TIMEOUT = 10000;

private static class StreamGobbler extends Thread {
Expand All @@ -65,7 +49,7 @@ public StreamGobbler(InputStream inputStream, PrintStream printStream) {
@Override
public void run() {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String lineContent = null;
String lineContent;
while (true) {
try {
lineContent = bufferedReader.readLine();
Expand Down Expand Up @@ -254,9 +238,7 @@ public void runMain(String command, String[] args, @Nullable Map<String, String>
ProcessBuilder processBuilder = new ProcessBuilder(cmdArgs).directory(new File(commandDir));
if (envProperties != null) {
Map<String, String> env = processBuilder.environment();
for (Map.Entry<String, String> entry : envProperties.entrySet()) {
env.put(entry.getKey(), entry.getValue());
}
env.putAll(envProperties);
}
addJavaAgents(processBuilder.environment());

Expand Down Expand Up @@ -322,9 +304,7 @@ public Process runCommandAndGetProcess(String command, String[] args, Map<String
ProcessBuilder processBuilder = new ProcessBuilder(cmdArgs).directory(new File(commandDir));
if (envProperties != null) {
Map<String, String> env = processBuilder.environment();
for (Map.Entry<String, String> entry : envProperties.entrySet()) {
env.put(entry.getKey(), entry.getValue());
}
env.putAll(envProperties);
}
return processBuilder.start();
} catch (IOException e) {
Expand Down Expand Up @@ -358,7 +338,7 @@ public Process debugMain(String command, String[] args, @Nullable Map<String, St
throws BallerinaTestException {
String scriptName = Constant.BALLERINA_SERVER_SCRIPT_NAME;
String[] cmdArray;
String[] cmdArgs = new String[0];
String[] cmdArgs;
Process process = null;

if (envProperties != null) {
Expand All @@ -378,9 +358,7 @@ public Process debugMain(String command, String[] args, @Nullable Map<String, St
ProcessBuilder processBuilder = new ProcessBuilder(cmdArgs).directory(new File(commandDir));
if (envProperties != null) {
Map<String, String> env = processBuilder.environment();
for (Map.Entry<String, String> entry : envProperties.entrySet()) {
env.put(entry.getKey(), entry.getValue());
}
env.putAll(envProperties);
}
process = processBuilder.start();

Expand Down Expand Up @@ -711,9 +689,9 @@ private void writeClientArgsToProcess(String[] clientArgs, Process process) thro
}

public void compilePackageAndPushToLocal(String packagPath, String balaFileName) throws BallerinaTestException {
LogLeecher buildLeecher = new LogLeecher("target/bala/" + balaFileName + ".bala");
LogLeecher pushLeecher = new LogLeecher("Successfully pushed target/bala/" + balaFileName + ".bala to " +
"'local' repository.");
String targetBala = Path.of("target/bala/" + balaFileName + ".bala").toString();
LogLeecher buildLeecher = new LogLeecher(targetBala);
LogLeecher pushLeecher = new LogLeecher("Successfully pushed " + targetBala + " to 'local' repository.");
this.runMain("pack", new String[]{}, null, null, new LogLeecher[]{buildLeecher}, packagPath);
buildLeecher.waitForText(5000);
this.runMain("push", new String[]{"--repository=local"}, null, null, new LogLeecher[]{pushLeecher},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
Expand Down Expand Up @@ -361,8 +356,8 @@ public void addErrorLogLeecher(LogLeecher leecher) {
public void removeAllLeechers() {
serverInfoLogReader.removeAllLeechers();
serverErrorLogReader.removeAllLeechers();
tmpInfoLeechers.forEach(logLeecher -> tmpInfoLeechers.remove(logLeecher));
tmpErrorLeechers.forEach(logLeecher -> tmpErrorLeechers.remove(logLeecher));
tmpInfoLeechers.forEach(tmpInfoLeechers::remove);
tmpErrorLeechers.forEach(tmpErrorLeechers::remove);
}

/**
Expand All @@ -388,9 +383,7 @@ private void runBuildTool(String command, String[] args, @Nullable Map<String, S
ProcessBuilder processBuilder = new ProcessBuilder(cmdArgs).directory(commandDir);
if (envProperties != null) {
Map<String, String> env = processBuilder.environment();
for (Map.Entry<String, String> entry : envProperties.entrySet()) {
env.put(entry.getKey(), entry.getValue());
}
env.putAll(envProperties);
}
process = processBuilder.start();

Expand Down Expand Up @@ -505,9 +498,7 @@ private void executeJarFile(String jarPath, String[] args, Map<String, String> e

ProcessBuilder processBuilder = new ProcessBuilder(runCmdSet).directory(commandDir);
Map<String, String> env = processBuilder.environment();
for (Map.Entry<String, String> entry : envProperties.entrySet()) {
env.put(entry.getKey(), entry.getValue());
}
env.putAll(envProperties);
process = processBuilder.start();

serverInfoLogReader = new ServerLogReader("inputStream", process.getInputStream());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,11 @@
package org.ballerinalang.test.util;

import org.ballerinalang.test.exceptions.BLangTestException;
import org.jetbrains.annotations.NotNull;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.CopyOption;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.List;
import java.util.Objects;
Expand All @@ -57,23 +48,23 @@ private BFileUtil() {
*/
public static void copy(Path sourcePath, Path targetPath) {
try {
Files.walkFileTree(sourcePath, new SimpleFileVisitor<Path>() {
Files.walkFileTree(sourcePath, new SimpleFileVisitor<>() {

@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
public @NotNull FileVisitResult visitFileFailed(Path file, @NotNull IOException exc) {
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
public @NotNull FileVisitResult preVisitDirectory(Path dir, @NotNull BasicFileAttributes attrs) throws IOException {
if (Files.exists(dir)) {
Files.createDirectories(targetPath.resolve(sourcePath.relativize(dir)));
}
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
public @NotNull FileVisitResult visitFile(Path file, @NotNull BasicFileAttributes attrs) throws IOException {
if (!IGNORE.equals(file.getFileName().toString()) && Files.exists(file)) {
CopyOption[] option = {
StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES
Expand All @@ -96,23 +87,23 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
*/
public static void delete(Path path) {
try {
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {

Files.walkFileTree(path, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
public @NotNull FileVisitResult visitFileFailed(Path file, @NotNull IOException exc) {
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
public @NotNull FileVisitResult visitFile(Path file, @NotNull BasicFileAttributes attrs) throws IOException {
if (Files.exists(file)) {
Files.delete(file);
}
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
public @NotNull FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
if (Files.exists(dir)) {
try (Stream<Path> paths = Files.list(dir)) {
paths.forEach(BFileUtil::delete);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.URL;
import java.net.URLConnection;
import java.io.*;
import java.net.*;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -240,7 +231,7 @@ private static HttpURLConnection getURLConnection(String requestUrl) throws IOEx
}

private static HttpURLConnection getURLConnection(String requestUrl, int readTimeout) throws IOException {
URL url = new URL(requestUrl);
URL url = URI.create(requestUrl).toURL();
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setReadTimeout(readTimeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ public class AsyncFunctionsTest extends BaseTest {
@BeforeClass
public void setup() throws BallerinaTestException {
bMainInstance = new BMainInstance(balServer);

String targetBala = Path.of("target/bala/testOrg-functionsLib-java21-0.1.0.bala").toString();
// Build and push config Lib project.
LogLeecher buildLeecher = new LogLeecher("target/bala/testOrg-functionsLib-java21-0.1.0.bala");
LogLeecher pushLeecher = new LogLeecher("Successfully pushed target/bala/testOrg-functionsLib-java21-0.1.0" +
".bala to 'local' repository.");
LogLeecher buildLeecher = new LogLeecher(targetBala);
LogLeecher pushLeecher = new LogLeecher("Successfully pushed " + targetBala + " to 'local' repository.");
LogLeecher runLeecher = new LogLeecher("Run the library package to fix code coverage");
bMainInstance.runMain(testFileLocation + "/", "functionsLib", null, new String[]{}, null, null,
new LogLeecher[]{runLeecher});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public class BindgenTestCase extends BaseTest {
public void setUp() throws IOException {
tempProjectsDir = Files.createTempDirectory("bal-test-integration-bindgen-");
// copy TestProject to a temp
Path testProject = Path.of("src", "test", "resources", "bindgen")
.toAbsolutePath();
Path testProject = Path.of("src/test/resources/bindgen").toAbsolutePath();
copyFolder(testProject, tempProjectsDir);
balClient = new BMainInstance(balServer);
}
Expand All @@ -61,7 +60,7 @@ public void setUp() throws IOException {
*/
@Test(description = "Test the bindgen command functionality.")
public void bindgenTest() throws BallerinaTestException {
String buildMsg = "target/bin/bindgen.jar";
String buildMsg = Path.of("target/bin/bindgen.jar").toString();
LogLeecher buildLeecher = new LogLeecher(buildMsg);

String bindgenMsg1 = "error: unable to generate the '";
Expand Down
Loading

0 comments on commit 68a3eb6

Please sign in to comment.