mirror of https://github.com/OpenVidu/openvidu.git
openvidu-test-e2e: move start and stop RTMP server util methods
parent
f3550c4f6a
commit
90dfd60a06
|
@ -3,10 +3,8 @@ package io.openvidu.test.e2e;
|
|||
import static org.openqa.selenium.OutputType.BASE64;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
@ -859,80 +857,4 @@ public class OpenViduTestE2e {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* https://github.com/tiangolo/nginx-rtmp-docker
|
||||
*
|
||||
* @return The IP address of the Docker container
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
protected static String startRtmpServer() throws IOException, TimeoutException, InterruptedException {
|
||||
File file = writeRtmpServerConfigInFile();
|
||||
String dockerRunCommand = "docker run -d --name broadcast-nginx -p 1935:1935 -v " + file.getAbsolutePath()
|
||||
+ ":/etc/nginx/nginx.conf tiangolo/nginx-rtmp";
|
||||
commandLine.executeCommand(dockerRunCommand, 10);
|
||||
return waitForContainerIpAddress("broadcast-nginx", 10);
|
||||
}
|
||||
|
||||
protected static void stopRtmpServer() {
|
||||
String dockerRemoveCommand = "docker rm -f broadcast-nginx";
|
||||
commandLine.executeCommand(dockerRemoveCommand, 10);
|
||||
}
|
||||
|
||||
protected static String waitForContainerIpAddress(String containerNameOrId, int secondsTimeout)
|
||||
throws TimeoutException, UnknownHostException, InterruptedException {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
long maxTime = currentTime + (secondsTimeout * 1000);
|
||||
try {
|
||||
while (System.currentTimeMillis() < maxTime) {
|
||||
try {
|
||||
String ip = MediaNodeDockerUtils.getContainerIp(containerNameOrId);
|
||||
if (ip.isBlank()) {
|
||||
log.warn("Container IP address is empty for container {}", containerNameOrId);
|
||||
} else {
|
||||
return ip;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Error obtaining container IP address for container {}: {}", containerNameOrId,
|
||||
e.getMessage());
|
||||
}
|
||||
Thread.sleep(50);
|
||||
}
|
||||
} finally {
|
||||
log.info("Logging docker inspect info");
|
||||
log.info(commandLine.executeCommand("docker inspect " + containerNameOrId, 10));
|
||||
}
|
||||
throw new TimeoutException();
|
||||
}
|
||||
|
||||
private static File writeRtmpServerConfigInFile() throws IOException {
|
||||
String newLine = System.getProperty("line.separator");
|
||||
// @formatter:off
|
||||
String config = String.join(newLine,
|
||||
"worker_processes auto;",
|
||||
"rtmp_auto_push on;",
|
||||
"events {}",
|
||||
"rtmp {",
|
||||
" server {",
|
||||
" listen 1935;",
|
||||
" listen [::]:1935 ipv6only=on;",
|
||||
" application live {",
|
||||
" live on;",
|
||||
" recorder all {",
|
||||
" record video;",
|
||||
" record_path /tmp;",
|
||||
" record_max_size 100000K;",
|
||||
" record_unique on;",
|
||||
" record_suffix rtmp.flv;",
|
||||
" }",
|
||||
" }",
|
||||
" }",
|
||||
"}");
|
||||
// @formatter:on
|
||||
Files.createDirectories(Paths.get("/opt/openvidu/tmp/"));
|
||||
File tmpFile = File.createTempFile("broadcast-nginx", ".conf", new File("/opt/openvidu/tmp/"));
|
||||
FileWriter writer = new FileWriter(tmpFile);
|
||||
writer.write(config);
|
||||
writer.close();
|
||||
return tmpFile;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
package io.openvidu.test.e2e.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.openvidu.test.browsers.utils.CommandLineExecutor;
|
||||
import io.openvidu.test.e2e.MediaNodeDockerUtils;
|
||||
|
||||
public class TestUtils {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TestUtils.class);
|
||||
private static final CommandLineExecutor commandLine = new CommandLineExecutor();
|
||||
|
||||
/**
|
||||
* https://github.com/tiangolo/nginx-rtmp-docker
|
||||
*
|
||||
* @return The IP address of the Docker container
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public static String startRtmpServer() throws IOException, TimeoutException, InterruptedException {
|
||||
File file = writeRtmpServerConfigInFile();
|
||||
String dockerRunCommand = "docker run -d --name broadcast-nginx -p 1935:1935 -v " + file.getAbsolutePath()
|
||||
+ ":/etc/nginx/nginx.conf tiangolo/nginx-rtmp";
|
||||
commandLine.executeCommand(dockerRunCommand, 10);
|
||||
return waitForContainerIpAddress("broadcast-nginx", 10);
|
||||
}
|
||||
|
||||
public static void stopRtmpServer() {
|
||||
String dockerRemoveCommand = "docker rm -f broadcast-nginx";
|
||||
commandLine.executeCommand(dockerRemoveCommand, 10);
|
||||
}
|
||||
|
||||
private static String waitForContainerIpAddress(String containerNameOrId, int secondsTimeout)
|
||||
throws TimeoutException, UnknownHostException, InterruptedException {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
long maxTime = currentTime + (secondsTimeout * 1000);
|
||||
while (System.currentTimeMillis() < maxTime) {
|
||||
try {
|
||||
String ip = MediaNodeDockerUtils.getContainerIp(containerNameOrId);
|
||||
if (ip.isBlank()) {
|
||||
log.warn("Container IP address is empty for container {}", containerNameOrId);
|
||||
} else {
|
||||
return ip;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Error obtaining container IP address for container {}: {}", containerNameOrId,
|
||||
e.getMessage());
|
||||
}
|
||||
Thread.sleep(50);
|
||||
}
|
||||
throw new TimeoutException();
|
||||
}
|
||||
|
||||
private static File writeRtmpServerConfigInFile() throws IOException {
|
||||
String newLine = System.getProperty("line.separator");
|
||||
// @formatter:off
|
||||
String config = String.join(newLine,
|
||||
"worker_processes auto;",
|
||||
"rtmp_auto_push on;",
|
||||
"events {}",
|
||||
"rtmp {",
|
||||
" server {",
|
||||
" listen 1935;",
|
||||
" listen [::]:1935 ipv6only=on;",
|
||||
" application live {",
|
||||
" live on;",
|
||||
" recorder all {",
|
||||
" record video;",
|
||||
" record_path /tmp;",
|
||||
" record_max_size 100000K;",
|
||||
" record_unique on;",
|
||||
" record_suffix rtmp.flv;",
|
||||
" }",
|
||||
" }",
|
||||
" }",
|
||||
"}");
|
||||
// @formatter:on
|
||||
Files.createDirectories(Paths.get("/opt/openvidu/tmp/"));
|
||||
File tmpFile = File.createTempFile("broadcast-nginx", ".conf", new File("/opt/openvidu/tmp/"));
|
||||
FileWriter writer = new FileWriter(tmpFile);
|
||||
writer.write(config);
|
||||
writer.close();
|
||||
return tmpFile;
|
||||
}
|
||||
|
||||
}
|
|
@ -60,6 +60,7 @@ import io.openvidu.test.browsers.utils.CustomHttpClient;
|
|||
import io.openvidu.test.browsers.utils.RecordingUtils;
|
||||
import io.openvidu.test.browsers.utils.Unzipper;
|
||||
import io.openvidu.test.browsers.utils.webhook.CustomWebhook;
|
||||
import io.openvidu.test.e2e.utils.TestUtils;
|
||||
|
||||
public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
||||
|
||||
|
@ -230,7 +231,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
io.openvidu.test.browsers.utils.webhook.CustomWebhook.main(new String[0], initLatch);
|
||||
|
||||
try {
|
||||
String BROADCAST_IP = startRtmpServer();
|
||||
String BROADCAST_IP = TestUtils.startRtmpServer();
|
||||
|
||||
if (!initLatch.await(30, TimeUnit.SECONDS)) {
|
||||
Assertions.fail("Timeout waiting for webhook springboot app to start");
|
||||
|
@ -591,7 +592,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
}
|
||||
|
||||
} finally {
|
||||
stopRtmpServer();
|
||||
TestUtils.stopRtmpServer();
|
||||
CustomWebhook.shutDown();
|
||||
}
|
||||
}
|
||||
|
@ -1090,7 +1091,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
Assertions.assertTrue(connection.getNetworkCache() == null, "Wrong networkCache property");
|
||||
|
||||
try {
|
||||
String BROADCAST_IP = startRtmpServer();
|
||||
String BROADCAST_IP = TestUtils.startRtmpServer();
|
||||
// Start broadcast
|
||||
try {
|
||||
OV.startBroadcast("NOT_EXISTS", "rtmp://" + BROADCAST_IP + "/live");
|
||||
|
@ -1134,7 +1135,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
Assertions.assertFalse(session.isBeingBroadcasted());
|
||||
|
||||
} finally {
|
||||
stopRtmpServer();
|
||||
TestUtils.stopRtmpServer();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2810,7 +2811,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
log.info("Successfull broadcast Test");
|
||||
|
||||
try {
|
||||
String BROADCAST_IP = startRtmpServer();
|
||||
String BROADCAST_IP = TestUtils.startRtmpServer();
|
||||
|
||||
OpenViduTestappUser user = setupBrowserAndConnectToOpenViduTestapp("chrome");
|
||||
user.getDriver().findElement(By.id("add-user-btn")).click();
|
||||
|
@ -2859,7 +2860,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
gracefullyLeaveParticipants(user, 1);
|
||||
|
||||
} finally {
|
||||
stopRtmpServer();
|
||||
TestUtils.stopRtmpServer();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2870,7 +2871,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
log.info("Wrong broadcast Test");
|
||||
|
||||
try {
|
||||
String BROADCAST_IP = startRtmpServer();
|
||||
String BROADCAST_IP = TestUtils.startRtmpServer();
|
||||
|
||||
OpenViduTestappUser user = setupBrowserAndConnectToOpenViduTestapp("chrome");
|
||||
user.getDriver().findElement(By.id("add-user-btn")).click();
|
||||
|
@ -2982,7 +2983,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
|
|||
gracefullyLeaveParticipants(user, 1);
|
||||
|
||||
} finally {
|
||||
stopRtmpServer();
|
||||
TestUtils.stopRtmpServer();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue