GeezerVison is showing github.com — TakeLastQueueProducer add request overflow check · jsanda/RxJava@01ceedc
File tree
Expand file treeCollapse file tree
Open diff view settings
main/java/rx/internal/operators test/java/rx/internal/operators
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/main/java/rx/internal/operators/TakeLastQueueProducer.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -55,7 +55,7 @@ public void request(long n) { |
55 | 55 | if (n == Long.MAX_VALUE) { |
56 | 56 | _c = REQUESTED_UPDATER.getAndSet(this, Long.MAX_VALUE); |
57 | 57 | } else { |
58 | | - _c = REQUESTED_UPDATER.getAndAdd(this, n); |
| 58 | + _c = BackpressureUtils.getAndAddRequest(REQUESTED_UPDATER, this, n); |
59 | 59 | } |
60 | 60 | if (!emittingStarted) { |
61 | 61 | // we haven't started yet, so record what was requested and return |
|
Collapse file
Copy file name to clipboardExpand all lines: src/test/java/rx/internal/operators/OperatorTakeLastTest.java +30Lines changed: 30 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
23 | 23 | import static org.mockito.Mockito.times; |
24 | 24 | import static org.mockito.Mockito.verify; |
25 | 25 |
|
| 26 | +import java.util.ArrayList; |
26 | 27 | import java.util.Arrays; |
| 28 | +import java.util.List; |
27 | 29 | import java.util.concurrent.atomic.AtomicInteger; |
28 | 30 |
|
29 | 31 | import org.junit.Test; |
@@ -293,4 +295,32 @@ public void onNext(Integer integer) { |
293 | 295 | }); |
294 | 296 | assertEquals(1,count.get()); |
295 | 297 | } |
| 298 | + |
| 299 | + @Test(timeout=10000) |
| 300 | + public void testRequestOverflow() { |
| 301 | + final List<Integer> list = new ArrayList<Integer>(); |
| 302 | + Observable.range(1, 100).takeLast(50).subscribe(new Subscriber<Integer>() { |
| 303 | + |
| 304 | + @Override |
| 305 | + public void onStart() { |
| 306 | + request(2); |
| 307 | + } |
| 308 | + |
| 309 | + @Override |
| 310 | + public void onCompleted() { |
| 311 | + |
| 312 | + } |
| 313 | + |
| 314 | + @Override |
| 315 | + public void onError(Throwable e) { |
| 316 | + |
| 317 | + } |
| 318 | + |
| 319 | + @Override |
| 320 | + public void onNext(Integer t) { |
| 321 | + list.add(t); |
| 322 | + request(Long.MAX_VALUE-1); |
| 323 | + }}); |
| 324 | + assertEquals(50, list.size()); |
| 325 | + } |
296 | 326 | } |