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));
}
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());
}
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());
}
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));
}
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));
}
Aggregations