use of com.alibaba.nacos.config.server.model.capacity.GroupCapacity in project nacos by alibaba.
the class CapacityService method updateGroupUsage.
private boolean updateGroupUsage(CounterMode counterMode, String group, int defaultQuota, boolean ignoreQuotaLimit) {
final Timestamp now = TimeUtils.getCurrentTime();
GroupCapacity groupCapacity = new GroupCapacity();
groupCapacity.setGroup(group);
groupCapacity.setQuota(defaultQuota);
groupCapacity.setGmtModified(now);
if (CounterMode.INCREMENT == counterMode) {
if (ignoreQuotaLimit) {
return groupCapacityPersistService.incrementUsage(groupCapacity);
}
// The quota field in the default value table is 0
return groupCapacityPersistService.incrementUsageWithDefaultQuotaLimit(groupCapacity) || groupCapacityPersistService.incrementUsageWithQuotaLimit(groupCapacity);
}
return groupCapacityPersistService.decrementUsage(groupCapacity);
}
use of com.alibaba.nacos.config.server.model.capacity.GroupCapacity in project nacos by alibaba.
the class CapacityServiceTest method testInsertAndUpdateGroupUsage.
@Test
public void testInsertAndUpdateGroupUsage() {
GroupCapacity groupCapacity = new GroupCapacity();
groupCapacity.setGroup("testGroup");
groupCapacity.setUsage(300);
when(groupCapacityPersistService.getGroupCapacity("testGroup")).thenReturn(groupCapacity);
when(groupCapacityPersistService.incrementUsage(any())).thenReturn(true);
when(groupCapacityPersistService.incrementUsageWithDefaultQuotaLimit(any())).thenReturn(true);
when(groupCapacityPersistService.decrementUsage(any())).thenReturn(true);
service.insertAndUpdateGroupUsage(CounterMode.INCREMENT, "testGroup", true);
Mockito.verify(groupCapacityPersistService, times(1)).incrementUsage(any());
service.insertAndUpdateClusterUsage(CounterMode.INCREMENT, false);
Mockito.verify(groupCapacityPersistService, times(1)).incrementUsageWithDefaultQuotaLimit(any());
service.insertAndUpdateClusterUsage(CounterMode.DECREMENT, true);
Mockito.verify(groupCapacityPersistService, times(1)).decrementUsage(any());
}
use of com.alibaba.nacos.config.server.model.capacity.GroupCapacity in project nacos by alibaba.
the class CapacityServiceTest method testInitGroupCapacity.
@Test
public void testInitGroupCapacity() {
GroupCapacity groupCapacity = new GroupCapacity();
groupCapacity.setGroup("testGroup");
groupCapacity.setUsage(300);
when(groupCapacityPersistService.insertGroupCapacity(any())).thenReturn(true);
when(groupCapacityPersistService.getGroupCapacity(eq("testGroup"))).thenReturn(groupCapacity);
when(groupCapacityPersistService.updateQuota(eq("testGroup"), eq(500))).thenReturn(true);
service.initGroupCapacity("testGroup");
Mockito.verify(groupCapacityPersistService, times(1)).insertGroupCapacity(any());
Mockito.verify(groupCapacityPersistService, times(1)).getGroupCapacity(eq("testGroup"));
Mockito.verify(groupCapacityPersistService, times(1)).updateQuota(eq("testGroup"), eq(500));
}
use of com.alibaba.nacos.config.server.model.capacity.GroupCapacity in project nacos by alibaba.
the class CapacityServiceTest method testCorrectUsage.
@Test
public void testCorrectUsage() {
List<GroupCapacity> groupCapacityList = new ArrayList<>();
GroupCapacity groupCapacity = new GroupCapacity();
groupCapacity.setId(1L);
groupCapacity.setGroup("testGroup");
groupCapacityList.add(groupCapacity);
when(groupCapacityPersistService.getCapacityList4CorrectUsage(0L, 100)).thenReturn(groupCapacityList);
when(groupCapacityPersistService.getCapacityList4CorrectUsage(1L, 100)).thenReturn(new ArrayList<>());
when(groupCapacityPersistService.correctUsage(eq("testGroup"), any())).thenReturn(true);
List<TenantCapacity> tenantCapacityList = new ArrayList<>();
TenantCapacity tenantCapacity = new TenantCapacity();
tenantCapacity.setId(1L);
tenantCapacity.setTenant("testTenant");
tenantCapacityList.add(tenantCapacity);
when(tenantCapacityPersistService.getCapacityList4CorrectUsage(0L, 100)).thenReturn(tenantCapacityList);
when(tenantCapacityPersistService.getCapacityList4CorrectUsage(1L, 100)).thenReturn(new ArrayList<>());
when(tenantCapacityPersistService.correctUsage(eq("testTenant"), any())).thenReturn(true);
service.correctUsage();
Mockito.verify(groupCapacityPersistService, times(1)).getCapacityList4CorrectUsage(0L, 100);
Mockito.verify(groupCapacityPersistService, times(1)).getCapacityList4CorrectUsage(1L, 100);
Mockito.verify(groupCapacityPersistService, times(1)).correctUsage(eq("testGroup"), any());
Mockito.verify(tenantCapacityPersistService, times(1)).getCapacityList4CorrectUsage(0L, 100);
Mockito.verify(tenantCapacityPersistService, times(1)).getCapacityList4CorrectUsage(1L, 100);
Mockito.verify(tenantCapacityPersistService, times(1)).correctUsage(eq("testTenant"), any());
}
use of com.alibaba.nacos.config.server.model.capacity.GroupCapacity in project nacos by alibaba.
the class CapacityServiceTest method testInitCapacityV1.
@Test
public void testInitCapacityV1() {
GroupCapacity groupCapacity = new GroupCapacity();
groupCapacity.setUsage(300);
when(groupCapacityPersistService.getGroupCapacity(eq("testGroup"))).thenReturn(groupCapacity);
when(groupCapacityPersistService.insertGroupCapacity(any())).thenReturn(true);
when(groupCapacityPersistService.updateQuota(eq("testGroup"), eq(500))).thenReturn(true);
TenantCapacity tenantCapacity = new TenantCapacity();
tenantCapacity.setUsage(300);
when(tenantCapacityPersistService.getTenantCapacity(eq("testTenant"))).thenReturn(tenantCapacity);
when(tenantCapacityPersistService.insertTenantCapacity(any())).thenReturn(true);
when(tenantCapacityPersistService.updateQuota(eq("testTenant"), eq(500))).thenReturn(true);
service.initCapacity("testGroup", null);
Mockito.verify(groupCapacityPersistService, times(1)).getGroupCapacity(eq("testGroup"));
Mockito.verify(groupCapacityPersistService, times(1)).insertGroupCapacity(any());
Mockito.verify(groupCapacityPersistService, times(1)).updateQuota(eq("testGroup"), eq(500));
service.initCapacity(null, "testTenant");
Mockito.verify(tenantCapacityPersistService, times(1)).getTenantCapacity(eq("testTenant"));
Mockito.verify(tenantCapacityPersistService, times(1)).insertTenantCapacity(any());
Mockito.verify(tenantCapacityPersistService, times(1)).updateQuota(eq("testTenant"), eq(500));
}
Aggregations