Package org.apache.solr.common.util

## Class CommonTestInjection

- java.lang.Object
- - org.apache.solr.common.util.CommonTestInjection

    public class CommonTestInjection
    extends Object

Allows random faults to be injected in running code during test runs across all solr packages.

NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

### Nested Class Summary

Nested Classes
`static interface` `CommonTestInjection.Breakpoint`
`static class` `CommonTestInjection.BreakpointSetter` Breakpoints should be set via this `CommonTestInjection.BreakpointSetter` within the test case and close should be invoked as cleanup.

### Constructor Summary

Constructors
`CommonTestInjection()`

### Method Summary

All Methods Static Methods Concrete Methods
`static Map<String,​String>` `injectAdditionalProps()`
`static boolean` `injectBreakpoint​(String key, Object... args)` Injects a breakpoint that pauses the existing code execution, executes the code defined in the breakpoint implementation and then resumes afterward.
`static boolean` `injectDelay()` Inject an artificial delay(sleep) into the code
`static void` `reset()`
`static void` `setAdditionalProps​(Map<String,​String> additionalSystemProps)`
`static void` `setDelay​(Integer delay)` Set test delay (sleep) in unit of milliseconds

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### CommonTestInjection

    public CommonTestInjection()

### Method Detail

#### reset

    public static void reset()

#### setAdditionalProps

    public static void setAdditionalProps​(Map<String,​String> additionalSystemProps)

#### injectAdditionalProps

    public static Map<String,​String> injectAdditionalProps()

#### setDelay

    public static void setDelay​(Integer delay)

Set test delay (sleep) in unit of milliseconds

Parameters:
  `delay` - delay in milliseconds, null to remove such delay

#### injectDelay

    public static boolean injectDelay()

Inject an artificial delay(sleep) into the code

Returns:
  true

#### injectBreakpoint

    public static boolean injectBreakpoint​(String key,
                                           Object... args)

Injects a breakpoint that pauses the existing code execution, executes the code defined in the breakpoint implementation and then resumes afterward. The breakpoint implementation is looked up by the corresponding key used in `CommonTestInjection.BreakpointSetter.setImplementation(String, Breakpoint)`

An example usages :

1. Inject a precise wait until a race condition is fulfilled before proceeding with original code execution
2. Inject a flag to catch exception statement which handles the exception without re-throwing. This could verify caught exception does get triggered

This should always be a part of an assert statement (ie assert injectBreakpoint(key)) such that it will be skipped for normal code execution

Parameters:
  `key` - could simply be the fully qualified class name or more granular like class name + other id (such as method name). This should only be set by corresponding unit test cases with CommonTestInjection#setBreakpoint
  `args` - optional arguments list to be passed to the Breakpoint
See Also:
  `CommonTestInjection.BreakpointSetter.setImplementation(String, Breakpoint)`