Skip to content

Commit e41f89f

Browse files
authored
Backfills tests for ES_HOSTS (openzipkin#1682)
1 parent 89a0365 commit e41f89f

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

zipkin-storage/elasticsearch-http/src/test/java/zipkin/storage/elasticsearch/http/ElasticsearchHttpStorageTest.java

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515

1616
import java.io.IOException;
1717
import java.util.concurrent.TimeUnit;
18+
import okhttp3.OkHttpClient;
19+
import okhttp3.internal.tls.SslClient;
1820
import okhttp3.mockwebserver.MockResponse;
1921
import okhttp3.mockwebserver.MockWebServer;
2022
import org.junit.After;
2123
import org.junit.Rule;
2224
import org.junit.Test;
25+
import zipkin.Component;
2326
import zipkin.storage.elasticsearch.http.internal.LenientDoubleCallbackAsyncSpanStore;
2427

2528
import static java.util.Arrays.asList;
@@ -144,4 +147,81 @@ void checkLegacyComponents(MockResponse response) throws InterruptedException {
144147
es.takeRequest(); // get version
145148
es.takeRequest(); // get legacy template
146149
}
150+
151+
String healthResponse = "{\n"
152+
+ " \"cluster_name\": \"elasticsearch_zipkin\",\n"
153+
+ " \"status\": \"yellow\",\n"
154+
+ " \"timed_out\": false,\n"
155+
+ " \"number_of_nodes\": 1,\n"
156+
+ " \"number_of_data_nodes\": 1,\n"
157+
+ " \"active_primary_shards\": 5,\n"
158+
+ " \"active_shards\": 5,\n"
159+
+ " \"relocating_shards\": 0,\n"
160+
+ " \"initializing_shards\": 0,\n"
161+
+ " \"unassigned_shards\": 5,\n"
162+
+ " \"delayed_unassigned_shards\": 0,\n"
163+
+ " \"number_of_pending_tasks\": 0,\n"
164+
+ " \"number_of_in_flight_fetch\": 0,\n"
165+
+ " \"task_max_waiting_in_queue_millis\": 0,\n"
166+
+ " \"active_shards_percent_as_number\": 50\n"
167+
+ "}";
168+
169+
@Test public void check() throws Exception {
170+
es.enqueue(new MockResponse().setBody(healthResponse));
171+
172+
assertThat(storage.check())
173+
.isEqualTo(Component.CheckResult.OK);
174+
}
175+
176+
@Test public void check_oneHostDown() throws Exception {
177+
storage.close();
178+
OkHttpClient client = new OkHttpClient.Builder()
179+
.connectTimeout(100, TimeUnit.MILLISECONDS)
180+
.build();
181+
storage = ElasticsearchHttpStorage.builder(client)
182+
.hosts(asList("http://1.2.3.4:" + es.getPort(), es.url("").toString()))
183+
.build();
184+
185+
es.enqueue(new MockResponse().setBody(healthResponse));
186+
187+
assertThat(storage.check())
188+
.isEqualTo(Component.CheckResult.OK);
189+
}
190+
191+
@Test public void check_ssl() throws Exception {
192+
storage.close();
193+
SslClient sslClient = SslClient.localhost();
194+
OkHttpClient client = new OkHttpClient.Builder()
195+
.sslSocketFactory(sslClient.socketFactory, sslClient.trustManager)
196+
.build();
197+
es.useHttps(sslClient.socketFactory, false);
198+
199+
storage = ElasticsearchHttpStorage.builder(client)
200+
.hosts(asList(es.url("").toString()))
201+
.build();
202+
203+
es.enqueue(new MockResponse().setBody(healthResponse));
204+
205+
assertThat(storage.check())
206+
.isEqualTo(Component.CheckResult.OK);
207+
208+
assertThat(es.takeRequest().getTlsVersion())
209+
.isNotNull();
210+
}
211+
212+
@Test(expected = IllegalArgumentException.class)
213+
public void multipleSslNotYetSupported() throws Exception {
214+
storage.close();
215+
SslClient sslClient = SslClient.localhost();
216+
OkHttpClient client = new OkHttpClient.Builder()
217+
.sslSocketFactory(sslClient.socketFactory, sslClient.trustManager)
218+
.build();
219+
es.useHttps(sslClient.socketFactory, false);
220+
221+
storage = ElasticsearchHttpStorage.builder(client)
222+
.hosts(asList("https://1.2.3.4:" + es.getPort(), es.url("").toString()))
223+
.build();
224+
225+
storage.check();
226+
}
147227
}

0 commit comments

Comments
 (0)