Skip to content

Replace stream with cycles #7182

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

Conversation

kostya05983
Copy link
Contributor

@kostya05983 kostya05983 commented Aug 4, 2019

Work in progress, change streams to for loops. Please see #7154

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 4, 2019
@kostya05983 kostya05983 force-pushed the gh-7154-replace-streams branch from 1f12771 to d9eadfb Compare August 5, 2019 11:04
@kostya05983 kostya05983 force-pushed the gh-7154-replace-streams branch 3 times, most recently from 8d0c823 to 00d3d7b Compare August 9, 2019 15:41
@kostya05983 kostya05983 changed the title draft commit Replace stream with cycles Aug 9, 2019
@kostya05983 kostya05983 marked this pull request as ready for review August 9, 2019 16:10
@kostya05983
Copy link
Contributor Author

Hello, @rwinch I think, it's ready for review. Now, you may review it.

@jzheaux jzheaux added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 14, 2019
@kostya05983
Copy link
Contributor Author

I updated changes from master.

Copy link
Contributor

@jzheaux jzheaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kostya05983 Thanks for the earlier updates!

I've added some additional inline feedback.

private static Map<String, ClientRegistration> toUnmodifiableConcurrentMap(List<ClientRegistration> registrations) {
final ConcurrentHashMap<String, ClientRegistration> result = new ConcurrentHashMap<>();
for (ClientRegistration registration : registrations) {
if (result.containsKey(registration.getRegistrationId())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this check necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jzheaux
When we use toConcurrentMap from Collectors, it uses uniqKeysMapAccumulator

 /**
     * {@code BiConsumer<Map, T>} that accumulates (key, value) pairs
     * extracted from elements into the map, throwing {@code IllegalStateException}
     * if duplicate keys are encountered.
     *
     * @param keyMapper a function that maps an element into a key
     * @param valueMapper a function that maps an element into a value
     * @param <T> type of elements
     * @param <K> type of map keys
     * @param <V> type of map values
     * @return an accumulating consumer
     */
    private static <T, K, V>
    BiConsumer<Map<K, V>, T> uniqKeysMapAccumulator(Function<? super T, ? extends K> keyMapper,
                                                    Function<? super T, ? extends V> valueMapper) {
        return (map, element) -> {
            K k = keyMapper.apply(element);
            V v = Objects.requireNonNull(valueMapper.apply(element));
            V u = map.putIfAbsent(k, v);
            if (u != null) throw duplicateKeyException(k, u, v);
        };
    }

I also add check to save logic with throwing an exception, if we find duplicate key. Maybe, I understand something wrong and logic with client Registration can just rewrite value, how do you think? Can we break something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collisions aren't a concern in this case but thank you for keeping an eye on this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, let's go ahead and remove this extra check and exception. Collisions aren't a concern here, @kostya05983

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oks, also I need a remove test for it, because there is a test which checks duplicates.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kostya05983 for some reason I'd missed that there is a test that relies on this functionality. I apologize, but because of that, we should add the duplicate checks as well as the test back in. My mistake.

@kostya05983 kostya05983 force-pushed the gh-7154-replace-streams branch 2 times, most recently from fb07d3a to a0bf098 Compare August 21, 2019 18:08
Copy link
Contributor

@jzheaux jzheaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates, @kostya05983. I've left some additional feedback inline.

private static Map<String, ClientRegistration> toUnmodifiableConcurrentMap(List<ClientRegistration> registrations) {
final ConcurrentHashMap<String, ClientRegistration> result = new ConcurrentHashMap<>();
for (ClientRegistration registration : registrations) {
if (result.containsKey(registration.getRegistrationId())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collisions aren't a concern in this case but thank you for keeping an eye on this.

@kostya05983 kostya05983 force-pushed the gh-7154-replace-streams branch from 43eee30 to da6f25c Compare August 24, 2019 09:52
Copy link
Contributor

@jzheaux jzheaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kostya05983, thanks for how responsive you've been in this PR. You're nearly there!

I've left just a bit more feedback inline. Note that there are still a couple of open conversations from past reviews, too.

Once you believe everything is resolved, please squash your commits into one, in perparation for merging.

@kostya05983
Copy link
Contributor Author

@jzheaux Thanks for guidance. I think it's ready, but I tried to rebase and squash my nearest commits into one,in such groups: [Replace stream, First version of replacing streams, fix wwAuthentication and code style] and other similar group with other dates. But I got a big diff on test branch. Can you tell me how I can squash into one my commits which between others commits and not to danger history. I tried with interactive git rebase.

@jzheaux
Copy link
Contributor

jzheaux commented Aug 30, 2019

To rebase, you can do something like (assuming that you've called Spring Security's upstream spring-projects)

git checkout master
git pull spring-projects master
git checkout gh-7154-replace-streams
git rebase master

You will likely have some conflicts to resolve, but at that point, the commits on your feature branch should be at the end of the chain. Once you've resolved the conflicts, then do (assuming your fork is called origin):

git push origin +gh-7154-replace-streams

@kostya05983 kostya05983 force-pushed the gh-7154-replace-streams branch 4 times, most recently from 7477224 to 203abbf Compare August 31, 2019 09:17
First version of replacing streams

fix wwwAuthenticate and codestyle

fix errors in implementation to pass tests

Fix review notes

Remove uneccessary final to align with cb

Short circuit way to authorize

Simplify error message, make code readably

Return error while duplicate key found

Delete check for duplicate, checkstyle issues

Return duplicate error
@kostya05983 kostya05983 force-pushed the gh-7154-replace-streams branch from 203abbf to a47053a Compare August 31, 2019 09:53
@kostya05983
Copy link
Contributor Author

@jzheaux , I squashed commits, it's ready for merge

@jzheaux
Copy link
Contributor

jzheaux commented Sep 2, 2019

@kostya05983 - thank you for your careful work on this. This is now merged into master via f6c650d.

I edited the commit message in order to align with the contributor guidelines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants