bkkothari2255 commented on code in PR #73: URL: https://github.com/apache/sling-org-apache-sling-distribution-core/pull/73#discussion_r2670459674
########## src/test/java/org/apache/sling/distribution/serialization/impl/DistributionPackageBuilderFactoryTest.java: ########## @@ -0,0 +1,84 @@ +/* + * 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.distribution.serialization.impl; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Dictionary; + +import org.apache.sling.api.resource.ResourceResolverFactory; +import org.apache.sling.commons.scheduler.Scheduler; +import org.apache.sling.distribution.serialization.DistributionContentSerializer; +import org.apache.sling.distribution.packaging.impl.ResourceDistributionPackageCleanup; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.osgi.framework.BundleContext; + +public class DistributionPackageBuilderFactoryTest { + + /** + * Tests that the cleanup task has a dedicated thread pool. + * see SLING-11026 + */ + @Test + public void testCleanupTaskHasDedicatedThreadPool() { + DistributionPackageBuilderFactory factory = new DistributionPackageBuilderFactory(); + + BundleContext context = mock(BundleContext.class); + DistributionPackageBuilderFactory.Config config = mock(DistributionPackageBuilderFactory.Config.class); + ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class); + DistributionContentSerializer contentSerializer = mock(DistributionContentSerializer.class); + + try { + java.lang.reflect.Field resolverFactoryField = DistributionPackageBuilderFactory.class.getDeclaredField("resolverFactory"); + resolverFactoryField.setAccessible(true); + resolverFactoryField.set(factory, resolverFactory); + + java.lang.reflect.Field contentSerializerField = DistributionPackageBuilderFactory.class.getDeclaredField("contentSerializer"); + contentSerializerField.setAccessible(true); + contentSerializerField.set(factory, contentSerializer); + } catch (Exception e) { + throw new RuntimeException(e); + } + when(config.type()).thenReturn("resource"); + when(config.package_filters()).thenReturn(new String[0]); + when(config.property_filters()).thenReturn(new String[0]); + when(config.tempFsFolder()).thenReturn("/tmp"); + when(config.digestAlgorithm()).thenReturn("NONE"); + + when(config.fileThreshold()).thenReturn(1); + when(config.memoryUnit()).thenReturn("MEGA_BYTES"); + when(config.useOffHeapMemory()).thenReturn(false); + when(config.monitoringQueueSize()).thenReturn(0); + when(config.cleanupDelay()).thenReturn(60L); Review Comment: Thanks for the review. I agree the manual mocking is overkill for a property change. To ensure we prevent regressions without the verbosity, I have rewriten this using Sling Mocks (OsgiContext), which would reduce the test to just a few lines. Would you prefer that approach, or should I simply remove the test entirely? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
