Search in sources :

Example 11 with TenantCapacity

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

the class TenantCapacityPersistServiceTest method testIncrementUsage.

@Test
public void testIncrementUsage() {
    TenantCapacity tenantCapacity = new TenantCapacity();
    Timestamp timestamp = new Timestamp(System.currentTimeMillis());
    tenantCapacity.setGmtModified(timestamp);
    tenantCapacity.setTenant("test3");
    when(jdbcTemplate.update(anyString(), eq(timestamp), eq("test3"))).thenReturn(1);
    Assert.assertTrue(service.incrementUsage(tenantCapacity));
}
Also used : TenantCapacity(com.alibaba.nacos.config.server.model.capacity.TenantCapacity) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 12 with TenantCapacity

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

the class TenantCapacityPersistServiceTest method testInsertTenantCapacity.

@Test
public void testInsertTenantCapacity() {
    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);
    TenantCapacity capacity = new TenantCapacity();
    capacity.setTenant("test");
    Assert.assertTrue(service.insertTenantCapacity(capacity));
}
Also used : TenantCapacity(com.alibaba.nacos.config.server.model.capacity.TenantCapacity) HashMap(java.util.HashMap) 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)

Example 13 with TenantCapacity

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

the class TenantCapacityPersistServiceTest method testGetCapacityList4CorrectUsage.

@Test
public void testGetCapacityList4CorrectUsage() {
    List<TenantCapacity> list = new ArrayList<>();
    TenantCapacity tenantCapacity = new TenantCapacity();
    tenantCapacity.setTenant("test");
    list.add(tenantCapacity);
    long lastId = 1;
    int pageSize = 1;
    when(jdbcTemplate.query(anyString(), eq(new Object[] { lastId, pageSize }), any(RowMapper.class))).thenReturn(list);
    List<TenantCapacity> ret = service.getCapacityList4CorrectUsage(lastId, pageSize);
    Assert.assertEquals(list.size(), ret.size());
    Assert.assertEquals(tenantCapacity.getTenant(), ret.get(0).getTenant());
}
Also used : TenantCapacity(com.alibaba.nacos.config.server.model.capacity.TenantCapacity) ArrayList(java.util.ArrayList) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.junit.Test)

Example 14 with TenantCapacity

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

the class TenantCapacityPersistServiceTest method testDecrementUsage.

@Test
public void testDecrementUsage() {
    TenantCapacity tenantCapacity = new TenantCapacity();
    Timestamp timestamp = new Timestamp(System.currentTimeMillis());
    tenantCapacity.setGmtModified(timestamp);
    tenantCapacity.setTenant("test4");
    when(jdbcTemplate.update(anyString(), eq(timestamp), eq("test4"))).thenReturn(1);
    Assert.assertTrue(service.decrementUsage(tenantCapacity));
}
Also used : TenantCapacity(com.alibaba.nacos.config.server.model.capacity.TenantCapacity) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 15 with TenantCapacity

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

the class CapacityServiceTest method testCorrectUsage.

@Test
public void testCorrectUsage() {
    List<GroupCapacity> groupCapacityList = new ArrayList<>();
    GroupCapacity groupCapacity = new GroupCapacity();
    groupCapacity.setId(1L);
    groupCapacity.setGroup("testGroup");
    groupCapacityList.add(groupCapacity);
    when(groupCapacityPersistService.getCapacityList4CorrectUsage(0L, 100)).thenReturn(groupCapacityList);
    when(groupCapacityPersistService.getCapacityList4CorrectUsage(1L, 100)).thenReturn(new ArrayList<>());
    when(groupCapacityPersistService.correctUsage(eq("testGroup"), any())).thenReturn(true);
    List<TenantCapacity> tenantCapacityList = new ArrayList<>();
    TenantCapacity tenantCapacity = new TenantCapacity();
    tenantCapacity.setId(1L);
    tenantCapacity.setTenant("testTenant");
    tenantCapacityList.add(tenantCapacity);
    when(tenantCapacityPersistService.getCapacityList4CorrectUsage(0L, 100)).thenReturn(tenantCapacityList);
    when(tenantCapacityPersistService.getCapacityList4CorrectUsage(1L, 100)).thenReturn(new ArrayList<>());
    when(tenantCapacityPersistService.correctUsage(eq("testTenant"), any())).thenReturn(true);
    service.correctUsage();
    Mockito.verify(groupCapacityPersistService, times(1)).getCapacityList4CorrectUsage(0L, 100);
    Mockito.verify(groupCapacityPersistService, times(1)).getCapacityList4CorrectUsage(1L, 100);
    Mockito.verify(groupCapacityPersistService, times(1)).correctUsage(eq("testGroup"), any());
    Mockito.verify(tenantCapacityPersistService, times(1)).getCapacityList4CorrectUsage(0L, 100);
    Mockito.verify(tenantCapacityPersistService, times(1)).getCapacityList4CorrectUsage(1L, 100);
    Mockito.verify(tenantCapacityPersistService, times(1)).correctUsage(eq("testTenant"), any());
}
Also used : TenantCapacity(com.alibaba.nacos.config.server.model.capacity.TenantCapacity) GroupCapacity(com.alibaba.nacos.config.server.model.capacity.GroupCapacity) ArrayList(java.util.ArrayList) 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