Java Code Examples for com.github.pagehelper.Page#count()

The following examples show how to use com.github.pagehelper.Page#count() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrokerTokensRepositoryImplTest.java    From pulsar-manager with Apache License 2.0 6 votes vote down vote up
@Test
public void brokerTokenTest() {
    BrokerTokenEntity brokerTokenEntity = new BrokerTokenEntity();
    brokerTokenEntity.setRole("test");
    brokerTokenEntity.setDescription("This role for test");
    brokerTokenEntity.setToken("xxxxxxxxxxxxx");
    brokerTokensRepository.save(brokerTokenEntity);
    Page<BrokerTokenEntity> brokerTokenEntityPage = brokerTokensRepository.getBrokerTokensList(1, 1);
    brokerTokenEntityPage.count(true);
    brokerTokenEntityPage.getResult().forEach((result) -> {
        Assert.assertEquals(brokerTokenEntity.getRole(), result.getRole());
        Assert.assertEquals(brokerTokenEntity.getDescription(), result.getDescription());
    });

    brokerTokenEntity.setDescription("This role for update test");
    brokerTokenEntity.setToken("tokentestupdate");
    brokerTokensRepository.update(brokerTokenEntity);
    Optional<BrokerTokenEntity> optionalBrokerTokenEntity = brokerTokensRepository.findTokenByRole(brokerTokenEntity.getRole());
    BrokerTokenEntity updatedBrokerTokenEntity = optionalBrokerTokenEntity.get();
    Assert.assertEquals(brokerTokenEntity.getRole(), updatedBrokerTokenEntity.getRole());
    Assert.assertEquals(brokerTokenEntity.getDescription(), updatedBrokerTokenEntity.getDescription());

    brokerTokensRepository.remove(brokerTokenEntity.getRole());
    Assert.assertFalse(brokerTokensRepository.findTokenByRole(brokerTokenEntity.getRole()).isPresent());
}
 
Example 2
Source File: RolesRepositoryImplTest.java    From pulsar-manager with Apache License 2.0 6 votes vote down vote up
@Test
public void findMultiIdTest() {
    RoleInfoEntity roleInfoEntity = new RoleInfoEntity();
    initRole(roleInfoEntity);

    long roleId = rolesRepository.save(roleInfoEntity);
    List<Long> roleIdList = new ArrayList<>();
    roleIdList.add(roleId);
    roleIdList.add(roleInfoEntity.getRoleId());
    Page<RoleInfoEntity> roleInfoEntities = rolesRepository.findRolesMultiId(1, 2, roleIdList);
    roleInfoEntities.count(true);
    for (RoleInfoEntity infoEntity : roleInfoEntities.getResult()) {
        validateRole(infoEntity);
        rolesRepository.delete(infoEntity.getRoleName(), infoEntity.getRoleSource());
    }
}
 
Example 3
Source File: NamespacesRepositoryImplTest.java    From pulsar-manager with Apache License 2.0 6 votes vote down vote up
@Test
public void getNamespaceByTenantOrNamespaceTest() {
    NamespaceEntity namespacesEntity = new NamespaceEntity();
    initNamespaceEntity(namespacesEntity);
    namespacesRepository.save(namespacesEntity);
    String tenant = "test-namespace-public";
    Page<NamespaceEntity> namespacesEntityPageByTenant = namespacesRepository.
            findByTenantOrNamespace(1, 2, tenant);
    namespacesEntityPageByTenant.count(true);
    checkResult(namespacesEntityPageByTenant);
    String namespace = "test-namespace-default";
    Page<NamespaceEntity> namespacesEntityPageByNamespace = namespacesRepository.
            findByTenantOrNamespace(1, 2, namespace);
    namespacesEntityPageByNamespace.count(true);
    checkResult(namespacesEntityPageByNamespace);
    namespacesEntityPageByNamespace.getResult().forEach((result) -> {
        namespacesRepository.remove(result.getTenant(), result.getNamespace());
    });
    Page<NamespaceEntity> deleteNamespace = namespacesRepository.getNamespacesList(1, 2);
    deleteNamespace.count(true);
    checkDeleteResult(deleteNamespace);
}
 
