patsonluk commented on code in PR #1460: URL: https://github.com/apache/solr/pull/1460#discussion_r1334779855
########## solr/solrj/src/java/org/apache/solr/common/util/CommonTestInjection.java: ########## @@ -129,15 +111,61 @@ public static boolean injectBreakpoint(String key, Object... args) { log.info("Breakpoint with key {} is triggered", key); breakpoint.executeAndResume(args); log.info("Breakpoint with key {} was executed and normal code execution resumes", key); + } else { + log.info( + "Breakpoint with key {} is triggered but there's no implementation set. Skipping...", + key); } return true; } public interface Breakpoint { /** * Code execution should break at where the breakpoint was injected, then it would execute this - * method and resumes the execution afterwards. + * method and resumes the execution afterward. */ void executeAndResume(Object... args); } + + /** + * Breakpoints should be set via this {@link BreakpointSetter} within the test case and close + * should be invoked as cleanup. Since this is closeable, it should usually be used in the + * try-with-resource syntax, such as: + * + * <pre>{@code + * try (BreakpointSetter breakpointSetter = new BreakpointSetter() { + * //... test code here that calls breakpointSetter.setImplementation(...) + * } + * }</pre> + */ + public static class BreakpointSetter implements Closeable { + private Set<String> keys = new HashSet<>(); + /** + * This is usually set by the test cases. + * + * <p>If a breakpoint implementation is set by this method, then code execution would break at + * the code execution point marked by CommonTestInjection#injectBreakpoint with matching key, + * executes the provided implementation in the {@link Breakpoint}, then resumes the normal code + * execution. + * + * @see CommonTestInjection#injectBreakpoint(String, Object...) + * @param key could simply be the fully qualified class name or more granular like class name + + * other id (such as method name). This should batch the key used in injectBreakpoint + * @param implementation The Breakpoint implementation + */ + public void setImplementation(String key, Breakpoint implementation) { + if (breakpoints.containsKey(key)) { + throw new IllegalArgumentException( + "Cannot refine Breakpoint implementation with key " + key); Review Comment: ahh was a typo, supposed to be "redefine" -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org