-
Notifications
You must be signed in to change notification settings - Fork 642
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#4510] Add test case for SpringSinkConnector. #4511
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
76 changes: 76 additions & 0 deletions
76
...st/java/org/apache/eventmesh/connector/spring/sink/connector/SpringSinkConnectorTest.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,76 @@ | ||
/* | ||
* 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.eventmesh.connector.spring.sink.connector; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import org.apache.eventmesh.connector.spring.sink.config.SpringSinkConfig; | ||
import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord; | ||
import org.apache.eventmesh.openconnect.offsetmgmt.api.data.RecordOffset; | ||
import org.apache.eventmesh.openconnect.offsetmgmt.api.data.RecordPartition; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.BlockingQueue; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Spy; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class SpringSinkConnectorTest { | ||
|
||
@Spy | ||
private SpringSinkConnector connector; | ||
|
||
@BeforeEach | ||
public void setUp() throws Exception { | ||
SpringSinkConfig sinkConfig = new SpringSinkConfig(); | ||
connector.init(sinkConfig); | ||
connector.start(); | ||
} | ||
|
||
@Test | ||
public void springSinkConnectorTest() throws Exception { | ||
final int count = 5; | ||
final String message = "testMessage"; | ||
writeMockedRecords(count, message); | ||
BlockingQueue<ConnectRecord> queue = connector.getQueue(); | ||
assertThat(count, is(queue.size())); | ||
for (int i = 0; i < count; i++) { | ||
ConnectRecord poll = queue.poll(); | ||
assertNotNull(poll); | ||
String expectedMessage = message + i; | ||
assertThat(poll.getData(), is(expectedMessage)); | ||
} | ||
} | ||
|
||
private void writeMockedRecords(int count, String message) throws Exception { | ||
List<ConnectRecord> records = new ArrayList<>(); | ||
for (int i = 0; i < count; i++) { | ||
RecordPartition partition = new RecordPartition(); | ||
RecordOffset offset = new RecordOffset(); | ||
records.add(new ConnectRecord(partition, offset, System.currentTimeMillis(), message + i)); | ||
} | ||
connector.put(records); | ||
} | ||
} |
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,22 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
[versions] | ||
hamcrest = "2.2" | ||
|
||
[libraries] | ||
hamcrest = { module = "org.hamcrest:hamcrest", version.ref = "hamcrest" } |
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.
Isn't it more convenient to use JUnit 5's
Assertions
directly? Why did you deliberately introduce 'hamcrest' to make assertions?直接使用JUnit 5的
Assertions
不是更方便吗?为何特意引入'hamcrest'来断言?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.
Hamcrest's assertion is more powerful than junit5, and I think can be combined.
hamcrest的断言比junit5更强大, 我认为两者可以组合使用。
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.
But your test case does not require more powerful features in 'hamcrest' than 'JUnit'. Shouldn't it be used on demand?
但是你的测试用例并不需要'hamcrest'比'JUnit'更强大的特性啊。不应该按需使用吗?
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.
Hamcrest is an additional dependency, and if we're using it solely for simple assertions, I believe that standard JUnit assertions should suffice. This can help us keep our project dependencies minimal and reduce complexity in our tests. This is just my opinion.
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.
I also think it's right to keep minimal dependencies, it has been fixed in new commit.