-
Notifications
You must be signed in to change notification settings - Fork 8.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
test : fix mockserverTest fail cause using same port with seata-server #6325
Merged
Merged
Changes from 30 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
4dfe7da
fix mocktest
Bughue cf5a58e
mock test
Bughue c6b7b97
rollback pom
Bughue a333430
style
Bughue 9fbe973
style
Bughue 64377e1
changes
Bughue 2910eb2
changes
Bughue fe00da5
resolve conflict
Bughue 35ba3c8
fix test
Bughue 1783295
fix test
Bughue 74731e2
config cache
Bughue 745b884
config cache
Bughue 7fa2247
style
Bughue 8d71daf
style
Bughue f57c260
style
Bughue aafda51
Update test-mock-server/pom.xml
funky-eyes 042fa88
config helper
Bughue 329fc7b
Merge remote-tracking branch 'origin/dev-fix-mockserver' into dev-fix…
Bughue c758839
style
Bughue 3c4d1f9
style
Bughue 940d5a2
style
Bughue 3e883aa
style
Bughue c0de496
branch type & default port
Bughue c5e4a8d
branch type & default port
Bughue 5af9432
maven build
Bughue 9fd4f63
branch report
Bughue 244c903
branch report
Bughue 9260a9f
app data
Bughue 45aa8cc
style
Bughue 1ee0980
style
Bughue 3029b08
countDownlatch
Bughue 266d17e
test
Bughue 557e34c
test
Bughue 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
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
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
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
# | ||
server: | ||
port: 7091 | ||
servicePort: 8091 | ||
|
||
spring: | ||
application: | ||
|
63 changes: 63 additions & 0 deletions
63
test/src/test/java/org/apache/seata/common/ConfigurationTestHelper.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,63 @@ | ||
/* | ||
* 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.seata.common; | ||
|
||
import org.apache.commons.lang.ObjectUtils; | ||
import org.apache.seata.config.ConfigurationCache; | ||
import org.apache.seata.config.ConfigurationFactory; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* the type ConfigurationTestHelper | ||
**/ | ||
public class ConfigurationTestHelper { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationTestHelper.class); | ||
private static final long PUT_CONFIG_TIMEOUT = 30000L; | ||
private static final long PUT_CONFIG_CHECK_GAP = 500L; | ||
|
||
public static void removeConfig(String dataId) { | ||
putConfig(dataId, null); | ||
} | ||
|
||
public static void putConfig(String dataId, String content) { | ||
ConfigurationCache.addConfigListener(ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL); | ||
if (content == null) { | ||
System.clearProperty(dataId); | ||
ConfigurationFactory.getInstance().removeConfig(dataId); | ||
return; | ||
} | ||
|
||
System.setProperty(dataId, content); | ||
ConfigurationFactory.getInstance().putConfig(dataId, content); | ||
|
||
long start = System.currentTimeMillis(); | ||
while (!ObjectUtils.equals(content, ConfigurationFactory.getInstance().getConfig(dataId))) { | ||
Bughue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (PUT_CONFIG_TIMEOUT < System.currentTimeMillis() - start) { | ||
LOGGER.error("putConfig timeout, dataId={}, timeout={}ms", dataId, PUT_CONFIG_TIMEOUT); | ||
return; | ||
} | ||
try { | ||
Thread.sleep(PUT_CONFIG_CHECK_GAP); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
LOGGER.info("putConfig ok, dataId={}, cost {}ms", dataId, System.currentTimeMillis() - start); | ||
} | ||
} |
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
Oops, something went wrong.
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.
You want to understand what the purpose of mock-server is? Connecting to the Seata-Server as if using a normal SDK eliminates the cumbersome Seata-Server setup, which is useful for testing client integration. If the user gets this mock-server, need to write such complex logic to test it, what is the point of 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.
I understand the point of mock-server, this class is only used for tests where you need to dynamically change the configuration in the unit test. It is only involved in the mock-server unit tests because it shares a key with TC-server.
Normal users don't need to use this test class to use mock-server, if they want to change the port they just need to use mock-server/resource/application.yml
This complexity arises because the unit tests for both mock-server and seata-server are in one package, or maybe we can create another test subproject for mock-server?
我理解mock-server的意义,这个类仅用于测试时需要动态改变单元测试里的配置。在mock-server的单元测试里因为和TC-server共用了一个key才会涉及它。
正常的用户在使用mock-server里是不需要用到这个test类的,他们如果想改变端口只需要使用mock-server/resource/application.yml
这个复杂性的出现是因为mock-server和seata-server的单元测试都在一个包里,又或者我们可以为mock-server再建一个test子项目?