List of usage examples for java.util.concurrent.atomic AtomicIntegerArray addAndGet
public final int addAndGet(int i, int delta)
From source file:com.netflix.iep.http.RxHttpTest.java
@Test public void relativeRedirect() throws Exception { int code = 200; statusCode.set(code);//from www . ja va 2s .c om redirects.set(2); AtomicIntegerArray expected = copy(statusCounts); expected.addAndGet(302, 2); expected.addAndGet(code, 1); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<Throwable> throwable = new AtomicReference<>(); rxHttp.get(uri("/relativeRedirect")).subscribe(Actions.empty(), new Action1<Throwable>() { @Override public void call(Throwable t) { latch.countDown(); throwable.set(t); } }, new Action0() { @Override public void call() { latch.countDown(); } }); latch.await(); assertEquals(expected, statusCounts); }
From source file:com.netflix.iep.http.RxHttpTest.java
@Test public void notModified() throws Exception { int code = 304; statusCode.set(code);/*from w w w .ja v a 2s. c om*/ redirects.set(2); AtomicIntegerArray expected = copy(statusCounts); expected.addAndGet(code, 1); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<Throwable> throwable = new AtomicReference<>(); rxHttp.get(uri("/notModified")).subscribe(Actions.empty(), new Action1<Throwable>() { @Override public void call(Throwable t) { latch.countDown(); throwable.set(t); } }, new Action0() { @Override public void call() { latch.countDown(); } }); latch.await(); assertEquals(expected, statusCounts); Assert.assertNull(throwable.get()); }
From source file:com.netflix.iep.http.RxHttpTest.java
@Test public void redirectResponseMissingLocation() throws Exception { int code = 302; statusCode.set(code);/*www. j av a 2s . co m*/ redirects.set(2); AtomicIntegerArray expected = copy(statusCounts); expected.addAndGet(code, 1); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<Throwable> throwable = new AtomicReference<>(); rxHttp.get(uri("/redirectNoLocation")).subscribe(Actions.empty(), new Action1<Throwable>() { @Override public void call(Throwable t) { latch.countDown(); throwable.set(t); } }, new Action0() { @Override public void call() { latch.countDown(); } }); latch.await(); assertEquals(expected, statusCounts); Assert.assertNotNull(throwable.get()); }
From source file:com.netflix.iep.http.RxHttpTest.java
@Test public void readTimeout() throws Exception { //set(client + ".niws.client.ReadTimeout", "100"); int code = 200; statusCode.set(code);/*from w w w.j av a2s . c o m*/ AtomicIntegerArray expected = copy(statusCounts); expected.addAndGet(code, 3); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<Throwable> throwable = new AtomicReference<>(); rxHttp.get(uri("/readTimeout")).subscribe(Actions.empty(), new Action1<Throwable>() { @Override public void call(Throwable t) { throwable.set(t); latch.countDown(); } }, new Action0() { @Override public void call() { latch.countDown(); } }); latch.await(); Assert.assertTrue(throwable.get() instanceof ReadTimeoutException); assertEquals(expected, statusCounts); }
From source file:com.netflix.iep.http.RxHttpTest.java
@Test public void readTimeoutDoesntRetry() throws Exception { //set(client + ".niws.client.ReadTimeout", "100"); set(client + ".niws.client.RetryReadTimeouts", "false"); int code = 200; statusCode.set(code);/*from ww w . j av a 2s .c o m*/ AtomicIntegerArray expected = copy(statusCounts); expected.addAndGet(code, 1); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<Throwable> throwable = new AtomicReference<>(); rxHttp.get(uri("/readTimeout")).subscribe(Actions.empty(), new Action1<Throwable>() { @Override public void call(Throwable t) { throwable.set(t); latch.countDown(); } }, new Action0() { @Override public void call() { latch.countDown(); } }); latch.await(); Assert.assertTrue(throwable.get() instanceof ReadTimeoutException); assertEquals(expected, statusCounts); }
From source file:com.netflix.iep.http.RxHttpTest.java
@Test public void gzipPost() throws Exception { //set(client + ".niws.client.ReadTimeout", "1000"); int code = 200; statusCode.set(code);//from w w w. java 2s .c o m AtomicIntegerArray expected = copy(statusCounts); expected.addAndGet(code, 1); StringBuilder content = new StringBuilder(); for (int i = 0; i < 500; ++i) { content.append(i).append(", "); } String body = content.toString(); final StringBuilder builder = new StringBuilder(); rxHttp.post(uri("/echo"), "text/plain", body.getBytes()) .flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<ByteBuf>>() { @Override public Observable<ByteBuf> call(HttpClientResponse<ByteBuf> res) { Assert.assertEquals(200, res.getStatus().code()); return res.getContent(); } }).toBlocking().forEach(new Action1<ByteBuf>() { @Override public void call(ByteBuf byteBuf) { builder.append(byteBuf.toString(Charset.defaultCharset())); } }); Assert.assertEquals(body, builder.toString()); assertEquals(expected, statusCounts); }
From source file:com.netflix.iep.http.RxHttpTest.java
@Test public void absoluteRedirect() throws Exception { int code = 200; statusCode.set(code);// w w w .j av a2 s. co m redirects.set(2); AtomicIntegerArray expected = copy(statusCounts); expected.incrementAndGet(code); expected.addAndGet(302, 3); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<Throwable> throwable = new AtomicReference<>(); rxHttp.get(uri("/absoluteRedirect")).subscribe(Actions.empty(), new Action1<Throwable>() { @Override public void call(Throwable t) { throwable.set(t); latch.countDown(); } }, new Action0() { @Override public void call() { latch.countDown(); } }); latch.await(); Assert.assertNull(throwable.get()); assertEquals(expected, statusCounts); }