Skip to content

concat can't display all the groupedBy observers on version 1.1.1 #3775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lvzhitingzhou opened this issue Mar 17, 2016 · 6 comments
Closed
Labels

Comments

@lvzhitingzhou
Copy link

Here are the code I‘m using to test:

        final Observable<GroupedObservable<String, AppInfo>> groupBy = Observable.from(appInfoList)
                .groupBy(appInfo -> {
                    SimpleDateFormat sdf = new SimpleDateFormat("MM/yyyy");
                    String groupedStr = sdf.format(new Date(appInfo.getLastUpdateTime()));
                    return groupedStr;
                });
        Observable.concat(groupBy)
                .subscribe(mSubscriber);

and the library is :

    compile 'io.reactivex:rxjava:1.1.1'
    compile 'io.reactivex:rxandroid:1.1.0'`

I got this result which apparently is not correct, I only got three results!:
device-2016-03-17-151005

but it should be like this as shown on the Rxjava-essential-code.
image

This problem never occurs on Version 1.1.0.

@akarnokd
Copy link
Member

Strange. This code works for me on 1.1.1:

public class GroupConcat {
    static final class AppInfo {
        String name;
        LocalDate date;
        @Override
        public String toString() {
            return name + " @ " + date;
        }
    }
    public static void main(String[] args) {
        System.setProperty("rx.ring-buffer.size", "16");

        List<AppInfo> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 3; j++) {
                AppInfo ai = new AppInfo();
                ai.name = i + " - " + j;
                ai.date = LocalDate.of(2016, 3, i + 1);
                list.add(ai);
            }
        }

        Observable<GroupedObservable<String, AppInfo>> o = Observable.from(list)
        .groupBy(v -> v.date.format(DateTimeFormatter.ofPattern("MM/yyyy")));

        Observable.concat(o)
        .subscribe(System.out::println);
    }
}

@yanglw
Copy link

yanglw commented Mar 21, 2016

public class Concat {
    public static class Student {
        public String classId;
        public String name;

        @Override
        public String toString() {
            return "Student{classId='" + classId + "', name='" + name + "'}";
        }
    }

    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            Student student = new Student();
            student.classId = String.valueOf(i % 5);
            student.name = String.valueOf(i);
            list.add(student);
        }

        Observable<GroupedObservable<String, Student>> groupBy =
                Observable.from(list)
                          .groupBy(new Func1<Student, String>() {
                              @Override
                              public String call(Student student) {
                                  return student.classId;
                              }
                          });

        Observable.concat(groupBy)
                  .subscribe(new Observer<Student>() {
                      @Override
                      public void onCompleted() {
                          System.out.println("Completed");
                      }

                      @Override
                      public void onError(Throwable e) {
                          System.out.println("Error");
                      }

                      @Override
                      public void onNext(Student student) {
                          System.out.println(student);
                      }
                  });
    }
}

in RxJava 1.1.1,console print :

Student{classId='0', name='0'}
Student{classId='0', name='5'}
Student{classId='0', name='10'}
Student{classId='0', name='15'}

Process finished with exit code 0

in RxJava 1.1.0,console print :

Student{classId='0', name='0'}
Student{classId='0', name='5'}
Student{classId='0', name='10'}
Student{classId='0', name='15'}
Student{classId='1', name='1'}
Student{classId='1', name='6'}
Student{classId='1', name='11'}
Student{classId='1', name='16'}
Student{classId='2', name='2'}
Student{classId='2', name='7'}
Student{classId='2', name='12'}
Student{classId='2', name='17'}
Student{classId='3', name='3'}
Student{classId='3', name='8'}
Student{classId='3', name='13'}
Student{classId='3', name='18'}
Student{classId='4', name='4'}
Student{classId='4', name='9'}
Student{classId='4', name='14'}
Student{classId='4', name='19'}
Completed

Process finished with exit code 0

1.1.1 only print first group, and not call onCompleted.
1.1.0 print all group.

System OS : windows 10 64-bit
JDK Version : Oracle JDK 1.7.0_80 64-bit
Gradle Version : 2.12
IntelliJ IDEA Version : 14.1.6

@akarnokd akarnokd added Bug and removed Question labels Mar 21, 2016
@akarnokd
Copy link
Member

Yep, this is a bug. The groups don't complete until all groups have been emitted which doesn't happen because concat() prefetches only 2 groups of the 5. I overlooked this case and apparently the unit tests weren't checking for this.

@akarnokd
Copy link
Member

See the fix in #3787.

@yanglw
Copy link

yanglw commented Mar 22, 2016

👍

@akarnokd
Copy link
Member

akarnokd commented Apr 2, 2016

Closing via #3787.

@akarnokd akarnokd closed this as completed Apr 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants