Fix the creation of the Usage Report (#1101)

* Use the forEachTenant method to generate the report for each tenant.
* add a test to verify the functionality of getSystemUsageStatisticsWithTenants

Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io>
This commit is contained in:
Michael Herdt
2021-03-18 11:25:21 +01:00
committed by GitHub
parent 81defa10a6
commit 10e69de838
2 changed files with 11 additions and 6 deletions

View File

@@ -183,12 +183,7 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
}
private void usageStatsPerTenant(final SystemUsageReportWithTenants report) {
final List<String> tenants = findTenants(PageRequest.of(0, MAX_TENANTS_QUERY)).getContent();
tenants.forEach(tenant -> tenantAware.runAsTenant(tenant, () -> {
report.addTenantData(systemStatsManagement.getStatsOfTenant());
return null;
}));
forEachTenant(tenant -> report.addTenantData(systemStatsManagement.getStatsOfTenant()));
}
@Override

View File

@@ -41,6 +41,16 @@ public class SystemManagementTest extends AbstractJpaIntegrationTest {
assertThat(systemManagement.findTenants(PAGE).getContent()).hasSize(3);
}
@Test
@Description("Ensures that getSystemUsageStatisticsWithTenants returns the usage of all tenants and not only the first 1000 (max page size).")
public void systemUsageReportCollectsStatisticsOfManyTenants() throws Exception {
// Prepare tenants
createTestTenantsForSystemStatistics(1050, 0, 0, 0);
final List<TenantUsage> tenants = systemManagement.getSystemUsageStatisticsWithTenants().getTenants();
assertThat(tenants).hasSize(1051); // +1 from the setup
}
@Test
@Description("Checks that the system report calculates correctly the artifact size of all tenants in the system. It ignores deleted software modules with their artifacts.")
public void systemUsageReportCollectsArtifactsOfAllTenants() throws Exception {