-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Begins migration off Elasticsearch 2.x library (and Guava) (#1495)
Currently, our Elasticsearch 2.x dependency makes it impossible to load recent versions of Elasticsearch or Guava. This begins work to migrate off by porting write and health code to not use guava types. See #1431
- Loading branch information
1 parent
cf4df43
commit b543f09
Showing
13 changed files
with
279 additions
and
89 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...e/elasticsearch-http/src/main/java/zipkin/storage/elasticsearch/http/CallbackAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright 2015-2017 The OpenZipkin Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package zipkin.storage.elasticsearch.http; | ||
|
||
import java.io.IOException; | ||
import okhttp3.Call; | ||
import okhttp3.Response; | ||
import okhttp3.ResponseBody; | ||
import zipkin.storage.Callback; | ||
|
||
import static zipkin.internal.Util.propagateIfFatal; | ||
|
||
class CallbackAdapter<V> implements okhttp3.Callback { | ||
final Call call; | ||
final Callback<V> delegate; | ||
|
||
CallbackAdapter(Call call, zipkin.storage.Callback<V> delegate) { | ||
this.call = call; | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override public void onFailure(Call call, IOException e) { | ||
delegate.onError(e); | ||
} | ||
|
||
void enqueue() { | ||
call.enqueue(this); | ||
} | ||
|
||
/** Note: this runs on the {@link okhttp3.OkHttpClient#dispatcher() dispatcher} thread! */ | ||
@Override public void onResponse(Call call, Response response) { | ||
try (ResponseBody responseBody = response.body()) { | ||
if (response.isSuccessful()) { | ||
delegate.onSuccess(convert(responseBody)); | ||
} else { | ||
delegate.onError(new IllegalStateException("response failed: " + response)); | ||
} | ||
} catch (Throwable t) { | ||
propagateIfFatal(t); | ||
delegate.onError(t); | ||
} | ||
} | ||
|
||
V convert(ResponseBody responseBody) throws IOException { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...asticsearch-http/src/test/java/zipkin/storage/elasticsearch/http/CallbackAdapterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** | ||
* Copyright 2015-2017 The OpenZipkin Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package zipkin.storage.elasticsearch.http; | ||
|
||
import com.google.common.util.concurrent.SimpleTimeLimiter; | ||
import com.google.common.util.concurrent.UncheckedTimeoutException; | ||
import java.io.IOException; | ||
import java.util.concurrent.TimeUnit; | ||
import okhttp3.Call; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.ResponseBody; | ||
import okhttp3.mockwebserver.MockResponse; | ||
import okhttp3.mockwebserver.MockWebServer; | ||
import org.junit.After; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import zipkin.internal.CallbackCaptor; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; | ||
|
||
public class CallbackAdapterTest { | ||
@Rule | ||
public MockWebServer mws = new MockWebServer(); | ||
|
||
OkHttpClient client = new OkHttpClient(); | ||
CallbackCaptor<Void> callback = new CallbackCaptor<>(); | ||
Call call = client.newCall(new Request.Builder().url(mws.url("")).build()); | ||
|
||
@After | ||
public void close() throws IOException { | ||
client.dispatcher().executorService().shutdownNow(); | ||
} | ||
|
||
@Test | ||
public void propagatesOnDispatcherThreadWhenFatal() throws Exception { | ||
mws.enqueue(new MockResponse()); | ||
|
||
new CallbackAdapter<Void>(call, callback) { | ||
@Override Void convert(ResponseBody responseBody) throws IOException { | ||
throw new LinkageError(); | ||
} | ||
}.enqueue(); | ||
|
||
SimpleTimeLimiter timeLimiter = new SimpleTimeLimiter(); | ||
try { | ||
timeLimiter.callWithTimeout(callback::get, 100, TimeUnit.MILLISECONDS, true); | ||
failBecauseExceptionWasNotThrown(UncheckedTimeoutException.class); | ||
} catch (UncheckedTimeoutException expected) { | ||
} | ||
} | ||
|
||
@Test | ||
public void executionException_conversionException() throws Exception { | ||
mws.enqueue(new MockResponse()); | ||
|
||
new CallbackAdapter<Void>(call, callback) { | ||
@Override Void convert(ResponseBody responseBody) throws IOException { | ||
throw new IllegalArgumentException("eeek"); | ||
} | ||
}.enqueue(); | ||
|
||
try { | ||
callback.get(); | ||
failBecauseExceptionWasNotThrown(IllegalArgumentException.class); | ||
} catch (IllegalArgumentException expected) { | ||
assertThat(expected).isInstanceOf(IllegalArgumentException.class); | ||
} | ||
} | ||
|
||
@Test | ||
public void executionException_httpFailure() throws Exception { | ||
mws.enqueue(new MockResponse().setResponseCode(500)); | ||
|
||
new CallbackAdapter<Void>(call, callback).enqueue(); | ||
|
||
try { | ||
callback.get(); | ||
failBecauseExceptionWasNotThrown(IllegalStateException.class); | ||
} catch (IllegalStateException expected) { | ||
assertThat(expected).isInstanceOf(IllegalStateException.class); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.