diff --git a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/VacuumServiceImpl.java b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/VacuumServiceImpl.java index eb9ff01a177..7fbb21716df 100644 --- a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/VacuumServiceImpl.java +++ b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/VacuumServiceImpl.java @@ -1,6 +1,7 @@ package com.enonic.xp.repo.impl.vacuum; import java.time.Duration; +import java.time.Instant; import java.util.Set; import org.osgi.service.component.annotations.Activate; @@ -11,7 +12,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.enonic.xp.node.DeleteSnapshotParams; import com.enonic.xp.repo.impl.SecurityHelper; +import com.enonic.xp.snapshot.SnapshotService; import com.enonic.xp.vacuum.VacuumParameters; import com.enonic.xp.vacuum.VacuumResult; import com.enonic.xp.vacuum.VacuumService; @@ -25,8 +28,16 @@ public class VacuumServiceImpl private final VacuumTasks tasks = new VacuumTasks(); + private final SnapshotService snapshotService; + private VacuumConfig config; + @Activate + public VacuumServiceImpl( @Reference final SnapshotService snapshotService ) + { + this.snapshotService = snapshotService; + } + @Activate public void activate( final VacuumConfig config ) { @@ -46,6 +57,8 @@ public VacuumResult vacuum( final VacuumParameters params ) private VacuumResult doVacuum( final VacuumParameters params ) { + final Instant vacuumStartedAt = Instant.now(); + //Retrieves the tasks to execute VacuumTasks tasks = getTasks( params ); LOG.info( "Starting vacuum. Running " + tasks.size() + " tasks..." ); @@ -61,22 +74,41 @@ private VacuumResult doVacuum( final VacuumParameters params ) { LOG.info( "Running vacuum task [" + task.name() + "]..." ); - final VacuumTaskParams taskParams = VacuumTaskParams.create(). - listener( params.getVacuumListener() ). - ageThreshold( ageThreshold ). - versionsBatchSize( config.versionsBatchSize() ). - build(); + final VacuumTaskParams taskParams = VacuumTaskParams.create() + .listener( params.getVacuumListener() ) + .ageThreshold( ageThreshold ) + .versionsBatchSize( config.versionsBatchSize() ) + .vacuumStartedAt( vacuumStartedAt ) + .build(); final VacuumTaskResult taskResult = task.execute( taskParams ); LOG.info( task.name() + " : " + taskResult.toString() ); taskResults.add( taskResult ); LOG.info( "Vacuum task [" + task.name() + "] done" ); } + + deleteSnapshotsIfNecessary( vacuumStartedAt ); + LOG.info( "Vacuum done" ); return taskResults.build(); } + private void deleteSnapshotsIfNecessary( final Instant startedAt ) + { + if ( tasks.hasTaskByName( "BinaryBlobVacuumTask" ) || tasks.hasTaskByName( "NodeBlobVacuumTask" ) ) + { + try + { + snapshotService.delete( DeleteSnapshotParams.create().before( startedAt ).build() ); + } + catch ( Exception e ) + { + LOG.error( "Failed to delete snapshots", e ); + } + } + } + private VacuumTasks getTasks( final VacuumParameters params ) { final Set taskNames = params.getTaskNames(); diff --git a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/VacuumTaskParams.java b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/VacuumTaskParams.java index 90f3f99f788..f0e00fa5e0a 100644 --- a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/VacuumTaskParams.java +++ b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/VacuumTaskParams.java @@ -1,6 +1,8 @@ package com.enonic.xp.repo.impl.vacuum; import java.time.Duration; +import java.time.Instant; +import java.util.Objects; import com.enonic.xp.vacuum.VacuumListener; @@ -14,11 +16,14 @@ public final class VacuumTaskParams private final int versionsBatchSize; + private final Instant vacuumStartedAt; + private VacuumTaskParams( final Builder builder ) { ageThreshold = builder.ageThreshold; listener = builder.listener; versionsBatchSize = builder.versionsBatchSize; + vacuumStartedAt = Objects.requireNonNull( builder.vacuumStartedAt ); } public long getAgeThreshold() @@ -31,7 +36,8 @@ public VacuumListener getListener() return listener; } - public boolean hasListener() { + public boolean hasListener() + { return listener != null; } @@ -40,6 +46,11 @@ public int getVersionsBatchSize() return versionsBatchSize; } + public Instant getVacuumStartedAt() + { + return vacuumStartedAt; + } + public static Builder create() { return new Builder(); @@ -53,6 +64,8 @@ public static final class Builder private int versionsBatchSize = DEFAULT_VERSIONS_BATCH_SIZE; + private Instant vacuumStartedAt; + private Builder() { } @@ -75,6 +88,12 @@ public Builder versionsBatchSize( final int versionsBatchSize ) return this; } + public Builder vacuumStartedAt( final Instant vacuumStartedAt ) + { + this.vacuumStartedAt = vacuumStartedAt; + return this; + } + public VacuumTaskParams build() { return new VacuumTaskParams( this ); diff --git a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/VacuumTasks.java b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/VacuumTasks.java index 99c62620309..ffd4b10586d 100644 --- a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/VacuumTasks.java +++ b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/VacuumTasks.java @@ -30,4 +30,9 @@ public boolean remove( final VacuumTask task ) { return this.tasks.remove( task ); } + + public boolean hasTaskByName( final String taskName ) + { + return this.tasks.stream().anyMatch( task -> task.name().equals( taskName ) ); + } } diff --git a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/blob/AbstractBlobVacuumCommand.java b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/blob/AbstractBlobVacuumCommand.java index 166797ed644..1be7683bbbf 100644 --- a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/blob/AbstractBlobVacuumCommand.java +++ b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/blob/AbstractBlobVacuumCommand.java @@ -98,7 +98,7 @@ private boolean shouldDelete( final Segment segment, final BlobRecord blobRecord private boolean isOldBlobRecord( final BlobRecord blobRecord ) { - return System.currentTimeMillis() - blobRecord.lastModified() >= params.getAgeThreshold(); + return params.getVacuumStartedAt().toEpochMilli() - blobRecord.lastModified() >= params.getAgeThreshold(); } private boolean isUsedByVersion( final Segment segment, final BlobKey blobKey ) diff --git a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/blob/BinaryBlobVacuumTask.java b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/blob/BinaryBlobVacuumTask.java index 5f6410ce864..68d20a2a224 100644 --- a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/blob/BinaryBlobVacuumTask.java +++ b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/blob/BinaryBlobVacuumTask.java @@ -1,5 +1,6 @@ package com.enonic.xp.repo.impl.vacuum.blob; +import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; @@ -17,9 +18,16 @@ public class BinaryBlobVacuumTask private static final String NAME = "BinaryBlobVacuumTask"; - private NodeService nodeService; + private final NodeService nodeService; - private BlobStore blobStore; + private final BlobStore blobStore; + + @Activate + public BinaryBlobVacuumTask( @Reference final NodeService nodeService, @Reference final BlobStore blobStore ) + { + this.nodeService = nodeService; + this.blobStore = blobStore; + } @Override public VacuumTaskResult execute( final VacuumTaskParams params ) @@ -28,14 +36,14 @@ public VacuumTaskResult execute( final VacuumTaskParams params ) { params.getListener().taskBegin( NAME, null ); } - return BinaryBlobVacuumCommand.create(). - blobStore( blobStore ). - nodeService( nodeService ). - params( params ). - build(). - execute(). - taskName( NAME ). - build(); + return BinaryBlobVacuumCommand.create() + .blobStore( blobStore ) + .nodeService( nodeService ) + .params( params ) + .build() + .execute() + .taskName( NAME ) + .build(); } @Override @@ -50,15 +58,4 @@ public String name() return NAME; } - @Reference - public void setBlobStore( final BlobStore blobStore ) - { - this.blobStore = blobStore; - } - - @Reference - public void setNodeService( final NodeService nodeService ) - { - this.nodeService = nodeService; - } } diff --git a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/blob/NodeBlobVacuumTask.java b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/blob/NodeBlobVacuumTask.java index 272eb9596cb..71e28b66804 100644 --- a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/blob/NodeBlobVacuumTask.java +++ b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/blob/NodeBlobVacuumTask.java @@ -1,5 +1,6 @@ package com.enonic.xp.repo.impl.vacuum.blob; +import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; @@ -17,24 +18,32 @@ public class NodeBlobVacuumTask private static final String NAME = "NodeBlobVacuumTask"; - private NodeService nodeService; + private final NodeService nodeService; - private BlobStore blobStore; + private final BlobStore blobStore; + + @Activate + public NodeBlobVacuumTask( @Reference final NodeService nodeService, @Reference final BlobStore blobStore ) + { + this.nodeService = nodeService; + this.blobStore = blobStore; + } @Override public VacuumTaskResult execute( final VacuumTaskParams params ) { - if (params.hasListener()) { + if ( params.hasListener() ) + { params.getListener().taskBegin( NAME, null ); } - return NodeBlobVacuumCommand.create(). - blobStore( blobStore ). - nodeService( nodeService ). - params( params ). - build(). - execute(). - taskName( NAME ). - build(); + return NodeBlobVacuumCommand.create() + .blobStore( blobStore ) + .nodeService( nodeService ) + .params( params ) + .build() + .execute() + .taskName( NAME ) + .build(); } @Override @@ -48,16 +57,4 @@ public String name() { return NAME; } - - @Reference - public void setBlobStore( final BlobStore blobStore ) - { - this.blobStore = blobStore; - } - - @Reference - public void setNodeService( final NodeService nodeService ) - { - this.nodeService = nodeService; - } } diff --git a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/segment/SegmentVacuumCommand.java b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/segment/SegmentVacuumCommand.java index f0412e20d97..d9e62723c78 100644 --- a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/segment/SegmentVacuumCommand.java +++ b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/segment/SegmentVacuumCommand.java @@ -10,7 +10,6 @@ import com.enonic.xp.blob.BlobStore; import com.enonic.xp.blob.Segment; -import com.enonic.xp.content.ContentConstants; import com.enonic.xp.context.Context; import com.enonic.xp.context.ContextAccessor; import com.enonic.xp.context.ContextBuilder; @@ -109,7 +108,7 @@ private boolean isRepositoryToKeep( final RepositoryId repositoryId ) .repositoryId( SystemConstants.SYSTEM_REPO_ID ) .branch( SystemConstants.BRANCH_SYSTEM ) .build(); - final Instant since = Instant.now().minusMillis( params.getAgeThreshold() ); + final Instant since = params.getVacuumStartedAt().minusMillis( params.getAgeThreshold() ); final NodeVersionQuery findRecentVersionsQuery = NodeVersionQuery.create() .nodeId( NodeId.from( repositoryId ) ) .addQueryFilter( RangeFilter.create() diff --git a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/snapshots/SnapshotsVacuumTask.java b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/snapshots/SnapshotsVacuumTask.java index 836ca06a92b..76a1488f75a 100644 --- a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/snapshots/SnapshotsVacuumTask.java +++ b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/snapshots/SnapshotsVacuumTask.java @@ -1,7 +1,5 @@ package com.enonic.xp.repo.impl.vacuum.snapshots; -import java.time.Instant; - import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; @@ -40,7 +38,7 @@ public VacuumTaskResult execute( final VacuumTaskParams params ) final VacuumTaskResult.Builder builder = VacuumTaskResult.create().taskName( NAME ); final DeleteSnapshotsResult deleteSnapshotsResult = - snapshotService.delete( DeleteSnapshotParams.create().before( Instant.now().minusMillis( params.getAgeThreshold() ) ).build() ); + snapshotService.delete( DeleteSnapshotParams.create().before( params.getVacuumStartedAt().minusMillis( params.getAgeThreshold() ) ).build() ); deleteSnapshotsResult.getDeletedSnapshots().forEach( snapshot -> builder.processed() ); deleteSnapshotsResult.getFailedSnapshots().forEach( snapshot -> builder.failed() ); diff --git a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/versiontable/VersionTableVacuumCommand.java b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/versiontable/VersionTableVacuumCommand.java index 1a0b0779ca1..2bf3312920d 100644 --- a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/versiontable/VersionTableVacuumCommand.java +++ b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/vacuum/versiontable/VersionTableVacuumCommand.java @@ -83,7 +83,7 @@ private VersionTableVacuumCommand( final Builder builder ) listener = builder.params.getListener(); batchSize = builder.params.getVersionsBatchSize(); - final Instant now = builder.clock != null ? Instant.now( builder.clock ) : Instant.now(); + final Instant now = builder.clock != null ? Instant.now( builder.clock ) : builder.params.getVacuumStartedAt(); until = now.minusMillis( builder.params.getAgeThreshold() ); untilForTransientRepository = now.minus( 1, ChronoUnit.MINUTES ); } @@ -149,8 +149,11 @@ private void doProcessRepository( final Repository repository ) version.getNodeVersionId() ); result.deleted(); versionService.delete( version.getNodeVersionId(), context ); - nodeBlobToCheckSet.add( version.getNodeVersionKey().getNodeBlobKey() ); - binaryBlobToCheckSet.addAll( version.getBinaryBlobKeys().getSet() ); + if ( repository.isTransient() ) + { + nodeBlobToCheckSet.add( version.getNodeVersionKey().getNodeBlobKey() ); + binaryBlobToCheckSet.addAll( version.getBinaryBlobKeys().getSet() ); + } } else { diff --git a/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/VacuumServiceImplTest.java b/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/VacuumServiceImplTest.java index 76455881070..efd2e1d3961 100644 --- a/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/VacuumServiceImplTest.java +++ b/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/VacuumServiceImplTest.java @@ -2,13 +2,24 @@ import org.junit.jupiter.api.Test; +import com.enonic.xp.blob.BlobStore; +import com.enonic.xp.node.DeleteSnapshotParams; +import com.enonic.xp.node.DeleteSnapshotsResult; +import com.enonic.xp.node.NodeService; import com.enonic.xp.repo.impl.node.NodeHelper; +import com.enonic.xp.repo.impl.vacuum.blob.BinaryBlobVacuumTask; +import com.enonic.xp.repo.impl.vacuum.blob.NodeBlobVacuumTask; +import com.enonic.xp.snapshot.SnapshotService; import com.enonic.xp.vacuum.VacuumParameters; import com.enonic.xp.vacuum.VacuumResult; import com.enonic.xp.vacuum.VacuumTaskResult; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class VacuumServiceImplTest { @@ -17,7 +28,10 @@ public class VacuumServiceImplTest public void runTasks() throws Exception { - final VacuumServiceImpl service = new VacuumServiceImpl(); + final SnapshotService snapshotService = mock( SnapshotService.class ); + when( snapshotService.delete( mock( DeleteSnapshotParams.class ) ) ).thenReturn( DeleteSnapshotsResult.create().build() ); + + final VacuumServiceImpl service = new VacuumServiceImpl( snapshotService ); service.activate( mock( VacuumConfig.class, i -> i.getMethod().getDefaultValue() ) ); service.addTask( new VacuumTask() @@ -66,5 +80,52 @@ public String name() final VacuumResult result = NodeHelper.runAsAdmin( () -> service.vacuum( VacuumParameters.create().build() ) ); assertEquals( 2, result.getResults().size() ); + + verify( snapshotService, times( 0 ) ).delete( any( DeleteSnapshotParams.class ) ); + } + + @Test + public void runTasksWithDeletingSnapshots() + { + final SnapshotService snapshotService = mock( SnapshotService.class ); + when( snapshotService.delete( any( DeleteSnapshotParams.class ) ) ).thenReturn( DeleteSnapshotsResult.create().build() ); + + final VacuumServiceImpl service = new VacuumServiceImpl( snapshotService ); + service.activate( mock( VacuumConfig.class, i -> i.getMethod().getDefaultValue() ) ); + + final NodeService nodeService = mock( NodeService.class ); + final BlobStore blobStore = mock( BlobStore.class ); + + service.addTask( new BinaryBlobVacuumTask( nodeService, blobStore ) ); + service.addTask( new NodeBlobVacuumTask( nodeService, blobStore ) ); + + final VacuumResult result = NodeHelper.runAsAdmin( () -> service.vacuum( VacuumParameters.create().build() ) ); + + assertEquals( 2, result.getResults().size() ); + + verify( snapshotService, times( 1 ) ).delete( any( DeleteSnapshotParams.class ) ); + } + + @Test + public void runTasksWithDeletingSnapshotsFailed() + { + final SnapshotService snapshotService = mock( SnapshotService.class ); + + when( snapshotService.delete( any( DeleteSnapshotParams.class ) ) ).thenThrow( RuntimeException.class ); + + final VacuumServiceImpl service = new VacuumServiceImpl( snapshotService ); + service.activate( mock( VacuumConfig.class, i -> i.getMethod().getDefaultValue() ) ); + + final NodeService nodeService = mock( NodeService.class ); + final BlobStore blobStore = mock( BlobStore.class ); + + service.addTask( new BinaryBlobVacuumTask( nodeService, blobStore ) ); + service.addTask( new NodeBlobVacuumTask( nodeService, blobStore ) ); + + final VacuumResult result = NodeHelper.runAsAdmin( () -> service.vacuum( VacuumParameters.create().build() ) ); + + assertEquals( 2, result.getResults().size() ); + + verify( snapshotService, times( 1 ) ).delete( any( DeleteSnapshotParams.class ) ); } } diff --git a/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/blob/AbstractBlobVacuumTaskTest.java b/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/blob/AbstractBlobVacuumTaskTest.java index e88a4f0ae1e..af3d62d9772 100644 --- a/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/blob/AbstractBlobVacuumTaskTest.java +++ b/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/blob/AbstractBlobVacuumTaskTest.java @@ -1,5 +1,6 @@ package com.enonic.xp.repo.impl.vacuum.blob; +import java.time.Instant; import java.util.concurrent.atomic.AtomicInteger; import org.mockito.Mockito; @@ -59,7 +60,7 @@ public void test_delete_unused() final VacuumTask task = createTask(); - final VacuumTaskResult result = task.execute( VacuumTaskParams.create().ageThreshold( 0 ).build() ); + final VacuumTaskResult result = task.execute( VacuumTaskParams.create().vacuumStartedAt( Instant.now() ).ageThreshold( 0 ).build() ); assertEquals( 3, result.getProcessed() ); assertEquals( 2, result.getDeleted() ); @@ -101,7 +102,8 @@ public void processed( final long count ) blobReportCount.incrementAndGet(); } }; - final VacuumTaskResult result = task.execute( VacuumTaskParams.create().ageThreshold( 0 ).listener( progressListener ).build() ); + final VacuumTaskResult result = task.execute( + VacuumTaskParams.create().vacuumStartedAt( Instant.now() ).ageThreshold( 0 ).listener( progressListener ).build() ); assertEquals( 3, result.getProcessed() ); assertEquals( 2, result.getDeleted() ); @@ -116,7 +118,7 @@ public void age_threshold() this.blobStore.addRecord( segment, createBlobRecord( 'a' ) ); final VacuumTask task = createTask(); - final VacuumTaskResult result = task.execute( VacuumTaskParams.create().build() ); + final VacuumTaskResult result = task.execute( VacuumTaskParams.create().vacuumStartedAt( Instant.now() ).build() ); assertEquals( 0, result.getProcessed() ); } diff --git a/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/blob/BinaryBlobVacuumTaskTest.java b/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/blob/BinaryBlobVacuumTaskTest.java index 859814b4f16..b8762266830 100644 --- a/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/blob/BinaryBlobVacuumTaskTest.java +++ b/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/blob/BinaryBlobVacuumTaskTest.java @@ -9,7 +9,8 @@ import com.enonic.xp.repo.impl.vacuum.VacuumTask; -public class BinaryBlobVacuumTaskTest extends AbstractBlobVacuumTaskTest +public class BinaryBlobVacuumTaskTest + extends AbstractBlobVacuumTaskTest { @Override @BeforeEach @@ -47,9 +48,6 @@ public void age_threshold() @Override protected VacuumTask createTask() { - final BinaryBlobVacuumTask task = new BinaryBlobVacuumTask(); - task.setBlobStore( this.blobStore ); - task.setNodeService( this.nodeService ); - return task; + return new BinaryBlobVacuumTask( this.nodeService, this.blobStore ); } } diff --git a/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/blob/NodeBlobVacuumTaskTest.java b/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/blob/NodeBlobVacuumTaskTest.java index cc0eec249f2..560b582da6d 100644 --- a/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/blob/NodeBlobVacuumTaskTest.java +++ b/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/blob/NodeBlobVacuumTaskTest.java @@ -48,9 +48,6 @@ public void age_threshold() @Override protected VacuumTask createTask() { - final NodeBlobVacuumTask task = new NodeBlobVacuumTask(); - task.setBlobStore( this.blobStore ); - task.setNodeService( this.nodeService ); - return task; + return new NodeBlobVacuumTask( this.nodeService, this.blobStore ); } } diff --git a/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/segment/SegmentVacuumTaskTest.java b/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/segment/SegmentVacuumTaskTest.java index 7315a76bd43..43e4136769e 100644 --- a/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/segment/SegmentVacuumTaskTest.java +++ b/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/segment/SegmentVacuumTaskTest.java @@ -1,5 +1,7 @@ package com.enonic.xp.repo.impl.vacuum.segment; +import java.time.Instant; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -76,8 +78,7 @@ public void test() task.setRepositoryService( repositoryService ); task.setNodeService( nodeService ); - final VacuumTaskParams vacuumParameters = VacuumTaskParams.create(). - build(); + final VacuumTaskParams vacuumParameters = VacuumTaskParams.create().vacuumStartedAt( Instant.now() ).build(); final VacuumTaskResult result = task.execute( vacuumParameters ); assertEquals( 2, result.getProcessed() ); diff --git a/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/snapshots/SnapshotsVacuumTaskTest.java b/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/snapshots/SnapshotsVacuumTaskTest.java index 6d639b3c8a9..44127c09709 100644 --- a/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/snapshots/SnapshotsVacuumTaskTest.java +++ b/modules/core/core-repo/src/test/java/com/enonic/xp/repo/impl/vacuum/snapshots/SnapshotsVacuumTaskTest.java @@ -1,5 +1,7 @@ package com.enonic.xp.repo.impl.vacuum.snapshots; +import java.time.Instant; + import org.junit.jupiter.api.Test; import com.enonic.xp.node.DeleteSnapshotParams; @@ -54,7 +56,7 @@ public void stepBegin( final String stepName, final Long toProcessCount ) public void processed( final long count ) { } - } ).ageThreshold( 60 * 1000 ).build() ); + } ).ageThreshold( 60 * 1000 ).vacuumStartedAt( Instant.now() ).build() ); assertEquals( "SnapshotsVacuumTask", result.getTaskName() ); assertEquals( 1, result.getProcessed() ); diff --git a/modules/itest/itest-core/src/test/java/com/enonic/xp/core/repo/vacuum/versiontable/VersionTableVacuumTaskTest.java b/modules/itest/itest-core/src/test/java/com/enonic/xp/core/repo/vacuum/versiontable/VersionTableVacuumTaskTest.java index 223d55b28d3..0193dd30bf2 100644 --- a/modules/itest/itest-core/src/test/java/com/enonic/xp/core/repo/vacuum/versiontable/VersionTableVacuumTaskTest.java +++ b/modules/itest/itest-core/src/test/java/com/enonic/xp/core/repo/vacuum/versiontable/VersionTableVacuumTaskTest.java @@ -72,7 +72,7 @@ void delete_node_deletes_versions() assertVersions( node1.id(), expectedVersionCount ); - final VacuumTaskResult result = NodeHelper.runAsAdmin( () -> this.task.execute( VacuumTaskParams.create(). + final VacuumTaskResult result = NodeHelper.runAsAdmin( () -> this.task.execute( VacuumTaskParams.create().vacuumStartedAt( Instant.now() ). ageThreshold( NEGATIVE_AGE_THRESHOLD_MILLIS ). versionsBatchSize( versionsBatchSize ). build() ) ); @@ -99,6 +99,7 @@ void version_deleted_in_all_branches() assertVersions( node1.id(), 1 ); final VacuumTaskResult result = NodeHelper.runAsAdmin( () -> this.task.execute( VacuumTaskParams.create(). + vacuumStartedAt( Instant.now() ). ageThreshold( NEGATIVE_AGE_THRESHOLD_MILLIS ). build() ) ); refresh(); @@ -122,6 +123,7 @@ void version_not_deleted_in_all_branches() assertVersions( node1.id(), 1 ); final VacuumTaskResult result = NodeHelper.runAsAdmin( () -> this.task.execute( VacuumTaskParams.create(). + vacuumStartedAt( Instant.now() ). ageThreshold( NEGATIVE_AGE_THRESHOLD_MILLIS ). build() ) ); refresh(); @@ -143,9 +145,12 @@ void age_threshold() refresh(); assertVersions( node1.id(), 3 ); - final VacuumTaskResult result = NodeHelper.runAsAdmin( () -> this.task.execute( VacuumTaskParams.create(). - ageThreshold( Duration.of( 1, ChronoUnit.HOURS ).toMillis() ). - build() ) ); + final VacuumTaskResult result = NodeHelper.runAsAdmin( () -> this.task.execute( VacuumTaskParams.create() + .vacuumStartedAt( Instant.now() ) + .ageThreshold( + Duration.of( 1, ChronoUnit.HOURS ) + .toMillis() ) + .build() ) ); refresh(); assertEquals( 0, result.getProcessed() ); @@ -190,7 +195,7 @@ void testDeleteOnTransientRepository() Instant newTime = initTime.plus( 3, ChronoUnit.MINUTES ); this.task.setClock( Clock.fixed( newTime, ZoneId.systemDefault() ) ); - final VacuumTaskResult result = NodeHelper.runAsAdmin( () -> this.task.execute( VacuumTaskParams.create().build() ) ); + final VacuumTaskResult result = NodeHelper.runAsAdmin( () -> this.task.execute( VacuumTaskParams.create().vacuumStartedAt( Instant.now() ).build() ) ); refresh();