use of com.alibaba.nacos.config.server.model.capacity.GroupCapacity in project nacos by alibaba.
the class CapacityServiceTest method testInsertOrUpdateCapacityV1.
@Test
public void testInsertOrUpdateCapacityV1() {
// tenant is null
GroupCapacity groupCapacity = new GroupCapacity();
groupCapacity.setUsage(300);
when(groupCapacityPersistService.getGroupCapacity(eq("testGroup"))).thenReturn(groupCapacity);
when(groupCapacityPersistService.updateGroupCapacity(eq("testGroup"), eq(0), eq(0), eq(0), eq(0))).thenReturn(true);
service.insertOrUpdateCapacity("testGroup", null, 0, 0, 0, 0);
Mockito.verify(groupCapacityPersistService, times(1)).getGroupCapacity(eq("testGroup"));
Mockito.verify(groupCapacityPersistService, times(1)).updateGroupCapacity(eq("testGroup"), eq(0), eq(0), eq(0), eq(0));
// tenant is not null
TenantCapacity tenantCapacity = new TenantCapacity();
tenantCapacity.setTenant("testTenant");
when(tenantCapacityPersistService.getTenantCapacity(eq("testTenant"))).thenReturn(tenantCapacity);
when(tenantCapacityPersistService.updateTenantCapacity(eq("testTenant"), eq(0), eq(0), eq(0), eq(0))).thenReturn(true);
service.insertOrUpdateCapacity(null, "testTenant", 0, 0, 0, 0);
Mockito.verify(tenantCapacityPersistService, times(1)).getTenantCapacity(eq("testTenant"));
Mockito.verify(tenantCapacityPersistService, times(1)).updateTenantCapacity(eq("testTenant"), eq(0), eq(0), eq(0), eq(0));
}
use of com.alibaba.nacos.config.server.model.capacity.GroupCapacity in project nacos by alibaba.
the class GroupCapacityPersistServiceTest method testIncrementUsageWithDefaultQuotaLimit.
@Test
public void testIncrementUsageWithDefaultQuotaLimit() {
GroupCapacity groupCapacity = new GroupCapacity();
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
groupCapacity.setGmtModified(timestamp);
groupCapacity.setGroup("test");
groupCapacity.setQuota(1);
when(jdbcTemplate.update(anyString(), eq(timestamp), eq("test"), eq(1))).thenReturn(1);
Assert.assertTrue(service.incrementUsageWithDefaultQuotaLimit(groupCapacity));
}
use of com.alibaba.nacos.config.server.model.capacity.GroupCapacity in project nacos by alibaba.
the class GroupCapacityPersistServiceTest method testGetGroupCapacity.
@Test
public void testGetGroupCapacity() {
List<GroupCapacity> list = new ArrayList<>();
GroupCapacity groupCapacity = new GroupCapacity();
groupCapacity.setGroup("test");
list.add(groupCapacity);
String groupId = "testId";
when(jdbcTemplate.query(anyString(), eq(new Object[] { groupId }), any(RowMapper.class))).thenReturn(list);
GroupCapacity ret = service.getGroupCapacity(groupId);
Assert.assertEquals(groupCapacity.getGroup(), ret.getGroup());
}
use of com.alibaba.nacos.config.server.model.capacity.GroupCapacity in project nacos by alibaba.
the class GroupCapacityPersistServiceTest method testGetClusterUsage.
@Test
public void testGetClusterUsage() {
List<GroupCapacity> list = new ArrayList<>();
GroupCapacity groupCapacity = new GroupCapacity();
groupCapacity.setId(1L);
groupCapacity.setUsage(10);
list.add(groupCapacity);
String groupId = GroupCapacityPersistService.CLUSTER;
when(jdbcTemplate.query(anyString(), eq(new Object[] { groupId }), any(RowMapper.class))).thenReturn(list);
Assert.assertEquals(groupCapacity.getUsage().intValue(), service.getClusterUsage());
when(jdbcTemplate.query(anyString(), eq(new Object[] { groupId }), any(RowMapper.class))).thenReturn(new ArrayList<>());
when(jdbcTemplate.queryForObject(anyString(), eq(Integer.class))).thenReturn(20);
Assert.assertEquals(20, service.getClusterUsage());
}
use of com.alibaba.nacos.config.server.model.capacity.GroupCapacity in project nacos by alibaba.
the class GroupCapacityPersistServiceTest method testInsertGroupCapacity.
@Test
public void testInsertGroupCapacity() {
when(jdbcTemplate.update(any(PreparedStatementCreator.class), argThat((ArgumentMatcher<GeneratedKeyHolder>) keyHolder -> {
List<Map<String, Object>> keyList = new ArrayList<>();
Map<String, Object> keyMap = new HashMap<>();
Number number = 1;
keyMap.put("test", number);
keyList.add(keyMap);
List<Map<String, Object>> expect = keyHolder.getKeyList();
expect.addAll(keyList);
return false;
}))).thenReturn(1);
GroupCapacity capacity = new GroupCapacity();
capacity.setGroup(GroupCapacityPersistService.CLUSTER);
Assert.assertTrue(service.insertGroupCapacity(capacity));
capacity.setGroup("test");
Assert.assertTrue(service.insertGroupCapacity(capacity));
}
Aggregations