Search in sources :

Example 1 with RepositoryStatistics

use of org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics in project archiva by apache.

the class RepositoryStatisticsManagerTest method testGetStatsRangeLowerAndUpperOutside.

@Test
public void testGetStatsRangeLowerAndUpperOutside() throws Exception {
    walkRepository(3);
    Date current = new Date();
    addStats(new Date(current.getTime() - 12345), new Date(current.getTime() - 6000));
    addStats(new Date(current.getTime() - 3000), new Date(current.getTime() - 2000));
    addStats(new Date(current.getTime() - 1000), current);
    ArrayList<String> keys = new ArrayList<>(statsCreated.keySet());
    expect(metadataRepository.getMetadataFacets(TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID)).andReturn(keys);
    String key = keys.get(0);
    expect(metadataRepository.getMetadataFacet(TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key)).andReturn(statsCreated.get(key));
    key = keys.get(1);
    expect(metadataRepository.getMetadataFacet(TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key)).andReturn(statsCreated.get(key));
    key = keys.get(2);
    expect(metadataRepository.getMetadataFacet(TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key)).andReturn(statsCreated.get(key));
    metadataRepositoryControl.replay();
    for (RepositoryStatistics stats : statsCreated.values()) {
        repositoryStatisticsManager.addStatisticsAfterScan(metadataRepository, TEST_REPO_ID, stats.getScanStartTime(), stats.getScanEndTime(), 56345, 45);
    }
    List<RepositoryStatistics> list = repositoryStatisticsManager.getStatisticsInRange(metadataRepository, TEST_REPO_ID, new Date(current.getTime() - 20000), current);
    assertEquals(3, list.size());
    assertEquals(new Date(current.getTime() - 12345), list.get(2).getScanStartTime());
    assertEquals(new Date(current.getTime() - 3000), list.get(1).getScanStartTime());
    assertEquals(new Date(current.getTime() - 1000), list.get(0).getScanStartTime());
    metadataRepositoryControl.verify();
}
Also used : ArrayList(java.util.ArrayList) RepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics) DefaultRepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.DefaultRepositoryStatistics) Date(java.util.Date) Test(org.junit.Test)

Example 2 with RepositoryStatistics

use of org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics in project archiva by apache.

the class RepositoryStatisticsManagerTest method testGetStatsRangeInside.

@Test
public void testGetStatsRangeInside() throws Exception {
    walkRepository(3);
    Date current = new Date();
    addStats(new Date(current.getTime() - 12345), new Date(current.getTime() - 6000));
    addStats(new Date(current.getTime() - 3000), new Date(current.getTime() - 2000));
    addStats(new Date(current.getTime() - 1000), current);
    ArrayList<String> keys = new ArrayList<>(statsCreated.keySet());
    expect(metadataRepository.getMetadataFacets(TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID)).andReturn(keys);
    // only match the middle one
    String key = keys.get(1);
    expect(metadataRepository.getMetadataFacet(TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key)).andReturn(statsCreated.get(key));
    metadataRepositoryControl.replay();
    for (RepositoryStatistics stats : statsCreated.values()) {
        repositoryStatisticsManager.addStatisticsAfterScan(metadataRepository, TEST_REPO_ID, stats.getScanStartTime(), stats.getScanEndTime(), 56345, 45);
    }
    List<RepositoryStatistics> list = repositoryStatisticsManager.getStatisticsInRange(metadataRepository, TEST_REPO_ID, new Date(current.getTime() - 4000), new Date(current.getTime() - 2000));
    assertEquals(1, list.size());
    assertEquals(new Date(current.getTime() - 3000), list.get(0).getScanStartTime());
    metadataRepositoryControl.verify();
}
Also used : ArrayList(java.util.ArrayList) RepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics) DefaultRepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.DefaultRepositoryStatistics) Date(java.util.Date) Test(org.junit.Test)

Example 3 with RepositoryStatistics

use of org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics in project archiva by apache.

the class RepositoryStatisticsManagerTest method testAddNewStats.

@Test
public void testAddNewStats() throws Exception {
    Date current = new Date();
    Date startTime = new Date(current.getTime() - 12345);
    RepositoryStatistics stats = createTestStats(startTime, current);
    walkRepository(1);
    metadataRepository.addMetadataFacet(TEST_REPO_ID, stats);
    expect(metadataRepository.getMetadataFacets(TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID)).andReturn(Arrays.asList(stats.getName()));
    expect(metadataRepository.getMetadataFacet(TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, stats.getName())).andReturn(stats);
    metadataRepositoryControl.replay();
    repositoryStatisticsManager.addStatisticsAfterScan(metadataRepository, TEST_REPO_ID, startTime, current, 56345, 45);
    stats = repositoryStatisticsManager.getLastStatistics(metadataRepository, TEST_REPO_ID);
    assertNotNull(stats);
    assertEquals(246900, stats.getTotalArtifactFileSize());
    assertEquals(45, stats.getNewFileCount());
    assertEquals(20, stats.getTotalArtifactCount());
    assertEquals(5, stats.getTotalProjectCount());
    assertEquals(4, stats.getTotalGroupCount());
    assertEquals(56345, stats.getTotalFileCount());
    assertEquals(current.getTime() - 12345, stats.getScanStartTime().getTime());
    assertEquals(current, stats.getScanEndTime());
    metadataRepositoryControl.verify();
}
Also used : RepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics) DefaultRepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.DefaultRepositoryStatistics) Date(java.util.Date) Test(org.junit.Test)

Example 4 with RepositoryStatistics

use of org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics in project archiva by apache.

the class RepositoryStatisticsManagerTest method testGetStatsRangeLowerOutside.

@Test
public void testGetStatsRangeLowerOutside() throws Exception {
    walkRepository(3);
    Date current = new Date();
    addStats(new Date(current.getTime() - 12345), new Date(current.getTime() - 6000));
    addStats(new Date(current.getTime() - 3000), new Date(current.getTime() - 2000));
    addStats(new Date(current.getTime() - 1000), current);
    List<String> keys = new ArrayList<>(statsCreated.keySet());
    expect(metadataRepository.getMetadataFacets(TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID)).andReturn(keys);
    String key = keys.get(0);
    expect(metadataRepository.getMetadataFacet(TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key)).andReturn(statsCreated.get(key));
    key = keys.get(1);
    expect(metadataRepository.getMetadataFacet(TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key)).andReturn(statsCreated.get(key));
    metadataRepositoryControl.replay();
    for (RepositoryStatistics stats : statsCreated.values()) {
        repositoryStatisticsManager.addStatisticsAfterScan(metadataRepository, TEST_REPO_ID, stats.getScanStartTime(), stats.getScanEndTime(), 56345, 45);
    }
    List<RepositoryStatistics> list = repositoryStatisticsManager.getStatisticsInRange(metadataRepository, TEST_REPO_ID, new Date(current.getTime() - 20000), new Date(current.getTime() - 2000));
    assertEquals(2, list.size());
    assertEquals(new Date(current.getTime() - 12345), list.get(1).getScanStartTime());
    assertEquals(new Date(current.getTime() - 3000), list.get(0).getScanStartTime());
    metadataRepositoryControl.verify();
}
Also used : ArrayList(java.util.ArrayList) RepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics) DefaultRepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.DefaultRepositoryStatistics) Date(java.util.Date) Test(org.junit.Test)

Example 5 with RepositoryStatistics

use of org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics in project archiva by apache.

the class RepositoryStatisticsManagerTest method testGetStatsRangeUpperOutside.

@Test
public void testGetStatsRangeUpperOutside() throws Exception {
    walkRepository(3);
    Date current = new Date();
    addStats(new Date(current.getTime() - 12345), new Date(current.getTime() - 6000));
    addStats(new Date(current.getTime() - 3000), new Date(current.getTime() - 2000));
    addStats(new Date(current.getTime() - 1000), current);
    List<String> keys = new ArrayList<>(statsCreated.keySet());
    expect(metadataRepository.getMetadataFacets(TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID)).andReturn(keys);
    String key = keys.get(1);
    expect(metadataRepository.getMetadataFacet(TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key)).andReturn(statsCreated.get(key));
    key = keys.get(2);
    expect(metadataRepository.getMetadataFacet(TEST_REPO_ID, DefaultRepositoryStatistics.FACET_ID, key)).andReturn(statsCreated.get(key));
    metadataRepositoryControl.replay();
    for (RepositoryStatistics stats : statsCreated.values()) {
        repositoryStatisticsManager.addStatisticsAfterScan(metadataRepository, TEST_REPO_ID, stats.getScanStartTime(), stats.getScanEndTime(), 56345, 45);
    }
    List<RepositoryStatistics> list = repositoryStatisticsManager.getStatisticsInRange(metadataRepository, TEST_REPO_ID, new Date(current.getTime() - 4000), current);
    assertEquals(2, list.size());
    assertEquals(new Date(current.getTime() - 3000), list.get(1).getScanStartTime());
    assertEquals(new Date(current.getTime() - 1000), list.get(0).getScanStartTime());
    metadataRepositoryControl.verify();
}
Also used : ArrayList(java.util.ArrayList) RepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics) DefaultRepositoryStatistics(org.apache.archiva.metadata.repository.stats.model.DefaultRepositoryStatistics) Date(java.util.Date) Test(org.junit.Test)

Aggregations

RepositoryStatistics (org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics)18 DefaultRepositoryStatistics (org.apache.archiva.metadata.repository.stats.model.DefaultRepositoryStatistics)14 Test (org.junit.Test)11 Date (java.util.Date)9 ArrayList (java.util.ArrayList)7 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)4 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)4 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)4 Path (java.nio.file.Path)3 ArtifactReference (org.apache.archiva.model.ArtifactReference)3 RepositoryTask (org.apache.archiva.scheduler.repository.model.RepositoryTask)3 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Locale (java.util.Locale)1 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 TaskExecutionException (org.apache.archiva.redback.components.taskqueue.execution.TaskExecutionException)1 ManagedRepository (org.apache.archiva.repository.ManagedRepository)1 RepositoryScanStatistics (org.apache.archiva.repository.scanner.RepositoryScanStatistics)1 RepositoryScannerException (org.apache.archiva.repository.scanner.RepositoryScannerException)1 ArchivaRepositoryStatistics (org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics)1