Search in sources :

Example 1 with VacuumTaskResult

use of com.enonic.xp.vacuum.VacuumTaskResult in project xp by enonic.

the class VersionTableVacuumTaskTest method delete_node_deletes_versions.

@Test
void delete_node_deletes_versions() {
    final int updates = 10_000;
    // to make sure nodes fetched in batches
    final int versionsBatchSize = updates / 2;
    final int expectedVersionCount = updates + 1;
    final Node node1 = createNode(NodePath.ROOT, "node1");
    updateNode(node1.id(), updates);
    doDeleteNode(node1.id());
    assertVersions(node1.id(), expectedVersionCount);
    final VacuumTaskResult result = NodeHelper.runAsAdmin(() -> this.task.execute(VacuumTaskParams.create().ageThreshold(NEGATIVE_AGE_THRESHOLD_MILLIS).versionsBatchSize(versionsBatchSize).build()));
    refresh();
    assertEquals(updates + 12, result.getProcessed());
    // Old version of CMS repository entry is also delete. Remove +1 when config to specify repository is implemented
    assertEquals(expectedVersionCount + 1, result.getDeleted());
    assertVersions(node1.id(), 0);
}
Also used : VacuumTaskResult(com.enonic.xp.vacuum.VacuumTaskResult) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 2 with VacuumTaskResult

use of com.enonic.xp.vacuum.VacuumTaskResult in project xp by enonic.

the class VersionTableVacuumTaskTest method version_not_deleted_in_all_branches.

@Test
void version_not_deleted_in_all_branches() {
    final Node node1 = createNode(NodePath.ROOT, "node1");
    pushNodes(NodeIds.from(node1.id()), WS_OTHER);
    refresh();
    this.nodeService.deleteById(node1.id());
    refresh();
    assertVersions(node1.id(), 1);
    final VacuumTaskResult result = NodeHelper.runAsAdmin(() -> this.task.execute(VacuumTaskParams.create().ageThreshold(NEGATIVE_AGE_THRESHOLD_MILLIS).build()));
    refresh();
    assertEquals(12, result.getProcessed());
    // Old version of CMS repository entry is also delete. Set to 0 when config to specify repository is implemented
    assertEquals(1, result.getDeleted());
    assertVersions(node1.id(), 1);
}
Also used : VacuumTaskResult(com.enonic.xp.vacuum.VacuumTaskResult) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 3 with VacuumTaskResult

use of com.enonic.xp.vacuum.VacuumTaskResult in project xp by enonic.

the class VersionTableVacuumTaskTest method version_deleted_in_all_branches.

@Test
void version_deleted_in_all_branches() {
    final Node node1 = createNode(NodePath.ROOT, "node1");
    pushNodes(NodeIds.from(node1.id()), WS_OTHER);
    refresh();
    this.nodeService.deleteById(node1.id());
    ctxOther().runWith(() -> this.nodeService.deleteById(node1.id()));
    refresh();
    assertVersions(node1.id(), 1);
    final VacuumTaskResult result = NodeHelper.runAsAdmin(() -> this.task.execute(VacuumTaskParams.create().ageThreshold(NEGATIVE_AGE_THRESHOLD_MILLIS).build()));
    refresh();
    assertEquals(12, result.getProcessed());
    // Old version of CMS repository entry is also delete. Set to 1 when config to specify repository is implemented
    assertEquals(2, result.getDeleted());
    assertVersions(node1.id(), 0);
}
Also used : VacuumTaskResult(com.enonic.xp.vacuum.VacuumTaskResult) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 4 with VacuumTaskResult

use of com.enonic.xp.vacuum.VacuumTaskResult in project xp by enonic.

the class VersionTableVacuumTaskTest method age_threshold.

@Test
void age_threshold() {
    final Node node1 = createNode(NodePath.ROOT, "node1");
    updateNode(node1.id(), 2);
    doDeleteNode(node1.id());
    refresh();
    assertVersions(node1.id(), 3);
    final VacuumTaskResult result = NodeHelper.runAsAdmin(() -> this.task.execute(VacuumTaskParams.create().ageThreshold(Duration.of(1, ChronoUnit.HOURS).toMillis()).build()));
    refresh();
    assertEquals(0, result.getProcessed());
    assertEquals(0, result.getDeleted());
    assertVersions(node1.id(), 3);
}
Also used : VacuumTaskResult(com.enonic.xp.vacuum.VacuumTaskResult) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 5 with VacuumTaskResult

use of com.enonic.xp.vacuum.VacuumTaskResult in project xp by enonic.

the class VacuumServiceImpl method doVacuum.

private VacuumResult doVacuum(final VacuumParameters params) {
    // Retrieves the tasks to execute
    VacuumTasks tasks = getTasks(params);
    LOG.info("Starting vacuum. Running " + tasks.size() + " tasks...");
    if (params.getVacuumListener() != null) {
        params.getVacuumListener().vacuumBegin(tasks.size());
    }
    final VacuumResult.Builder taskResults = VacuumResult.create();
    for (final VacuumTask task : tasks) {
        LOG.info("Running vacuum task [" + task.name() + "]...");
        final VacuumTaskParams taskParams = VacuumTaskParams.create().listener(params.getVacuumListener()).ageThreshold(getAgeThresholdMs(params)).versionsBatchSize(config.versionsBatchSize()).build();
        final VacuumTaskResult taskResult = task.execute(taskParams);
        LOG.info(task.name() + " : " + taskResult.toString());
        taskResults.add(taskResult);
        LOG.info("Vacuum task [" + task.name() + "] done");
    }
    LOG.info("Vacuum done");
    return taskResults.build();
}
Also used : VacuumTaskResult(com.enonic.xp.vacuum.VacuumTaskResult) VacuumResult(com.enonic.xp.vacuum.VacuumResult)

Aggregations

VacuumTaskResult (com.enonic.xp.vacuum.VacuumTaskResult)10 Test (org.junit.jupiter.api.Test)6 Node (com.enonic.xp.node.Node)4 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)4 VacuumTask (com.enonic.xp.repo.impl.vacuum.VacuumTask)3 VacuumResult (com.enonic.xp.vacuum.VacuumResult)2 BlobRecord (com.enonic.xp.blob.BlobRecord)1 NodeHelper (com.enonic.xp.repo.impl.node.NodeHelper)1 VacuumTaskParams (com.enonic.xp.repo.impl.vacuum.VacuumTaskParams)1 VacuumListener (com.enonic.xp.vacuum.VacuumListener)1 VacuumParameters (com.enonic.xp.vacuum.VacuumParameters)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Mockito.mock (org.mockito.Mockito.mock)1