This is an automated email from the ASF dual-hosted git repository. aldettinger pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push: new ef4b836 leveldb: remove useless substitutions in favor of graalvm built-in MethodHandles support #1908 ef4b836 is described below commit ef4b836df511f3971515e66a1ae0cb7f98a8b1c9 Author: aldettinger <aldettin...@gmail.com> AuthorDate: Wed Aug 4 11:13:06 2021 +0200 leveldb: remove useless substitutions in favor of graalvm built-in MethodHandles support #1908 --- extensions/leveldb/runtime/pom.xml | 5 -- .../component/leveldb/MMapLogWriterSubstitute.java | 40 ------------- .../component/leveldb/MMapTableSubstitute.java | 68 --------------------- .../leveldb/OriginalByteBufferSupport.java | 69 ---------------------- .../component/leveldb/it/LeveldbResource.java | 6 +- .../component/leveldb/it/LeveldbRouteBuilder.java | 2 +- .../quarkus/component/leveldb/it/LeveldbTest.java | 8 +-- 7 files changed, 5 insertions(+), 193 deletions(-) diff --git a/extensions/leveldb/runtime/pom.xml b/extensions/leveldb/runtime/pom.xml index 58acfee..5620a82 100644 --- a/extensions/leveldb/runtime/pom.xml +++ b/extensions/leveldb/runtime/pom.xml @@ -70,11 +70,6 @@ <groupId>io.quarkus</groupId> <artifactId>quarkus-jackson</artifactId> </dependency> - <dependency> - <groupId>org.graalvm.nativeimage</groupId> - <artifactId>svm</artifactId> - <scope>provided</scope> - </dependency> </dependencies> <build> diff --git a/extensions/leveldb/runtime/src/main/java/org/apache/camel/quarkus/component/leveldb/MMapLogWriterSubstitute.java b/extensions/leveldb/runtime/src/main/java/org/apache/camel/quarkus/component/leveldb/MMapLogWriterSubstitute.java deleted file mode 100644 index 5fefa9e..0000000 --- a/extensions/leveldb/runtime/src/main/java/org/apache/camel/quarkus/component/leveldb/MMapLogWriterSubstitute.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.camel.quarkus.component.leveldb; - -import java.nio.MappedByteBuffer; - -import com.oracle.svm.core.annotate.Alias; -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import org.iq80.leveldb.impl.MMapLogWriter; - -/** - * Workaround for https://github.com/oracle/graal/issues/2761 - * (see OriginalByteBufferSupport for more information) - */ -@TargetClass(value = MMapLogWriter.class) -final class MMapLogWriterSubstitute { - - @Alias - private MappedByteBuffer mappedByteBuffer; - - @Substitute - private void unmap() { - OriginalByteBufferSupport.unmap(mappedByteBuffer); - } -} diff --git a/extensions/leveldb/runtime/src/main/java/org/apache/camel/quarkus/component/leveldb/MMapTableSubstitute.java b/extensions/leveldb/runtime/src/main/java/org/apache/camel/quarkus/component/leveldb/MMapTableSubstitute.java deleted file mode 100644 index 3e3882a..0000000 --- a/extensions/leveldb/runtime/src/main/java/org/apache/camel/quarkus/component/leveldb/MMapTableSubstitute.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.camel.quarkus.component.leveldb; - -import java.io.Closeable; -import java.nio.MappedByteBuffer; -import java.nio.channels.FileChannel; -import java.util.concurrent.Callable; - -import com.oracle.svm.core.annotate.Alias; -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import org.iq80.leveldb.table.MMapTable; -import org.iq80.leveldb.util.Closeables; - -/** - * Workaround for https://github.com/oracle/graal/issues/2761 - * (see OriginalByteBufferSupport for more information) - */ -@TargetClass(value = MMapTable.class) -final class MMapTableSubstitute { - - @Alias - protected String name; - @Alias - protected FileChannel fileChannel; - @Alias - private MappedByteBuffer data; - - @Substitute - public Callable<?> closer() { - return new Closer(name, fileChannel, data); - } - - private static class Closer - implements Callable<Void> { - private final String name; - private final Closeable closeable; - private final MappedByteBuffer data; - - public Closer(String name, Closeable closeable, MappedByteBuffer data) { - this.name = name; - this.closeable = closeable; - this.data = data; - } - - public Void call() { - OriginalByteBufferSupport.unmap(data); - Closeables.closeQuietly(closeable); - return null; - } - } - -} diff --git a/extensions/leveldb/runtime/src/main/java/org/apache/camel/quarkus/component/leveldb/OriginalByteBufferSupport.java b/extensions/leveldb/runtime/src/main/java/org/apache/camel/quarkus/component/leveldb/OriginalByteBufferSupport.java deleted file mode 100755 index b7ec630..0000000 --- a/extensions/leveldb/runtime/src/main/java/org/apache/camel/quarkus/component/leveldb/OriginalByteBufferSupport.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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.camel.quarkus.component.leveldb; - -import java.lang.reflect.Method; -import java.nio.MappedByteBuffer; - -import com.google.common.base.Throwables; - -/** - * Unmap support was changed because of jdk9+ (see - * https://github.com/dain/leveldb/commit/39b6e0c38045281fba5f6532c52dc06905890cad) - * Current version of levelDB is using MethodHandle, which is not supported by GraalVM (see - * https://github.com/oracle/graal/issues/2761) - * Original way of using Method (instead of MethodHandle) is working in native mode, - * therefore this class contains code from levelDB class `ByteBufferSupport` from the time before mentioned change and - * is used via substitutions. - * Issue https://github.com/apache/camel-quarkus/issues/1908 is reported to remove class once it is possible. - */ -public final class OriginalByteBufferSupport { - private static final Method getCleaner; - private static final Method clean; - - static { - try { - getCleaner = Class.forName("java.nio.DirectByteBuffer").getDeclaredMethod("cleaner"); - getCleaner.setAccessible(true); - } catch (ReflectiveOperationException e) { - throw new AssertionError(e); - } - - try { - Class<?> returnType = getCleaner.getReturnType(); - if (Runnable.class.isAssignableFrom(returnType)) { - clean = Runnable.class.getMethod("run"); - } else { - clean = returnType.getMethod("clean"); - } - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } - } - - private OriginalByteBufferSupport() { - } - - public static void unmap(MappedByteBuffer buffer) { - try { - Object cleaner = getCleaner.invoke(buffer); - clean.invoke(cleaner); - } catch (Exception ignored) { - throw Throwables.propagate(ignored); - } - } -} diff --git a/integration-tests/leveldb/src/main/java/org/apache/camel/quarkus/component/leveldb/it/LeveldbResource.java b/integration-tests/leveldb/src/main/java/org/apache/camel/quarkus/component/leveldb/it/LeveldbResource.java index 6f2199a..d327bb0 100644 --- a/integration-tests/leveldb/src/main/java/org/apache/camel/quarkus/component/leveldb/it/LeveldbResource.java +++ b/integration-tests/leveldb/src/main/java/org/apache/camel/quarkus/component/leveldb/it/LeveldbResource.java @@ -79,9 +79,9 @@ public class LeveldbResource { producerTemplate.sendBodyAndHeader(path, message, "id", 123); } - mocks[0].assertIsSatisfied(context, 30, TimeUnit.SECONDS); + MockEndpoint.assertIsSatisfied(context, 30, TimeUnit.SECONDS); - Map<String, List<Map<String, Object>>> data = new HashMap(); + Map<String, List<Map<String, Object>>> data = new HashMap<>(); for (int i = 0; i < mocks.length; i++) { data.put(mockNamesArray[i], extractDataFromMock(mocks[i])); } @@ -111,7 +111,7 @@ public class LeveldbResource { } } - mockResult.assertIsSatisfied(context, 30, TimeUnit.SECONDS); + MockEndpoint.assertIsSatisfied(context, 30, TimeUnit.SECONDS); byte[] result = mockResult.getExchanges().get(0).getIn().getBody(byte[].class); diff --git a/integration-tests/leveldb/src/main/java/org/apache/camel/quarkus/component/leveldb/it/LeveldbRouteBuilder.java b/integration-tests/leveldb/src/main/java/org/apache/camel/quarkus/component/leveldb/it/LeveldbRouteBuilder.java index a5f7b8b..00d580f 100644 --- a/integration-tests/leveldb/src/main/java/org/apache/camel/quarkus/component/leveldb/it/LeveldbRouteBuilder.java +++ b/integration-tests/leveldb/src/main/java/org/apache/camel/quarkus/component/leveldb/it/LeveldbRouteBuilder.java @@ -39,7 +39,7 @@ public class LeveldbRouteBuilder extends RouteBuilder { private static AtomicInteger counter = new AtomicInteger(0); @Override - public void configure() throws Exception { + public void configure() { LevelDBAggregationRepository repo = new QuarkusLevelDBAggregationRepository("repo", DATA_FOLDER + "leveldb.dat"); from(DIRECT_START) diff --git a/integration-tests/leveldb/src/test/java/org/apache/camel/quarkus/component/leveldb/it/LeveldbTest.java b/integration-tests/leveldb/src/test/java/org/apache/camel/quarkus/component/leveldb/it/LeveldbTest.java index 3d473b8..cdb9f3a 100644 --- a/integration-tests/leveldb/src/test/java/org/apache/camel/quarkus/component/leveldb/it/LeveldbTest.java +++ b/integration-tests/leveldb/src/test/java/org/apache/camel/quarkus/component/leveldb/it/LeveldbTest.java @@ -91,7 +91,7 @@ class LeveldbTest { } @Test - public void testBinaryData() throws Exception { + public void testBinaryData() { boolean theSame = RestAssured.given() .contentType(ContentType.JSON) @@ -130,12 +130,6 @@ class LeveldbTest { FileUtils.deleteDirectory(data); } - private byte[] readQuarkusFile(String fileName) throws Exception { - try (InputStream is = getClass().getClassLoader().getResourceAsStream(fileName)) { - return readBytes(is); - } - } - static byte[] readBytes(InputStream is) throws Exception { ByteArrayOutputStream os = new ByteArrayOutputStream(); byte[] buffer = new byte[4096];