Search in sources :

Example 16 with GroupCapacity

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());
}
Also used : GroupCapacity(com.alibaba.nacos.config.server.model.capacity.GroupCapacity) Test(org.junit.Test)

Example 17 with GroupCapacity

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());
}
Also used : TenantCapacity(com.alibaba.nacos.config.server.model.capacity.TenantCapacity) GroupCapacity(com.alibaba.nacos.config.server.model.capacity.GroupCapacity) TenantCapacity(com.alibaba.nacos.config.server.model.capacity.TenantCapacity) Capacity(com.alibaba.nacos.config.server.model.capacity.Capacity) GroupCapacity(com.alibaba.nacos.config.server.model.capacity.GroupCapacity) Test(org.junit.Test)

Example 18 with GroupCapacity

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());
}
Also used : GroupCapacity(com.alibaba.nacos.config.server.model.capacity.GroupCapacity) ArrayList(java.util.ArrayList) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.junit.Test)

Example 19 with GroupCapacity

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));
}
Also used : GroupCapacity(com.alibaba.nacos.config.server.model.capacity.GroupCapacity) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 20 with 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));
}
Also used : GroupCapacity(com.alibaba.nacos.config.server.model.capacity.GroupCapacity) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Aggregations

GroupCapacity (com.alibaba.nacos.config.server.model.capacity.GroupCapacity)22 Test (org.junit.Test)18 Timestamp (java.sql.Timestamp)7 ArrayList (java.util.ArrayList)7 TenantCapacity (com.alibaba.nacos.config.server.model.capacity.TenantCapacity)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 RowMapper (org.springframework.jdbc.core.RowMapper)5 Capacity (com.alibaba.nacos.config.server.model.capacity.Capacity)4 PreparedStatementCreator (org.springframework.jdbc.core.PreparedStatementCreator)2 CollectionUtils (com.alibaba.nacos.common.utils.CollectionUtils)1 DataSourceService (com.alibaba.nacos.config.server.service.datasource.DataSourceService)1 DynamicDataSource (com.alibaba.nacos.config.server.service.datasource.DynamicDataSource)1 FATAL_LOG (com.alibaba.nacos.config.server.utils.LogUtil.FATAL_LOG)1 PropertyUtil (com.alibaba.nacos.config.server.utils.PropertyUtil)1 TimeUtils (com.alibaba.nacos.config.server.utils.TimeUtils)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 HashMap (java.util.HashMap)1