@InterfaceAudience.Private public class EnvironmentEdgeManager extends Object
EnvironmentEdge
, then
defer to the delegate on invocation.
EnvironmentEdgeManager
).
The idea is to have a central place where time can be assigned in HBase. That makes
it easier to inject different implementations of time. The default environment edge is the Java
Current Time in millis. The environment edge manager class is designed to be able
to plug in a new implementation of time by simply injecting an implementation
of EnvironmentEdge
interface to
EnvironmentEdgeManager
Problems with Environment Edge:
1. One of the major problems is the side effects of injecting an Environment Edge into
Environment Edge Manager.
For example, A test could inject an edge to fast forward time in order to avoid thread
sleep to save time, but it could trigger a premature waking up of another thread waiting
on a condition dependent on time lapse, which could potentially affect the normal
working of the system leading to failure of tests.
2. Every test should ensure it is setting the Environment Edge it needs for the test to
perform in an expected way. Because another test which might have run before the current test
could have injected its own custom Environment Edge which may not be applicable to this
test. This is still solvable but the problem is that the tests can run in parallel
leading to different combinations of environment edges being injected causing unexpected
results.
3. Another important issue with respect to injecting time through Environment Edge is that
the milliseconds unit of time is ingrained throughout the codebase in the form of hardcoded
sleep time or timeouts that any change of time unit or making it fast or slow can potentially
trigger unexpected failures due to timeout or unintended flow of execution.
DefaultEnvironmentEdge
is being used, whose implementation of time returns the System.currentTimeMillis()
. It
is advised not to inject any other EnvironmentEdge
.Modifier and Type | Field and Description |
---|---|
private static EnvironmentEdge |
delegate |
Modifier | Constructor and Description |
---|---|
private |
EnvironmentEdgeManager() |
Modifier and Type | Method and Description |
---|---|
static long |
currentTime()
Defers to the delegate and calls the
EnvironmentEdge.currentTime() method. |
static EnvironmentEdge |
getDelegate()
Retrieves the singleton instance of the
EnvironmentEdge that is
being managed. |
static void |
injectEdge(EnvironmentEdge edge)
Injects the given edge such that it becomes the managed entity.
|
static void |
reset()
Resets the managed instance to the default instance:
DefaultEnvironmentEdge . |
private static volatile EnvironmentEdge delegate
private EnvironmentEdgeManager()
public static EnvironmentEdge getDelegate()
EnvironmentEdge
that is
being managed.public static void reset()
DefaultEnvironmentEdge
.public static void injectEdge(EnvironmentEdge edge)
edge
- the new edge.public static long currentTime()
EnvironmentEdge.currentTime()
method.Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.