Search in sources :

Example 6 with GroupCapacity

use of com.alibaba.nacos.config.server.model.capacity.GroupCapacity 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)

Example 7 with GroupCapacity

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

the class GroupCapacityPersistServiceTest method testIncrementUsageWithDefaultQuotaLimit.

@Test
public void testIncrementUsageWithDefaultQuotaLimit() {
    GroupCapacity groupCapacity = new GroupCapacity();
    Timestamp timestamp = new Timestamp(System.currentTimeMillis());
    groupCapacity.setGmtModified(timestamp);
    groupCapacity.setGroup("test");
    groupCapacity.setQuota(1);
    when(jdbcTemplate.update(anyString(), eq(timestamp), eq("test"), eq(1))).thenReturn(1);
    Assert.assertTrue(service.incrementUsageWithDefaultQuotaLimit(groupCapacity));
}
Also used : GroupCapacity(com.alibaba.nacos.config.server.model.capacity.GroupCapacity) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 8 with GroupCapacity

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

the class GroupCapacityPersistServiceTest method testGetGroupCapacity.

@Test
public void testGetGroupCapacity() {
    List<GroupCapacity> list = new ArrayList<>();
    GroupCapacity groupCapacity = new GroupCapacity();
    groupCapacity.setGroup("test");
    list.add(groupCapacity);
    String groupId = "testId";
    when(jdbcTemplate.query(anyString(), eq(new Object[] { groupId }), any(RowMapper.class))).thenReturn(list);
    GroupCapacity ret = service.getGroupCapacity(groupId);
    Assert.assertEquals(groupCapacity.getGroup(), ret.getGroup());
}
Also used : GroupCapacity(com.alibaba.nacos.config.server.model.capacity.GroupCapacity) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.junit.Test)

Example 9 with GroupCapacity

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

the class GroupCapacityPersistServiceTest method testGetClusterUsage.

@Test
public void testGetClusterUsage() {
    List<GroupCapacity> list = new ArrayList<>();
    GroupCapacity groupCapacity = new GroupCapacity();
    groupCapacity.setId(1L);
    groupCapacity.setUsage(10);
    list.add(groupCapacity);
    String groupId = GroupCapacityPersistService.CLUSTER;
    when(jdbcTemplate.query(anyString(), eq(new Object[] { groupId }), any(RowMapper.class))).thenReturn(list);
    Assert.assertEquals(groupCapacity.getUsage().intValue(), service.getClusterUsage());
    when(jdbcTemplate.query(anyString(), eq(new Object[] { groupId }), any(RowMapper.class))).thenReturn(new ArrayList<>());
    when(jdbcTemplate.queryForObject(anyString(), eq(Integer.class))).thenReturn(20);
    Assert.assertEquals(20, service.getClusterUsage());
}
Also used : GroupCapacity(com.alibaba.nacos.config.server.model.capacity.GroupCapacity) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.junit.Test)

Example 10 with GroupCapacity

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

the class GroupCapacityPersistServiceTest method testInsertGroupCapacity.

@Test
public void testInsertGroupCapacity() {
    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);
    GroupCapacity capacity = new GroupCapacity();
    capacity.setGroup(GroupCapacityPersistService.CLUSTER);
    Assert.assertTrue(service.insertGroupCapacity(capacity));
    capacity.setGroup("test");
    Assert.assertTrue(service.insertGroupCapacity(capacity));
}
Also used : HashMap(java.util.HashMap) GroupCapacity(com.alibaba.nacos.config.server.model.capacity.GroupCapacity) ArgumentMatcher(org.mockito.ArgumentMatcher) PreparedStatementCreator(org.springframework.jdbc.core.PreparedStatementCreator) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HashMap(java.util.HashMap) Map(java.util.Map) 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