Skip to content

Commit 727378d

Browse files
committed
Trying Caddy to see if it fixes connection issues on Jenkins
1 parent d08b0e1 commit 727378d

File tree

6 files changed

+59
-18
lines changed

6 files changed

+59
-18
lines changed

caddy/config/Caddyfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# See https://caddyserver.com/docs/caddyfile-tutorial for more information.
2+
3+
:8115 {
4+
reverse_proxy marklogic:8015 {
5+
transport http {
6+
dial_timeout 31s
7+
}
8+
# Required for MLCP to work; "ip_hash" also works.
9+
# See https://caddyserver.com/docs/caddyfile/directives/reverse_proxy#load-balancing for more information.
10+
lb_policy cookie
11+
}
12+
}
13+
14+
:8116 {
15+
reverse_proxy marklogic:8016 {
16+
transport http {
17+
dial_timeout 31s
18+
}
19+
lb_policy cookie
20+
}
21+
}

docker-compose.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ name: marklogic_spark
22

33
services:
44

5+
# See https://caddyserver.com/docs/quick-starts/reverse-proxy for more information on using Caddy as a reverse proxy
6+
# and load balancer.
7+
caddy-load-balancer:
8+
image: caddy:2-alpine
9+
volumes:
10+
- ./caddy/data:/data
11+
- ./caddy/config/Caddyfile:/etc/caddy/Caddyfile
12+
ports:
13+
# Expand this range as needed. See Caddyfile for which ports are used for reverse proxies.
14+
- "8115:8115"
15+
- "8116:8116"
16+
517
marklogic:
618
image: "${MARKLOGIC_TAG}"
719
platform: linux/amd64

src/test/java/com/marklogic/spark/AbstractIntegrationTest.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
import com.marklogic.client.io.DocumentMetadataHandle;
88
import com.marklogic.junit5.XmlNode;
99
import com.marklogic.junit5.spring.AbstractSpringMarkLogicTest;
10-
import com.marklogic.junit5.spring.SimpleTestConfig;
1110
import org.apache.spark.SparkException;
1211
import org.apache.spark.sql.*;
1312
import org.apache.spark.util.VersionUtils;
1413
import org.jdom2.Namespace;
1514
import org.junit.jupiter.api.AfterEach;
15+
import org.junit.jupiter.api.BeforeEach;
1616
import org.springframework.beans.factory.annotation.Autowired;
1717
import org.springframework.core.io.ClassPathResource;
18+
import org.springframework.test.context.ContextConfiguration;
1819
import org.springframework.util.FileCopyUtils;
1920

2021
import java.io.IOException;
@@ -31,6 +32,7 @@
3132
* <p>
3233
* Use this as the base class for all tests that need to connect to MarkLogic.
3334
*/
35+
@ContextConfiguration(classes = {TestConfig.class})
3436
public abstract class AbstractIntegrationTest extends AbstractSpringMarkLogicTest {
3537

3638
// User credentials for all calls to MarkLogic by the Spark connector
@@ -49,28 +51,20 @@ public abstract class AbstractIntegrationTest extends AbstractSpringMarkLogicTes
4951
* operations requiring an admin-like user.
5052
*/
5153
@Autowired
52-
protected SimpleTestConfig testConfig;
54+
protected TestConfig testConfig;
5355

5456
protected SparkSession sparkSession;
5557

58+
@BeforeEach
59+
void logConnectionString() {
60+
logger.info("Default connection string: {}", makeClientUri());
61+
}
62+
5663
@AfterEach
5764
public void closeSparkSession() {
5865
if (sparkSession != null) {
5966
sparkSession.close();
6067
}
61-
smallDelayUntilNextTest();
62-
}
63-
64-
// Tell Sonar not to worry about this for now.
65-
@SuppressWarnings({"java:S2925"})
66-
private void smallDelayUntilNextTest() {
67-
// Hopefully a temporary hack to see if we get fewer random failures on Jenkins due to connectivity issues that
68-
// are likely due to Docker restarting MarkLogic due to insufficient memory.
69-
try {
70-
Thread.sleep(100);
71-
} catch (InterruptedException e) {
72-
// No need to handle.
73-
}
7468
}
7569

7670
@Override
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright © 2024 MarkLogic Corporation. All Rights Reserved.
3+
*/
4+
package com.marklogic.spark;
5+
6+
import com.marklogic.junit5.spring.SimpleTestConfig;
7+
8+
public class TestConfig extends SimpleTestConfig {
9+
10+
@Override
11+
public Integer getRestPort() {
12+
// Use the Caddy port to avoid connection failures on Jenkins.
13+
return 8116;
14+
}
15+
}

src/test/java/com/marklogic/spark/reader/triples/ReadTriplesTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
import org.apache.spark.sql.DataFrameReader;
99
import org.apache.spark.sql.Row;
1010
import org.apache.spark.sql.SaveMode;
11-
import org.junit.jupiter.api.Disabled;
1211
import org.junit.jupiter.api.Test;
1312

1413
import java.util.List;
1514

1615
import static org.junit.jupiter.api.Assertions.assertEquals;
1716
import static org.junit.jupiter.api.Assertions.assertTrue;
1817

19-
@Disabled("Annoying")
2018
class ReadTriplesTest extends AbstractIntegrationTest {
2119

2220
@Test

src/test/java/com/marklogic/spark/writer/WriteRowsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ void insufficientPrivilegeForOtherDatabase() {
7777
DataFrameWriter writer = newWriter(2)
7878
.option(Options.WRITE_THREAD_COUNT_PER_PARTITION, 8)
7979
.option(Options.WRITE_BATCH_SIZE, 10)
80-
.option(Options.CLIENT_URI, "spark-test-user:spark@localhost:8016/Documents");
80+
.option(Options.CLIENT_URI, String.format("spark-test-user:spark@%s:%d/Documents",
81+
testConfig.getHost(), testConfig.getRestPort()));
8182

8283
SparkException ex = assertThrows(SparkException.class, () -> writer.save());
8384
assertNull(ex.getCause(), "Surprisingly, in this scenario where the exception is thrown during the " +

0 commit comments

Comments
 (0)