use of fixtures.custombaseuri.implementation.AutoRestParameterizedHostTestClientImpl in project autorest.java by Azure.
the class CustomBaseUriTests method getEmptyMultipleThreads.
@Test
public void getEmptyMultipleThreads() throws Exception {
final CountDownLatch latch = new CountDownLatch(2);
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder().addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// do nothing
}
return chain.proceed(chain.request());
}
});
final AutoRestParameterizedHostTestClient client1 = new AutoRestParameterizedHostTestClientImpl(clientBuilder, new Retrofit.Builder());
client1.withHost("host:3000");
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
try {
client1.paths().getEmpty("badlocal");
fail();
} catch (RuntimeException e) {
latch.countDown();
} catch (Exception e) {
fail();
}
}
});
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
try {
client1.paths().getEmpty("local");
latch.countDown();
} catch (Exception ex) {
fail();
}
}
});
t1.start();
t2.start();
Assert.assertTrue(latch.await(15, TimeUnit.SECONDS));
}
Aggregations