-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix namespace quota and parameter optimize (#12581)
* 34567 * fix namespace quota,fix some security problem * Revert "34567" This reverts commit 25743c6. * avoid print content to log * check style * check style * check style * check style
- Loading branch information
1 parent
98a6e22
commit ac48fb3
Showing
4 changed files
with
124 additions
and
18 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
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
95 changes: 95 additions & 0 deletions
95
...src/test/java/com/alibaba/nacos/config/server/service/NamespaceConfigInfoServiceTest.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,95 @@ | ||
/* | ||
* Copyright 1999-2023 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed 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 com.alibaba.nacos.config.server.service; | ||
|
||
import com.alibaba.nacos.config.server.model.capacity.TenantCapacity; | ||
import com.alibaba.nacos.config.server.service.capacity.TenantCapacityPersistService; | ||
import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService; | ||
import com.alibaba.nacos.config.server.utils.PropertyUtil; | ||
import com.alibaba.nacos.core.namespace.model.Namespace; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.Mockito; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
public class NamespaceConfigInfoServiceTest { | ||
|
||
@Mock | ||
private ConfigInfoPersistService configInfoPersistService; | ||
|
||
@Mock | ||
private TenantCapacityPersistService tenantCapacityPersistService; | ||
|
||
MockedStatic<PropertyUtil> propertyUtilMockedStatic; | ||
|
||
@BeforeEach | ||
void setUp() throws Exception { | ||
propertyUtilMockedStatic = Mockito.mockStatic(PropertyUtil.class); | ||
|
||
} | ||
|
||
@AfterEach | ||
void after() throws Exception { | ||
propertyUtilMockedStatic.close(); | ||
} | ||
|
||
@Test | ||
public void testInjectDetailNotDefault() { | ||
|
||
String namespaceId = "test1234"; | ||
TenantCapacity tenantCapacity = new TenantCapacity(); | ||
tenantCapacity.setQuota(1023); | ||
|
||
when(tenantCapacityPersistService.getTenantCapacity(namespaceId)).thenReturn(tenantCapacity); | ||
when(configInfoPersistService.configInfoCount(namespaceId)).thenReturn(101); | ||
Namespace namespace = new Namespace(namespaceId, "test123ShowName"); | ||
NamespaceConfigInfoService namespaceConfigInfoService = new NamespaceConfigInfoService(configInfoPersistService, | ||
tenantCapacityPersistService); | ||
namespaceConfigInfoService.injectDetail(namespace); | ||
assertEquals(101, namespace.getConfigCount()); | ||
assertEquals(1023, namespace.getQuota()); | ||
|
||
} | ||
|
||
@Test | ||
public void testInjectDetailDefaultQuota() { | ||
|
||
String namespaceId = "test1234"; | ||
TenantCapacity tenantCapacity = new TenantCapacity(); | ||
tenantCapacity.setQuota(0); | ||
when(tenantCapacityPersistService.getTenantCapacity(namespaceId)).thenReturn(tenantCapacity); | ||
when(configInfoPersistService.configInfoCount(namespaceId)).thenReturn(105); | ||
|
||
when(PropertyUtil.getDefaultTenantQuota()).thenReturn(1025); | ||
Namespace namespace = new Namespace(namespaceId, "test123ShowName"); | ||
NamespaceConfigInfoService namespaceConfigInfoService = new NamespaceConfigInfoService(configInfoPersistService, | ||
tenantCapacityPersistService); | ||
namespaceConfigInfoService.injectDetail(namespace); | ||
|
||
assertEquals(105, namespace.getConfigCount()); | ||
assertEquals(1025, namespace.getQuota()); | ||
} | ||
|
||
} |