Skip to content

Commit a1e8bcb

Browse files
committed
QE demo => added docker test version
1 parent b924a3d commit a1e8bcb

File tree

3 files changed

+727
-0
lines changed

3 files changed

+727
-0
lines changed
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
package io.elastest.qe.openvidu.docker;
2+
3+
import static java.lang.invoke.MethodHandles.lookup;
4+
import static org.slf4j.LoggerFactory.getLogger;
5+
6+
import java.io.BufferedReader;
7+
import java.io.InputStream;
8+
import java.io.InputStreamReader;
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
import java.util.concurrent.ExecutorService;
12+
import java.util.concurrent.Executors;
13+
import java.util.concurrent.TimeUnit;
14+
15+
import org.junit.jupiter.api.AfterAll;
16+
import org.junit.jupiter.api.AfterEach;
17+
import org.junit.jupiter.api.BeforeAll;
18+
import org.junit.jupiter.api.BeforeEach;
19+
import org.junit.jupiter.api.TestInfo;
20+
import org.slf4j.Logger;
21+
22+
import io.elastest.qe.utils.CountDownLatchWithException;
23+
import io.elastest.qe.utils.CountDownLatchWithException.AbortedException;
24+
import io.elastest.qe.utils.MonitoringManager;
25+
import io.github.bonigarcia.wdm.WebDriverManager;
26+
27+
public class BaseTest {
28+
protected static final Logger logger = getLogger(lookup().lookupClass());
29+
30+
public static int USERS_BY_SESSION = 3;
31+
public static int MAX_SESSIONS = 2;
32+
33+
public static String OPENVIDU_SECRET = "MY_SECRET";
34+
protected static String OPENVIDU_SUT_URL;
35+
protected static String OPENVIDU_WEBAPP_URL;
36+
37+
public static int SECONDS_OF_WAIT = 40;
38+
public static int BROWSER_POLL_INTERVAL = 1000;
39+
40+
protected static boolean USE_OPENVIDU_FAKE_RESOURCES = false;
41+
42+
protected static String EUS_URL;
43+
protected static String ET_ETM_TJOB_ATTACHMENT_API;
44+
45+
protected static List<BrowserClient> browserClientList;
46+
47+
protected static boolean isDevelopment = false;
48+
public static MonitoringManager monitoringManager;
49+
50+
public static void initParameters() {
51+
String openviduSecret = System.getenv("OPENVIDU_SECRET");
52+
String sessions = System.getenv("MAX_SESSIONS");
53+
String usersSession = System.getenv("USERS_BY_SESSION");
54+
String secondsOfWait = System.getenv("SECONDS_OF_WAIT");
55+
String browserPollInterval = System.getenv("BROWSER_POLL_INTERVAL");
56+
String useOpenviduFakeResources = System.getenv("USE_OPENVIDU_FAKE_RESOURCES");
57+
58+
if (openviduSecret != null) {
59+
OPENVIDU_SECRET = openviduSecret;
60+
}
61+
if (sessions != null) {
62+
MAX_SESSIONS = Integer.parseInt(sessions);
63+
}
64+
if (usersSession != null) {
65+
USERS_BY_SESSION = Integer.parseInt(usersSession);
66+
}
67+
if (secondsOfWait != null) {
68+
SECONDS_OF_WAIT = Integer.parseInt(secondsOfWait);
69+
}
70+
71+
if (browserPollInterval != null) {
72+
BROWSER_POLL_INTERVAL = Integer.parseInt(browserPollInterval);
73+
}
74+
75+
if (useOpenviduFakeResources != null) {
76+
USE_OPENVIDU_FAKE_RESOURCES = useOpenviduFakeResources.equals("true") ? true : false;
77+
}
78+
79+
}
80+
81+
@BeforeAll
82+
public static void setupClass() throws Exception {
83+
initParameters();
84+
browserClientList = new ArrayList<>();
85+
86+
ET_ETM_TJOB_ATTACHMENT_API = System.getenv("ET_ETM_TJOB_ATTACHMENT_API");
87+
88+
/* *********************************** */
89+
/* ******** Openvidu Sut init ******** */
90+
/* *********************************** */
91+
92+
String sutHost = System.getenv("ET_SUT_HOST");
93+
String sutPort = System.getenv("ET_SUT_PORT");
94+
String sutProtocol = System.getenv("ET_SUT_PROTOCOL");
95+
96+
if (sutHost != null) {
97+
sutPort = sutPort != null ? sutPort : "4443";
98+
sutProtocol = sutProtocol != null ? sutProtocol : "https";
99+
100+
OPENVIDU_SUT_URL = sutProtocol + "://" + sutHost + ":" + sutPort;
101+
OPENVIDU_WEBAPP_URL = sutProtocol + "://" + sutHost;
102+
} else {
103+
throw new Exception("No Sut URL");
104+
}
105+
106+
logger.info("OpenVidu Sut URL: {}", OPENVIDU_SUT_URL);
107+
logger.info("OpenVidu Webapp URL: {}", OPENVIDU_WEBAPP_URL);
108+
109+
/* ************************************ */
110+
/* ************* EUS init ************* */
111+
/* ************************************ */
112+
EUS_URL = System.getenv("ET_EUS_API");
113+
114+
if (EUS_URL == null) {
115+
logger.warn("NOT Using EUS URL");
116+
WebDriverManager.chromedriver().setup();
117+
} else {
118+
logger.info("Using EUS URL: {}", EUS_URL);
119+
}
120+
121+
if (OPENVIDU_WEBAPP_URL == null || OPENVIDU_WEBAPP_URL.isEmpty()) {
122+
throw new Exception(
123+
"OpenVidu WebApp Url is empty, probably because the stack was not obtained correctly");
124+
}
125+
126+
monitoringManager = new MonitoringManager();
127+
logger.info("Configured new Monitoring Manager: {}", monitoringManager);
128+
}
129+
130+
@BeforeEach
131+
public void setupTest(TestInfo info) {
132+
String testName = info.getTestMethod().get().getName();
133+
logger.info("##### Start test: {}", testName);
134+
}
135+
136+
@AfterEach
137+
public void teardown(TestInfo info) {
138+
if (browserClientList != null) {
139+
ExecutorService browserDisposeTaskExecutor = Executors.newCachedThreadPool();
140+
CountDownLatchWithException waitForBrowsersEndLatch = new CountDownLatchWithException(
141+
browserClientList.size());
142+
List<Runnable> browserThreads = new ArrayList<>();
143+
for (BrowserClient browserClient : browserClientList) {
144+
if (browserClient != null) {
145+
browserThreads.add(() -> {
146+
browserClient.dispose();
147+
waitForBrowsersEndLatch.countDown();
148+
});
149+
}
150+
}
151+
152+
for (Runnable r : browserThreads) {
153+
browserDisposeTaskExecutor.execute(r);
154+
}
155+
156+
try {
157+
waitForBrowsersEndLatch.await();
158+
} catch (AbortedException e1) {
159+
}
160+
161+
browserDisposeTaskExecutor.shutdown();
162+
try {
163+
browserDisposeTaskExecutor.awaitTermination(5, TimeUnit.MINUTES);
164+
} catch (InterruptedException e) {
165+
}
166+
}
167+
168+
String testName = info.getTestMethod().get().getName();
169+
logger.info("##### Finish test: {}", testName);
170+
browserClientList = new ArrayList<>();
171+
172+
}
173+
174+
@AfterAll
175+
public static void clear() {
176+
177+
}
178+
179+
public static String convertStreamToString(InputStream in) throws Exception {
180+
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
181+
StringBuilder stringbuilder = new StringBuilder();
182+
String line = null;
183+
while ((line = reader.readLine()) != null) {
184+
stringbuilder.append(line + "\n");
185+
}
186+
in.close();
187+
return stringbuilder.toString();
188+
}
189+
190+
public static void sleep(int millis) {
191+
try {
192+
Thread.sleep(millis);
193+
} catch (InterruptedException e) {
194+
}
195+
}
196+
}

0 commit comments

Comments
 (0)