|
1 | 1 | /* |
2 | | - * Copyright (c) 2012, 2022 Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2012, 2025 Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * |
4 | 4 | * This program and the accompanying materials are made available under the |
5 | 5 | * terms of the Eclipse Public License v. 2.0, which is available at |
|
17 | 17 | package org.glassfish.jersey.tests.e2e.common.process.internal; |
18 | 18 |
|
19 | 19 | import java.lang.reflect.Type; |
| 20 | +import java.util.concurrent.atomic.AtomicInteger; |
| 21 | +import java.util.function.Consumer; |
20 | 22 |
|
21 | 23 | import org.glassfish.jersey.inject.hk2.Hk2RequestScope; |
22 | 24 | import org.glassfish.jersey.internal.inject.ForeignDescriptor; |
|
25 | 27 | import org.glassfish.hk2.api.ServiceHandle; |
26 | 28 | import org.glassfish.hk2.utilities.AbstractActiveDescriptor; |
27 | 29 |
|
| 30 | +import org.junit.jupiter.api.Assertions; |
28 | 31 | import org.junit.jupiter.api.Test; |
29 | 32 | import static org.junit.jupiter.api.Assertions.assertEquals; |
30 | 33 | import static org.junit.jupiter.api.Assertions.assertNull; |
@@ -140,6 +143,34 @@ public void testMultipleGetInstanceCalls() throws Exception { |
140 | 143 | assertNull(instance.get(inhab)); |
141 | 144 | } |
142 | 145 |
|
| 146 | + @Test |
| 147 | + public void testOrderOfRelease() { |
| 148 | + final RequestScope requestScope = new Hk2RequestScope(); |
| 149 | + final AtomicInteger instanceRelease = new AtomicInteger(0); |
| 150 | + final Hk2RequestScope.Instance instance = requestScope.runInScope(() -> { |
| 151 | + final Hk2RequestScope.Instance internalInstance = (Hk2RequestScope.Instance) requestScope.current(); |
| 152 | + for (int index = 1; index != 10; index++) { |
| 153 | + final int in = index; |
| 154 | + TestProvider testProvider = new TestProvider(String.valueOf(in)) { |
| 155 | + @Override |
| 156 | + public int hashCode() { |
| 157 | + return super.hashCode() + in; |
| 158 | + } |
| 159 | + }; |
| 160 | + final ForeignDescriptor fd = ForeignDescriptor.wrap(testProvider, new Consumer<Object>() { |
| 161 | + @Override |
| 162 | + public void accept(Object o) { |
| 163 | + instanceRelease.set(instanceRelease.get() * 10 + in); |
| 164 | + } |
| 165 | + }); |
| 166 | + internalInstance.put(fd, String.valueOf(index)); |
| 167 | + } |
| 168 | + return internalInstance; |
| 169 | + }); |
| 170 | + instance.release(); |
| 171 | + Assertions.assertEquals(987654321, instanceRelease.get()); |
| 172 | + } |
| 173 | + |
143 | 174 | /** |
144 | 175 | * Test request scope inhabitant. |
145 | 176 | */ |
|
0 commit comments