Skip to content

Commit

Permalink
chore:add runtime hints for sample test.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhumin8 committed Jun 12, 2023
1 parent 61182eb commit 2b7eb8a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.context.annotation.ImportRuntimeHints;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
Expand All @@ -52,6 +53,7 @@
@SpringBootTest(
webEnvironment = WebEnvironment.RANDOM_PORT,
classes = {Application.class})
@ImportRuntimeHints(TestRuntimeHints.class)
class LoggingSampleApplicationIntegrationTests {

private static final String LOG_FILTER_FORMAT =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2023 Google LLC
*
* Licensed 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
*
* https://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 com.example;

import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.core.ConsoleAppender;
import java.util.Arrays;
import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.TypeReference;

/** Runtime Hints for GraalVM Native Images * */
public class TestRuntimeHints implements RuntimeHintsRegistrar {
@Override
public void registerHints(
org.springframework.aot.hint.RuntimeHints hints, ClassLoader classLoader) {
hints
.reflection()
.registerTypes(
Arrays.asList(
TypeReference.of(ConsoleAppender.class),
TypeReference.of(PatternLayoutEncoder.class)),
hint ->
hint.withMembers(
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
MemberCategory.INVOKE_PUBLIC_METHODS));
hints.resources().registerPattern("logback-test.xml");
hints.resources().registerPattern("com/google/cloud/spring/logging/logback-appender.xml");
}
}

0 comments on commit 2b7eb8a

Please sign in to comment.