-
Notifications
You must be signed in to change notification settings - Fork 5.1k
CAMEL-23267: Use a LinkedHashMap as inProgressRepository for file com… #22311
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,49 @@ | ||||||
| /* | ||||||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||||||
| * contributor license agreements. See the NOTICE file distributed with | ||||||
| * this work for additional information regarding copyright ownership. | ||||||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||||||
| * (the "License"); you may not use this file except in compliance with | ||||||
| * the License. You may obtain a copy of the License at | ||||||
| * | ||||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||||
| * | ||||||
| * Unless required by applicable law or agreed to in writing, software | ||||||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
| * See the License for the specific language governing permissions and | ||||||
| * limitations under the License. | ||||||
| */ | ||||||
| package org.apache.camel.support; | ||||||
|
|
||||||
| import java.io.IOException; | ||||||
|
|
||||||
| import org.apache.camel.spi.IdempotentRepository; | ||||||
| import org.apache.camel.support.processor.idempotent.MemoryIdempotentRepository; | ||||||
| import org.junit.jupiter.api.Test; | ||||||
|
|
||||||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||||||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||||||
|
|
||||||
| class MemoryIdempotentRepositoryTest { | ||||||
|
|
||||||
| @Test | ||||||
| void repositoryEvictsOldestEntryWhenRepositoryIsFull() throws IOException { | ||||||
| final int cacheSize = 5; | ||||||
| final int entriesNotFittingInRepository = 4; | ||||||
| try (IdempotentRepository repository = MemoryIdempotentRepository.memoryIdempotentRepositoryInsertionOrder( | ||||||
| cacheSize)) { | ||||||
|
|
||||||
| for (int i = 0; i < cacheSize + entriesNotFittingInRepository; i++) { | ||||||
| repository.add(String.valueOf(i)); | ||||||
| } | ||||||
|
|
||||||
| for (int i = entriesNotFittingInRepository; i < cacheSize + entriesNotFittingInRepository; i++) { | ||||||
| assertTrue(repository.contains(String.valueOf(i)), "Repository should contain entry " + i); | ||||||
| } | ||||||
| for (int i = 0; i < entriesNotFittingInRepository; i++) { | ||||||
| assertFalse(repository.contains(String.valueOf(i)), "Repository should not contain entry " + i); | ||||||
| } | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The loop condition
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Great, such a small test, and I managed to mess it up 😢 . Fixed in second commit. |
||||||
| } | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This factory method passes the map to the
MemoryIdempotentRepository(Map)constructor, which does not set thecacheSizefield. As a result,getMaxCacheSize()(a JMX-exposed@ManagedAttribute) will return 0.Consider setting it:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I guess I am not supposed to change the name of that
cacheSizetomaxCacheSize, since that's annotated with@Metadata? Or am I? I'd find that clearer. I find it confusing thatgetCacheSize()andsetCacheSize(int cacheSize)are not targeting the same thing.I'm also calling
ServiceHelper.startService(answer);, since that's also what's done inpublic static IdempotentRepository memoryIdempotentRepository(int cacheSize), but I don't have a clue what the benefit of that is.