[ 
https://issues.apache.org/jira/browse/KNOX-3042?focusedWorklogId=923725&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-923725
 ]

ASF GitHub Bot logged work on KNOX-3042:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 17/Jun/24 14:22
            Start Date: 17/Jun/24 14:22
    Worklog Time Spent: 10m 
      Work Description: bonampak opened a new pull request, #918:
URL: https://github.com/apache/knox/pull/918

   (It is very **important** that you created an Apache Knox JIRA for this 
change and that the PR title/commit message includes the Apache Knox JIRA ID!)
   
   ## What changes were proposed in this pull request?
   
   Correct KnoxToken comparator so that TokenStateService.fetchTokens() would 
return all the tokens, even if their issue time is the same. If two tokens have 
the same issue time, then one with the smaller token id (uuid) will be revoked.
   ## How was this patch tested?
   So far only the existing tests are run and we could add a revocation test to 
TokenServiceResourceTest.
   
   




Issue Time Tracking
-------------------

            Worklog Id:     (was: 923725)
    Remaining Estimate: 0h
            Time Spent: 10m

> TokenServiceResourceTest.testUnlimitedTokensPerUser intermittently fails
> ------------------------------------------------------------------------
>
>                 Key: KNOX-3042
>                 URL: https://issues.apache.org/jira/browse/KNOX-3042
>             Project: Apache Knox
>          Issue Type: Test
>          Components: Tests
>    Affects Versions: 2.0.1
>            Reporter: Philip Zampino
>            Assignee: Philip Zampino
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> just trying with 1000 tokens (plus the test adds 5 SSO tokens as a given):
> (original value was 100, sometimes fails, sometimes passes).
>  
> {code:java}
>   @Test
>   public void testUnlimitedTokensPerUser() throws Exception {
>     testLimitingTokensPerUser(-1, 1000);
>   }{code}
> this fails all the time it seems.    
> assertEquals(tokens.size(), revokeOldestToken ? configuredLimit + 
> numberOfKnoxSsoCookies : numberOfTokens + numberOfKnoxSsoCookies);
> This assert has the expected and actual in the wrong order, but that is not a 
> big 
> deal.tokenMetadata.entrySet().stream().filter(filterPredicate).collect(Collectors.toList())
>  = \{ArrayList@3784}  size = 1005
> tokenMetadata.entrySet().stream().filter(filterPredicate).map(this::createKnoxTokenFromMetadata).collect(Collectors.toCollection(TreeSet::new))
>  = \{TreeSet@3797}  size = 848
> (This createKnoxTokenFromMetadata() is just a slight refactor of the below 
> part in the try-catch)
> Root cause:
> TokenServiceResourceTest has this method:
> {code:java}
> private Collection<KnoxToken> fetchTokens(String userName, boolean 
> createdBy){code}
> this collects the filtered tokens into a TreeSet<KnoxToken>.
>  
> {code:java}
> final Collection<KnoxToken> tokens = new TreeSet<>(); // TODO should be 
> LinkedList but not a TreeSet ... try {
>   tokens.add(new KnoxToken(tokenId, getTokenIssueTime(tokenId), 
> getTokenExpiration(tokenId), getMaxLifetime(tokenId), metadata.getValue())); 
> } catch (UnknownTokenException e) { // NOP }{code}
> But this KnoxToken has a custom compareTo method.
> {code:java}
>   @Override
>   public int compareTo(KnoxToken other) {
>     return Long.compare(this.issueTime, other.issueTime);
>   }{code}
> now this TreeSet will only contain 800+ elements instead of 1005, because it 
> will treat tokens with the same issue time as 
> duplicates.[https://stackoverflow.com/questions/43845136/equal-elements-and-tree-set]
> "If you look at the source of TreeSet you will see that by default it uses a 
> TreeMap to save data and in the TreeMap class put method it only uses the 
> comparator or compareTo methods of the objects to check for equality, but 
> never the equals method"A simple solution is to use a LinkedList instead of a 
> TreeSet



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to