Example 4
Source File: NamespacesServiceImpl.java    From pulsar-manager with Apache License 2.0 5 votes vote down vote up
public Map<String, Object> getNamespaceStats(
        String tenant,
        String namespace,
        String env) {
    Map<String, Object> namespaceStatsMap = Maps.newHashMap();
    Optional<TopicStatsEntity> topicStatsEntity = topicsStatsRepository.findMaxTime();
    if (topicStatsEntity.isPresent()) {
        double msgRateIn = 0;
        double msgThroughputIn = 0;
        double msgRateOut = 0;
        double msgThroughputOut = 0;
        TopicStatsEntity topicStats = topicStatsEntity.get();
        Page<TopicStatsEntity> topicCountPage = topicsStatsRepository.findByNamespace(
                1, 1, env, tenant, namespace, topicStats.getTime_stamp());
        topicCountPage.count(true);
        Page<TopicStatsEntity> topicStatsEntities = topicsStatsRepository.findByNamespace(
                1, (int) topicCountPage.getTotal(), env, tenant, namespace, topicStats.getTime_stamp());
        for (TopicStatsEntity statsEntity : topicStatsEntities.getResult()) {
            msgRateIn += statsEntity.getMsgRateIn();
            msgRateOut += statsEntity.getMsgRateOut();
            msgThroughputIn += statsEntity.getMsgThroughputIn();
            msgThroughputOut += statsEntity.getMsgThroughputOut();
        }
        namespaceStatsMap.put("inMsg", msgRateIn);
        namespaceStatsMap.put("outMsg", msgRateOut);
        namespaceStatsMap.put("msgThroughputIn", msgThroughputIn);
        namespaceStatsMap.put("msgThroughputOut", msgThroughputOut);
    }
    return namespaceStatsMap;
}
 
Example 5
Source File: UsersRepositoryImplTest.java    From pulsar-manager with Apache License 2.0 5 votes vote down vote up
@Test
public void getUsersListTest() {
    UserInfoEntity userInfoEntity = new UserInfoEntity();
    initUser(userInfoEntity);

    usersRepository.save(userInfoEntity);

    Page<UserInfoEntity> userInfoEntities = usersRepository.findUsersList(1, 10);
    userInfoEntities.count(true);
    userInfoEntities.getResult().forEach((user) -> {
        validateUser(user, true);
        usersRepository.delete(user.getName());
    });
}
 
Example 6
Source File: RolesRepositoryImplTest.java    From pulsar-manager with Apache License 2.0 5 votes vote down vote up
@Test
public void getRolesListTest() {
    RoleInfoEntity roleInfoEntity = new RoleInfoEntity();
    initRole(roleInfoEntity);

    rolesRepository.save(roleInfoEntity);

    Page<RoleInfoEntity> rolesList = rolesRepository.findRolesList(1, 10);
    rolesList.count(true);
    rolesList.getResult().forEach((role) -> {
        validateRole(role);
        rolesRepository.delete(role.getRoleName(), role.getRoleSource());
    });
}
 
Example 7
Source File: EnvironmentsRepositoryImplTest.java    From pulsar-manager with Apache License 2.0 5 votes vote down vote up
@Test
public void getEnvironmentsList() {
    EnvironmentEntity environmentEntity = new EnvironmentEntity();
    environmentEntity.setName("test-environment");
    environmentEntity.setBroker("http://localhost:8080");
    environmentsRepository.save(environmentEntity);
    Page<EnvironmentEntity> environmentEntityPage = environmentsRepository.getEnvironmentsList(1, 1);
    environmentEntityPage.count(true);
    environmentEntityPage.getResult().forEach((result) -> {
        Assert.assertEquals("test-environment", result.getName());
        Assert.assertEquals("http://localhost:8080", result.getBroker());
        environmentsRepository.remove(result.getName());
    });
}
 
Example 8
Source File: NamespacesRepositoryImplTest.java    From pulsar-manager with Apache License 2.0 5 votes vote down vote up
@Test
public void getNamespacesListTest() {
    NamespaceEntity namespacesEntity = new NamespaceEntity();
    initNamespaceEntity(namespacesEntity);
    namespacesRepository.save(namespacesEntity);
    Page<NamespaceEntity> namespacesEntityPage = namespacesRepository.getNamespacesList(1, 2);
    namespacesEntityPage.count(true);
    checkResult(namespacesEntityPage);
    namespacesEntityPage.getResult().forEach((result) -> {
        namespacesRepository.remove(result.getTenant(), result.getNamespace());
    });
    Page<NamespaceEntity> deleteNamespace = namespacesRepository.getNamespacesList(1, 2);
    deleteNamespace.count(true);
    checkDeleteResult(deleteNamespace);
}
 
Example 9
Source File: NamespacesRepositoryImplTest.java    From pulsar-manager with Apache License 2.0 5 votes vote down vote up
@Test
public void findByTenantTest() {
    NamespaceEntity namespacesEntity = new NamespaceEntity();
    initNamespaceEntity(namespacesEntity);
    namespacesRepository.save(namespacesEntity);
    Page<NamespaceEntity> namespacesEntityPage = namespacesRepository.findByTenant(
            1, 2, namespacesEntity.getTenant());
    namespacesEntityPage.count(true);
    checkResult(namespacesEntityPage);
    namespacesEntityPage.getResult().forEach((result) -> {
        namespacesRepository.remove(result.getTenant(), result.getNamespace());
    });
}
 
