use of com.alibaba.nacos.config.server.model.capacity.TenantCapacity 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));
}
use of com.alibaba.nacos.config.server.model.capacity.TenantCapacity in project nacos by alibaba.
the class CapacityServiceTest method testGetTenantCapacity.
@Test
public void testGetTenantCapacity() {
TenantCapacity tenantCapacity = new TenantCapacity();
tenantCapacity.setId(1L);
tenantCapacity.setTenant("testTenant");
when(tenantCapacityPersistService.getTenantCapacity(eq("testTenant"))).thenReturn(tenantCapacity);
TenantCapacity resTenantCapacity = service.getTenantCapacity("testTenant");
Assert.assertEquals(tenantCapacity.getId(), resTenantCapacity.getId());
Assert.assertEquals(tenantCapacity.getTenant(), resTenantCapacity.getTenant());
}
use of com.alibaba.nacos.config.server.model.capacity.TenantCapacity in project nacos by alibaba.
the class CapacityServiceTest method testGetCapacityWithDefault.
@Test
public void testGetCapacityWithDefault() {
TenantCapacity tenantCapacity = new TenantCapacity();
tenantCapacity.setQuota(0);
tenantCapacity.setMaxSize(0);
tenantCapacity.setMaxAggrCount(0);
tenantCapacity.setMaxAggrSize(0);
when(tenantCapacityPersistService.getTenantCapacity(anyString())).thenReturn(tenantCapacity);
GroupCapacity groupCapacity1 = new GroupCapacity();
groupCapacity1.setQuota(0);
groupCapacity1.setMaxSize(0);
groupCapacity1.setMaxAggrCount(0);
groupCapacity1.setMaxAggrSize(0);
when(groupCapacityPersistService.getGroupCapacity(anyString())).thenReturn(groupCapacity1);
// group is null
Capacity resCapacity1 = service.getCapacityWithDefault(null, "testTenant");
Assert.assertEquals(PropertyUtil.getDefaultGroupQuota(), resCapacity1.getQuota().intValue());
Assert.assertEquals(PropertyUtil.getDefaultMaxSize(), resCapacity1.getMaxSize().intValue());
Assert.assertEquals(PropertyUtil.getDefaultMaxAggrCount(), resCapacity1.getMaxAggrCount().intValue());
Assert.assertEquals(PropertyUtil.getDefaultMaxAggrSize(), resCapacity1.getMaxAggrSize().intValue());
// group is GroupCapacityPersistService.CLUSTER
Capacity resCapacity2 = service.getCapacityWithDefault(GroupCapacityPersistService.CLUSTER, null);
Assert.assertEquals(PropertyUtil.getDefaultClusterQuota(), resCapacity2.getQuota().intValue());
Assert.assertEquals(PropertyUtil.getDefaultMaxSize(), resCapacity2.getMaxSize().intValue());
Assert.assertEquals(PropertyUtil.getDefaultMaxAggrCount(), resCapacity2.getMaxAggrCount().intValue());
Assert.assertEquals(PropertyUtil.getDefaultMaxAggrSize(), resCapacity2.getMaxAggrSize().intValue());
GroupCapacity groupCapacity2 = new GroupCapacity();
groupCapacity2.setQuota(0);
groupCapacity2.setMaxSize(0);
groupCapacity2.setMaxAggrCount(0);
groupCapacity2.setMaxAggrSize(0);
when(groupCapacityPersistService.getGroupCapacity(anyString())).thenReturn(groupCapacity2);
// tenant is null
Capacity resCapacity3 = service.getCapacityWithDefault("testGroup", null);
Assert.assertEquals(PropertyUtil.getDefaultGroupQuota(), resCapacity3.getQuota().intValue());
Assert.assertEquals(PropertyUtil.getDefaultMaxSize(), resCapacity3.getMaxSize().intValue());
Assert.assertEquals(PropertyUtil.getDefaultMaxAggrCount(), resCapacity3.getMaxAggrCount().intValue());
Assert.assertEquals(PropertyUtil.getDefaultMaxAggrSize(), resCapacity3.getMaxAggrSize().intValue());
}
use of com.alibaba.nacos.config.server.model.capacity.TenantCapacity in project nacos by alibaba.
the class TenantCapacityPersistServiceTest method testIncrementUsageWithDefaultQuotaLimit.
@Test
public void testIncrementUsageWithDefaultQuotaLimit() {
TenantCapacity tenantCapacity = new TenantCapacity();
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
tenantCapacity.setGmtModified(timestamp);
tenantCapacity.setTenant("test");
tenantCapacity.setQuota(1);
when(jdbcTemplate.update(anyString(), eq(timestamp), eq("test"), eq(1))).thenReturn(1);
Assert.assertTrue(service.incrementUsageWithDefaultQuotaLimit(tenantCapacity));
}
use of com.alibaba.nacos.config.server.model.capacity.TenantCapacity in project nacos by alibaba.
the class TenantCapacityPersistServiceTest method testGetTenantCapacity.
@Test
public void testGetTenantCapacity() {
List<TenantCapacity> list = new ArrayList<>();
TenantCapacity tenantCapacity = new TenantCapacity();
tenantCapacity.setTenant("test");
list.add(tenantCapacity);
String tenantId = "testId";
when(jdbcTemplate.query(anyString(), eq(new Object[] { tenantId }), any(RowMapper.class))).thenReturn(list);
TenantCapacity ret = service.getTenantCapacity(tenantId);
Assert.assertEquals(tenantCapacity.getTenant(), ret.getTenant());
}
Aggregations