use of com.alibaba.nacos.config.server.model.capacity.TenantCapacity in project nacos by alibaba.
the class TenantCapacityPersistServiceTest method testIncrementUsage.
@Test
public void testIncrementUsage() {
TenantCapacity tenantCapacity = new TenantCapacity();
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
tenantCapacity.setGmtModified(timestamp);
tenantCapacity.setTenant("test3");
when(jdbcTemplate.update(anyString(), eq(timestamp), eq("test3"))).thenReturn(1);
Assert.assertTrue(service.incrementUsage(tenantCapacity));
}
use of com.alibaba.nacos.config.server.model.capacity.TenantCapacity in project nacos by alibaba.
the class TenantCapacityPersistServiceTest method testInsertTenantCapacity.
@Test
public void testInsertTenantCapacity() {
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);
TenantCapacity capacity = new TenantCapacity();
capacity.setTenant("test");
Assert.assertTrue(service.insertTenantCapacity(capacity));
}
use of com.alibaba.nacos.config.server.model.capacity.TenantCapacity in project nacos by alibaba.
the class TenantCapacityPersistServiceTest method testGetCapacityList4CorrectUsage.
@Test
public void testGetCapacityList4CorrectUsage() {
List<TenantCapacity> list = new ArrayList<>();
TenantCapacity tenantCapacity = new TenantCapacity();
tenantCapacity.setTenant("test");
list.add(tenantCapacity);
long lastId = 1;
int pageSize = 1;
when(jdbcTemplate.query(anyString(), eq(new Object[] { lastId, pageSize }), any(RowMapper.class))).thenReturn(list);
List<TenantCapacity> ret = service.getCapacityList4CorrectUsage(lastId, pageSize);
Assert.assertEquals(list.size(), ret.size());
Assert.assertEquals(tenantCapacity.getTenant(), ret.get(0).getTenant());
}
use of com.alibaba.nacos.config.server.model.capacity.TenantCapacity in project nacos by alibaba.
the class TenantCapacityPersistServiceTest method testDecrementUsage.
@Test
public void testDecrementUsage() {
TenantCapacity tenantCapacity = new TenantCapacity();
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
tenantCapacity.setGmtModified(timestamp);
tenantCapacity.setTenant("test4");
when(jdbcTemplate.update(anyString(), eq(timestamp), eq("test4"))).thenReturn(1);
Assert.assertTrue(service.decrementUsage(tenantCapacity));
}
use of com.alibaba.nacos.config.server.model.capacity.TenantCapacity 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());
}
Aggregations