Skip to content

Commit

Permalink
2.: Fix flatMapX over-cancellation in case of an inner error (#4686)
Browse files Browse the repository at this point in the history
  • Loading branch information
akarnokd authored Oct 10, 2016
1 parent 5209ba3 commit d9dabab
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 8 deletions.
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ jacoco {
toolVersion = '0.7.7.201606060606' // See http://www.eclemma.org/jacoco/.
}

task GCandMem(dependsOn: 'check') << {
System.gc()
Thread.sleep(200)
print("Memory usage: ")
println(java.lang.management.ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed() / 1024.0 / 1024.0)
}

jacocoTestReport {
reports {
xml.enabled = true
Expand All @@ -129,6 +136,8 @@ jacocoTestReport {
}
}

jacocoTestReport.dependsOn GCandMem

build.dependsOn jacocoTestReport

// pmd {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ void innerError(InnerObserver inner, Throwable e) {
set.delete(inner);
if (errors.addThrowable(e)) {
if (!delayErrors) {
cancel();
s.cancel();
set.dispose();
}
active.decrementAndGet();
drain();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ void innerError(InnerObserver inner, Throwable e) {
set.delete(inner);
if (errors.addThrowable(e)) {
if (!delayErrors) {
cancel();
s.cancel();
set.dispose();
}
active.decrementAndGet();
drain();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ void innerError(InnerObserver inner, Throwable e) {
set.delete(inner);
if (errors.addThrowable(e)) {
if (!delayErrors) {
dispose();
d.dispose();
set.dispose();
}
active.decrementAndGet();
drain();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ void innerError(InnerObserver inner, Throwable e) {
set.delete(inner);
if (errors.addThrowable(e)) {
if (!delayErrors) {
dispose();
d.dispose();
set.dispose();
}
active.decrementAndGet();
drain();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static org.junit.Assert.*;

import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;

import org.junit.Test;

Expand Down Expand Up @@ -253,4 +253,22 @@ public MaybeSource<Integer> apply(Integer v) throws Exception {
.test()
.assertResult(1, 2);
}

@Test
public void middleError() {
Flowable.fromArray(new String[]{"1","a","2"}).flatMapMaybe(new Function<String, MaybeSource<Integer>>() {
@Override
public MaybeSource<Integer> apply(final String s) throws NumberFormatException {
//return Single.just(Integer.valueOf(s)); //This works
return Maybe.fromCallable(new Callable<Integer>() {
@Override
public Integer call() throws NumberFormatException {
return Integer.valueOf(s);
}
});
}
})
.test()
.assertFailure(NumberFormatException.class, 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static org.junit.Assert.*;

import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;

import org.junit.Test;

Expand Down Expand Up @@ -240,4 +240,22 @@ public SingleSource<Integer> apply(Integer v) throws Exception {
.test()
.assertResult(1, 2);
}

@Test
public void middleError() {
Flowable.fromArray(new String[]{"1","a","2"}).flatMapSingle(new Function<String, SingleSource<Integer>>() {
@Override
public SingleSource<Integer> apply(final String s) throws NumberFormatException {
//return Single.just(Integer.valueOf(s)); //This works
return Single.fromCallable(new Callable<Integer>() {
@Override
public Integer call() throws NumberFormatException {
return Integer.valueOf(s);
}
});
}
})
.test()
.assertFailure(NumberFormatException.class, 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static org.junit.Assert.*;

import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;

import org.junit.Test;

Expand Down Expand Up @@ -181,4 +181,22 @@ public MaybeSource<Integer> apply(Integer v) throws Exception {
.test()
.assertResult(1, 2);
}

@Test
public void middleError() {
Observable.fromArray(new String[]{"1","a","2"}).flatMapMaybe(new Function<String, MaybeSource<Integer>>() {
@Override
public MaybeSource<Integer> apply(final String s) throws NumberFormatException {
//return Single.just(Integer.valueOf(s)); //This works
return Maybe.fromCallable(new Callable<Integer>() {
@Override
public Integer call() throws NumberFormatException {
return Integer.valueOf(s);
}
});
}
})
.test()
.assertFailure(NumberFormatException.class, 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static org.junit.Assert.*;

import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;

import org.junit.Test;

Expand Down Expand Up @@ -168,4 +168,22 @@ public SingleSource<Integer> apply(Integer v) throws Exception {
.test()
.assertResult(1, 2);
}

@Test
public void middleError() {
Observable.fromArray(new String[]{"1","a","2"}).flatMapSingle(new Function<String, SingleSource<Integer>>() {
@Override
public SingleSource<Integer> apply(final String s) throws NumberFormatException {
//return Single.just(Integer.valueOf(s)); //This works
return Single.fromCallable(new Callable<Integer>() {
@Override
public Integer call() throws NumberFormatException {
return Integer.valueOf(s);
}
});
}
})
.test()
.assertFailure(NumberFormatException.class, 1);
}
}

0 comments on commit d9dabab

Please sign in to comment.