-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
[ISSUE #8090] Optimize isSetEqual for DefaultLitePullConsumerImpl #8091
Merged
RongtongJin
merged 4 commits into
apache:develop
from
Willhow-Gao:optimize-isSetEqual-method
May 8, 2024
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9b8a0b4
[ISSUE #8090]1.optimize isSetEqual method and add Unit tests; 2.fix a…
Willhow-Gao 015559e
remove author message
Willhow-Gao d656b4c
Modify code style
Willhow-Gao 049d20d
Merge branch 'apache:develop' into optimize-isSetEqual-method
Willhow-Gao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...c/test/java/org/apache/rocketmq/client/impl/consumer/DefaultLitePullConsumerImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.apache.rocketmq.client.impl.consumer; | ||
|
||
import org.apache.rocketmq.client.consumer.DefaultLitePullConsumer; | ||
import org.apache.rocketmq.common.message.MessageQueue; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author Willhow | ||
* @since 2024/5/3 | ||
*/ | ||
public class DefaultLitePullConsumerImplTest { | ||
private final DefaultLitePullConsumerImpl consumer = new DefaultLitePullConsumerImpl(new DefaultLitePullConsumer(), null); | ||
|
||
private static Method isSetEqualMethod; | ||
|
||
@BeforeClass | ||
public static void initReflectionMethod() throws NoSuchMethodException { | ||
Class<DefaultLitePullConsumerImpl> consumerClass = DefaultLitePullConsumerImpl.class; | ||
Method testMethod = consumerClass.getDeclaredMethod("isSetEqual", Set.class, Set.class); | ||
testMethod.setAccessible(true); | ||
isSetEqualMethod = testMethod; | ||
} | ||
|
||
|
||
/** | ||
* The two empty sets should be equal | ||
*/ | ||
@Test | ||
public void testIsSetEqual1() throws InvocationTargetException, IllegalAccessException { | ||
Set<MessageQueue> set1 = new HashSet<>(); | ||
Set<MessageQueue> set2 = new HashSet<>(); | ||
boolean equalResult = (boolean) isSetEqualMethod.invoke(consumer, set1, set2); | ||
Assert.assertTrue(equalResult); | ||
} | ||
|
||
|
||
/** | ||
* When a set has elements and one does not, the two sets are not equal | ||
*/ | ||
@Test | ||
public void testIsSetEqual2() throws InvocationTargetException, IllegalAccessException { | ||
Set<MessageQueue> set1 = new HashSet<>(); | ||
set1.add(new MessageQueue("testTopic","testBroker",111)); | ||
Set<MessageQueue> set2 = new HashSet<>(); | ||
boolean equalResult = (boolean) isSetEqualMethod.invoke(consumer, set1, set2); | ||
Assert.assertFalse(equalResult); | ||
} | ||
|
||
/** | ||
* The two null sets should be equal | ||
*/ | ||
@Test | ||
public void testIsSetEqual3() throws InvocationTargetException, IllegalAccessException{ | ||
Set<MessageQueue> set1 = null; | ||
Set<MessageQueue> set2 = null; | ||
boolean equalResult = (boolean) isSetEqualMethod.invoke(consumer, set1, set2); | ||
Assert.assertTrue(equalResult); | ||
} | ||
|
||
@Test | ||
public void testIsSetEqual4() throws InvocationTargetException, IllegalAccessException{ | ||
Set<MessageQueue> set1 = null; | ||
Set<MessageQueue> set2 = new HashSet<>(); | ||
boolean equalResult = (boolean) isSetEqualMethod.invoke(consumer, set1, set2); | ||
Assert.assertFalse(equalResult); | ||
} | ||
|
||
@Test | ||
public void testIsSetEqual5() throws InvocationTargetException, IllegalAccessException{ | ||
Set<MessageQueue> set1 = new HashSet<>(); | ||
set1.add(new MessageQueue("testTopic","testBroker",111)); | ||
Set<MessageQueue> set2 = new HashSet<>(); | ||
set2.add(new MessageQueue("testTopic","testBroker",111)); | ||
boolean equalResult = (boolean) isSetEqualMethod.invoke(consumer, set1, set2); | ||
Assert.assertTrue(equalResult); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Author information needs to be removed
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.
already removed. Also revised code style and added license comments