Search in sources :

Example 1 with AutoRestParameterizedHostTestClientImpl

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));
}
Also used : OkHttpClient(okhttp3.OkHttpClient) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) Response(okhttp3.Response) Retrofit(retrofit2.Retrofit) AutoRestParameterizedHostTestClientImpl(fixtures.custombaseuri.implementation.AutoRestParameterizedHostTestClientImpl) Interceptor(okhttp3.Interceptor) Test(org.junit.Test)

Aggregations

AutoRestParameterizedHostTestClientImpl (fixtures.custombaseuri.implementation.AutoRestParameterizedHostTestClientImpl)1 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Interceptor (okhttp3.Interceptor)1 OkHttpClient (okhttp3.OkHttpClient)1 Response (okhttp3.Response)1 Test (org.junit.Test)1 Retrofit (retrofit2.Retrofit)1