13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
-
17
16
package rx .internal .operators ;
18
17
19
18
import java .util .Random ;
19
+
20
20
import static org .junit .Assert .assertEquals ;
21
21
import static org .junit .Assert .assertTrue ;
22
22
import static org .junit .Assert .fail ;
23
23
24
24
import java .util .concurrent .CountDownLatch ;
25
+ import java .util .concurrent .Executors ;
25
26
import java .util .concurrent .TimeUnit ;
26
27
import java .util .concurrent .atomic .AtomicInteger ;
27
28
29
+ import org .junit .Ignore ;
28
30
import org .junit .Test ;
29
31
30
32
import rx .Observable ;
31
33
import rx .Observable .OnSubscribe ;
32
34
import rx .Observer ;
35
+ import rx .Scheduler ;
33
36
import rx .Subscriber ;
34
37
import rx .functions .Func1 ;
35
38
import rx .observables .GroupedObservable ;
38
41
39
42
public class OperatorPivotTest {
40
43
41
- @ Test
44
+ @ Test ( timeout = 10000 )
42
45
public void testPivotEvenAndOdd () throws InterruptedException {
43
- Observable <GroupedObservable <Boolean , Integer >> o1 = Observable .range (1 , 10 ).groupBy (modKeySelector ).subscribeOn (Schedulers .newThread ());
44
- Observable <GroupedObservable <Boolean , Integer >> o2 = Observable .range (11 , 10 ).groupBy (modKeySelector ).subscribeOn (Schedulers .newThread ());
46
+ for (int i =0 ; i <1000 ; i ++) {
47
+ System .out .println ("------------------------------------------ testPivotEvenAndOdd -------------------------------------------" );
48
+ Observable <GroupedObservable <Boolean , Integer >> o1 = Observable .range (1 , 10 ).groupBy (modKeySelector ).subscribeOn (Schedulers .computation ());
49
+ Observable <GroupedObservable <Boolean , Integer >> o2 = Observable .range (11 , 10 ).groupBy (modKeySelector ).subscribeOn (Schedulers .computation ());
45
50
Observable <GroupedObservable <String , GroupedObservable <Boolean , Integer >>> groups = Observable .from (GroupedObservable .from ("o1" , o1 ), GroupedObservable .from ("o2" , o2 ));
46
51
Observable <GroupedObservable <Boolean , GroupedObservable <String , Integer >>> pivoted = Observable .pivot (groups );
47
52
@@ -53,10 +58,12 @@ public void testPivotEvenAndOdd() throws InterruptedException {
53
58
54
59
@ Override
55
60
public Observable <String > call (final GroupedObservable <Boolean , GroupedObservable <String , Integer >> outerGroup ) {
61
+ System .out .println ("Outer Group: " + outerGroup .getKey ());
56
62
return outerGroup .flatMap (new Func1 <GroupedObservable <String , Integer >, Observable <String >>() {
57
63
58
64
@ Override
59
65
public Observable <String > call (final GroupedObservable <String , Integer > innerGroup ) {
66
+ System .out .println ("Inner Group: " + innerGroup .getKey ());
60
67
return innerGroup .map (new Func1 <Integer , String >() {
61
68
62
69
@ Override
@@ -94,14 +101,16 @@ public void onNext(String t) {
94
101
95
102
});
96
103
97
- if (!latch .await (800 , TimeUnit .MILLISECONDS )) {
104
+ if (!latch .await (20000000 , TimeUnit .MILLISECONDS )) {
98
105
System .out .println ("xxxxxxxxxxxxxxxxxx> TIMED OUT <xxxxxxxxxxxxxxxxxxxx" );
99
106
System .out .println ("Received count: " + count .get ());
100
107
fail ("Timed Out" );
101
108
}
102
109
103
110
System .out .println ("Received count: " + count .get ());
111
+ // TODO sometimes this test fails and gets 15 instead of 20 so there is a bug somewhere
104
112
assertEquals (20 , count .get ());
113
+ }
105
114
}
106
115
107
116
/**
@@ -112,7 +121,7 @@ public void onNext(String t) {
112
121
* It's NOT easy to understand though, and easy to end up with far more data consumed than expected, because pivot by definition
113
122
* is inverting the data so we can not unsubscribe from the parent until all children are done since the top key becomes the leaf once pivoted.
114
123
*/
115
- @ Test
124
+ @ Test ( timeout = 10000 )
116
125
public void testUnsubscribeFromGroups () throws InterruptedException {
117
126
AtomicInteger counter1 = new AtomicInteger ();
118
127
AtomicInteger counter2 = new AtomicInteger ();
@@ -221,7 +230,7 @@ public String call(Integer i) {
221
230
*
222
231
* Then a subsequent step can merge them if desired and add serialization, such as merge(even.o1, even.o2) to become a serialized "even"
223
232
*/
224
- @ Test
233
+ @ Test ( timeout = 10000 )
225
234
public void testConcurrencyAndSerialization () throws InterruptedException {
226
235
final AtomicInteger maxOuterConcurrency = new AtomicInteger ();
227
236
final AtomicInteger maxGroupConcurrency = new AtomicInteger ();
0 commit comments