This is an automated email from the ASF dual-hosted git repository. henrykuijpers pushed a commit to branch SLING-13146 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit 76c6532328a731237f15a46003728ac24e2a8ea9 Author: Henry Kuijpers <[email protected]> AuthorDate: Mon Mar 30 11:36:25 2026 +0200 SLING-13146 Add test case to reproduce the issue --- core/pom.xml | 6 ++ .../ThreadsafeMockAdapterManagerWrapperTest.java | 77 ++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/core/pom.xml b/core/pom.xml index 3ba54f0..7ec4186 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -305,6 +305,12 @@ <version>1.0</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.awaitility</groupId> + <artifactId>awaitility</artifactId> + <version>4.3.0</version> + <scope>test</scope> + </dependency> </dependencies> diff --git a/core/src/test/java/org/apache/sling/testing/mock/sling/ThreadsafeMockAdapterManagerWrapperTest.java b/core/src/test/java/org/apache/sling/testing/mock/sling/ThreadsafeMockAdapterManagerWrapperTest.java new file mode 100644 index 0000000..22c81ed --- /dev/null +++ b/core/src/test/java/org/apache/sling/testing/mock/sling/ThreadsafeMockAdapterManagerWrapperTest.java @@ -0,0 +1,77 @@ +/* + * 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.testing.mock.sling; + +import java.util.Objects; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import org.apache.sling.api.resource.Resource; +import org.apache.sling.testing.mock.sling.junit.SlingContext; +import org.apache.sling.testing.mock.sling.junit.SlingContextBuilder; +import org.jetbrains.annotations.NotNull; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.awaitility.Awaitility.await; +import static org.junit.Assert.assertNotNull; + +public class ThreadsafeMockAdapterManagerWrapperTest { + @Rule + public final SlingContext context = + new SlingContextBuilder().registerSlingModelsFromClassPath(false).build(); + + @Before + public void setUp() { + context.registerAdapter(Resource.class, AdapterClass.class, new AdapterClass()); + } + + @Test + public void x() { + assertNotNull(context.create().resource("/content/test").adaptTo(AdapterClass.class)); + final MyService myService = context.registerService(new MyService()); + final ScheduledExecutorService executor = Executors.newScheduledThreadPool(10); + executor.schedule( + () -> myService.onChange( + Objects.requireNonNull(context.resourceResolver().getResource("/content/test"))), + 2, + TimeUnit.SECONDS); + await().until(() -> myService.getValue() != null); + } + + private static class AdapterClass {} + + private static class MyService { + private AdapterClass value; + + public AdapterClass getValue() { + System.out.println("Returning value: " + this.value); + return this.value; + } + + public void onChange(@NotNull Resource list) { + System.out.println("ON CHANGE"); + final AdapterClass result = list.adaptTo(AdapterClass.class); + System.out.println("Result: " + result); + value = result; + } + } +}
