-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from nacos-group/feature/v2
Feature/v2
- Loading branch information
Showing
76 changed files
with
5,526 additions
and
24 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pydantic~=2.7.4 | ||
requests~=2.32.0 | ||
setuptools~=49.2.1 | ||
psutil~=5.9.6 | ||
aiohttp~=3.10.11 | ||
aiofiles~=24.1.0 |
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 |
---|---|---|
|
@@ -337,4 +337,4 @@ def test_inject_auth_info_of_naming(self): | |
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() | ||
unittest.main() |
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,132 @@ | ||
import asyncio | ||
import os | ||
import unittest | ||
|
||
from v2.nacos.common.client_config import GRPCConfig | ||
from v2.nacos.common.client_config_builder import ClientConfigBuilder | ||
from v2.nacos.naming.model.instance import Instance | ||
from v2.nacos.naming.model.naming_param import RegisterInstanceParam, DeregisterInstanceParam, \ | ||
BatchRegisterInstanceParam, GetServiceParam, ListServiceParam, SubscribeServiceParam, ListInstanceParam | ||
from v2.nacos.naming.nacos_naming_service import NacosNamingService | ||
|
||
client_config = (ClientConfigBuilder() | ||
.access_key(os.getenv('NACOS_ACCESS_KEY')) | ||
.secret_key(os.getenv('NACOS_SECRET_KEY')) | ||
.server_address(os.getenv('NACOS_SERVER_ADDR', 'localhost:8848')) | ||
.log_level('INFO') | ||
.grpc_config(GRPCConfig(grpc_timeout=5000)) | ||
.build()) | ||
|
||
|
||
class TestClientV2(unittest.IsolatedAsyncioTestCase): | ||
|
||
async def test_register(self): | ||
client = await NacosNamingService.create_naming_service(client_config) | ||
assert await client.server_health() | ||
|
||
async def cb(instance_list: list[Instance]): | ||
print('received subscribe callback', str(instance_list)) | ||
|
||
await client.subscribe( | ||
SubscribeServiceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', subscribe_callback=cb)) | ||
|
||
print('subscribe service') | ||
|
||
response = await client.register_instance( | ||
request=RegisterInstanceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', ip='1.1.1.1', | ||
port=7001, weight=1.0, cluster_name='c1', metadata={'a': 'b'}, | ||
enabled=True, | ||
healthy=True, ephemeral=True)) | ||
self.assertEqual(response, True) | ||
|
||
print('register instance') | ||
|
||
await asyncio.sleep(1) | ||
|
||
response = await client.update_instance( | ||
request=RegisterInstanceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', ip='1.1.1.1', | ||
port=7001, weight=2.0, cluster_name='c1', metadata={'a': 'b'}, | ||
enabled=True, | ||
healthy=True, ephemeral=True)) | ||
self.assertEqual(response, True) | ||
|
||
print('update instance') | ||
|
||
await asyncio.sleep(1) | ||
|
||
response = await client.deregister_instance( | ||
request=DeregisterInstanceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', ip='1.1.1.1', | ||
port=7001, cluster_name='c1', ephemeral=True) | ||
) | ||
self.assertEqual(response, True) | ||
|
||
print('deregister instance') | ||
|
||
await asyncio.sleep(1) | ||
|
||
param1 = RegisterInstanceParam(service_name='nacos.test.1', | ||
group_name='DEFAULT_GROUP', | ||
ip='1.1.1.1', | ||
port=7001, | ||
weight=1.0, | ||
cluster_name='c1', | ||
metadata={'a': 'b'}, | ||
enabled=True, | ||
healthy=True, | ||
ephemeral=True | ||
) | ||
param2 = RegisterInstanceParam(service_name='nacos.test.1', | ||
group_name='DEFAULT_GROUP', | ||
ip='1.1.1.1', | ||
port=7002, | ||
weight=1.0, | ||
cluster_name='c1', | ||
metadata={'a': 'b'}, | ||
enabled=True, | ||
healthy=True, | ||
ephemeral=True | ||
) | ||
param3 = RegisterInstanceParam(service_name='nacos.test.1', | ||
group_name='DEFAULT_GROUP', | ||
ip='1.1.1.1', | ||
port=7003, | ||
weight=1.0, | ||
cluster_name='c1', | ||
metadata={'a': 'b'}, | ||
enabled=True, | ||
healthy=False, | ||
ephemeral=True | ||
) | ||
response = await client.batch_register_instances( | ||
request=BatchRegisterInstanceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', | ||
instances=[param1, param2, param3])) | ||
self.assertEqual(response, True) | ||
|
||
print('batch register instance') | ||
await asyncio.sleep(1) | ||
|
||
service = await client.get_service( | ||
GetServiceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', cluster_name='c1')) | ||
print('get service', str(service)) | ||
assert service.name == 'nacos.test.1' | ||
|
||
service_list = await client.list_services(ListServiceParam()) | ||
assert service_list.count == 1 | ||
|
||
instance_list = await client.list_instances(ListInstanceParam(service_name='nacos.test.1', healthy_only=True)) | ||
assert len(instance_list) == 2 | ||
|
||
instance_list = await client.list_instances(ListInstanceParam(service_name='nacos.test.1', healthy_only=False)) | ||
assert len(instance_list) == 1 | ||
|
||
instance_list = await client.list_instances(ListInstanceParam(service_name='nacos.test.1', healthy_only=None)) | ||
assert len(instance_list) == 3 | ||
|
||
await client.unsubscribe( | ||
SubscribeServiceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', subscribe_callback=cb)) | ||
|
||
await client.shutdown() | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.