use of cyclops.reactive.Spouts.of in project cyclops by aol.
the class FlatMapPublisherTest method concurrentFlatMapPIteration.
@Test
public void concurrentFlatMapPIteration() {
for (int k = 0; k < 500; k++) {
System.out.println("****************************NEXT ITERATION " + k);
System.out.println("****************************NEXT ITERATION " + k);
System.out.println("****************************NEXT ITERATION " + k);
System.out.println("****************************NEXT ITERATION " + k);
System.out.println("****************************NEXT ITERATION " + k);
System.out.println("****************************NEXT ITERATION " + k);
System.out.println("****************************NEXT ITERATION " + k + "*************************!!!!!!!!!!!!!!!!!!!!!!!!!!!");
List<Integer> res = new ArrayList<>();
Iterator<Integer> it = Spouts.of(1, 2, 3).mergeMap(3, i -> nextAsync()).iterator();
while (it.hasNext()) {
res.add(it.next());
}
System.out.println("Result is " + res);
assertThat(res.size(), equalTo(Arrays.asList(1, 2, 1, 2, 1, 2).size()));
assertThat(res, hasItems(1, 2));
int one = 0;
int two = 0;
for (Integer next : res) {
if (next == 1) {
one++;
}
if (next == 2) {
two++;
}
}
assertThat(one, equalTo(3));
assertThat(two, equalTo(3));
}
}
use of cyclops.reactive.Spouts.of in project cyclops by aol.
the class FlatMapPublisherTest method flatMapPAsyncRS.
@Test
public void flatMapPAsyncRS() {
for (int k = 0; k < 1000; k++) {
System.out.println("****************************NEXT ITERATION " + k);
System.out.println("****************************NEXT ITERATION " + k);
System.out.println("****************************NEXT ITERATION " + k);
System.out.println("****************************NEXT ITERATION " + k);
System.out.println("****************************NEXT ITERATION " + k);
System.out.println("****************************NEXT ITERATION " + k);
System.out.println("****************************NEXT ITERATION " + k + "*************************!!!!!!!!!!!!!!!!!!!!!!!!!!!");
complete = new AtomicBoolean(false);
count = new AtomicInteger(0);
ReactiveSubscriber<Integer> sub = Spouts.reactiveSubscriber();
Spouts.of(1, 2, 3).peek(System.out::println).mergeMap(i -> nextAsync()).subscribe(new Subscriber<Integer>() {
@Override
public void onSubscribe(Subscription s) {
subs = s;
}
@Override
public void onNext(Integer integer) {
System.out.println("RECIEVED " + integer);
assertThat(integer, Matchers.isOneOf(1, 2));
System.out.println("count " + count.incrementAndGet());
}
@Override
public void onError(Throwable t) {
}
@Override
public void onComplete() {
complete.set(true);
}
});
subs.request(Long.MAX_VALUE);
while (!complete.get()) {
}
assertThat(count.get(), equalTo(6));
}
}
use of cyclops.reactive.Spouts.of in project cyclops by aol.
the class FlatMapTest method flatMapAsyncRS2.
@Test
public void flatMapAsyncRS2() {
for (int k = 0; k < 1000; k++) {
System.out.println("********0---------------------K " + k);
ReactiveSubscriber<Integer> sub = Spouts.reactiveSubscriber();
Spouts.of(1, 2, 3).peek(System.out::println).flatMap(i -> nextAsyncRS()).subscribe(sub);
List<Integer> res = sub.reactiveStream().collect(Collectors.toList());
System.out.println(res);
assertThat(res.size(), equalTo(Arrays.asList(1, 2, 1, 2, 1, 2).size()));
assertThat(res, hasItems(1, 2));
int one = 0;
int two = 0;
for (Integer next : res) {
if (next == 1) {
one++;
}
if (next == 2) {
two++;
}
}
assertThat(one, equalTo(3));
assertThat(two, equalTo(3));
}
}
use of cyclops.reactive.Spouts.of in project cyclops by aol.
the class FlatMapTest method flatMapPAsync3.
@Test
public void flatMapPAsync3() {
for (int k = 0; k < 10; k++) {
List<Integer> res = Spouts.of(1, 2, 3).flatMap(i -> nextAsyncRS()).toList();
assertThat(res.size(), equalTo(Arrays.asList(1, 2, 1, 2, 1, 2).size()));
assertThat(res, hasItems(1, 2));
int one = 0;
int two = 0;
for (Integer next : res) {
if (next == 1) {
one++;
}
if (next == 2) {
two++;
}
}
assertThat(one, equalTo(3));
assertThat(two, equalTo(3));
}
}
use of cyclops.reactive.Spouts.of in project cyclops by aol.
the class FlatMapTest method flatMapAsyncRS3.
@Test
public void flatMapAsyncRS3() {
for (int k = 0; k < 100; k++) {
List<Integer> res = Spouts.of(1, 2, 3).peek(System.out::println).flatMap(i -> nextAsyncRS()).collect(Collectors.toList());
System.out.println(res);
assertThat(res.size(), equalTo(Arrays.asList(1, 2, 1, 2, 1, 2).size()));
assertThat(res, hasItems(1, 2));
int one = 0;
int two = 0;
for (Integer next : res) {
if (next == 1) {
one++;
}
if (next == 2) {
two++;
}
}
assertThat(one, equalTo(3));
assertThat(two, equalTo(3));
}
}
Aggregations