Skip to content
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

fix derby usage filed #12659

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

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.constant.PropertiesConstant;
import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService;
import com.alibaba.nacos.config.server.utils.PropertyUtil;
import com.alibaba.nacos.core.namespace.injector.AbstractNamespaceDetailInjector;
import com.alibaba.nacos.core.namespace.model.Namespace;
import com.alibaba.nacos.sys.env.EnvUtil;
import org.springframework.stereotype.Service;

/**
Expand All @@ -34,23 +33,17 @@ public class NamespaceConfigInfoService extends AbstractNamespaceDetailInjector

private final ConfigInfoPersistService configInfoPersistService;

private final TenantCapacityPersistService tenantCapacityPersistService;

public NamespaceConfigInfoService(ConfigInfoPersistService configInfoPersistService,
TenantCapacityPersistService tenantCapacityPersistService) {
public NamespaceConfigInfoService(ConfigInfoPersistService configInfoPersistService) {
this.configInfoPersistService = configInfoPersistService;
this.tenantCapacityPersistService = tenantCapacityPersistService;
}

@Override
public void injectDetail(Namespace namespace) {
// set tenant quota
TenantCapacity tenantCapacity = tenantCapacityPersistService.getTenantCapacity(namespace.getNamespace());
if (tenantCapacity != null && tenantCapacity.getQuota() != null && tenantCapacity.getQuota() > 0) {
namespace.setQuota(tenantCapacity.getQuota());
} else {
namespace.setQuota(PropertyUtil.getDefaultTenantQuota());

if (EnvUtil.getProperty(PropertiesConstant.DEFAULT_TENANT_QUOTA, Integer.class) != null) {
namespace.setQuota(EnvUtil.getProperty(PropertiesConstant.DEFAULT_TENANT_QUOTA, Integer.class));
}

// set config count.
int configCount = configInfoPersistService.configInfoCount(namespace.getNamespace());
namespace.setConfigCount(configCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package com.alibaba.nacos.config.server.service;

import com.alibaba.nacos.config.server.constant.PropertiesConstant;
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 com.alibaba.nacos.sys.env.EnvUtil;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -31,6 +31,7 @@
import org.springframework.test.context.junit.jupiter.SpringExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;

@ExtendWith(SpringExtension.class)
Expand All @@ -39,14 +40,11 @@ public class NamespaceConfigInfoServiceTest {
@Mock
private ConfigInfoPersistService configInfoPersistService;

@Mock
private TenantCapacityPersistService tenantCapacityPersistService;

MockedStatic<PropertyUtil> propertyUtilMockedStatic;
MockedStatic<EnvUtil> propertyUtilMockedStatic;

@BeforeEach
void setUp() throws Exception {
propertyUtilMockedStatic = Mockito.mockStatic(PropertyUtil.class);
propertyUtilMockedStatic = Mockito.mockStatic(EnvUtil.class);

}

Expand All @@ -59,14 +57,12 @@ void after() throws Exception {
public void testInjectDetailNotDefault() {

String namespaceId = "test1234";
TenantCapacity tenantCapacity = new TenantCapacity();
tenantCapacity.setQuota(1023);

when(tenantCapacityPersistService.getTenantCapacity(namespaceId)).thenReturn(tenantCapacity);
when(EnvUtil.getProperty(eq(PropertiesConstant.DEFAULT_TENANT_QUOTA), eq(Integer.class))).thenReturn(1023);
when(configInfoPersistService.configInfoCount(namespaceId)).thenReturn(101);
Namespace namespace = new Namespace(namespaceId, "test123ShowName");
NamespaceConfigInfoService namespaceConfigInfoService = new NamespaceConfigInfoService(configInfoPersistService,
tenantCapacityPersistService);
namespace.setQuota(200);
NamespaceConfigInfoService namespaceConfigInfoService = new NamespaceConfigInfoService(
configInfoPersistService);
namespaceConfigInfoService.injectDetail(namespace);
assertEquals(101, namespace.getConfigCount());
assertEquals(1023, namespace.getQuota());
Expand All @@ -79,17 +75,17 @@ 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);
when(EnvUtil.getProperty(eq(PropertiesConstant.DEFAULT_TENANT_QUOTA), eq(Integer.class))).thenReturn(null);
Namespace namespace = new Namespace(namespaceId, "test123ShowName");
NamespaceConfigInfoService namespaceConfigInfoService = new NamespaceConfigInfoService(configInfoPersistService,
tenantCapacityPersistService);
namespace.setQuota(200);
NamespaceConfigInfoService namespaceConfigInfoService = new NamespaceConfigInfoService(
configInfoPersistService);
namespaceConfigInfoService.injectDetail(namespace);

assertEquals(105, namespace.getConfigCount());
assertEquals(1025, namespace.getQuota());
assertEquals(200, namespace.getQuota());
}

}
Loading