This is an automated email from the ASF dual-hosted git repository. dklco pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git
commit 93a0d15ef663fc078140a9d15f6aa9683a9eeb64 Author: Dan Klco <[email protected]> AuthorDate: Mon Mar 29 23:01:38 2021 -0400 Removing Maintenance jobs since they are no longer needed with SLING-10116 --- .../repository/AbstractMaintenanceJob.java | 124 ------------------- .../repository/DataStoreCleanupConfig.java | 31 ----- .../repository/DataStoreCleanupScheduler.java | 78 ------------ .../internal/repository/RevisionCleanupConfig.java | 31 ----- .../repository/RevisionCleanupScheduler.java | 77 ------------ .../repository/AbstractMaintenanceJobTest.java | 135 --------------------- .../internal/repository/CompositeDataMock.java | 55 --------- .../repository/DataStoreCleanupSchedulerTest.java | 73 ----------- .../repository/RevisionCleanupSchedulerTest.java | 73 ----------- 9 files changed, 677 deletions(-) diff --git a/core/src/main/java/org/apache/sling/cms/core/internal/repository/AbstractMaintenanceJob.java b/core/src/main/java/org/apache/sling/cms/core/internal/repository/AbstractMaintenanceJob.java deleted file mode 100644 index af0fef1..0000000 --- a/core/src/main/java/org/apache/sling/cms/core/internal/repository/AbstractMaintenanceJob.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sling.cms.core.internal.repository; - -import java.util.Arrays; -import java.util.Collections; -import java.util.Optional; - -import javax.management.openmbean.CompositeData; - -import org.apache.jackrabbit.oak.api.jmx.RepositoryManagementMBean.StatusCode; -import org.apache.sling.event.jobs.Job; -import org.apache.sling.event.jobs.JobManager; -import org.apache.sling.event.jobs.consumer.JobExecutionContext; -import org.apache.sling.event.jobs.consumer.JobExecutionContext.ResultBuilder; -import org.apache.sling.event.jobs.consumer.JobExecutionResult; -import org.apache.sling.event.jobs.consumer.JobExecutor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Service for running the Jackrabbit OAK Segment Store cleanup on a schedule. - */ -public abstract class AbstractMaintenanceJob implements Runnable, JobExecutor { - - private static final Logger log = LoggerFactory.getLogger(AbstractMaintenanceJob.class); - - protected JobManager jobManager; - - protected final JobExecutionResult createResult(JobExecutionContext context, Optional<CompositeData> data, - Integer startId) { - String message = data.map(d -> ((String) d.get("message"))).orElse(null); - StatusCode code = data.map(d -> ((Integer) d.get("code"))).map(c -> Arrays.stream(StatusCode.values()) - .filter(sc -> sc.ordinal() == c).findFirst().orElse(StatusCode.NONE)).orElse(StatusCode.NONE); - log.trace("Loaded status code: {}", code); - Integer id = data.map(d -> ((Integer) d.get("id"))).orElse(null); - boolean success = false; - StringBuilder sb = new StringBuilder(getPrefix()); - if (!data.isPresent() || code == null) { - log.trace("No result..."); - sb.append("No result."); - } else if (startId != null && (id == null || id.intValue() != startId.intValue())) { - log.trace("ID does not match original ID, assuming successful..."); - sb.append(StatusCode.SUCCEEDED.name); - success = true; - } else if (code == StatusCode.INITIATED || code == StatusCode.SUCCEEDED) { - log.trace("Successful result: {}...", code.name); - sb.append(code.name); - success = true; - } else if (code == StatusCode.UNAVAILABLE || code == StatusCode.NONE || code == StatusCode.FAILED) { - log.trace("Failed result: {}...", code.name); - sb.append(code.name); - } else { - return null; - } - if (message != null) { - sb.append(" "); - sb.append(message); - } - ResultBuilder rb = context.result().message(sb.toString()); - return success ? rb.succeeded() : rb.failed(); - } - - public abstract String getJobTopic(); - - public abstract String getPrefix(); - - public abstract Optional<CompositeData> getStatus(); - - public JobExecutionResult process(Job job, JobExecutionContext context) { - log.info("Starting {}", getPrefix()); - Optional<CompositeData> data = startMaintenance(); - Integer id = data.map(d -> ((Integer) d.get("id"))).orElse(null); - JobExecutionResult result = null; - while (result == null) { - data = getStatus(); - result = createResult(context, data, id); - if (result == null) { - if (context.isStopped()) { - log.info( - "Canceling {}. The task was either stopped by the user or the Maintenance Window reached its end", - getPrefix()); - stopMaintenance(); - return context.result().message(String.format("%sStopped by user.", getPrefix())).failed(); - } - try { - Thread.sleep(1000L); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } else { - log.debug("Retrieved result: {}", result); - } - } - return result; - } - - @Override - public void run() { - log.trace("Kicking off job: {}", getJobTopic()); - jobManager.addJob(getJobTopic(), Collections.emptyMap()); - } - - public abstract void setJobManager(JobManager jobManager); - - public abstract Optional<CompositeData> startMaintenance(); - - public abstract Optional<CompositeData> stopMaintenance(); - -} diff --git a/core/src/main/java/org/apache/sling/cms/core/internal/repository/DataStoreCleanupConfig.java b/core/src/main/java/org/apache/sling/cms/core/internal/repository/DataStoreCleanupConfig.java deleted file mode 100644 index 7ca6ca8..0000000 --- a/core/src/main/java/org/apache/sling/cms/core/internal/repository/DataStoreCleanupConfig.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sling.cms.core.internal.repository; - -import org.osgi.service.metatype.annotations.ObjectClassDefinition; -import org.osgi.service.metatype.annotations.AttributeDefinition; - -/** - * Configuration for the DataStore Cleanup Service - */ -@ObjectClassDefinition(name = "%datastore.cleanup.name", description = "%datastore.cleanup.description", localization = "OSGI-INF/l10n/bundle") -public @interface DataStoreCleanupConfig { - - @AttributeDefinition(name = "%scheduler.expression.name", description = "%scheduler.expression.description") - String scheduler_expression(); - -} \ No newline at end of file diff --git a/core/src/main/java/org/apache/sling/cms/core/internal/repository/DataStoreCleanupScheduler.java b/core/src/main/java/org/apache/sling/cms/core/internal/repository/DataStoreCleanupScheduler.java deleted file mode 100644 index 7211f02..0000000 --- a/core/src/main/java/org/apache/sling/cms/core/internal/repository/DataStoreCleanupScheduler.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sling.cms.core.internal.repository; - -import java.util.Optional; - -import javax.management.openmbean.CompositeData; - -import org.apache.jackrabbit.oak.api.jmx.RepositoryManagementMBean; -import org.apache.sling.event.jobs.JobManager; -import org.apache.sling.event.jobs.consumer.JobExecutor; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.ConfigurationPolicy; -import org.osgi.service.component.annotations.Reference; -import org.osgi.service.metatype.annotations.Designate; - -/** - * Service for running the Jackrabbit OAK Segment Store cleanup on a schedule. - */ -@Component(service = { JobExecutor.class, Runnable.class }, property = { JobExecutor.PROPERTY_TOPICS - + "=org/apache/sling/cms/repository/DataStoreCleanup" }, configurationPolicy = ConfigurationPolicy.REQUIRE, immediate = true) -@Designate(ocd = DataStoreCleanupConfig.class) -public class DataStoreCleanupScheduler extends AbstractMaintenanceJob { - - private RepositoryManagementMBean repositoryManager; - - @Override - public String getJobTopic() { - return "org/apache/sling/cms/repository/DataStoreCleanup"; - } - - @Override - public String getPrefix() { - return "DataStore Cleanup"; - } - - @Override - public Optional<CompositeData> getStatus() { - return Optional.ofNullable(repositoryManager.getDataStoreGCStatus()); - } - - @Reference - @Override - public void setJobManager(final JobManager jobManager) { - super.jobManager = jobManager; - } - - @Reference - public void setRepositoryManager(final RepositoryManagementMBean repositoryManager) { - this.repositoryManager = repositoryManager; - } - - @Override - public Optional<CompositeData> startMaintenance() { - return Optional.ofNullable(repositoryManager.startDataStoreGC(false)); - } - - @Override - public Optional<CompositeData> stopMaintenance() { - // Can't really stop this one - return Optional.ofNullable(repositoryManager.getDataStoreGCStatus()); - } - -} diff --git a/core/src/main/java/org/apache/sling/cms/core/internal/repository/RevisionCleanupConfig.java b/core/src/main/java/org/apache/sling/cms/core/internal/repository/RevisionCleanupConfig.java deleted file mode 100644 index 14c0c1f..0000000 --- a/core/src/main/java/org/apache/sling/cms/core/internal/repository/RevisionCleanupConfig.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sling.cms.core.internal.repository; - -import org.osgi.service.metatype.annotations.ObjectClassDefinition; -import org.osgi.service.metatype.annotations.AttributeDefinition; - -/** - * Configuration for the Reference Mapping Transformer - */ -@ObjectClassDefinition(name = "%revision.cleanup.name", description = "%revision.cleanup.description", localization = "OSGI-INF/l10n/bundle") -public @interface RevisionCleanupConfig { - - @AttributeDefinition(name = "%scheduler.expression.name", description = "%scheduler.expression.description") - String scheduler_expression(); - -} \ No newline at end of file diff --git a/core/src/main/java/org/apache/sling/cms/core/internal/repository/RevisionCleanupScheduler.java b/core/src/main/java/org/apache/sling/cms/core/internal/repository/RevisionCleanupScheduler.java deleted file mode 100644 index 3d5afcd..0000000 --- a/core/src/main/java/org/apache/sling/cms/core/internal/repository/RevisionCleanupScheduler.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sling.cms.core.internal.repository; - -import java.util.Optional; - -import javax.management.openmbean.CompositeData; - -import org.apache.jackrabbit.oak.api.jmx.RepositoryManagementMBean; -import org.apache.sling.event.jobs.JobManager; -import org.apache.sling.event.jobs.consumer.JobExecutor; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.ConfigurationPolicy; -import org.osgi.service.component.annotations.Reference; -import org.osgi.service.metatype.annotations.Designate; - -/** - * Service for running the Jackrabbit OAK Segment Store cleanup on a schedule. - */ -@Component(service = { JobExecutor.class, Runnable.class }, property = { JobExecutor.PROPERTY_TOPICS - + "=org/apache/sling/cms/repository/RevisionCleanup" }, configurationPolicy = ConfigurationPolicy.REQUIRE, immediate = true) -@Designate(ocd = RevisionCleanupConfig.class) -public class RevisionCleanupScheduler extends AbstractMaintenanceJob { - - private RepositoryManagementMBean repositoryManager; - - @Override - public String getJobTopic() { - return "org/apache/sling/cms/repository/RevisionCleanup"; - } - - @Override - public String getPrefix() { - return "Revision Cleanup"; - } - - @Override - public Optional<CompositeData> getStatus() { - return Optional.ofNullable(repositoryManager.getRevisionGCStatus()); - } - - @Reference - @Override - public void setJobManager(final JobManager jobManager) { - super.jobManager = jobManager; - } - - @Reference - public void setRepositoryManager(final RepositoryManagementMBean repositoryManager) { - this.repositoryManager = repositoryManager; - } - - @Override - public Optional<CompositeData> startMaintenance() { - return Optional.ofNullable(repositoryManager.startRevisionGC()); - } - - @Override - public Optional<CompositeData> stopMaintenance() { - return Optional.ofNullable(repositoryManager.cancelRevisionGC()); - } - -} diff --git a/core/src/test/java/org/apache/sling/cms/core/internal/repository/AbstractMaintenanceJobTest.java b/core/src/test/java/org/apache/sling/cms/core/internal/repository/AbstractMaintenanceJobTest.java deleted file mode 100644 index 9b0521a..0000000 --- a/core/src/test/java/org/apache/sling/cms/core/internal/repository/AbstractMaintenanceJobTest.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sling.cms.core.internal.repository; - -import static org.junit.Assert.assertNull; - -import java.util.Optional; - -import javax.management.openmbean.CompositeData; - -import org.apache.jackrabbit.oak.api.jmx.RepositoryManagementMBean.StatusCode; -import org.apache.sling.event.jobs.JobManager; -import org.apache.sling.event.jobs.consumer.JobExecutionContext; -import org.apache.sling.event.jobs.consumer.JobExecutionContext.ResultBuilder; -import org.apache.sling.event.jobs.consumer.JobExecutionResult; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; - -public class AbstractMaintenanceJobTest { - - private AbstractMaintenanceJob amj; - private JobExecutionContext context; - private ResultBuilder resultBuilder; - - @Before - public void init() { - amj = new AbstractMaintenanceJob() { - @Override - public String getJobTopic() { - throw new UnsupportedOperationException(); - } - - @Override - public String getPrefix() { - return "Test Job"; - } - - @Override - public Optional<CompositeData> getStatus() { - throw new UnsupportedOperationException(); - } - - @Override - public void setJobManager(JobManager jobManager) { - throw new UnsupportedOperationException(); - } - - @Override - public Optional<CompositeData> startMaintenance() { - throw new UnsupportedOperationException(); - } - - @Override - public Optional<CompositeData> stopMaintenance() { - throw new UnsupportedOperationException(); - } - }; - - context = Mockito.mock(JobExecutionContext.class); - resultBuilder = Mockito.mock(ResultBuilder.class); - Mockito.when(resultBuilder.message(Mockito.anyString())).thenReturn(resultBuilder); - Mockito.when(context.result()).thenReturn(resultBuilder); - } - - @Test - public void testRunningResult() { - int id = 1; - CompositeData data = CompositeDataMock.init().put("code", StatusCode.RUNNING.ordinal()) - .put("message", "Hello World").put("id", id).build(); - JobExecutionResult result = amj.createResult(context, Optional.ofNullable(data), id); - assertNull(result); - } - - @Test - public void testNewIdResult() { - int id = 1; - CompositeData data = CompositeDataMock.init().put("code", StatusCode.RUNNING.ordinal()) - .put("message", "Hello World").put("id", 2).build(); - amj.createResult(context, Optional.ofNullable(data), id); - Mockito.verify(resultBuilder).succeeded(); - } - - @Test - public void testFailedResult() { - int id = 1; - CompositeData data = CompositeDataMock.init().put("code", StatusCode.FAILED.ordinal()) - .put("message", "Hello World").put("id", id).build(); - amj.createResult(context, Optional.ofNullable(data), id); - Mockito.verify(resultBuilder).failed(); - - } - - @Test - public void testNoneResult() { - int id = 1; - CompositeData data = CompositeDataMock.init().put("code", StatusCode.NONE.ordinal()) - .put("message", "Hello World").put("id", id).build(); - amj.createResult(context, Optional.ofNullable(data), id); - Mockito.verify(resultBuilder).failed(); - } - - @Test - public void testInvalidCode() { - int id = 1; - CompositeData data = CompositeDataMock.init().put("code", 2345677).put("message", "Hello World").put("id", id) - .build(); - amj.createResult(context, Optional.ofNullable(data), id); - Mockito.verify(resultBuilder).failed(); - } - - @Test - public void testSucceededResult() { - int id = 1; - CompositeData data = CompositeDataMock.init().put("code", StatusCode.SUCCEEDED.ordinal()) - .put("message", "Hello World").put("id", id).build(); - amj.createResult(context, Optional.ofNullable(data), id); - Mockito.verify(resultBuilder).succeeded(); - } - -} \ No newline at end of file diff --git a/core/src/test/java/org/apache/sling/cms/core/internal/repository/CompositeDataMock.java b/core/src/test/java/org/apache/sling/cms/core/internal/repository/CompositeDataMock.java deleted file mode 100644 index 28f628d..0000000 --- a/core/src/test/java/org/apache/sling/cms/core/internal/repository/CompositeDataMock.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sling.cms.core.internal.repository; - -import java.util.HashMap; -import java.util.Map; - -import javax.management.openmbean.CompositeData; - -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - -/** - * A mock for creating a fluent API version of a CompositeData Object. - */ -public class CompositeDataMock { - - private Map<String, Object> data = new HashMap<>(); - - public static CompositeDataMock init() { - return new CompositeDataMock(); - } - - public CompositeDataMock put(String key, Object value) { - this.data.put(key, value); - return this; - } - - public CompositeData build() { - CompositeData dc = Mockito.mock(CompositeData.class); - Mockito.when(dc.get(Mockito.anyString())).thenAnswer(new Answer<Object>() { - @Override - public Object answer(InvocationOnMock invocation) throws Throwable { - return data.get(invocation.getArguments()[0]); - } - }); - return dc; - } - -} \ No newline at end of file diff --git a/core/src/test/java/org/apache/sling/cms/core/internal/repository/DataStoreCleanupSchedulerTest.java b/core/src/test/java/org/apache/sling/cms/core/internal/repository/DataStoreCleanupSchedulerTest.java deleted file mode 100644 index d3918a6..0000000 --- a/core/src/test/java/org/apache/sling/cms/core/internal/repository/DataStoreCleanupSchedulerTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sling.cms.core.internal.repository; - -import javax.management.openmbean.CompositeData; - -import org.apache.jackrabbit.oak.api.jmx.RepositoryManagementMBean; -import org.apache.jackrabbit.oak.api.jmx.RepositoryManagementMBean.StatusCode; -import org.apache.sling.event.jobs.Job; -import org.apache.sling.event.jobs.JobManager; -import org.apache.sling.event.jobs.consumer.JobExecutionContext; -import org.apache.sling.event.jobs.consumer.JobExecutionResult; -import org.apache.sling.event.jobs.consumer.JobExecutionContext.ResultBuilder; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; - -public class DataStoreCleanupSchedulerTest { - - private JobExecutionContext context; - private ResultBuilder resultBuilder; - - @Before - public void init() { - context = Mockito.mock(JobExecutionContext.class); - resultBuilder = Mockito.mock(ResultBuilder.class); - Mockito.when(resultBuilder.message(Mockito.anyString())).thenReturn(resultBuilder); - Mockito.when(resultBuilder.succeeded()).thenReturn(Mockito.mock(JobExecutionResult.class)); - Mockito.when(resultBuilder.failed()).thenReturn(Mockito.mock(JobExecutionResult.class)); - Mockito.when(context.result()).thenReturn(resultBuilder); - } - - @Test - public void testRunnable() { - final DataStoreCleanupScheduler dscs = new DataStoreCleanupScheduler(); - final JobManager jobManager = Mockito.mock(JobManager.class); - dscs.setJobManager(jobManager); - - Mockito.when(jobManager.addJob(Mockito.eq(dscs.getJobTopic()), Mockito.anyMap())).then((answer) -> { - dscs.process(Mockito.mock(Job.class), context); - return null; - }); - - Integer id = 1; - final RepositoryManagementMBean repositoryManager = Mockito.mock(RepositoryManagementMBean.class); - CompositeData startingCd = CompositeDataMock.init().put("id", id).build(); - Mockito.when(repositoryManager.startDataStoreGC(false)).thenReturn(startingCd); - CompositeData doneCd = CompositeDataMock.init().put("id", id).put("code", StatusCode.SUCCEEDED.ordinal()) - .build(); - Mockito.when(repositoryManager.getDataStoreGCStatus()).thenReturn(doneCd); - dscs.setRepositoryManager(repositoryManager); - - dscs.run(); - - Mockito.verify(repositoryManager).startDataStoreGC(false); - Mockito.verify(resultBuilder).succeeded(); - } - -} \ No newline at end of file diff --git a/core/src/test/java/org/apache/sling/cms/core/internal/repository/RevisionCleanupSchedulerTest.java b/core/src/test/java/org/apache/sling/cms/core/internal/repository/RevisionCleanupSchedulerTest.java deleted file mode 100644 index ba8f255..0000000 --- a/core/src/test/java/org/apache/sling/cms/core/internal/repository/RevisionCleanupSchedulerTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.sling.cms.core.internal.repository; - -import javax.management.openmbean.CompositeData; - -import org.apache.jackrabbit.oak.api.jmx.RepositoryManagementMBean; -import org.apache.jackrabbit.oak.api.jmx.RepositoryManagementMBean.StatusCode; -import org.apache.sling.event.jobs.Job; -import org.apache.sling.event.jobs.JobManager; -import org.apache.sling.event.jobs.consumer.JobExecutionContext; -import org.apache.sling.event.jobs.consumer.JobExecutionContext.ResultBuilder; -import org.apache.sling.event.jobs.consumer.JobExecutionResult; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; - -public class RevisionCleanupSchedulerTest { - - private JobExecutionContext context; - private ResultBuilder resultBuilder; - - @Before - public void init() { - context = Mockito.mock(JobExecutionContext.class); - resultBuilder = Mockito.mock(ResultBuilder.class); - Mockito.when(resultBuilder.message(Mockito.anyString())).thenReturn(resultBuilder); - Mockito.when(resultBuilder.succeeded()).thenReturn(Mockito.mock(JobExecutionResult.class)); - Mockito.when(resultBuilder.failed()).thenReturn(Mockito.mock(JobExecutionResult.class)); - Mockito.when(context.result()).thenReturn(resultBuilder); - } - - @Test - public void testRunnable() { - final RevisionCleanupScheduler dscs = new RevisionCleanupScheduler(); - final JobManager jobManager = Mockito.mock(JobManager.class); - dscs.setJobManager(jobManager); - - Mockito.when(jobManager.addJob(Mockito.eq(dscs.getJobTopic()), Mockito.anyMap())).then((answer) -> { - dscs.process(Mockito.mock(Job.class), context); - return null; - }); - - Integer id = 1; - final RepositoryManagementMBean repositoryManager = Mockito.mock(RepositoryManagementMBean.class); - CompositeData startingCd = CompositeDataMock.init().put("id", id).build(); - Mockito.when(repositoryManager.startDataStoreGC(false)).thenReturn(startingCd); - CompositeData doneCd = CompositeDataMock.init().put("id", id).put("code", StatusCode.SUCCEEDED.ordinal()) - .build(); - Mockito.when(repositoryManager.getRevisionGCStatus()).thenReturn(doneCd); - dscs.setRepositoryManager(repositoryManager); - - dscs.run(); - - Mockito.verify(repositoryManager).startRevisionGC(); - Mockito.verify(resultBuilder).succeeded(); - } - -} \ No newline at end of file
