@@ -1875,8 +1875,8 @@ public String call(Integer x) {
1875
1875
assertEquals (expected , ts .getOnNextEvents ());
1876
1876
}
1877
1877
1878
+ private static final Func1 <Integer , Integer > EVICTING_MAP_ELEMENT_SELECTOR = UtilityFunctions .identity ();
1878
1879
1879
- Func1 <Integer , Integer > elementSelector = UtilityFunctions .identity ();
1880
1880
private static final Func1 <Integer , Integer > EVICTING_MAP_KEY_SELECTOR = new Func1 <Integer , Integer > (){
1881
1881
@ Override
1882
1882
public Integer call (Integer t ) {
@@ -1885,38 +1885,30 @@ public Integer call(Integer t) {
1885
1885
1886
1886
@ Test
1887
1887
public void testEvictingMapFactoryIfMapPutThrowsRuntimeExceptionThenErrorEmittedByStream () {
1888
- Func1 <Integer , Integer > elementSelector = UtilityFunctions .identity ();
1889
- Exceptions .throwIfFatal (null );
1890
1888
final RuntimeException exception = new RuntimeException ("boo" );
1891
- //normally we would use Guava CacheBuilder for instance but to save a test dependency
1892
- //we make something custom
1893
1889
Func1 <Action1 <Integer >, Map <Integer , Object >> mapFactory = createMapFactoryThatThrowsOnPut (exception );
1894
1890
TestSubscriber <Object > ts = TestSubscriber .create ();
1895
1891
Observable
1896
1892
.range (1 , 100 )
1897
- .groupBy (EVICTING_MAP_KEY_SELECTOR , elementSelector , mapFactory )
1893
+ .groupBy (EVICTING_MAP_KEY_SELECTOR , EVICTING_MAP_ELEMENT_SELECTOR , mapFactory )
1898
1894
.flatMap (UtilityFunctions .<Observable <Integer >>identity ())
1899
1895
.subscribe (ts );
1900
1896
ts .assertError (exception );
1901
1897
}
1902
1898
1903
1899
@ Test (expected = OnErrorNotImplementedException .class )
1904
- public void testEvictingMapFactoryIfMapPutThrowsOnErrorNotImplementedExceptionThenErrorEmittedByStream () {
1905
-
1906
- Exceptions .throwIfFatal (null );
1900
+ public void testEvictingMapFactoryIfMapPutThrowsFatalErrorThenErrorThrownBySubscribe () {
1907
1901
final RuntimeException exception = new OnErrorNotImplementedException ("boo" , new RuntimeException ());
1908
- //normally we would use Guava CacheBuilder for instance but to save a test dependency
1909
- //we make something custom
1910
1902
Func1 <Action1 <Integer >, Map <Integer , Object >> mapFactory = createMapFactoryThatThrowsOnPut (exception );
1911
1903
TestSubscriber <Object > ts = TestSubscriber .create ();
1912
1904
Observable
1913
1905
.range (1 , 100 )
1914
- .groupBy (EVICTING_MAP_KEY_SELECTOR , elementSelector , mapFactory )
1906
+ .groupBy (EVICTING_MAP_KEY_SELECTOR , EVICTING_MAP_ELEMENT_SELECTOR , mapFactory )
1915
1907
.flatMap (UtilityFunctions .<Observable <Integer >>identity ())
1916
1908
.subscribe (ts );
1917
1909
}
1918
1910
1919
- private Func1 <Action1 <Integer >, Map <Integer , Object >> createMapFactoryThatThrowsOnPut (
1911
+ private static Func1 <Action1 <Integer >, Map <Integer , Object >> createMapFactoryThatThrowsOnPut (
1920
1912
final RuntimeException exception ) {
1921
1913
return new Func1 <Action1 <Integer >, Map <Integer , Object >>() {
1922
1914
@ SuppressWarnings ("serial" )
@@ -1954,11 +1946,10 @@ public void onRemoval(RemovalNotification<Integer, Object> notification) {
1954
1946
.build ().asMap ();
1955
1947
}
1956
1948
};
1957
- Func1 <Integer , Integer > elementSelector = UtilityFunctions .identity ();
1958
1949
TestSubscriber <String > ts = TestSubscriber .create ();
1959
1950
Observable
1960
1951
.range (1 , 100 )
1961
- .groupBy (EVICTING_MAP_KEY_SELECTOR , elementSelector , mapFactory )
1952
+ .groupBy (EVICTING_MAP_KEY_SELECTOR , EVICTING_MAP_ELEMENT_SELECTOR , mapFactory )
1962
1953
.flatMap (new Func1 <GroupedObservable <Integer , Integer >, Observable <String >>() {
1963
1954
@ Override
1964
1955
public Observable <String > call (final GroupedObservable <Integer , Integer > g ) {
@@ -1988,6 +1979,41 @@ public String call(Integer x) {
1988
1979
public void testGroupByThrowsNpeIfEvictingMapFactoryNull () {
1989
1980
Observable
1990
1981
.range (1 , 100 )
1991
- .groupBy (EVICTING_MAP_KEY_SELECTOR , elementSelector , null );
1982
+ .groupBy (EVICTING_MAP_KEY_SELECTOR , EVICTING_MAP_ELEMENT_SELECTOR , null );
1983
+ }
1984
+
1985
+ @ Test
1986
+ public void testEvictingMapFactoryIfMapCreateThrowsRuntimeExceptionThenErrorEmittedByStream () {
1987
+ final RuntimeException exception = new RuntimeException ("boo" );
1988
+ Func1 <Action1 <Integer >, Map <Integer , Object >> mapFactory = createMapFactoryThatThrowsOnCreate (exception );
1989
+ TestSubscriber <Object > ts = TestSubscriber .create ();
1990
+ Observable
1991
+ .range (1 , 100 )
1992
+ .groupBy (EVICTING_MAP_KEY_SELECTOR , EVICTING_MAP_ELEMENT_SELECTOR , mapFactory )
1993
+ .flatMap (UtilityFunctions .<Observable <Integer >>identity ())
1994
+ .subscribe (ts );
1995
+ ts .assertError (exception );
1996
+ }
1997
+
1998
+ @ Test (expected =OnErrorNotImplementedException .class )
1999
+ public void testEvictingMapFactoryIfMapCreateThrowsFatalErrorThenSubscribeThrows () {
2000
+ final OnErrorNotImplementedException exception = new OnErrorNotImplementedException ("boo" , new RuntimeException ());
2001
+ Func1 <Action1 <Integer >, Map <Integer , Object >> mapFactory = createMapFactoryThatThrowsOnCreate (exception );
2002
+ TestSubscriber <Object > ts = TestSubscriber .create ();
2003
+ Observable
2004
+ .range (1 , 100 )
2005
+ .groupBy (EVICTING_MAP_KEY_SELECTOR , EVICTING_MAP_ELEMENT_SELECTOR , mapFactory )
2006
+ .flatMap (UtilityFunctions .<Observable <Integer >>identity ())
2007
+ .subscribe (ts );
2008
+ }
2009
+
2010
+ private static Func1 <Action1 <Integer >, Map <Integer , Object >> createMapFactoryThatThrowsOnCreate (
2011
+ final RuntimeException exception ) {
2012
+ return new Func1 <Action1 <Integer >, Map <Integer , Object >>() {
2013
+
2014
+ @ Override
2015
+ public Map <Integer , Object > call (Action1 <Integer > t ) {
2016
+ throw exception ;
2017
+ }};
1992
2018
}
1993
2019
}
0 commit comments