Example 10
Source File: NamespacesRepositoryImplTest.java    From pulsar-manager with Apache License 2.0 5 votes vote down vote up
@Test
public void findByMultiIdTest() {
    NamespaceEntity namespacesEntity = new NamespaceEntity();
    initNamespaceEntity(namespacesEntity);
    long namespaceId = namespacesRepository.save(namespacesEntity);
    List<Long> idList = new ArrayList<>();
    idList.add(namespaceId);
    Page<NamespaceEntity> namespacesEntityPage = namespacesRepository.findByMultiId(
            1, 2, idList);
    namespacesEntityPage.count(true);
    checkResult(namespacesEntityPage);
    namespacesEntityPage.getResult().forEach((result) -> {
        namespacesRepository.remove(result.getTenant(), result.getNamespace());
    });
}
 
Example 11
Source File: NamespacesRepositoryImplTest.java    From pulsar-manager with Apache License 2.0 5 votes vote down vote up
@Test
public void findByNamespaceTest() {
    NamespaceEntity namespacesEntity = new NamespaceEntity();
    initNamespaceEntity(namespacesEntity);
    namespacesRepository.save(namespacesEntity);
    Page<NamespaceEntity> namespacesEntityPage = namespacesRepository.findByNamespace(
            1, 2, namespacesEntity.getNamespace());
    namespacesEntityPage.count(true);
    checkResult(namespacesEntityPage);
    namespacesEntityPage.getResult().forEach((result) -> {
        namespacesRepository.remove(result.getTenant(), result.getNamespace());
    });
}
 
Example 12
Source File: BrokerStatsServiceImplTest.java    From pulsar-manager with Apache License 2.0 4 votes vote down vote up
@Test
public void findByMultiTenantOrMultiNamespace() throws Exception {
    String environment = "staging";
    String cluster = "standalone";
    String serviceUrl = "http://localhost:8080";

    Map<String, Object> brokersMap = new HashMap<>();
    List<Map<String, Object>> brokersArray = new ArrayList<>();
    Map<String, Object> brokerEntity = Maps.newHashMap();
    brokerEntity.put("broker", "localhost:8080");
    brokersArray.add(brokerEntity);
    brokersMap.put("data", brokersArray);
    Mockito.when(brokersService.getBrokersList(0,0, cluster, serviceUrl))
            .thenReturn(brokersMap);
    Mockito.when(pulsarAdminService.brokerStats(serviceUrl)).thenReturn(stats);
    JsonObject data = new Gson().fromJson(testData, JsonObject.class);
    Mockito.when(stats.getTopics())
            .thenReturn(data);

    brokerStatsService.collectStatsToDB(
            System.currentTimeMillis() / 1000,
            environment,
            cluster,
            serviceUrl
    );
    Optional<TopicStatsEntity> topicStatsEntity = topicsStatsRepository.findMaxTime();
    TopicStatsEntity topicStatsEntity1 = topicStatsEntity.get();
    ArrayList<String> tenantList = new ArrayList<>();
    tenantList.add(topicStatsEntity1.getTenant());
    Page<TopicStatsEntity> tenantCountPage = brokerStatsService.findByMultiTenant(
            1, 1, environment, tenantList, topicStatsEntity1.getTimestamp());
    tenantCountPage.count(true);
    Page<TopicStatsEntity> tenantAllCountPage = brokerStatsService.findByMultiTenant(
            1, (int)tenantCountPage.getTotal(), environment, tenantList, topicStatsEntity1.getTimestamp());


    tenantAllCountPage.getResult().forEach((result) -> {
        Assert.assertEquals(0.0, result.getAverageMsgSize(), 1);
        Assert.assertEquals(0.0, result.getMsgRateIn(), 1);
        Assert.assertEquals(0.0, result.getMsgRateOut(), 1);
        Assert.assertEquals(0.0, result.getMsgThroughputIn(), 1);
        Assert.assertEquals(0.0, result.getMsgThroughputOut(), 1);
        Assert.assertEquals(0, result.getStorageSize(), 0);
    });

    ArrayList<String> namespaceList = new ArrayList<>();
    namespaceList.add(topicStatsEntity1.getNamespace());
    Page<TopicStatsEntity> namespaceCountPage = brokerStatsService.findByMultiNamespace(
            1, 1, environment, topicStatsEntity1.getTenant(),
            namespaceList, topicStatsEntity1.getTimestamp());
    namespaceCountPage.count(true);
    Page<TopicStatsEntity> namespaceAllCountPage = brokerStatsService.findByMultiNamespace(
            1, (int)namespaceCountPage.getTotal(), environment, topicStatsEntity1.getTenant(),
            namespaceList, topicStatsEntity1.getTimestamp());


    namespaceAllCountPage.getResult().forEach((result) -> {
        Assert.assertEquals(0.0, result.getAverageMsgSize(), 1);
        Assert.assertEquals(0.0, result.getMsgRateIn(), 1);
        Assert.assertEquals(0.0, result.getMsgRateOut(), 1);
        Assert.assertEquals(0.0, result.getMsgThroughputIn(), 1);
        Assert.assertEquals(0.0, result.getMsgThroughputOut(), 1);
        Assert.assertEquals(0, result.getStorageSize(), 0);
    });

    long unixTime = System.currentTimeMillis() / 1000L;
    brokerStatsService.clearStats(unixTime, 0);
}