Search in sources :

Example 6 with TenantCapacity

use of com.alibaba.nacos.config.server.model.capacity.TenantCapacity in project nacos by alibaba.

the class CapacityServiceTest method testInitTenantCapacityV1.

@Test
public void testInitTenantCapacityV1() {
    TenantCapacity tenantCapacity = new TenantCapacity();
    tenantCapacity.setTenant("testTenant");
    tenantCapacity.setUsage(300);
    when(tenantCapacityPersistService.insertTenantCapacity(any())).thenReturn(true);
    when(tenantCapacityPersistService.getTenantCapacity(eq("testTenant"))).thenReturn(tenantCapacity);
    when(tenantCapacityPersistService.updateQuota(eq("testTenant"), eq(500))).thenReturn(true);
    service.initTenantCapacity("testTenant");
    Mockito.verify(tenantCapacityPersistService, times(1)).insertTenantCapacity(any());
    Mockito.verify(tenantCapacityPersistService, times(1)).getTenantCapacity(eq("testTenant"));
    Mockito.verify(tenantCapacityPersistService, times(1)).updateQuota(eq("testTenant"), eq(500));
}
Also used : TenantCapacity(com.alibaba.nacos.config.server.model.capacity.TenantCapacity) Test(org.junit.Test)

Example 7 with TenantCapacity

use of com.alibaba.nacos.config.server.model.capacity.TenantCapacity in project nacos by alibaba.

the class CapacityServiceTest method testInitTenantCapacityV2.

@Test
public void testInitTenantCapacityV2() {
    TenantCapacity tenantCapacity = new TenantCapacity();
    tenantCapacity.setTenant("testTenant");
    tenantCapacity.setUsage(300);
    when(tenantCapacityPersistService.insertTenantCapacity(any())).thenReturn(true);
    service.initTenantCapacity("testTenant", 0, 0, 0, 0);
    Mockito.verify(tenantCapacityPersistService, times(1)).insertTenantCapacity(any());
}
Also used : TenantCapacity(com.alibaba.nacos.config.server.model.capacity.TenantCapacity) Test(org.junit.Test)

Example 8 with TenantCapacity

use of com.alibaba.nacos.config.server.model.capacity.TenantCapacity in project nacos by alibaba.

the class CapacityServiceTest method testGetCapacity.

@Test
public void testGetCapacity() {
    GroupCapacity groupCapacity = new GroupCapacity();
    groupCapacity.setId(1L);
    when(groupCapacityPersistService.getGroupCapacity(eq("testGroup"))).thenReturn(groupCapacity);
    TenantCapacity tenantCapacity = new TenantCapacity();
    tenantCapacity.setId(2L);
    when(tenantCapacityPersistService.getTenantCapacity(eq("testTenant"))).thenReturn(tenantCapacity);
    Capacity resCapacity1 = service.getCapacity("testGroup", null);
    Assert.assertEquals(1L, resCapacity1.getId().longValue());
    Capacity resCapacity2 = service.getCapacity(null, "testTenant");
    Assert.assertEquals(2L, resCapacity2.getId().longValue());
}
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 9 with TenantCapacity

use of com.alibaba.nacos.config.server.model.capacity.TenantCapacity in project nacos by alibaba.

the class CapacityServiceTest method testInitAllCapacity.

@Test
public void testInitAllCapacity() {
    List<String> groupList = new ArrayList<>();
    groupList.add("testGroup");
    when(persistService.getGroupIdList(eq(1), eq(500))).thenReturn(groupList);
    List<String> tenantList = new ArrayList<>();
    tenantList.add("testTenant");
    when(persistService.getTenantIdList(eq(1), eq(500))).thenReturn(tenantList);
    GroupCapacity groupCapacity = new GroupCapacity();
    groupCapacity.setGroup("testGroup");
    groupCapacity.setUsage(300);
    when(groupCapacityPersistService.insertGroupCapacity(any())).thenReturn(true);
    when(groupCapacityPersistService.getGroupCapacity(eq("testGroup"))).thenReturn(groupCapacity);
    when(groupCapacityPersistService.updateQuota(eq("testGroup"), eq(500))).thenReturn(true);
    TenantCapacity tenantCapacity = new TenantCapacity();
    tenantCapacity.setTenant("testTenant");
    tenantCapacity.setUsage(300);
    when(tenantCapacityPersistService.insertTenantCapacity(any())).thenReturn(true);
    when(tenantCapacityPersistService.getTenantCapacity(eq("testTenant"))).thenReturn(tenantCapacity);
    when(tenantCapacityPersistService.updateQuota(eq("testTenant"), eq(500))).thenReturn(true);
    service.initAllCapacity();
    Mockito.verify(groupCapacityPersistService, times(1)).insertGroupCapacity(any());
    Mockito.verify(groupCapacityPersistService, times(1)).getGroupCapacity(eq("testGroup"));
    Mockito.verify(groupCapacityPersistService, times(1)).updateQuota(eq("testGroup"), eq(500));
    Mockito.verify(tenantCapacityPersistService, times(1)).insertTenantCapacity(any());
    Mockito.verify(tenantCapacityPersistService, times(1)).getTenantCapacity(eq("testTenant"));
    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) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 10 with TenantCapacity

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