|
15 | 15 |
|
16 | 16 | import java.io.IOException;
|
17 | 17 | import java.util.concurrent.TimeUnit;
|
| 18 | +import okhttp3.OkHttpClient; |
| 19 | +import okhttp3.internal.tls.SslClient; |
18 | 20 | import okhttp3.mockwebserver.MockResponse;
|
19 | 21 | import okhttp3.mockwebserver.MockWebServer;
|
20 | 22 | import org.junit.After;
|
21 | 23 | import org.junit.Rule;
|
22 | 24 | import org.junit.Test;
|
| 25 | +import zipkin.Component; |
23 | 26 | import zipkin.storage.elasticsearch.http.internal.LenientDoubleCallbackAsyncSpanStore;
|
24 | 27 |
|
25 | 28 | import static java.util.Arrays.asList;
|
@@ -144,4 +147,81 @@ void checkLegacyComponents(MockResponse response) throws InterruptedException {
|
144 | 147 | es.takeRequest(); // get version
|
145 | 148 | es.takeRequest(); // get legacy template
|
146 | 149 | }
|
| 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 | + } |
147 | 227 | }
|
0 commit comments