Search in sources :

Example 16 with TenantCapacity

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

Example 17 with TenantCapacity

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

Example 18 with TenantCapacity

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());
}
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 19 with TenantCapacity

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

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

Aggregations

TenantCapacity (com.alibaba.nacos.config.server.model.capacity.TenantCapacity)21 Test (org.junit.Test)17 Timestamp (java.sql.Timestamp)7 GroupCapacity (com.alibaba.nacos.config.server.model.capacity.GroupCapacity)6 ArrayList (java.util.ArrayList)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 RowMapper (org.springframework.jdbc.core.RowMapper)3 Capacity (com.alibaba.nacos.config.server.model.capacity.Capacity)2 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