-
Notifications
You must be signed in to change notification settings - Fork 139
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
Develop v2 for config_client #183
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import asyncio | ||
import time | ||
import unittest | ||
|
||
from v2.nacos.common.client_config import GRPCConfig | ||
|
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,158 @@ | ||
import asyncio | ||
import unittest | ||
|
||
from v2.nacos.common.client_config import GRPCConfig | ||
from v2.nacos.common.client_config_builder import ClientConfigBuilder | ||
from v2.nacos.config.model.config_param import ConfigParam, Listener | ||
from v2.nacos.config.nacos_config_service import NacosConfigService | ||
|
||
client_config = (ClientConfigBuilder() | ||
.username('xxx') | ||
.password('xxx') | ||
.server_address('xxx') | ||
.grpc_config(GRPCConfig()) | ||
.cache_dir('xxx') | ||
.log_dir('xxx') | ||
.build()) | ||
|
||
def generate_random_string(length=4): | ||
import random | ||
import string | ||
letters = string.ascii_letters + string.digits | ||
return ''.join(random.choices(letters, k=length)) | ||
|
||
|
||
class TestListener(Listener): | ||
def listen(self, namespace: str, group: str, data_id: str, content: str): | ||
print(namespace, group, data_id, content, "listener") | ||
|
||
|
||
class TestClientV2(unittest.IsolatedAsyncioTestCase): | ||
async def test_publish_config(self): | ||
client = await NacosConfigService.create_config_service(client_config) | ||
try: | ||
await asyncio.sleep(5) | ||
response = await client.publish_config( | ||
param=ConfigParam(data_id="testttt", group="group", content="content", src_user='nacos')) | ||
self.assertEqual(response, True) | ||
if response: | ||
print("success to publish") | ||
await asyncio.sleep(1000) | ||
except Exception as e: | ||
print(str(e)) | ||
|
||
async def test_get_config(self): | ||
client = await NacosConfigService.create_config_service(client_config) | ||
try: | ||
await asyncio.sleep(5) | ||
response = await client.get_config( | ||
param=ConfigParam(data_id="testttt", group="group")) | ||
print(response) | ||
# self.assertEqual(response, True) | ||
if response: | ||
print("success to get config") | ||
await asyncio.sleep(1000) | ||
except Exception as e: | ||
print(str(e)) | ||
|
||
async def test_remove_config(self): | ||
client = await NacosConfigService.create_config_service(client_config) | ||
try: | ||
await asyncio.sleep(5) | ||
response = await client.remove_config( | ||
param=ConfigParam(data_id="testttt", group="group")) | ||
if response: | ||
print("success to remove config") | ||
await asyncio.sleep(1000) | ||
except Exception as e: | ||
print(str(e)) | ||
|
||
async def test_add_listener(self): | ||
client = await NacosConfigService.create_config_service(client_config) | ||
try: | ||
a = generate_random_string() | ||
b = generate_random_string() | ||
|
||
await asyncio.sleep(5) | ||
response = await client.publish_config( | ||
param=ConfigParam(data_id="testttt", group="group", content="1{}".format(a), src_user='nacos')) | ||
if response: | ||
print("publish1") | ||
|
||
await asyncio.sleep(5) | ||
|
||
listener = TestListener() | ||
response = await client.add_listener( | ||
param=ConfigParam(data_id="testttt", group="group"), listener=listener) | ||
|
||
print("add listen") | ||
await asyncio.sleep(5) | ||
|
||
response = await client.publish_config( | ||
param=ConfigParam(data_id="testttt", group="group", content="3{}".format(b), src_user='nacos')) | ||
if response: | ||
print("publish2") | ||
await asyncio.sleep(1000) | ||
except Exception as e: | ||
print(str(e)) | ||
|
||
async def test_cipher_config(self): | ||
client = await NacosConfigService.create_config_service(client_config) | ||
try: | ||
|
||
# await asyncio.sleep(5) | ||
response = await client.publish_config( | ||
param=ConfigParam(data_id="cipher-aes-testttt", group="group", content="你好nacos", src_user='nacos')) | ||
if response: | ||
print("publish1") | ||
|
||
await asyncio.sleep(5) | ||
|
||
response = await client.get_config( | ||
param=ConfigParam(data_id="cipher-aes-testttt", group="group")) | ||
print(response) | ||
|
||
await asyncio.sleep(1000) | ||
except Exception as e: | ||
print(str(e)) | ||
|
||
async def test_cipher_listener(self): | ||
client = await NacosConfigService.create_config_service(client_config) | ||
try: | ||
a = generate_random_string() | ||
b = generate_random_string() | ||
|
||
await asyncio.sleep(5) | ||
response = await client.publish_config( | ||
param=ConfigParam(data_id="cipher-aes-testttt", group="group", content="1{}".format(a))) | ||
print("publish1") | ||
|
||
await asyncio.sleep(5) | ||
|
||
listener = TestListener() | ||
response = await client.add_listener( | ||
param=ConfigParam(data_id="cipher-aes-testttt", group="group"), listener=listener) | ||
|
||
print("add listen") | ||
await asyncio.sleep(5) | ||
|
||
response = await client.publish_config( | ||
param=ConfigParam(data_id="cipher-aes-testttt", group="group", content="3{}".format(b))) | ||
print("publish2") | ||
|
||
# self.assertEqual(response, True) | ||
if response: | ||
print("success to test listen") | ||
|
||
await asyncio.sleep(1000) | ||
except Exception as e: | ||
print(str(e)) | ||
|
||
async def test_remove_listener(self): | ||
client = await NacosConfigService.create_config_service(client_config) | ||
try: | ||
await client.remove_listener( | ||
param=ConfigParam(data_id="testttt", group="group")) | ||
await asyncio.sleep(1000) | ||
except Exception as e: | ||
print(str(e)) |
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
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.
仅保留一个测试类,里面的根据不同测试例子方法名区分开,最好能备注上注释