-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Make sure Graal picks up service providers by itself. - Use more sensical packages.
- Loading branch information
Showing
19 changed files
with
370 additions
and
67 deletions.
There are no files selected for viewing
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
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,40 @@ | ||
plugins { | ||
id("conventions.java-library") | ||
id("conventions.static-analysis") | ||
id("conventions.testing") | ||
id("conventions.coverage") | ||
id("org.graalvm.buildtools.native") version "0.10.1" | ||
} | ||
|
||
dependencies { | ||
implementation(project(":methanol")) | ||
implementation(project(":methanol-jackson")) | ||
implementation(project(":methanol-testing")) | ||
implementation(libs.jackson.databind) | ||
implementation(libs.mockwebserver) | ||
implementation(libs.autoservice.annotations) | ||
annotationProcessor(libs.autoservice.annprocess) | ||
} | ||
|
||
graalvmNative { | ||
agent { | ||
binaries { | ||
named("main") { | ||
// For debuggability. | ||
buildArgs("-H:+ReportExceptionStackTraces") | ||
} | ||
|
||
named("test") { | ||
// Okhttp accesses internal GraalVM APIs. | ||
buildArgs( | ||
"-J--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.configure=ALL-UNNAMED" | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Always run native tests. | ||
tasks.named("check") { | ||
dependsOn(tasks.named("nativeTest")) | ||
} |
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
65 changes: 65 additions & 0 deletions
65
...e-test/src/test/java/com/github/mizosoft/methanol/nativeimage/test/PointPingPongTest.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,65 @@ | ||
/* | ||
* Copyright (c) 2024 Moataz Abdelnasser | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package com.github.mizosoft.methanol.nativeimage.test; | ||
|
||
import static com.github.mizosoft.methanol.testing.verifiers.Verifiers.verifyThat; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.github.mizosoft.methanol.MediaType; | ||
import com.github.mizosoft.methanol.Methanol; | ||
import com.github.mizosoft.methanol.MutableRequest; | ||
import com.github.mizosoft.methanol.testing.MockWebServerExtension; | ||
import mockwebserver3.Dispatcher; | ||
import mockwebserver3.MockResponse; | ||
import mockwebserver3.MockWebServer; | ||
import mockwebserver3.RecordedRequest; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
@ExtendWith(MockWebServerExtension.class) | ||
class PointPingPongTest { | ||
@Test | ||
void pointPingPong(MockWebServer server) throws Exception { | ||
server.setDispatcher( | ||
new Dispatcher() { | ||
@NotNull | ||
@Override | ||
public MockResponse dispatch(@NotNull RecordedRequest recordedRequest) { | ||
var contentType = recordedRequest.getHeader("Content-Type"); | ||
assertThat(contentType).isNotNull(); | ||
return new MockResponse() | ||
.setHeader("Content-Type", contentType) | ||
.setBody(recordedRequest.getBody()); | ||
} | ||
}); | ||
|
||
var client = Methanol.create(); | ||
verifyThat( | ||
client.send( | ||
MutableRequest.POST( | ||
server.url("/").uri(), new Point(1, 2), MediaType.APPLICATION_JSON), | ||
Point.class)) | ||
.hasBody(new Point(1, 2)); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...rc/test/java/com/github/mizosoft/methanol/nativeimage/test/ServiceProviderLookupTest.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,44 @@ | ||
/* | ||
* Copyright (c) 2024 Moataz Abdelnasser | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package com.github.mizosoft.methanol.nativeimage.test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.github.mizosoft.methanol.BodyAdapter; | ||
import com.github.mizosoft.methanol.BodyDecoder; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ServiceProviderLookupTest { | ||
@Test | ||
void bodyDecoderServiceProvidersAreAccessible() { | ||
assertThat(BodyDecoder.Factory.installedBindings().keySet()).contains("gzip", "deflate"); | ||
} | ||
|
||
@Test | ||
void bodyAdapterServiceProvidersAreAccessible() { | ||
assertThat(BodyAdapter.Encoder.installed()) | ||
.anyMatch(encoder -> encoder.getClass().equals(JacksonAdapters.JacksonEncoder.class)); | ||
assertThat(BodyAdapter.Decoder.installed()) | ||
.anyMatch(encoder -> encoder.getClass().equals(JacksonAdapters.JacksonDecoder.class)); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
native-test/src/test/resources/META-INF/native-image/reflect-config.json
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,31 @@ | ||
[ | ||
{ | ||
"name": "com.github.mizosoft.methanol.testing.MockWebServerExtension$ManagedServers", | ||
"methods": [ | ||
{ | ||
"name": "<init>", | ||
"parameterTypes": [] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "com.github.mizosoft.methanol.nativeimage.test.Point", | ||
"fields": [ | ||
{ | ||
"name": "x" | ||
}, | ||
{ | ||
"name": "y" | ||
} | ||
], | ||
"methods": [ | ||
{ | ||
"name": "<init>", | ||
"parameterTypes": [ | ||
"int", | ||
"int" | ||
] | ||
} | ||
] | ||
} | ||
] |
50 changes: 50 additions & 0 deletions
50
.../src/main/java/com/github/mizosoft/methanol/quarkus/nativeimage/test/JacksonAdapters.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,50 @@ | ||
/* | ||
* Copyright (c) 2024 Moataz Abdelnasser | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package com.github.mizosoft.methanol.quarkus.nativeimage.test; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.github.mizosoft.methanol.BodyAdapter; | ||
import com.github.mizosoft.methanol.adapter.ForwardingDecoder; | ||
import com.github.mizosoft.methanol.adapter.ForwardingEncoder; | ||
import com.github.mizosoft.methanol.adapter.jackson.JacksonAdapterFactory; | ||
import com.google.auto.service.AutoService; | ||
|
||
public class JacksonAdapters { | ||
private static final ObjectMapper mapper = new ObjectMapper(); | ||
|
||
private JacksonAdapters() {} | ||
|
||
@AutoService(BodyAdapter.Encoder.class) | ||
public static class JacksonEncoder extends ForwardingEncoder { | ||
public JacksonEncoder() { | ||
super(JacksonAdapterFactory.createJsonEncoder(mapper)); | ||
} | ||
} | ||
|
||
@AutoService(BodyAdapter.Decoder.class) | ||
public static class JacksonDecoder extends ForwardingDecoder { | ||
public JacksonDecoder() { | ||
super(JacksonAdapterFactory.createJsonDecoder(mapper)); | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...ative-test/src/main/java/com/github/mizosoft/methanol/quarkus/nativeimage/test/Point.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,56 @@ | ||
/* | ||
* Copyright (c) 2024 Moataz Abdelnasser | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package com.github.mizosoft.methanol.quarkus.nativeimage.test; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.util.Objects; | ||
|
||
public final class Point { | ||
public final int x; | ||
public final int y; | ||
|
||
@JsonCreator | ||
public Point(@JsonProperty("x") int x, @JsonProperty("y") int y) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof Point)) return false; | ||
|
||
var that = (Point) obj; | ||
return this.x == that.x && this.y == that.y; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(x, y); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Point(" + "x=" + x + ", " + "y=" + y + ")"; | ||
} | ||
} |
Oops, something went wrong.