Search in sources :

Example 6 with VacuumTaskResult

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

the class VacuumServiceImplTest method runTasks.

@Test
public void runTasks() throws Exception {
    final VacuumServiceImpl service = new VacuumServiceImpl();
    service.activate(mock(VacuumConfig.class, i -> i.getMethod().getDefaultValue()));
    service.addTask(new VacuumTask() {

        @Override
        public VacuumTaskResult execute(final VacuumTaskParams params) {
            return VacuumTaskResult.create().processed().build();
        }

        @Override
        public int order() {
            return 10;
        }

        @Override
        public String name() {
            return "ATask";
        }
    });
    service.addTask(new VacuumTask() {

        @Override
        public VacuumTaskResult execute(final VacuumTaskParams params) {
            return VacuumTaskResult.create().failed().build();
        }

        @Override
        public int order() {
            return 0;
        }

        @Override
        public String name() {
            return "AnotherTask";
        }
    });
    final VacuumResult result = NodeHelper.runAsAdmin(() -> service.vacuum(VacuumParameters.create().build()));
    assertEquals(2, result.getResults().size());
}
Also used : Test(org.junit.jupiter.api.Test) VacuumTaskResult(com.enonic.xp.vacuum.VacuumTaskResult) VacuumResult(com.enonic.xp.vacuum.VacuumResult) VacuumParameters(com.enonic.xp.vacuum.VacuumParameters) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NodeHelper(com.enonic.xp.repo.impl.node.NodeHelper) Mockito.mock(org.mockito.Mockito.mock) VacuumTaskResult(com.enonic.xp.vacuum.VacuumTaskResult) VacuumResult(com.enonic.xp.vacuum.VacuumResult) Test(org.junit.jupiter.api.Test)

Example 7 with VacuumTaskResult

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

the class AbstractBlobVacuumTaskTest method age_threshold.

public void age_threshold() throws Exception {
    this.blobStore.addRecord(segment, createBlobRecord('a'));
    final VacuumTask task = createTask();
    final VacuumTaskResult result = task.execute(VacuumTaskParams.create().build());
    assertEquals(0, result.getProcessed());
}
Also used : VacuumTaskResult(com.enonic.xp.vacuum.VacuumTaskResult) VacuumTask(com.enonic.xp.repo.impl.vacuum.VacuumTask)

Example 8 with VacuumTaskResult

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

the class SegmentVacuumTaskTest method test.

@Test
public void test() {
    final BlobRecord record = blobStore.addRecord(segment, ByteSource.wrap("hello".getBytes()));
    final BlobRecord record2 = blobStore.addRecord(segment2, ByteSource.wrap("hello".getBytes()));
    assertEquals(2, blobStore.listSegments().count());
    blobStore.removeRecord(segment, record2.getKey());
    assertEquals(2, blobStore.listSegments().count());
    final SegmentVacuumTask task = new SegmentVacuumTask();
    task.setBlobStore(blobStore);
    task.setRepositoryService(repositoryService);
    task.setNodeService(nodeService);
    final VacuumTaskParams vacuumParameters = VacuumTaskParams.create().build();
    final VacuumTaskResult result = task.execute(vacuumParameters);
    assertEquals(2, result.getProcessed());
    assertEquals(1, result.getDeleted());
    assertEquals(1, result.getInUse());
    assertEquals(1, blobStore.listSegments().count());
    assertEquals(segment, blobStore.listSegments().findFirst().get());
}
Also used : BlobRecord(com.enonic.xp.blob.BlobRecord) VacuumTaskResult(com.enonic.xp.vacuum.VacuumTaskResult) VacuumTaskParams(com.enonic.xp.repo.impl.vacuum.VacuumTaskParams) Test(org.junit.jupiter.api.Test)

Example 9 with VacuumTaskResult

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

the class AbstractBlobVacuumTaskTest method test_progress_report.

public void test_progress_report() throws Exception {
    this.blobStore.addRecord(segment, createBlobRecord('a'));
    this.blobStore.addRecord(segment, createBlobRecord('b'));
    this.blobStore.addRecord(segment, createBlobRecord('c'));
    final VacuumTask task = createTask();
    AtomicInteger blobReportCount = new AtomicInteger(0);
    final VacuumListener progressListener = new VacuumListener() {

        @Override
        public void vacuumBegin(final long taskCount) {
        }

        @Override
        public void taskBegin(final String task, final Long stepCount) {
        }

        @Override
        public void stepBegin(final String stepName, final Long toProcessCount) {
        }

        @Override
        public void processed(final long count) {
            blobReportCount.incrementAndGet();
        }
    };
    final VacuumTaskResult result = task.execute(VacuumTaskParams.create().ageThreshold(0).listener(progressListener).build());
    assertEquals(3, result.getProcessed());
    assertEquals(2, result.getDeleted());
    assertEquals(1, result.getInUse());
    assertEquals(3, blobReportCount.get());
}
Also used : VacuumTaskResult(com.enonic.xp.vacuum.VacuumTaskResult) VacuumListener(com.enonic.xp.vacuum.VacuumListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VacuumTask(com.enonic.xp.repo.impl.vacuum.VacuumTask)

Example 10 with VacuumTaskResult

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

the class AbstractBlobVacuumTaskTest method test_delete_unused.

public void test_delete_unused() throws Exception {
    this.blobStore.addRecord(segment, createBlobRecord('a'));
    this.blobStore.addRecord(segment, createBlobRecord('b'));
    this.blobStore.addRecord(segment, createBlobRecord('c'));
    final VacuumTask task = createTask();
    final VacuumTaskResult result = task.execute(VacuumTaskParams.create().ageThreshold(0).build());
    assertEquals(3, result.getProcessed());
    assertEquals(2, result.getDeleted());
    assertEquals(1, result.getInUse());
}
Also used : VacuumTaskResult(com.enonic.xp.vacuum.VacuumTaskResult) VacuumTask(com.enonic.xp.repo.impl.vacuum.VacuumTask)

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