Skip to content

Commit 2e383b1

Browse files
committed
Trying Copilot's suggestion
1 parent d069870 commit 2e383b1

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

Jenkinsfile

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,48 @@ pipeline {
175175
export PATH=$GRADLE_USER_HOME:$JAVA_HOME/bin:$PATH
176176
cd java-client-api
177177
// Ensure all modules can be built first.
178-
./gradlew clean build -x test
178+
// ./gradlew clean build -x test
179179
180180
// Run a sufficient number of tests to verify the PR.
181181
// Temporarily running a single test to debug the reverse proxy server
182182
//./gradlew cleanTest marklogic-client-api:test || true
183-
./gradlew -PtestUseReverseProxyServer=true runReverseProxyServer marklogic-client-api:test --tests ReadDocumentPageTest || true
183+
184+
// Use a random port to avoid conflicts from previous builds
185+
PROXY_PORT=$((8020 + RANDOM % 1000))
186+
echo "Using reverse proxy port: $PROXY_PORT"
187+
188+
// Check if anything is already using this port
189+
echo "Checking what's using port $PROXY_PORT before starting proxy..."
190+
netstat -tuln | grep $PROXY_PORT || echo "Port $PROXY_PORT is free"
191+
192+
// Start reverse proxy server in background and capture its PID
193+
./gradlew -PtestUseReverseProxyServer=true -PrpsHttpPort=$PROXY_PORT test-app:runBlockingReverseProxyServer --stacktrace > reverse-proxy.log 2>&1 &
194+
PROXY_PID=$!
195+
echo "Started reverse proxy server with PID: $PROXY_PID"
196+
197+
// Wait for proxy server to be ready
198+
sleep 5
199+
200+
// Check if proxy server is actually listening on the port
201+
echo "Checking if reverse proxy is listening on port $PROXY_PORT..."
202+
netstat -tuln | grep $PROXY_PORT || echo "WARNING: No process listening on port $PROXY_PORT!"
203+
204+
// Show the last few lines of the proxy log
205+
echo "Reverse proxy log (last 20 lines):"
206+
tail -20 reverse-proxy.log || echo "No log file found"
207+
208+
// Run tests
209+
./gradlew -PtestUseReverseProxyServer=true -DTEST_REVERSE_PROXY_PORT=$PROXY_PORT marklogic-client-api:test --tests ReadDocumentPageTest || true
210+
211+
// Show the reverse proxy log after tests complete
212+
echo "Reverse proxy log after tests (last 50 lines):"
213+
tail -50 reverse-proxy.log || echo "No log file found"
214+
215+
// Kill the reverse proxy server
216+
echo "Stopping reverse proxy server (PID: $PROXY_PID)"
217+
kill $PROXY_PID 2>/dev/null || true
218+
sleep 2
219+
kill -9 $PROXY_PID 2>/dev/null || true
184220
'''
185221
// Omitting this until MLE-24523 can be addressed
186222
// ./gradlew -PtestUseReverseProxyServer=true test-app:runReverseProxyServer marklogic-client-api-functionaltests:runFastFunctionalTests || true

marklogic-client-api/src/test/java/com/marklogic/client/test/Common.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class Common {
4848
final public static String HOST = System.getProperty("TEST_HOST", "localhost");
4949

5050
final public static boolean USE_REVERSE_PROXY_SERVER = Boolean.parseBoolean(System.getProperty("TEST_USE_REVERSE_PROXY_SERVER", "false"));
51-
final public static int PORT = USE_REVERSE_PROXY_SERVER ? 8020 : Integer.parseInt(System.getProperty("TEST_PORT", "8012"));
51+
final public static int PORT = USE_REVERSE_PROXY_SERVER ? Integer.parseInt(System.getProperty("TEST_REVERSE_PROXY_PORT", "8020")) : Integer.parseInt(System.getProperty("TEST_PORT", "8012"));
5252
final public static String AUTH_TYPE = USE_REVERSE_PROXY_SERVER ? "basic" : System.getProperty("TEST_AUTH_TYPE", "digest");
5353
final public static String BASE_PATH = USE_REVERSE_PROXY_SERVER ? "test/marklogic/unit" : System.getProperty("TEST_BASE_PATH", null);
5454
final public static boolean WITH_WAIT = Boolean.parseBoolean(System.getProperty("TEST_WAIT", "false"));

test-app/src/main/java/com/marklogic/client/test/ReverseProxyServer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,18 @@ public ReverseProxyServer(String markLogicHost, String serverHost, int serverPor
143143

144144
Undertow.Builder undertowBuilder = Undertow.builder()
145145
.addHttpListener(serverPort, serverHost)
146-
.addHttpListener(8022, serverHost, new BlockingHandler(exchange -> handleMarkLogicCloudTokenRequest(exchange)))
146+
// Only add the token endpoint listener if secure server port is configured (indicating Data Cloud emulation is needed)
147+
// This avoids port conflicts when the /token endpoint isn't needed
147148
.setIoThreads(4)
148149
.setHandler(ProxyHandler.builder()
149150
.setProxyClient(new ReverseProxyClient(mapping))
150151
.setMaxRequestTime(30000)
151152
.build()
152153
);
154+
155+
if (secureServerPort > 0) {
156+
undertowBuilder.addHttpListener(8022, serverHost, new BlockingHandler(exchange -> handleMarkLogicCloudTokenRequest(exchange)));
157+
}
153158

154159
if (secureServerPort > 0) {
155160
logger.info("Adding an HTTPS listener on port: " + secureServerPort + "; note that if this port 443 " +

0 commit comments

Comments
 (0)