use of com.alibaba.nacos.config.server.model.capacity.GroupCapacity in project nacos by alibaba.
the class CapacityServiceTest method testGetGroupCapacity.
@Test
public void testGetGroupCapacity() {
GroupCapacity groupCapacity = new GroupCapacity();
groupCapacity.setId(1L);
groupCapacity.setGroup("testGroup");
when(groupCapacityPersistService.getGroupCapacity(eq("testGroup"))).thenReturn(groupCapacity);
GroupCapacity resGroupCapacity = service.getGroupCapacity("testGroup");
Assert.assertEquals(groupCapacity.getId(), resGroupCapacity.getId());
Assert.assertEquals(groupCapacity.getGroup(), resGroupCapacity.getGroup());
}
use of com.alibaba.nacos.config.server.model.capacity.GroupCapacity 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.GroupCapacity in project nacos by alibaba.
the class GroupCapacityPersistServiceTest method testGetCapacityList4CorrectUsage.
@Test
public void testGetCapacityList4CorrectUsage() {
List<GroupCapacity> list = new ArrayList<>();
GroupCapacity groupCapacity = new GroupCapacity();
groupCapacity.setGroup("test");
list.add(groupCapacity);
long lastId = 1;
int pageSize = 1;
when(jdbcTemplate.query(anyString(), eq(new Object[] { lastId, pageSize }), any(RowMapper.class))).thenReturn(list);
List<GroupCapacity> ret = service.getCapacityList4CorrectUsage(lastId, pageSize);
Assert.assertEquals(list.size(), ret.size());
Assert.assertEquals(groupCapacity.getGroup(), ret.get(0).getGroup());
}
use of com.alibaba.nacos.config.server.model.capacity.GroupCapacity in project nacos by alibaba.
the class GroupCapacityPersistServiceTest method testIncrementUsageWithQuotaLimit.
@Test
public void testIncrementUsageWithQuotaLimit() {
GroupCapacity groupCapacity = new GroupCapacity();
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
groupCapacity.setGmtModified(timestamp);
groupCapacity.setGroup("test2");
when(jdbcTemplate.update(anyString(), eq(timestamp), eq("test2"))).thenReturn(1);
Assert.assertTrue(service.incrementUsageWithQuotaLimit(groupCapacity));
}
use of com.alibaba.nacos.config.server.model.capacity.GroupCapacity in project nacos by alibaba.
the class GroupCapacityPersistServiceTest method testDecrementUsage.
@Test
public void testDecrementUsage() {
GroupCapacity groupCapacity = new GroupCapacity();
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
groupCapacity.setGmtModified(timestamp);
groupCapacity.setGroup("test4");
when(jdbcTemplate.update(anyString(), eq(timestamp), eq("test4"))).thenReturn(1);
Assert.assertTrue(service.decrementUsage(groupCapacity));
}
Aggregations