forked from testcontainers/testcontainers-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolrContainerTest.java
More file actions
86 lines (71 loc) · 2.72 KB
/
SolrContainerTest.java
File metadata and controls
86 lines (71 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package org.testcontainers.containers;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.Http2SolrClient;
import org.apache.solr.client.solrj.response.SolrPingResponse;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(Parameterized.class)
public class SolrContainerTest {
@Parameterized.Parameters(name = "{0}")
public static String[] getVersionsToTest() {
return new String[] { "solr:8.11.4", "solr:9.8.0" };
}
@Parameterized.Parameter
public String solrImage;
private SolrClient client = null;
@After
public void stopRestClient() throws IOException {
if (client != null) {
client.close();
client = null;
}
}
@Test
public void solrCloudTest() throws IOException, SolrServerException {
try (SolrContainer container = new SolrContainer(solrImage)) {
container.start();
SolrPingResponse response = getClient(container).ping("dummy");
assertThat(response.getStatus()).isZero();
assertThat(response.jsonStr()).contains("zkConnected\":true");
}
}
@Test
public void solrStandaloneTest() throws IOException, SolrServerException {
try (SolrContainer container = new SolrContainer(solrImage).withZookeeper(false)) {
container.start();
SolrPingResponse response = getClient(container).ping("dummy");
assertThat(response.getStatus()).isZero();
assertThat(response.jsonStr()).contains("zkConnected\":null");
}
}
@Test
public void solrCloudPingTest() throws IOException, SolrServerException {
// solrContainerUsage {
// Create the solr container.
SolrContainer container = new SolrContainer(solrImage);
// Start the container. This step might take some time...
container.start();
// Do whatever you want with the client ...
SolrClient client = new Http2SolrClient.Builder(
"http://" + container.getHost() + ":" + container.getSolrPort() + "/solr"
)
.build();
SolrPingResponse response = client.ping("dummy");
// Stop the container.
container.stop();
// }
}
private SolrClient getClient(SolrContainer container) {
if (client == null) {
client =
new Http2SolrClient.Builder("http://" + container.getHost() + ":" + container.getSolrPort() + "/solr")
.build();
}
return client;
}
}