Skip to content

Commit

Permalink
Updated deprecated methods and tests (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
stanbrub authored Feb 9, 2024
1 parent e09f04e commit d98bc2c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* Copyright (c) 2022-2023 Deephaven Data Labs and Patent Pending */
/* Copyright (c) 2022-2024 Deephaven Data Labs and Patent Pending */
package io.deephaven.benchmark.tests.internal.workflow;

import static org.junit.jupiter.api.Assertions.assertEquals;
import java.net.URI;
import java.net.URL;
import org.junit.jupiter.api.*;
import io.deephaven.benchmark.api.Bench;
Expand Down Expand Up @@ -99,7 +100,7 @@ private void stageRuns(String srcUri, String dstDir, String... runIds) throws Ex
}

private void stageFile(String srcUri, String dstPath) throws Exception {
var fileContents = getURLText(new URL(srcUri));
var fileContents = getURLText(new URI(srcUri).toURL());
var q = """
contents = '''${fileContents}'''
import os, sys
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/deephaven/benchmark/api/Profile.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* Copyright (c) 2022-2023 Deephaven Data Labs and Patent Pending */
/* Copyright (c) 2022-2024 Deephaven Data Labs and Patent Pending */
package io.deephaven.benchmark.api;

import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -177,7 +178,7 @@ private URL findProfileUrl(String uri) {

private URL findProfileAsHttp(String uri) {
try {
return (uri.matches("^[A-Za-z][:][/].*")) ? new URL(uri) : null;
return (uri.matches("^[A-Za-z][:][/].*")) ? new URI(uri).toURL() : null;
} catch (Exception ex) {
throw new RuntimeException("Failed to find remote profile: " + uri);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public boolean startService() {
return false;
var composeRunPath = getRunningComposePath();
if (composeRunPath != null)
exec("sudo docker compose -f " + composeRunPath + " down");
exec("sudo docker compose -f " + composePropPath + " up -d");
exec("sudo", "docker", "compose", "-f", composeRunPath, "down");
exec("sudo", "docker", "compose", "-f", composePropPath, "up", "-d");
waitForEngineReady();
return true;
}
Expand All @@ -59,7 +59,7 @@ public boolean startService() {
public boolean stopService() {
if (composePropPath.isBlank())
return false;
exec("sudo docker compose -f " + composePropPath + " down --timeout 0");
exec("sudo", "docker", "compose", "-f", composePropPath, "down", "--timeout", "0");
return true;
}

Expand All @@ -86,7 +86,7 @@ public String getLog() {
return "";
var composePath = getRunningComposePath();
if (composePath != null)
return exec("sudo docker compose -f " + composePath + " logs");
return exec("sudo", "docker", "compose", "-f", composePath, "logs");
return "";
}

Expand Down Expand Up @@ -132,12 +132,12 @@ String getRunningComposePath() {
}

List<String> getRunningContainerIds() {
var out = exec("sudo docker ps");
var out = exec("sudo", "docker", "ps");
return parseContainerIds(out);
}

ContainerInfo getContainerInfo(String containerId) {
var out = exec("sudo docker container inspect " + containerId);
var out = exec("sudo", "docker", "container", "inspect", containerId);
return parseContainerInfo(out);
}

Expand All @@ -161,7 +161,7 @@ String getPropValue(String props, String name, String containsVal) {
return matches.get(0).replaceAll("\"[,]?", "").split("[:]\s*")[1].trim();
}

String exec(String command) {
String exec(String... command) {
return Exec.exec(workDir, command);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* Copyright (c) 2022-2023 Deephaven Data Labs and Patent Pending */
/* Copyright (c) 2022-2024 Deephaven Data Labs and Patent Pending */
package io.deephaven.benchmark.run;

import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
Expand Down Expand Up @@ -91,7 +92,7 @@ void publishToSlack(Path outDir) {
payload = payload.replace("${msg}", message);
try {
System.out.println("-- Pushing notification to Slack --");
URL url = new URL("https://slack.com/api/chat.postMessage");
URL url = new URI("https://slack.com/api/chat.postMessage").toURL();
var c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("POST");
c.setDoOutput(true);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/deephaven/benchmark/util/Exec.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2022-2023 Deephaven Data Labs and Patent Pending */
/* Copyright (c) 2022-2024 Deephaven Data Labs and Patent Pending */
package io.deephaven.benchmark.util;

import java.io.*;
Expand All @@ -17,7 +17,7 @@ public class Exec {
* @param command the shell command to run
* @return the standard output of the process
*/
static public String exec(Path workingDir, String command) {
static public String exec(Path workingDir, String... command) {
try {
Process process = Runtime.getRuntime().exec(command, null, workingDir.toFile());
var out = getStdout(process);
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/io/deephaven/benchmark/util/ExecTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
/* Copyright (c) 2022-2023 Deephaven Data Labs and Patent Pending */
/* Copyright (c) 2022-2024 Deephaven Data Labs and Patent Pending */
package io.deephaven.benchmark.util;

import static org.junit.jupiter.api.Assertions.assertEquals;
import java.nio.file.Paths;
import org.junit.jupiter.api.Test;

public class ExecTest {
String[] windowsEcho = {"cmd", "/c", "echo", "Ack"};
String[] bashEcho = {"echo", "Ack"};

@Test
public void exec() {
var os = System.getProperty("os.name");
var cmd = os.contains("Windows") ? "cmd /c echo Ack" : "echo Ack";
var cmd = os.contains("Windows") ? windowsEcho : bashEcho;
assertEquals("Ack", Exec.exec(Paths.get("."), cmd), "Wrong response");
}

Expand Down

0 comments on commit d98bc2c

Please sign in to comment.