forked from eclipse-ee4j/jersey
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix memory leak when client does not use HK2
Signed-off-by: jansupol <jan.supol@oracle.com>
- Loading branch information
Showing
7 changed files
with
628 additions
and
99 deletions.
There are no files selected for viewing
253 changes: 162 additions & 91 deletions
253
core-client/src/main/java/org/glassfish/jersey/client/innate/inject/NonInjectionManager.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved. | ||
This program and the accompanying materials are made available under the | ||
terms of the Eclipse Public License v. 2.0, which is available at | ||
http://www.eclipse.org/legal/epl-2.0. | ||
This Source Code may also be made available under the following Secondary | ||
Licenses when the conditions for such availability set forth in the | ||
Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
version 2 with the GNU Classpath Exception, which is available at | ||
https://www.gnu.org/software/classpath/license.html. | ||
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>e2e-inject</artifactId> | ||
<groupId>org.glassfish.jersey.tests</groupId> | ||
<version>2.46-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>e2e-inject-noninject</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.incubator</groupId> | ||
<artifactId>jersey-injectless-client</artifactId> | ||
<version>2.46-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.core</groupId> | ||
<artifactId>jersey-client</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</project> |
98 changes: 98 additions & 0 deletions
98
...nject/src/test/org/glassfish/jersey/tests/e2e/inject/noninject/DisposableSuplierTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.jersey.tests.e2e.inject.noninject; | ||
|
||
import org.glassfish.jersey.internal.inject.AbstractBinder; | ||
import org.glassfish.jersey.internal.inject.DisposableSupplier; | ||
import org.glassfish.jersey.process.internal.RequestScoped; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.ClientBuilder; | ||
import javax.ws.rs.client.ClientRequestContext; | ||
import javax.ws.rs.client.ClientRequestFilter; | ||
import javax.ws.rs.core.Response; | ||
import java.io.IOException; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class DisposableSuplierTest { | ||
private static final AtomicInteger disposeCounter = new AtomicInteger(0); | ||
private static final String HOST = "http://somewhere.anywhere"; | ||
|
||
public interface ResponseObject { | ||
Response getResponse(); | ||
} | ||
|
||
private static class TestDisposableSupplier implements DisposableSupplier<ResponseObject> { | ||
AtomicInteger counter = new AtomicInteger(300); | ||
|
||
@Override | ||
public void dispose(ResponseObject instance) { | ||
disposeCounter.incrementAndGet(); | ||
} | ||
|
||
@Override | ||
public ResponseObject get() { | ||
return new ResponseObject() { | ||
|
||
@Override | ||
public Response getResponse() { | ||
return Response.ok().build(); | ||
} | ||
}; | ||
} | ||
} | ||
|
||
private static class DisposableSupplierInjectingFilter implements ClientRequestFilter { | ||
private final ResponseObject responseSupplier; | ||
|
||
@Inject | ||
private DisposableSupplierInjectingFilter(ResponseObject responseSupplier) { | ||
this.responseSupplier = responseSupplier; | ||
} | ||
|
||
@Override | ||
public void filter(ClientRequestContext requestContext) throws IOException { | ||
requestContext.abortWith(responseSupplier.getResponse()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testDisposeCount() { | ||
disposeCounter.set(0); | ||
int CNT = 4; | ||
Client client = ClientBuilder.newClient() | ||
.register(new AbstractBinder() { | ||
@Override | ||
protected void configure() { | ||
bindFactory(TestDisposableSupplier.class).to(ResponseObject.class) | ||
.proxy(true).proxyForSameScope(false).in(RequestScoped.class); | ||
} | ||
}).register(DisposableSupplierInjectingFilter.class); | ||
|
||
for (int i = 0; i != CNT; i++) { | ||
try (Response response = client.target(HOST).request().get()) { | ||
MatcherAssert.assertThat(response.getStatus(), Matchers.is(200)); | ||
} | ||
} | ||
|
||
MatcherAssert.assertThat(disposeCounter.get(), Matchers.is(CNT)); | ||
} | ||
} |
Oops, something went wrong.