target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public void fromString1440m() { String s = "metrics_1440m"; Granularity gran = Granularity.fromString(s); Assert.assertNotNull(gran); Assert.assertSame(Granularity.MIN_1440, gran); } | public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void maxTimeRetryOnUnavailable_shouldRethrow() throws Exception { RetryNTimes retryPolicy = new RetryNTimes(3, 3, 3); Statement mockStatement = mock( Statement.class ); RetryPolicy.RetryDecision retryResult = retryPolicy.onUnavailable(mockStatement, ConsistencyLevel.LOCAL_ONE, 1, 0, 3); RetryPolicy.RetryDecision retryExpected = RetryPolicy.RetryDecision.rethrow(); assertRetryDecisionEquals(retryExpected, retryResult); } | @Override public RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl, int requiredResponses, int receivedResponses, int uTime) { if (uTime < unavailableAttempts) { LOG.info(String.format("Retrying on unavailable: stmnt %s, consistency %s, " + "requiredResponse %d, receivedResponse %d, rTime %d", stmnt, cl, requiredResponses, receivedResponses, uTime)); return RetryDecision.retry(ConsistencyLevel.ONE); } return RetryDecision.rethrow(); } | RetryNTimes implements RetryPolicy { @Override public RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl, int requiredResponses, int receivedResponses, int uTime) { if (uTime < unavailableAttempts) { LOG.info(String.format("Retrying on unavailable: stmnt %s, consistency %s, " + "requiredResponse %d, receivedResponse %d, rTime %d", stmnt, cl, requiredResponses, receivedResponses, uTime)); return RetryDecision.retry(ConsistencyLevel.ONE); } return RetryDecision.rethrow(); } } | RetryNTimes implements RetryPolicy { @Override public RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl, int requiredResponses, int receivedResponses, int uTime) { if (uTime < unavailableAttempts) { LOG.info(String.format("Retrying on unavailable: stmnt %s, consistency %s, " + "requiredResponse %d, receivedResponse %d, rTime %d", stmnt, cl, requiredResponses, receivedResponses, uTime)); return RetryDecision.retry(ConsistencyLevel.ONE); } return RetryDecision.rethrow(); } RetryNTimes(int readAttempts, int writeAttempts, int unavailableAttempts); } | RetryNTimes implements RetryPolicy { @Override public RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl, int requiredResponses, int receivedResponses, int uTime) { if (uTime < unavailableAttempts) { LOG.info(String.format("Retrying on unavailable: stmnt %s, consistency %s, " + "requiredResponse %d, receivedResponse %d, rTime %d", stmnt, cl, requiredResponses, receivedResponses, uTime)); return RetryDecision.retry(ConsistencyLevel.ONE); } return RetryDecision.rethrow(); } RetryNTimes(int readAttempts, int writeAttempts, int unavailableAttempts); @Override RetryDecision onReadTimeout(Statement stmnt, ConsistencyLevel cl,
int requiredResponses, int receivedResponses,
boolean dataReceived, int rTime); @Override RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl,
WriteType wt, int requiredResponses,
int receivedResponses, int wTime); @Override RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl,
int requiredResponses, int receivedResponses, int uTime); @Override RetryDecision onRequestError(Statement statement, ConsistencyLevel cl, DriverException e, int nbRetry); @Override void init(Cluster cluster); @Override void close(); } | RetryNTimes implements RetryPolicy { @Override public RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl, int requiredResponses, int receivedResponses, int uTime) { if (uTime < unavailableAttempts) { LOG.info(String.format("Retrying on unavailable: stmnt %s, consistency %s, " + "requiredResponse %d, receivedResponse %d, rTime %d", stmnt, cl, requiredResponses, receivedResponses, uTime)); return RetryDecision.retry(ConsistencyLevel.ONE); } return RetryDecision.rethrow(); } RetryNTimes(int readAttempts, int writeAttempts, int unavailableAttempts); @Override RetryDecision onReadTimeout(Statement stmnt, ConsistencyLevel cl,
int requiredResponses, int receivedResponses,
boolean dataReceived, int rTime); @Override RetryDecision onWriteTimeout(Statement stmnt, ConsistencyLevel cl,
WriteType wt, int requiredResponses,
int receivedResponses, int wTime); @Override RetryDecision onUnavailable(Statement stmnt, ConsistencyLevel cl,
int requiredResponses, int receivedResponses, int uTime); @Override RetryDecision onRequestError(Statement statement, ConsistencyLevel cl, DriverException e, int nbRetry); @Override void init(Cluster cluster); @Override void close(); } |
@Test public void fromStringOtherReturnsNull() { String s = "metrics_1990m"; Granularity gran = Granularity.fromString(s); Assert.assertNull(gran); } | public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void fromStringFullShortName() { String s = "full"; Granularity gran = Granularity.fromString(s); Assert.assertNotNull(gran); Assert.assertSame(Granularity.FULL, gran); } | public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void fromString5mShortName() { String s = "5m"; Granularity gran = Granularity.fromString(s); Assert.assertNotNull(gran); Assert.assertSame(Granularity.MIN_5, gran); } | public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void fromString20mShortName() { String s = "20m"; Granularity gran = Granularity.fromString(s); Assert.assertNotNull(gran); Assert.assertSame(Granularity.MIN_20, gran); } | public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void fromString60mShortName() { String s = "60m"; Granularity gran = Granularity.fromString(s); Assert.assertNotNull(gran); Assert.assertSame(Granularity.MIN_60, gran); } | public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void fromString240mShortName() { String s = "240m"; Granularity gran = Granularity.fromString(s); Assert.assertSame(Granularity.MIN_240, gran); } | public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void fromString1440mShortName() { String s = "1440m"; Granularity gran = Granularity.fromString(s); Assert.assertNotNull(gran); Assert.assertSame(Granularity.MIN_1440, gran); } | public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void fromStringCaseSensitive() { String s = "METRICS_1440M"; Granularity gran = Granularity.fromString(s); Assert.assertNull(gran); } | public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void fromStringNullReturnsNull() { Granularity gran = Granularity.fromString(null); Assert.assertNull(gran); } | public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity fromString(String s) { for (Granularity g : granularities) if (g.name().equals(s) || g.shortName().equals(s)) return g; return null; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void testBadGranularityFromPointsInterval() { try { Granularity.granularityFromPointsInInterval("TENANTID1234",fromBaseMillis+2, fromBaseMillis+1, 3); Assert.fail("Should not have worked"); } catch (RuntimeException e) { Assert.assertEquals("Invalid interval specified for fromPointsInInterval", e.getMessage()); } } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void testCacher() throws Exception { MetricsCollection collection = createTestData(); MetadataCache rollupTypeCache = mock(MetadataCache.class); ThreadPoolExecutor tpe = new ThreadPoolBuilder().withName("rtc test").build(); RollupTypeCacher rollupTypeCacher = new RollupTypeCacher(tpe, rollupTypeCache); rollupTypeCacher.apply(collection); while (tpe.getCompletedTaskCount() < 1) { Thread.sleep(1); } verifyZeroInteractions(rollupTypeCache); } | @Override public Void apply(final MetricsCollection input) throws Exception { getThreadPool().submit(new Runnable() { @Override public void run() { recordWithTimer(input); } }); return null; } | RollupTypeCacher extends FunctionWithThreadPool<MetricsCollection, Void> { @Override public Void apply(final MetricsCollection input) throws Exception { getThreadPool().submit(new Runnable() { @Override public void run() { recordWithTimer(input); } }); return null; } } | RollupTypeCacher extends FunctionWithThreadPool<MetricsCollection, Void> { @Override public Void apply(final MetricsCollection input) throws Exception { getThreadPool().submit(new Runnable() { @Override public void run() { recordWithTimer(input); } }); return null; } RollupTypeCacher(ThreadPoolExecutor executor, MetadataCache cache); } | RollupTypeCacher extends FunctionWithThreadPool<MetricsCollection, Void> { @Override public Void apply(final MetricsCollection input) throws Exception { getThreadPool().submit(new Runnable() { @Override public void run() { recordWithTimer(input); } }); return null; } RollupTypeCacher(ThreadPoolExecutor executor, MetadataCache cache); @Override Void apply(final MetricsCollection input); } | RollupTypeCacher extends FunctionWithThreadPool<MetricsCollection, Void> { @Override public Void apply(final MetricsCollection input) throws Exception { getThreadPool().submit(new Runnable() { @Override public void run() { recordWithTimer(input); } }); return null; } RollupTypeCacher(ThreadPoolExecutor executor, MetadataCache cache); @Override Void apply(final MetricsCollection input); } |
@Test public void coarserGranularitiesAreCoarserThanFinerOnes() { Assert.assertFalse(Granularity.FULL.isCoarser(Granularity.MIN_5)); Assert.assertFalse(Granularity.MIN_5.isCoarser(Granularity.MIN_20)); Assert.assertFalse(Granularity.MIN_20.isCoarser(Granularity.MIN_60)); Assert.assertFalse(Granularity.MIN_60.isCoarser(Granularity.MIN_240)); Assert.assertFalse(Granularity.MIN_240.isCoarser(Granularity.MIN_1440)); Assert.assertFalse(Granularity.FULL.isCoarser(Granularity.MIN_20)); Assert.assertFalse(Granularity.FULL.isCoarser(Granularity.MIN_60)); Assert.assertFalse(Granularity.FULL.isCoarser(Granularity.MIN_240)); Assert.assertFalse(Granularity.FULL.isCoarser(Granularity.MIN_1440)); Assert.assertFalse(Granularity.MIN_5.isCoarser(Granularity.MIN_60)); Assert.assertFalse(Granularity.MIN_5.isCoarser(Granularity.MIN_240)); Assert.assertFalse(Granularity.MIN_5.isCoarser(Granularity.MIN_1440)); Assert.assertFalse(Granularity.MIN_20.isCoarser(Granularity.MIN_240)); Assert.assertFalse(Granularity.MIN_20.isCoarser(Granularity.MIN_1440)); Assert.assertFalse(Granularity.MIN_60.isCoarser(Granularity.MIN_1440)); Assert.assertTrue(Granularity.MIN_5.isCoarser(Granularity.FULL)); Assert.assertTrue(Granularity.MIN_20.isCoarser(Granularity.MIN_5)); Assert.assertTrue(Granularity.MIN_60.isCoarser(Granularity.MIN_20)); Assert.assertTrue(Granularity.MIN_240.isCoarser(Granularity.MIN_60)); Assert.assertTrue(Granularity.MIN_1440.isCoarser(Granularity.MIN_240)); Assert.assertTrue(Granularity.MIN_20.isCoarser(Granularity.FULL)); Assert.assertTrue(Granularity.MIN_60.isCoarser(Granularity.FULL)); Assert.assertTrue(Granularity.MIN_60.isCoarser(Granularity.MIN_5)); Assert.assertTrue(Granularity.MIN_240.isCoarser(Granularity.FULL)); Assert.assertTrue(Granularity.MIN_240.isCoarser(Granularity.MIN_5)); Assert.assertTrue(Granularity.MIN_240.isCoarser(Granularity.MIN_20)); Assert.assertTrue(Granularity.MIN_1440.isCoarser(Granularity.FULL)); Assert.assertTrue(Granularity.MIN_1440.isCoarser(Granularity.MIN_5)); Assert.assertTrue(Granularity.MIN_1440.isCoarser(Granularity.MIN_20)); Assert.assertTrue(Granularity.MIN_1440.isCoarser(Granularity.MIN_60)); Assert.assertFalse(Granularity.FULL.isCoarser(Granularity.FULL)); Assert.assertFalse(Granularity.MIN_5.isCoarser(Granularity.MIN_5)); Assert.assertFalse(Granularity.MIN_20.isCoarser(Granularity.MIN_20)); Assert.assertFalse(Granularity.MIN_60.isCoarser(Granularity.MIN_60)); Assert.assertFalse(Granularity.MIN_240.isCoarser(Granularity.MIN_240)); Assert.assertFalse(Granularity.MIN_1440.isCoarser(Granularity.MIN_1440)); } | public boolean isCoarser(Granularity other) { return indexOf(this) > indexOf(other); } | Granularity { public boolean isCoarser(Granularity other) { return indexOf(this) > indexOf(other); } } | Granularity { public boolean isCoarser(Granularity other) { return indexOf(this) > indexOf(other); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public boolean isCoarser(Granularity other) { return indexOf(this) > indexOf(other); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public boolean isCoarser(Granularity other) { return indexOf(this) > indexOf(other); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test(expected = NullPointerException.class) public void isCoarserWithNullThrowsException() { Assert.assertFalse(Granularity.FULL.isCoarser(null)); } | public boolean isCoarser(Granularity other) { return indexOf(this) > indexOf(other); } | Granularity { public boolean isCoarser(Granularity other) { return indexOf(this) > indexOf(other); } } | Granularity { public boolean isCoarser(Granularity other) { return indexOf(this) > indexOf(other); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public boolean isCoarser(Granularity other) { return indexOf(this) > indexOf(other); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public boolean isCoarser(Granularity other) { return indexOf(this) > indexOf(other); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void snapMillisOnFullReturnsSameValue() { Assert.assertEquals(1234L, Granularity.FULL.snapMillis(1234L)); Assert.assertEquals(1000L, Granularity.FULL.snapMillis(1000L)); Assert.assertEquals(0L, Granularity.FULL.snapMillis(0L)); Assert.assertEquals(1234567L, Granularity.FULL.snapMillis(1234567L)); } | public long snapMillis(long millis) { if (this == FULL) return millis; else return (millis / milliseconds) * milliseconds; } | Granularity { public long snapMillis(long millis) { if (this == FULL) return millis; else return (millis / milliseconds) * milliseconds; } } | Granularity { public long snapMillis(long millis) { if (this == FULL) return millis; else return (millis / milliseconds) * milliseconds; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public long snapMillis(long millis) { if (this == FULL) return millis; else return (millis / milliseconds) * milliseconds; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public long snapMillis(long millis) { if (this == FULL) return millis; else return (millis / milliseconds) * milliseconds; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void snapMillisOnOtherReturnsSnappedValue() { Assert.assertEquals(0L, Granularity.MIN_5.snapMillis(1234L)); Assert.assertEquals(0L, Granularity.MIN_5.snapMillis(1000L)); Assert.assertEquals(0L, Granularity.MIN_5.snapMillis(0L)); Assert.assertEquals(0L, Granularity.MIN_5.snapMillis(299999L)); Assert.assertEquals(300000L, Granularity.MIN_5.snapMillis(300000L)); Assert.assertEquals(300000L, Granularity.MIN_5.snapMillis(300001L)); Assert.assertEquals(1200000L, Granularity.MIN_5.snapMillis(1234567L)); Assert.assertEquals(0L, Granularity.MIN_20.snapMillis(1234L)); Assert.assertEquals(0L, Granularity.MIN_20.snapMillis(1000L)); Assert.assertEquals(0L, Granularity.MIN_20.snapMillis(0L)); Assert.assertEquals(0L, Granularity.MIN_20.snapMillis(1199999L)); Assert.assertEquals(1200000L, Granularity.MIN_20.snapMillis(1200000)); Assert.assertEquals(1200000L, Granularity.MIN_20.snapMillis(1200001L)); Assert.assertEquals(1200000L, Granularity.MIN_20.snapMillis(1234567L)); Assert.assertEquals(0L, Granularity.MIN_60.snapMillis(1234L)); Assert.assertEquals(0L, Granularity.MIN_60.snapMillis(1000L)); Assert.assertEquals(0L, Granularity.MIN_60.snapMillis(0L)); Assert.assertEquals(0L, Granularity.MIN_60.snapMillis(3599999L)); Assert.assertEquals(3600000L, Granularity.MIN_60.snapMillis(3600000L)); Assert.assertEquals(3600000L, Granularity.MIN_60.snapMillis(3600001L)); Assert.assertEquals(122400000L, Granularity.MIN_60.snapMillis(123456789L)); Assert.assertEquals(0L, Granularity.MIN_240.snapMillis(1234L)); Assert.assertEquals(0L, Granularity.MIN_240.snapMillis(1000L)); Assert.assertEquals(0L, Granularity.MIN_240.snapMillis(0L)); Assert.assertEquals(0L, Granularity.MIN_240.snapMillis(14399999L)); Assert.assertEquals(14400000L, Granularity.MIN_240.snapMillis(14400000L)); Assert.assertEquals(14400000L, Granularity.MIN_240.snapMillis(14400001L)); Assert.assertEquals(115200000L, Granularity.MIN_240.snapMillis(123456789L)); Assert.assertEquals(0L, Granularity.MIN_1440.snapMillis(1234L)); Assert.assertEquals(0L, Granularity.MIN_1440.snapMillis(1000L)); Assert.assertEquals(0L, Granularity.MIN_1440.snapMillis(0L)); Assert.assertEquals(0L, Granularity.MIN_1440.snapMillis(86399999L)); Assert.assertEquals(86400000L, Granularity.MIN_1440.snapMillis(86400000L)); Assert.assertEquals(86400000L, Granularity.MIN_1440.snapMillis(86400001L)); Assert.assertEquals(86400000L, Granularity.MIN_1440.snapMillis(123456789L)); } | public long snapMillis(long millis) { if (this == FULL) return millis; else return (millis / milliseconds) * milliseconds; } | Granularity { public long snapMillis(long millis) { if (this == FULL) return millis; else return (millis / milliseconds) * milliseconds; } } | Granularity { public long snapMillis(long millis) { if (this == FULL) return millis; else return (millis / milliseconds) * milliseconds; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public long snapMillis(long millis) { if (this == FULL) return millis; else return (millis / milliseconds) * milliseconds; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public long snapMillis(long millis) { if (this == FULL) return millis; else return (millis / milliseconds) * milliseconds; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void millisToSlotReturnsNumberOfSlotForGivenTime() { Assert.assertEquals(0, Granularity.millisToSlot(0)); Assert.assertEquals(0, Granularity.millisToSlot(1)); Assert.assertEquals(0, Granularity.millisToSlot(299999L)); Assert.assertEquals(1, Granularity.millisToSlot(300000L)); Assert.assertEquals(1, Granularity.millisToSlot(300001L)); Assert.assertEquals(1, Granularity.millisToSlot(599999L)); Assert.assertEquals(2, Granularity.millisToSlot(600000L)); Assert.assertEquals(2, Granularity.millisToSlot(600001L)); Assert.assertEquals(4030, Granularity.millisToSlot(1209299999L)); Assert.assertEquals(4031, Granularity.millisToSlot(1209300000L)); Assert.assertEquals(4031, Granularity.millisToSlot(1209300001L)); Assert.assertEquals(4031, Granularity.millisToSlot(1209599999L)); Assert.assertEquals(0, Granularity.millisToSlot(1209600000L)); } | static int millisToSlot(long millis) { return (int)((millis % (BASE_SLOTS_PER_GRANULARITY * MILLISECONDS_IN_SLOT)) / MILLISECONDS_IN_SLOT); } | Granularity { static int millisToSlot(long millis) { return (int)((millis % (BASE_SLOTS_PER_GRANULARITY * MILLISECONDS_IN_SLOT)) / MILLISECONDS_IN_SLOT); } } | Granularity { static int millisToSlot(long millis) { return (int)((millis % (BASE_SLOTS_PER_GRANULARITY * MILLISECONDS_IN_SLOT)) / MILLISECONDS_IN_SLOT); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { static int millisToSlot(long millis) { return (int)((millis % (BASE_SLOTS_PER_GRANULARITY * MILLISECONDS_IN_SLOT)) / MILLISECONDS_IN_SLOT); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { static int millisToSlot(long millis) { return (int)((millis % (BASE_SLOTS_PER_GRANULARITY * MILLISECONDS_IN_SLOT)) / MILLISECONDS_IN_SLOT); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void millisToSlotWithNegativeReturnsNegative() { Assert.assertEquals(0, Granularity.millisToSlot(-0)); Assert.assertEquals(0, Granularity.millisToSlot(-1)); Assert.assertEquals(0, Granularity.millisToSlot(-299999L)); Assert.assertEquals(-1, Granularity.millisToSlot(-300000L)); Assert.assertEquals(-1, Granularity.millisToSlot(-300001L)); Assert.assertEquals(-1, Granularity.millisToSlot(-599999L)); Assert.assertEquals(-2, Granularity.millisToSlot(-600000L)); Assert.assertEquals(-2, Granularity.millisToSlot(-600001L)); Assert.assertEquals(-4030, Granularity.millisToSlot(-1209299999L)); Assert.assertEquals(-4031, Granularity.millisToSlot(-1209300000L)); Assert.assertEquals(-4031, Granularity.millisToSlot(-1209300001L)); Assert.assertEquals(-4031, Granularity.millisToSlot(-1209599999L)); Assert.assertEquals(0, Granularity.millisToSlot(-1209600000L)); } | static int millisToSlot(long millis) { return (int)((millis % (BASE_SLOTS_PER_GRANULARITY * MILLISECONDS_IN_SLOT)) / MILLISECONDS_IN_SLOT); } | Granularity { static int millisToSlot(long millis) { return (int)((millis % (BASE_SLOTS_PER_GRANULARITY * MILLISECONDS_IN_SLOT)) / MILLISECONDS_IN_SLOT); } } | Granularity { static int millisToSlot(long millis) { return (int)((millis % (BASE_SLOTS_PER_GRANULARITY * MILLISECONDS_IN_SLOT)) / MILLISECONDS_IN_SLOT); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { static int millisToSlot(long millis) { return (int)((millis % (BASE_SLOTS_PER_GRANULARITY * MILLISECONDS_IN_SLOT)) / MILLISECONDS_IN_SLOT); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { static int millisToSlot(long millis) { return (int)((millis % (BASE_SLOTS_PER_GRANULARITY * MILLISECONDS_IN_SLOT)) / MILLISECONDS_IN_SLOT); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void slotReturnsTheSlotNumber() { Assert.assertEquals(0, Granularity.FULL.slot(1234L)); Assert.assertEquals(0, Granularity.FULL.slot(1000L)); Assert.assertEquals(0, Granularity.FULL.slot(0L)); Assert.assertEquals(0, Granularity.FULL.slot(299999L)); Assert.assertEquals(1, Granularity.FULL.slot(300000L)); Assert.assertEquals(1, Granularity.FULL.slot(300001L)); Assert.assertEquals(4, Granularity.FULL.slot(1234567L)); Assert.assertEquals(4031, Granularity.FULL.slot(1209599999L)); Assert.assertEquals(0, Granularity.FULL.slot(1209600000L)); Assert.assertEquals(0, Granularity.FULL.slot(1209600001L)); Assert.assertEquals(0, Granularity.MIN_5.slot(1234L)); Assert.assertEquals(0, Granularity.MIN_5.slot(1000L)); Assert.assertEquals(0, Granularity.MIN_5.slot(0L)); Assert.assertEquals(0, Granularity.MIN_5.slot(299999L)); Assert.assertEquals(1, Granularity.MIN_5.slot(300000L)); Assert.assertEquals(1, Granularity.MIN_5.slot(300001L)); Assert.assertEquals(4, Granularity.MIN_5.slot(1234567L)); Assert.assertEquals(4031, Granularity.MIN_5.slot(1209599999L)); Assert.assertEquals(0, Granularity.MIN_5.slot(1209600000L)); Assert.assertEquals(0, Granularity.MIN_5.slot(1209600001L)); Assert.assertEquals(0, Granularity.MIN_20.slot(1234L)); Assert.assertEquals(0, Granularity.MIN_20.slot(1000L)); Assert.assertEquals(0, Granularity.MIN_20.slot(0L)); Assert.assertEquals(0, Granularity.MIN_20.slot(1199999L)); Assert.assertEquals(1, Granularity.MIN_20.slot(1200000)); Assert.assertEquals(1, Granularity.MIN_20.slot(1200001L)); Assert.assertEquals(1, Granularity.MIN_20.slot(1234567L)); Assert.assertEquals(102, Granularity.MIN_20.slot(123456789L)); Assert.assertEquals(1007, Granularity.MIN_20.slot(1209599999L)); Assert.assertEquals(0, Granularity.MIN_20.slot(1209600000L)); Assert.assertEquals(0, Granularity.MIN_20.slot(1209600001L)); Assert.assertEquals(0, Granularity.MIN_60.slot(1234L)); Assert.assertEquals(0, Granularity.MIN_60.slot(1000L)); Assert.assertEquals(0, Granularity.MIN_60.slot(0L)); Assert.assertEquals(0, Granularity.MIN_60.slot(3599999L)); Assert.assertEquals(1, Granularity.MIN_60.slot(3600000L)); Assert.assertEquals(1, Granularity.MIN_60.slot(3600001L)); Assert.assertEquals(34, Granularity.MIN_60.slot(123456789L)); Assert.assertEquals(69, Granularity.MIN_60.slot(12345678901L)); Assert.assertEquals(335, Granularity.MIN_60.slot(1209599999L)); Assert.assertEquals(0, Granularity.MIN_60.slot(1209600000L)); Assert.assertEquals(0, Granularity.MIN_60.slot(1209600001L)); Assert.assertEquals(0, Granularity.MIN_240.slot(1234L)); Assert.assertEquals(0, Granularity.MIN_240.slot(1000L)); Assert.assertEquals(0, Granularity.MIN_240.slot(0L)); Assert.assertEquals(0, Granularity.MIN_240.slot(14399999L)); Assert.assertEquals(1, Granularity.MIN_240.slot(14400000L)); Assert.assertEquals(1, Granularity.MIN_240.slot(14400001L)); Assert.assertEquals(8, Granularity.MIN_240.slot(123456789L)); Assert.assertEquals(17, Granularity.MIN_240.slot(12345678901L)); Assert.assertEquals(83, Granularity.MIN_240.slot(1209599999L)); Assert.assertEquals(0, Granularity.MIN_240.slot(1209600000L)); Assert.assertEquals(0, Granularity.MIN_240.slot(1209600001L)); Assert.assertEquals(0, Granularity.MIN_1440.slot(1234L)); Assert.assertEquals(0, Granularity.MIN_1440.slot(1000L)); Assert.assertEquals(0, Granularity.MIN_1440.slot(0L)); Assert.assertEquals(0, Granularity.MIN_1440.slot(86399999L)); Assert.assertEquals(1, Granularity.MIN_1440.slot(86400000L)); Assert.assertEquals(1, Granularity.MIN_1440.slot(86400001L)); Assert.assertEquals(2, Granularity.MIN_1440.slot(12345678901L)); Assert.assertEquals(13, Granularity.MIN_1440.slot(1209599999L)); Assert.assertEquals(0, Granularity.MIN_1440.slot(1209600000L)); Assert.assertEquals(0, Granularity.MIN_1440.slot(1209600001L)); } | public int slot(long millis) { int fullSlot = millisToSlot(millis); return (numSlots * fullSlot) / BASE_SLOTS_PER_GRANULARITY; } | Granularity { public int slot(long millis) { int fullSlot = millisToSlot(millis); return (numSlots * fullSlot) / BASE_SLOTS_PER_GRANULARITY; } } | Granularity { public int slot(long millis) { int fullSlot = millisToSlot(millis); return (numSlots * fullSlot) / BASE_SLOTS_PER_GRANULARITY; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public int slot(long millis) { int fullSlot = millisToSlot(millis); return (numSlots * fullSlot) / BASE_SLOTS_PER_GRANULARITY; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public int slot(long millis) { int fullSlot = millisToSlot(millis); return (numSlots * fullSlot) / BASE_SLOTS_PER_GRANULARITY; } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void granFromPointsLinear100PointsBoundaryBetween5And20() { Granularity gran; gran = Granularity.granularityFromPointsInInterval("abc123", 0, 48000000, 100, "LINEAR", 1); Assert.assertSame(Granularity.MIN_5, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 48000001, 100, "LINEAR", 1); Assert.assertSame(Granularity.MIN_20, gran); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void granFromPointsLinear1000PointsBoundaryBetween5And20() { Granularity gran; gran = Granularity.granularityFromPointsInInterval("abc123", 0, 480000000L, 1000, "LINEAR", 1); Assert.assertSame(Granularity.MIN_5, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 480000001L, 1000, "LINEAR", 1); Assert.assertSame(Granularity.MIN_20, gran); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void granFromPointsLinear10000PointsBoundaryBetween5And20() { Granularity gran; gran = Granularity.granularityFromPointsInInterval("abc123", 0, 4800000000L, 10000, "LINEAR", 1); Assert.assertNull(gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 4800000001L, 10000, "LINEAR", 1); Assert.assertNull(gran); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void testCacherDoesCacheRollupTypeForPreAggregatedMetrics() throws Exception { MetricsCollection collection = createPreaggregatedTestMetrics(); MetadataCache rollupTypeCache = mock(MetadataCache.class); ThreadPoolExecutor tpe = new ThreadPoolBuilder().withName("rtc test").build(); RollupTypeCacher rollupTypeCacher = new RollupTypeCacher(tpe, rollupTypeCache); rollupTypeCacher.apply(collection); while (tpe.getCompletedTaskCount() < 1) { Thread.sleep(1); } for (IMetric m : collection.toMetrics()) { verify(rollupTypeCache).put(m.getLocator(), cacheKey, m.getRollupType().toString()); } } | @Override public Void apply(final MetricsCollection input) throws Exception { getThreadPool().submit(new Runnable() { @Override public void run() { recordWithTimer(input); } }); return null; } | RollupTypeCacher extends FunctionWithThreadPool<MetricsCollection, Void> { @Override public Void apply(final MetricsCollection input) throws Exception { getThreadPool().submit(new Runnable() { @Override public void run() { recordWithTimer(input); } }); return null; } } | RollupTypeCacher extends FunctionWithThreadPool<MetricsCollection, Void> { @Override public Void apply(final MetricsCollection input) throws Exception { getThreadPool().submit(new Runnable() { @Override public void run() { recordWithTimer(input); } }); return null; } RollupTypeCacher(ThreadPoolExecutor executor, MetadataCache cache); } | RollupTypeCacher extends FunctionWithThreadPool<MetricsCollection, Void> { @Override public Void apply(final MetricsCollection input) throws Exception { getThreadPool().submit(new Runnable() { @Override public void run() { recordWithTimer(input); } }); return null; } RollupTypeCacher(ThreadPoolExecutor executor, MetadataCache cache); @Override Void apply(final MetricsCollection input); } | RollupTypeCacher extends FunctionWithThreadPool<MetricsCollection, Void> { @Override public Void apply(final MetricsCollection input) throws Exception { getThreadPool().submit(new Runnable() { @Override public void run() { recordWithTimer(input); } }); return null; } RollupTypeCacher(ThreadPoolExecutor executor, MetadataCache cache); @Override Void apply(final MetricsCollection input); } |
@Test public void granFromPointsLinearBoundaryBetween20And60() { Granularity gran; gran = Granularity.granularityFromPointsInInterval("abc123", 0, 18000000, 10, "LINEAR", 1); Assert.assertSame(Granularity.MIN_20, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 18000001, 10, "LINEAR", 1); Assert.assertSame(Granularity.MIN_60, gran); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void granFromPointsLinearBoundaryBetween60And240() { Granularity gran; gran = Granularity.granularityFromPointsInInterval("abc123", 0, 57600000, 10, "LINEAR", 1); Assert.assertSame(Granularity.MIN_60, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 57600001, 10, "LINEAR", 1); Assert.assertSame(Granularity.MIN_240, gran); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void granFromPointsLinearBoundaryBetween240And1440() { Granularity gran; gran = Granularity.granularityFromPointsInInterval("abc123", 0, 246857142, 10, "LINEAR", 1); Assert.assertSame(Granularity.MIN_240, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 246857143, 10, "LINEAR", 1); Assert.assertSame(Granularity.MIN_240, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 259199999, 10, "LINEAR", 1); Assert.assertSame(Granularity.MIN_240, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 259200000, 10, "LINEAR", 1); Assert.assertSame(Granularity.MIN_1440, gran); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test(expected = RuntimeException.class) public void granFromPointsWithFromGreaterThanToThrowsException() { Granularity gran = Granularity.granularityFromPointsInInterval("abc123", 10, 5, 10, "LINEAR", 1); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test(expected = RuntimeException.class) public void granFromPointsWithFromEqualToThrowsException() { Granularity gran = Granularity.granularityFromPointsInInterval("abc123", 10, 10, 10, "LINEAR", 1); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void granFromPointsLessThanEqual100PointsBoundaryBetween5And20() { Granularity gran; gran = Granularity.granularityFromPointsInInterval("abc123", 0, 30000000, 100, "LESSTHANEQUAL", 1); Assert.assertSame(Granularity.MIN_5, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 30000001, 100, "LESSTHANEQUAL", 1); Assert.assertSame(Granularity.MIN_20, gran); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void granFromPointsLessThanEqual1000PointsBoundaryBetween5And20() { Granularity gran; gran = Granularity.granularityFromPointsInInterval("abc123", 0, 300000000L, 1000, "LESSTHANEQUAL", 1); Assert.assertSame(Granularity.MIN_5, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 300000001L, 1000, "LESSTHANEQUAL", 1); Assert.assertSame(Granularity.MIN_20, gran); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test(expected = NullPointerException.class) public void granFromPointsLessThanEqual10000PointsBoundaryBetween5And20() { Granularity gran; gran = Granularity.granularityFromPointsInInterval("abc123", 0, 3000000000L, 10000, "LESSTHANEQUAL", 1); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void granFromPointsLessThanEqualBoundaryBetween20And60() { Granularity gran; gran = Granularity.granularityFromPointsInInterval("abc123", 0, 12000000, 10, "LESSTHANEQUAL", 1); Assert.assertSame(Granularity.MIN_20, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 12000001, 10, "LESSTHANEQUAL", 1); Assert.assertSame(Granularity.MIN_60, gran); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void granFromPointsLessThanEqualBoundaryBetween60And240() { Granularity gran; gran = Granularity.granularityFromPointsInInterval("abc123", 0, 36000000, 10, "LESSTHANEQUAL", 1); Assert.assertSame(Granularity.MIN_60, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 36000001, 10, "LESSTHANEQUAL", 1); Assert.assertSame(Granularity.MIN_240, gran); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void test() throws Exception { MetricsCollection collection = createTestData(); IncomingMetricMetadataAnalyzer metricMetadataAnalyzer = mock(IncomingMetricMetadataAnalyzer.class); ThreadPoolExecutor tpe = new ThreadPoolBuilder().withName("rtc test").build(); TypeAndUnitProcessor typeAndUnitProcessor = new TypeAndUnitProcessor( tpe, metricMetadataAnalyzer); typeAndUnitProcessor.apply(collection); while (tpe.getCompletedTaskCount() < 1) { Thread.sleep(1); } verify(metricMetadataAnalyzer).scanMetrics(collection.toMetrics()); } | @Override public Void apply(final MetricsCollection input) throws Exception { getThreadPool().submit(new Callable<MetricsCollection>() { public MetricsCollection call() throws Exception { Collection<IncomingMetricException> problems = metricMetadataAnalyzer.scanMetrics(input.toMetrics()); for (IncomingMetricException problem : problems) getLogger().warn(problem.getMessage()); return input; } }); return null; } | TypeAndUnitProcessor extends FunctionWithThreadPool<MetricsCollection, Void> { @Override public Void apply(final MetricsCollection input) throws Exception { getThreadPool().submit(new Callable<MetricsCollection>() { public MetricsCollection call() throws Exception { Collection<IncomingMetricException> problems = metricMetadataAnalyzer.scanMetrics(input.toMetrics()); for (IncomingMetricException problem : problems) getLogger().warn(problem.getMessage()); return input; } }); return null; } } | TypeAndUnitProcessor extends FunctionWithThreadPool<MetricsCollection, Void> { @Override public Void apply(final MetricsCollection input) throws Exception { getThreadPool().submit(new Callable<MetricsCollection>() { public MetricsCollection call() throws Exception { Collection<IncomingMetricException> problems = metricMetadataAnalyzer.scanMetrics(input.toMetrics()); for (IncomingMetricException problem : problems) getLogger().warn(problem.getMessage()); return input; } }); return null; } TypeAndUnitProcessor(ThreadPoolExecutor threadPool, IncomingMetricMetadataAnalyzer metricMetadataAnalyzer); } | TypeAndUnitProcessor extends FunctionWithThreadPool<MetricsCollection, Void> { @Override public Void apply(final MetricsCollection input) throws Exception { getThreadPool().submit(new Callable<MetricsCollection>() { public MetricsCollection call() throws Exception { Collection<IncomingMetricException> problems = metricMetadataAnalyzer.scanMetrics(input.toMetrics()); for (IncomingMetricException problem : problems) getLogger().warn(problem.getMessage()); return input; } }); return null; } TypeAndUnitProcessor(ThreadPoolExecutor threadPool, IncomingMetricMetadataAnalyzer metricMetadataAnalyzer); @Override Void apply(final MetricsCollection input); } | TypeAndUnitProcessor extends FunctionWithThreadPool<MetricsCollection, Void> { @Override public Void apply(final MetricsCollection input) throws Exception { getThreadPool().submit(new Callable<MetricsCollection>() { public MetricsCollection call() throws Exception { Collection<IncomingMetricException> problems = metricMetadataAnalyzer.scanMetrics(input.toMetrics()); for (IncomingMetricException problem : problems) getLogger().warn(problem.getMessage()); return input; } }); return null; } TypeAndUnitProcessor(ThreadPoolExecutor threadPool, IncomingMetricMetadataAnalyzer metricMetadataAnalyzer); @Override Void apply(final MetricsCollection input); } |
@Test public void granFromPointsLessThanEqualBoundaryBetween240And1440() { Granularity gran; gran = Granularity.granularityFromPointsInInterval("abc123", 0, 144000000, 10, "LESSTHANEQUAL", 1); Assert.assertSame(Granularity.MIN_240, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 144000001, 10, "LESSTHANEQUAL", 1); Assert.assertSame(Granularity.MIN_1440, gran); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void granFromPointsLessThanEqualWouldBeUpperBoundaryOf1440() { Granularity gran; gran = Granularity.granularityFromPointsInInterval("abc123", 0, 864000000, 10, "LESSTHANEQUAL", 1); Assert.assertSame(Granularity.MIN_1440, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 864000001, 10, "LESSTHANEQUAL", 1); Assert.assertSame(Granularity.MIN_1440, gran); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void granFromPointsGeometricBoundaryBetween5And20() { Granularity gran; gran = Granularity.granularityFromPointsInInterval("abc123", 0, 6000000, 10, "GEOMETRIC", 1, alwaysZeroClock); Assert.assertSame(Granularity.MIN_5, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 6000001, 10, "GEOMETRIC", 1, alwaysZeroClock); Assert.assertSame(Granularity.MIN_20, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 60000000, 100, "GEOMETRIC", 1, alwaysZeroClock); Assert.assertSame(Granularity.MIN_5, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 60000001, 100, "GEOMETRIC", 1, alwaysZeroClock); Assert.assertSame(Granularity.MIN_20, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 600000000, 1000, "GEOMETRIC", 1, alwaysZeroClock); Assert.assertSame(Granularity.MIN_5, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 600000001, 1000, "GEOMETRIC", 1, alwaysZeroClock); Assert.assertSame(Granularity.MIN_20, gran); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void granFromPointsGeometricBoundaryBetween20And60() { Granularity gran; gran = Granularity.granularityFromPointsInInterval("abc123", 0, 20784609, 10, "GEOMETRIC", 1, alwaysZeroClock); Assert.assertSame(Granularity.MIN_20, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 20784610, 10, "GEOMETRIC", 1, alwaysZeroClock); Assert.assertSame(Granularity.MIN_60, gran); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void granFromPointsGeometricBoundaryBetween60And240() { Granularity gran; gran = Granularity.granularityFromPointsInInterval("abc123", 0, 72000000, 10, "GEOMETRIC", 1, alwaysZeroClock); Assert.assertSame(Granularity.MIN_60, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 72000001, 10, "GEOMETRIC", 1, alwaysZeroClock); Assert.assertSame(Granularity.MIN_240, gran); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void granFromPointsGeometricBoundaryBetween240And1440() { Granularity gran; gran = Granularity.granularityFromPointsInInterval("abc123", 0, 352726522, 10, "GEOMETRIC", 1, alwaysZeroClock); Assert.assertSame(Granularity.MIN_240, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 352726523, 10, "GEOMETRIC", 1, alwaysZeroClock); Assert.assertSame(Granularity.MIN_1440, gran); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void granFromPointsGeometricWithDefaultClockAndAllGranularitiesSkippedReturnsCoarsest() { Granularity gran; gran = Granularity.granularityFromPointsInInterval("abc123", 0, 6000000, 10, "GEOMETRIC", 1, alwaysZeroClock); Assert.assertSame(Granularity.MIN_5, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 6000000, 10, "GEOMETRIC", 1); Assert.assertSame(Granularity.MIN_1440, gran); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void granFromPointsInvalidAlgorithmDefaultsToGeometric() { Granularity gran; gran = Granularity.granularityFromPointsInInterval("abc123", 0, 48000000, 100, "LINEAR", 1); Assert.assertSame(Granularity.MIN_5, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 48000001, 100, "LINEAR", 1); Assert.assertSame(Granularity.MIN_20, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 30000000, 100, "LESSTHANEQUAL", 1); Assert.assertSame(Granularity.MIN_5, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 30000001, 100, "LESSTHANEQUAL", 1); Assert.assertSame(Granularity.MIN_20, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 60000000, 100, "GEOMETRIC", 1, alwaysZeroClock); Assert.assertSame(Granularity.MIN_5, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 60000001, 100, "GEOMETRIC", 1, alwaysZeroClock); Assert.assertSame(Granularity.MIN_20, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 60000000, 100, "INVALID", 1, alwaysZeroClock); Assert.assertSame(Granularity.MIN_5, gran); gran = Granularity.granularityFromPointsInInterval("abc123", 0, 60000001, 100, "INVALID", 1, alwaysZeroClock); Assert.assertSame(Granularity.MIN_20, gran); } | public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points) { return granularityFromPointsInInterval(tenantid, from, to, points, GET_BY_POINTS_SELECTION_ALGORITHM, GET_BY_POINTS_ASSUME_INTERVAL, DEFAULT_TTL_COMPARISON_SOURCE); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void deriveRangeFiveMinuteFirstSlot() { Granularity gran = Granularity.MIN_5; Range range; range = gran.deriveRange(0, 0); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(299999, range.getStop()); range = gran.deriveRange(0, 1); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(299999, range.getStop()); range = gran.deriveRange(0, 299999); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(299999, range.getStop()); range = gran.deriveRange(0, 300000); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(299999, range.getStop()); range = gran.deriveRange(0, 300001); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(299999, range.getStop()); } | public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void deriveRangeFiveMinuteSecondSlot() { Granularity gran = Granularity.MIN_5; Range range; range = gran.deriveRange(1, 0); Assert.assertEquals(-1209300000, range.getStart()); Assert.assertEquals(-1209000001, range.getStop()); range = gran.deriveRange(1, 1); Assert.assertEquals(-1209300000, range.getStart()); Assert.assertEquals(-1209000001, range.getStop()); range = gran.deriveRange(1, 299999); Assert.assertEquals(-1209300000, range.getStart()); Assert.assertEquals(-1209000001, range.getStop()); range = gran.deriveRange(1, 300000); Assert.assertEquals(300000, range.getStart()); Assert.assertEquals(599999, range.getStop()); range = gran.deriveRange(1, 300001); Assert.assertEquals(300000, range.getStart()); Assert.assertEquals(599999, range.getStop()); range = gran.deriveRange(1, 599999); Assert.assertEquals(300000, range.getStart()); Assert.assertEquals(599999, range.getStop()); range = gran.deriveRange(1, 600000); Assert.assertEquals(300000, range.getStart()); Assert.assertEquals(599999, range.getStop()); range = gran.deriveRange(1, 600001); Assert.assertEquals(300000, range.getStart()); Assert.assertEquals(599999, range.getStop()); } | public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void testWriter() throws Exception { Counter bufferedMetrics = mock(Counter.class); IngestionContext context = mock(IngestionContext.class); AbstractMetricsRW basicRW = mock(AbstractMetricsRW.class); AbstractMetricsRW preAggrRW = mock(AbstractMetricsRW.class); MetricsRWDelegator metricsRWDelegator = new MetricsRWDelegator(basicRW, preAggrRW); List<List<IMetric>> testdata = createTestData(Metric.class); List<List<IMetric>> pTestdata = createTestData(PreaggregatedMetric.class); List<List<IMetric>> allTestdata = new ArrayList<List<IMetric>>(); allTestdata.addAll(testdata); allTestdata.addAll(pTestdata); BatchWriter batchWriter = new BatchWriter( new ThreadPoolBuilder().build(), timeout, bufferedMetrics, context, metricsRWDelegator ); ListenableFuture<List<Boolean>> futures = batchWriter.apply(allTestdata); List<Boolean> persisteds = futures.get(timeout.getValue(), timeout.getUnit()); Assert.assertTrue(persisteds.size() == (NUM_LISTS * 2)); for (Boolean batchStatus : persisteds) { Assert.assertTrue(batchStatus); } for (List<IMetric> l : testdata) { verify(basicRW).insertMetrics((List<IMetric>)(List<?>)l); } for (List<IMetric> l : pTestdata) { verify(preAggrRW).insertMetrics(l); } for (List<IMetric> l : allTestdata) { Assert.assertTrue(l.size() == METRICS_PER_LIST); for (IMetric m : l) { verify(context).update(m.getCollectionTime(), Util.getShard(m.getLocator().toString())); } } } | @Override public ListenableFuture<List<Boolean>> apply(List<List<IMetric>> input) throws Exception { final long writeStartTime = System.currentTimeMillis(); final Timer.Context actualWriteCtx = writeDurationTimer.time(); final List<ListenableFuture<Boolean>> resultFutures = new ArrayList<ListenableFuture<Boolean>>(); for (List<IMetric> metrics: input) { final int batchId = batchIdGenerator.next(); final List<IMetric> batch = metrics; ListenableFuture<Boolean> futureBatchResult = getThreadPool().submit(new Callable<Boolean>() { public Boolean call() throws Exception { final Timer.Context singleBatchWriteCtx = batchWriteDurationTimer.time(); try { metricsRWDelegator.insertMetrics(batch); final Timer.Context dirtyTimerCtx = slotUpdateTimer.time(); try { for (IMetric metric : batch) { context.update(metric.getCollectionTime(), Util.getShard(metric.getLocator().toString())); } } finally { dirtyTimerCtx.stop(); } return true; } catch (Exception ex) { getLogger().error(ex.getMessage(), ex); getLogger().warn("Did not persist all metrics successfully for batch " + batchId); if ( getLogger().isDebugEnabled() ) { List<String> failedLocators = new ArrayList<String>() {{ for (IMetric metric : batch) { add(metric.getLocator().toString()); } }}; getLogger().debug("Failed batch contains: " + Arrays.toString(failedLocators.toArray())); } return false; } finally { singleBatchWriteCtx.stop(); bufferedMetrics.dec(batch.size()); long now = System.currentTimeMillis(); if ( now - writeStartTime > timeout.toMillis()) { exceededScribeProcessingTime.mark(); getLogger().debug( String.format("Batch write time %d (ms) exceeded timeout %s before persisting " + "all metrics for batch %d", now - writeStartTime, timeout.toString(), batchId)); } } } }); resultFutures.add(futureBatchResult); } ListenableFuture<List<Boolean>> finalFuture = Futures.allAsList(resultFutures); finalFuture.addListener(new Runnable() { @Override public void run() { actualWriteCtx.stop(); } }, MoreExecutors.sameThreadExecutor()); return finalFuture; } | BatchWriter extends FunctionWithThreadPool<List<List<IMetric>>, ListenableFuture<List<Boolean>>> { @Override public ListenableFuture<List<Boolean>> apply(List<List<IMetric>> input) throws Exception { final long writeStartTime = System.currentTimeMillis(); final Timer.Context actualWriteCtx = writeDurationTimer.time(); final List<ListenableFuture<Boolean>> resultFutures = new ArrayList<ListenableFuture<Boolean>>(); for (List<IMetric> metrics: input) { final int batchId = batchIdGenerator.next(); final List<IMetric> batch = metrics; ListenableFuture<Boolean> futureBatchResult = getThreadPool().submit(new Callable<Boolean>() { public Boolean call() throws Exception { final Timer.Context singleBatchWriteCtx = batchWriteDurationTimer.time(); try { metricsRWDelegator.insertMetrics(batch); final Timer.Context dirtyTimerCtx = slotUpdateTimer.time(); try { for (IMetric metric : batch) { context.update(metric.getCollectionTime(), Util.getShard(metric.getLocator().toString())); } } finally { dirtyTimerCtx.stop(); } return true; } catch (Exception ex) { getLogger().error(ex.getMessage(), ex); getLogger().warn("Did not persist all metrics successfully for batch " + batchId); if ( getLogger().isDebugEnabled() ) { List<String> failedLocators = new ArrayList<String>() {{ for (IMetric metric : batch) { add(metric.getLocator().toString()); } }}; getLogger().debug("Failed batch contains: " + Arrays.toString(failedLocators.toArray())); } return false; } finally { singleBatchWriteCtx.stop(); bufferedMetrics.dec(batch.size()); long now = System.currentTimeMillis(); if ( now - writeStartTime > timeout.toMillis()) { exceededScribeProcessingTime.mark(); getLogger().debug( String.format("Batch write time %d (ms) exceeded timeout %s before persisting " + "all metrics for batch %d", now - writeStartTime, timeout.toString(), batchId)); } } } }); resultFutures.add(futureBatchResult); } ListenableFuture<List<Boolean>> finalFuture = Futures.allAsList(resultFutures); finalFuture.addListener(new Runnable() { @Override public void run() { actualWriteCtx.stop(); } }, MoreExecutors.sameThreadExecutor()); return finalFuture; } } | BatchWriter extends FunctionWithThreadPool<List<List<IMetric>>, ListenableFuture<List<Boolean>>> { @Override public ListenableFuture<List<Boolean>> apply(List<List<IMetric>> input) throws Exception { final long writeStartTime = System.currentTimeMillis(); final Timer.Context actualWriteCtx = writeDurationTimer.time(); final List<ListenableFuture<Boolean>> resultFutures = new ArrayList<ListenableFuture<Boolean>>(); for (List<IMetric> metrics: input) { final int batchId = batchIdGenerator.next(); final List<IMetric> batch = metrics; ListenableFuture<Boolean> futureBatchResult = getThreadPool().submit(new Callable<Boolean>() { public Boolean call() throws Exception { final Timer.Context singleBatchWriteCtx = batchWriteDurationTimer.time(); try { metricsRWDelegator.insertMetrics(batch); final Timer.Context dirtyTimerCtx = slotUpdateTimer.time(); try { for (IMetric metric : batch) { context.update(metric.getCollectionTime(), Util.getShard(metric.getLocator().toString())); } } finally { dirtyTimerCtx.stop(); } return true; } catch (Exception ex) { getLogger().error(ex.getMessage(), ex); getLogger().warn("Did not persist all metrics successfully for batch " + batchId); if ( getLogger().isDebugEnabled() ) { List<String> failedLocators = new ArrayList<String>() {{ for (IMetric metric : batch) { add(metric.getLocator().toString()); } }}; getLogger().debug("Failed batch contains: " + Arrays.toString(failedLocators.toArray())); } return false; } finally { singleBatchWriteCtx.stop(); bufferedMetrics.dec(batch.size()); long now = System.currentTimeMillis(); if ( now - writeStartTime > timeout.toMillis()) { exceededScribeProcessingTime.mark(); getLogger().debug( String.format("Batch write time %d (ms) exceeded timeout %s before persisting " + "all metrics for batch %d", now - writeStartTime, timeout.toString(), batchId)); } } } }); resultFutures.add(futureBatchResult); } ListenableFuture<List<Boolean>> finalFuture = Futures.allAsList(resultFutures); finalFuture.addListener(new Runnable() { @Override public void run() { actualWriteCtx.stop(); } }, MoreExecutors.sameThreadExecutor()); return finalFuture; } BatchWriter(ThreadPoolExecutor threadPool, TimeValue timeout, Counter bufferedMetrics, IngestionContext context); @VisibleForTesting BatchWriter(ThreadPoolExecutor threadPool,
TimeValue timeout, Counter bufferedMetrics,
IngestionContext context,
MetricsRWDelegator metricsRWDelegator); } | BatchWriter extends FunctionWithThreadPool<List<List<IMetric>>, ListenableFuture<List<Boolean>>> { @Override public ListenableFuture<List<Boolean>> apply(List<List<IMetric>> input) throws Exception { final long writeStartTime = System.currentTimeMillis(); final Timer.Context actualWriteCtx = writeDurationTimer.time(); final List<ListenableFuture<Boolean>> resultFutures = new ArrayList<ListenableFuture<Boolean>>(); for (List<IMetric> metrics: input) { final int batchId = batchIdGenerator.next(); final List<IMetric> batch = metrics; ListenableFuture<Boolean> futureBatchResult = getThreadPool().submit(new Callable<Boolean>() { public Boolean call() throws Exception { final Timer.Context singleBatchWriteCtx = batchWriteDurationTimer.time(); try { metricsRWDelegator.insertMetrics(batch); final Timer.Context dirtyTimerCtx = slotUpdateTimer.time(); try { for (IMetric metric : batch) { context.update(metric.getCollectionTime(), Util.getShard(metric.getLocator().toString())); } } finally { dirtyTimerCtx.stop(); } return true; } catch (Exception ex) { getLogger().error(ex.getMessage(), ex); getLogger().warn("Did not persist all metrics successfully for batch " + batchId); if ( getLogger().isDebugEnabled() ) { List<String> failedLocators = new ArrayList<String>() {{ for (IMetric metric : batch) { add(metric.getLocator().toString()); } }}; getLogger().debug("Failed batch contains: " + Arrays.toString(failedLocators.toArray())); } return false; } finally { singleBatchWriteCtx.stop(); bufferedMetrics.dec(batch.size()); long now = System.currentTimeMillis(); if ( now - writeStartTime > timeout.toMillis()) { exceededScribeProcessingTime.mark(); getLogger().debug( String.format("Batch write time %d (ms) exceeded timeout %s before persisting " + "all metrics for batch %d", now - writeStartTime, timeout.toString(), batchId)); } } } }); resultFutures.add(futureBatchResult); } ListenableFuture<List<Boolean>> finalFuture = Futures.allAsList(resultFutures); finalFuture.addListener(new Runnable() { @Override public void run() { actualWriteCtx.stop(); } }, MoreExecutors.sameThreadExecutor()); return finalFuture; } BatchWriter(ThreadPoolExecutor threadPool, TimeValue timeout, Counter bufferedMetrics, IngestionContext context); @VisibleForTesting BatchWriter(ThreadPoolExecutor threadPool,
TimeValue timeout, Counter bufferedMetrics,
IngestionContext context,
MetricsRWDelegator metricsRWDelegator); @Override ListenableFuture<List<Boolean>> apply(List<List<IMetric>> input); } | BatchWriter extends FunctionWithThreadPool<List<List<IMetric>>, ListenableFuture<List<Boolean>>> { @Override public ListenableFuture<List<Boolean>> apply(List<List<IMetric>> input) throws Exception { final long writeStartTime = System.currentTimeMillis(); final Timer.Context actualWriteCtx = writeDurationTimer.time(); final List<ListenableFuture<Boolean>> resultFutures = new ArrayList<ListenableFuture<Boolean>>(); for (List<IMetric> metrics: input) { final int batchId = batchIdGenerator.next(); final List<IMetric> batch = metrics; ListenableFuture<Boolean> futureBatchResult = getThreadPool().submit(new Callable<Boolean>() { public Boolean call() throws Exception { final Timer.Context singleBatchWriteCtx = batchWriteDurationTimer.time(); try { metricsRWDelegator.insertMetrics(batch); final Timer.Context dirtyTimerCtx = slotUpdateTimer.time(); try { for (IMetric metric : batch) { context.update(metric.getCollectionTime(), Util.getShard(metric.getLocator().toString())); } } finally { dirtyTimerCtx.stop(); } return true; } catch (Exception ex) { getLogger().error(ex.getMessage(), ex); getLogger().warn("Did not persist all metrics successfully for batch " + batchId); if ( getLogger().isDebugEnabled() ) { List<String> failedLocators = new ArrayList<String>() {{ for (IMetric metric : batch) { add(metric.getLocator().toString()); } }}; getLogger().debug("Failed batch contains: " + Arrays.toString(failedLocators.toArray())); } return false; } finally { singleBatchWriteCtx.stop(); bufferedMetrics.dec(batch.size()); long now = System.currentTimeMillis(); if ( now - writeStartTime > timeout.toMillis()) { exceededScribeProcessingTime.mark(); getLogger().debug( String.format("Batch write time %d (ms) exceeded timeout %s before persisting " + "all metrics for batch %d", now - writeStartTime, timeout.toString(), batchId)); } } } }); resultFutures.add(futureBatchResult); } ListenableFuture<List<Boolean>> finalFuture = Futures.allAsList(resultFutures); finalFuture.addListener(new Runnable() { @Override public void run() { actualWriteCtx.stop(); } }, MoreExecutors.sameThreadExecutor()); return finalFuture; } BatchWriter(ThreadPoolExecutor threadPool, TimeValue timeout, Counter bufferedMetrics, IngestionContext context); @VisibleForTesting BatchWriter(ThreadPoolExecutor threadPool,
TimeValue timeout, Counter bufferedMetrics,
IngestionContext context,
MetricsRWDelegator metricsRWDelegator); @Override ListenableFuture<List<Boolean>> apply(List<List<IMetric>> input); } |
@Test public void deriveRangeFiveMinuteLastSlot() { Granularity gran = Granularity.MIN_5; Range range; range = gran.deriveRange(3, 0); Assert.assertEquals(-1208700000, range.getStart()); Assert.assertEquals(-1208400001, range.getStop()); range = gran.deriveRange(3, 1); Assert.assertEquals(-1208700000, range.getStart()); Assert.assertEquals(-1208400001, range.getStop()); range = gran.deriveRange(3, 899999); Assert.assertEquals(-1208700000, range.getStart()); Assert.assertEquals(-1208400001, range.getStop()); range = gran.deriveRange(3, 900000); Assert.assertEquals(900000, range.getStart()); Assert.assertEquals(1199999, range.getStop()); range = gran.deriveRange(3, 900001); Assert.assertEquals(900000, range.getStart()); Assert.assertEquals(1199999, range.getStop()); range = gran.deriveRange(3, 1199999); Assert.assertEquals(900000, range.getStart()); Assert.assertEquals(1199999, range.getStop()); range = gran.deriveRange(3, 1200000); Assert.assertEquals(900000, range.getStart()); Assert.assertEquals(1199999, range.getStop()); range = gran.deriveRange(3, 1200001); Assert.assertEquals(900000, range.getStart()); Assert.assertEquals(1199999, range.getStop()); } | public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void deriveRangeTwentyMinuteFirstSlot() { Granularity gran = Granularity.MIN_20; Range range; range = gran.deriveRange(0, 0); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(1199999, range.getStop()); range = gran.deriveRange(0, 1); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(1199999, range.getStop()); range = gran.deriveRange(0, 1199999); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(1199999, range.getStop()); range = gran.deriveRange(0, 1200000); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(1199999, range.getStop()); range = gran.deriveRange(0, 1200001); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(1199999, range.getStop()); } | public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void deriveRangeTwentyMinuteSecondSlot() { Granularity gran = Granularity.MIN_20; Range range; range = gran.deriveRange(1, 0); Assert.assertEquals(-1208400000, range.getStart()); Assert.assertEquals(-1207200001, range.getStop()); range = gran.deriveRange(1, 1); Assert.assertEquals(-1208400000, range.getStart()); Assert.assertEquals(-1207200001, range.getStop()); range = gran.deriveRange(1, 299999); Assert.assertEquals(-1208400000, range.getStart()); Assert.assertEquals(-1207200001, range.getStop()); range = gran.deriveRange(1, 1200000); Assert.assertEquals(1200000, range.getStart()); Assert.assertEquals(2399999, range.getStop()); range = gran.deriveRange(1, 1200001); Assert.assertEquals(1200000, range.getStart()); Assert.assertEquals(2399999, range.getStop()); range = gran.deriveRange(1, 2399999); Assert.assertEquals(1200000, range.getStart()); Assert.assertEquals(2399999, range.getStop()); range = gran.deriveRange(1, 2400000); Assert.assertEquals(1200000, range.getStart()); Assert.assertEquals(2399999, range.getStop()); range = gran.deriveRange(1, 2400001); Assert.assertEquals(1200000, range.getStart()); Assert.assertEquals(2399999, range.getStop()); } | public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void deriveRangeSixtyMinuteFirstSlot() { Granularity gran = Granularity.MIN_60; Range range; range = gran.deriveRange(0, 0); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(3599999, range.getStop()); range = gran.deriveRange(0, 1); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(3599999, range.getStop()); range = gran.deriveRange(0, 3599999); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(3599999, range.getStop()); range = gran.deriveRange(0, 3600000); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(3599999, range.getStop()); range = gran.deriveRange(0, 3600001); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(3599999, range.getStop()); } | public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void deriveRangeSixtyMinuteSecondSlot() { Granularity gran = Granularity.MIN_60; Range range; range = gran.deriveRange(1, 0); Assert.assertEquals(-1206000000, range.getStart()); Assert.assertEquals(-1202400001, range.getStop()); range = gran.deriveRange(1, 1); Assert.assertEquals(-1206000000, range.getStart()); Assert.assertEquals(-1202400001, range.getStop()); range = gran.deriveRange(1, 899999); Assert.assertEquals(-1206000000, range.getStart()); Assert.assertEquals(-1202400001, range.getStop()); range = gran.deriveRange(1, 3600000); Assert.assertEquals(3600000, range.getStart()); Assert.assertEquals(7199999, range.getStop()); range = gran.deriveRange(1, 3600001); Assert.assertEquals(3600000, range.getStart()); Assert.assertEquals(7199999, range.getStop()); range = gran.deriveRange(1, 7199999); Assert.assertEquals(3600000, range.getStart()); Assert.assertEquals(7199999, range.getStop()); range = gran.deriveRange(1, 7200000); Assert.assertEquals(3600000, range.getStart()); Assert.assertEquals(7199999, range.getStop()); range = gran.deriveRange(1, 7200001); Assert.assertEquals(3600000, range.getStart()); Assert.assertEquals(7199999, range.getStop()); } | public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void deriveRange240MinuteFirstSlot() { Granularity gran = Granularity.MIN_240; Range range; range = gran.deriveRange(0, 0); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(14399999, range.getStop()); range = gran.deriveRange(0, 1); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(14399999, range.getStop()); range = gran.deriveRange(0, 14399999); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(14399999, range.getStop()); range = gran.deriveRange(0, 14400000); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(14399999, range.getStop()); range = gran.deriveRange(0, 14400001); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(14399999, range.getStop()); } | public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void deriveRange240MinuteSecondSlot() { Granularity gran = Granularity.MIN_240; Range range; range = gran.deriveRange(1, 0); Assert.assertEquals(-1195200000, range.getStart()); Assert.assertEquals(-1180800001, range.getStop()); range = gran.deriveRange(1, 1); Assert.assertEquals(-1195200000, range.getStart()); Assert.assertEquals(-1180800001, range.getStop()); range = gran.deriveRange(1, 14399999); Assert.assertEquals(-1195200000, range.getStart()); Assert.assertEquals(-1180800001, range.getStop()); range = gran.deriveRange(1, 14400000); Assert.assertEquals(14400000, range.getStart()); Assert.assertEquals(28799999, range.getStop()); range = gran.deriveRange(1, 14400001); Assert.assertEquals(14400000, range.getStart()); Assert.assertEquals(28799999, range.getStop()); range = gran.deriveRange(1, 28799999); Assert.assertEquals(14400000, range.getStart()); Assert.assertEquals(28799999, range.getStop()); range = gran.deriveRange(1, 28800000); Assert.assertEquals(14400000, range.getStart()); Assert.assertEquals(28799999, range.getStop()); range = gran.deriveRange(1, 28800001); Assert.assertEquals(14400000, range.getStart()); Assert.assertEquals(28799999, range.getStop()); } | public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void deriveRange1440MinuteFirstSlot() { Granularity gran = Granularity.MIN_1440; Range range; range = gran.deriveRange(0, 0); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(86399999, range.getStop()); range = gran.deriveRange(0, 1); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(86399999, range.getStop()); range = gran.deriveRange(0, 86399999); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(86399999, range.getStop()); range = gran.deriveRange(0, 86400000); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(86399999, range.getStop()); range = gran.deriveRange(0, 86400001); Assert.assertEquals(0, range.getStart()); Assert.assertEquals(86399999, range.getStop()); } | public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void deriveRange1440MinuteSecondSlot() { Granularity gran = Granularity.MIN_1440; Range range; range = gran.deriveRange(1, 0); Assert.assertEquals(-1123200000, range.getStart()); Assert.assertEquals(-1036800001, range.getStop()); range = gran.deriveRange(1, 1); Assert.assertEquals(-1123200000, range.getStart()); Assert.assertEquals(-1036800001, range.getStop()); range = gran.deriveRange(1, 86399999); Assert.assertEquals(-1123200000, range.getStart()); Assert.assertEquals(-1036800001, range.getStop()); range = gran.deriveRange(1, 86400000); Assert.assertEquals(86400000, range.getStart()); Assert.assertEquals(172799999, range.getStop()); range = gran.deriveRange(1, 86400001); Assert.assertEquals(86400000, range.getStart()); Assert.assertEquals(172799999, range.getStop()); range = gran.deriveRange(1, 172799999); Assert.assertEquals(86400000, range.getStart()); Assert.assertEquals(172799999, range.getStop()); range = gran.deriveRange(1, 172800000); Assert.assertEquals(86400000, range.getStart()); Assert.assertEquals(172799999, range.getStop()); range = gran.deriveRange(1, 172800001); Assert.assertEquals(86400000, range.getStart()); Assert.assertEquals(172799999, range.getStop()); } | public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public Range deriveRange(int slot, long referenceMillis) { referenceMillis = snapMillis(referenceMillis); int refSlot = slot(referenceMillis); int slotDiff = slot > refSlot ? (numSlots() - slot + refSlot) : (refSlot - slot); long rangeStart = referenceMillis - slotDiff * milliseconds(); return new Range(rangeStart, rangeStart + milliseconds() - 1); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void slotFromFiner() throws GranularityException { Assert.assertEquals(0, Granularity.MIN_5.slotFromFinerSlot(0)); Assert.assertEquals(1, Granularity.MIN_5.slotFromFinerSlot(1)); Assert.assertEquals(4031, Granularity.MIN_5.slotFromFinerSlot(4031)); Assert.assertEquals(4032, Granularity.MIN_5.slotFromFinerSlot(4032)); Assert.assertEquals(0, Granularity.MIN_20.slotFromFinerSlot(0)); Assert.assertEquals(0, Granularity.MIN_20.slotFromFinerSlot(1)); Assert.assertEquals(0, Granularity.MIN_20.slotFromFinerSlot(2)); Assert.assertEquals(0, Granularity.MIN_20.slotFromFinerSlot(3)); Assert.assertEquals(1, Granularity.MIN_20.slotFromFinerSlot(4)); Assert.assertEquals(1006, Granularity.MIN_20.slotFromFinerSlot(4027)); Assert.assertEquals(1007, Granularity.MIN_20.slotFromFinerSlot(4028)); Assert.assertEquals(1007, Granularity.MIN_20.slotFromFinerSlot(4029)); Assert.assertEquals(1007, Granularity.MIN_20.slotFromFinerSlot(4030)); Assert.assertEquals(1007, Granularity.MIN_20.slotFromFinerSlot(4031)); Assert.assertEquals(1008, Granularity.MIN_20.slotFromFinerSlot(4032)); Assert.assertEquals(0, Granularity.MIN_60.slotFromFinerSlot(0)); Assert.assertEquals(0, Granularity.MIN_60.slotFromFinerSlot(1)); Assert.assertEquals(0, Granularity.MIN_60.slotFromFinerSlot(2)); Assert.assertEquals(1, Granularity.MIN_60.slotFromFinerSlot(3)); Assert.assertEquals(1, Granularity.MIN_60.slotFromFinerSlot(4)); Assert.assertEquals(1, Granularity.MIN_60.slotFromFinerSlot(5)); Assert.assertEquals(2, Granularity.MIN_60.slotFromFinerSlot(6)); Assert.assertEquals(333, Granularity.MIN_60.slotFromFinerSlot(1001)); Assert.assertEquals(334, Granularity.MIN_60.slotFromFinerSlot(1002)); Assert.assertEquals(334, Granularity.MIN_60.slotFromFinerSlot(1003)); Assert.assertEquals(334, Granularity.MIN_60.slotFromFinerSlot(1004)); Assert.assertEquals(335, Granularity.MIN_60.slotFromFinerSlot(1005)); Assert.assertEquals(335, Granularity.MIN_60.slotFromFinerSlot(1006)); Assert.assertEquals(335, Granularity.MIN_60.slotFromFinerSlot(1007)); Assert.assertEquals(336, Granularity.MIN_60.slotFromFinerSlot(1008)); Assert.assertEquals(0, Granularity.MIN_240.slotFromFinerSlot(0)); Assert.assertEquals(0, Granularity.MIN_240.slotFromFinerSlot(1)); Assert.assertEquals(0, Granularity.MIN_240.slotFromFinerSlot(2)); Assert.assertEquals(0, Granularity.MIN_240.slotFromFinerSlot(3)); Assert.assertEquals(1, Granularity.MIN_240.slotFromFinerSlot(4)); Assert.assertEquals(1, Granularity.MIN_240.slotFromFinerSlot(5)); Assert.assertEquals(1, Granularity.MIN_240.slotFromFinerSlot(6)); Assert.assertEquals(1, Granularity.MIN_240.slotFromFinerSlot(7)); Assert.assertEquals(2, Granularity.MIN_240.slotFromFinerSlot(8)); Assert.assertEquals(81, Granularity.MIN_240.slotFromFinerSlot(327)); Assert.assertEquals(82, Granularity.MIN_240.slotFromFinerSlot(328)); Assert.assertEquals(82, Granularity.MIN_240.slotFromFinerSlot(329)); Assert.assertEquals(82, Granularity.MIN_240.slotFromFinerSlot(330)); Assert.assertEquals(82, Granularity.MIN_240.slotFromFinerSlot(331)); Assert.assertEquals(83, Granularity.MIN_240.slotFromFinerSlot(332)); Assert.assertEquals(83, Granularity.MIN_240.slotFromFinerSlot(333)); Assert.assertEquals(83, Granularity.MIN_240.slotFromFinerSlot(334)); Assert.assertEquals(83, Granularity.MIN_240.slotFromFinerSlot(335)); Assert.assertEquals(84, Granularity.MIN_240.slotFromFinerSlot(336)); Assert.assertEquals(0, Granularity.MIN_1440.slotFromFinerSlot(0)); Assert.assertEquals(0, Granularity.MIN_1440.slotFromFinerSlot(1)); Assert.assertEquals(0, Granularity.MIN_1440.slotFromFinerSlot(2)); Assert.assertEquals(0, Granularity.MIN_1440.slotFromFinerSlot(3)); Assert.assertEquals(0, Granularity.MIN_1440.slotFromFinerSlot(4)); Assert.assertEquals(0, Granularity.MIN_1440.slotFromFinerSlot(5)); Assert.assertEquals(1, Granularity.MIN_1440.slotFromFinerSlot(6)); Assert.assertEquals(12, Granularity.MIN_1440.slotFromFinerSlot(77)); Assert.assertEquals(13, Granularity.MIN_1440.slotFromFinerSlot(78)); Assert.assertEquals(13, Granularity.MIN_1440.slotFromFinerSlot(79)); Assert.assertEquals(13, Granularity.MIN_1440.slotFromFinerSlot(80)); Assert.assertEquals(13, Granularity.MIN_1440.slotFromFinerSlot(81)); Assert.assertEquals(13, Granularity.MIN_1440.slotFromFinerSlot(82)); Assert.assertEquals(13, Granularity.MIN_1440.slotFromFinerSlot(83)); Assert.assertEquals(14, Granularity.MIN_1440.slotFromFinerSlot(84)); } | public int slotFromFinerSlot(int finerSlot) throws GranularityException { return (finerSlot * numSlots()) / this.finer().numSlots(); } | Granularity { public int slotFromFinerSlot(int finerSlot) throws GranularityException { return (finerSlot * numSlots()) / this.finer().numSlots(); } } | Granularity { public int slotFromFinerSlot(int finerSlot) throws GranularityException { return (finerSlot * numSlots()) / this.finer().numSlots(); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public int slotFromFinerSlot(int finerSlot) throws GranularityException { return (finerSlot * numSlots()) / this.finer().numSlots(); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public int slotFromFinerSlot(int finerSlot) throws GranularityException { return (finerSlot * numSlots()) / this.finer().numSlots(); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void pollSchedulesEligibleSlots() { service.poll(); verify(context).scheduleEligibleSlots(anyLong(), anyLong(), anyLong()); verifyNoMoreInteractions(context); verifyZeroInteractions(shardStateManager); verifyZeroInteractions(locatorFetchExecutors); verifyZeroInteractions(rollupReadExecutors); verifyZeroInteractions(rollupWriteExecutors); } | final void poll() { Timer.Context timer = polltimer.time(); context.scheduleEligibleSlots(rollupDelayMillis, rollupDelayForMetricsWithShortDelay, rollupWaitForMetricsWithLongDelay); timer.stop(); } | RollupService implements Runnable, RollupServiceMBean { final void poll() { Timer.Context timer = polltimer.time(); context.scheduleEligibleSlots(rollupDelayMillis, rollupDelayForMetricsWithShortDelay, rollupWaitForMetricsWithLongDelay); timer.stop(); } } | RollupService implements Runnable, RollupServiceMBean { final void poll() { Timer.Context timer = polltimer.time(); context.scheduleEligibleSlots(rollupDelayMillis, rollupDelayForMetricsWithShortDelay, rollupWaitForMetricsWithLongDelay); timer.stop(); } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
ThreadPoolExecutor locatorFetchExecutors,
ThreadPoolExecutor rollupReadExecutors,
ThreadPoolExecutor rollupWriteExecutors,
long rollupDelayMillis,
long rollupDelayForMetricsWithShortDelay,
long rollupWaitForMetricsWithLongDelay,
long pollerPeriod,
long configRefreshInterval); } | RollupService implements Runnable, RollupServiceMBean { final void poll() { Timer.Context timer = polltimer.time(); context.scheduleEligibleSlots(rollupDelayMillis, rollupDelayForMetricsWithShortDelay, rollupWaitForMetricsWithLongDelay); timer.stop(); } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
ThreadPoolExecutor locatorFetchExecutors,
ThreadPoolExecutor rollupReadExecutors,
ThreadPoolExecutor rollupWriteExecutors,
long rollupDelayMillis,
long rollupDelayForMetricsWithShortDelay,
long rollupWaitForMetricsWithLongDelay,
long pollerPeriod,
long configRefreshInterval); void initializeGauges(); void forcePoll(); void run(); synchronized void setServerTime(long millis); synchronized long getServerTime(); synchronized void setKeepingServerTime(boolean b); synchronized boolean getKeepingServerTime(); synchronized void setPollerPeriod(long l); synchronized long getPollerPeriod(); synchronized int getScheduledSlotCheckCount(); synchronized int getSecondsSinceLastSlotCheck(); synchronized int getSlotCheckConcurrency(); synchronized void setSlotCheckConcurrency(int i); synchronized int getRollupConcurrency(); synchronized void setRollupConcurrency(int i); synchronized int getQueuedRollupCount(); synchronized int getInFlightRollupCount(); synchronized boolean getActive(); synchronized void setActive(boolean b); void addShard(Integer shard); void removeShard(Integer shard); Collection<Integer> getManagedShards(); synchronized Collection<Integer> getRecentlyScheduledShards(); synchronized Collection<String> getOldestUnrolledSlotPerGranularity(int shard); } | RollupService implements Runnable, RollupServiceMBean { final void poll() { Timer.Context timer = polltimer.time(); context.scheduleEligibleSlots(rollupDelayMillis, rollupDelayForMetricsWithShortDelay, rollupWaitForMetricsWithLongDelay); timer.stop(); } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
ThreadPoolExecutor locatorFetchExecutors,
ThreadPoolExecutor rollupReadExecutors,
ThreadPoolExecutor rollupWriteExecutors,
long rollupDelayMillis,
long rollupDelayForMetricsWithShortDelay,
long rollupWaitForMetricsWithLongDelay,
long pollerPeriod,
long configRefreshInterval); void initializeGauges(); void forcePoll(); void run(); synchronized void setServerTime(long millis); synchronized long getServerTime(); synchronized void setKeepingServerTime(boolean b); synchronized boolean getKeepingServerTime(); synchronized void setPollerPeriod(long l); synchronized long getPollerPeriod(); synchronized int getScheduledSlotCheckCount(); synchronized int getSecondsSinceLastSlotCheck(); synchronized int getSlotCheckConcurrency(); synchronized void setSlotCheckConcurrency(int i); synchronized int getRollupConcurrency(); synchronized void setRollupConcurrency(int i); synchronized int getQueuedRollupCount(); synchronized int getInFlightRollupCount(); synchronized boolean getActive(); synchronized void setActive(boolean b); void addShard(Integer shard); void removeShard(Integer shard); Collection<Integer> getManagedShards(); synchronized Collection<Integer> getRecentlyScheduledShards(); synchronized Collection<String> getOldestUnrolledSlotPerGranularity(int shard); } |
@Test(expected = GranularityException.class) public void slotFromFinerWithFullThrowsException() throws GranularityException { Granularity.FULL.slotFromFinerSlot(0); } | public int slotFromFinerSlot(int finerSlot) throws GranularityException { return (finerSlot * numSlots()) / this.finer().numSlots(); } | Granularity { public int slotFromFinerSlot(int finerSlot) throws GranularityException { return (finerSlot * numSlots()) / this.finer().numSlots(); } } | Granularity { public int slotFromFinerSlot(int finerSlot) throws GranularityException { return (finerSlot * numSlots()) / this.finer().numSlots(); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public int slotFromFinerSlot(int finerSlot) throws GranularityException { return (finerSlot * numSlots()) / this.finer().numSlots(); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public int slotFromFinerSlot(int finerSlot) throws GranularityException { return (finerSlot * numSlots()) / this.finer().numSlots(); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void slotFromFinerDoesNotWrap() throws GranularityException { Assert.assertEquals(4031, Granularity.MIN_20.slotFromFinerSlot(16124)); Assert.assertEquals(4031, Granularity.MIN_20.slotFromFinerSlot(16125)); Assert.assertEquals(4031, Granularity.MIN_20.slotFromFinerSlot(16126)); Assert.assertEquals(4031, Granularity.MIN_20.slotFromFinerSlot(16127)); Assert.assertEquals(4032, Granularity.MIN_20.slotFromFinerSlot(16128)); } | public int slotFromFinerSlot(int finerSlot) throws GranularityException { return (finerSlot * numSlots()) / this.finer().numSlots(); } | Granularity { public int slotFromFinerSlot(int finerSlot) throws GranularityException { return (finerSlot * numSlots()) / this.finer().numSlots(); } } | Granularity { public int slotFromFinerSlot(int finerSlot) throws GranularityException { return (finerSlot * numSlots()) / this.finer().numSlots(); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); } | Granularity { public int slotFromFinerSlot(int finerSlot) throws GranularityException { return (finerSlot * numSlots()) / this.finer().numSlots(); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); } | Granularity { public int slotFromFinerSlot(int finerSlot) throws GranularityException { return (finerSlot * numSlots()) / this.finer().numSlots(); } private Granularity(String cf, int milliseconds, int numSlots, String shortName); String name(); String shortName(); int milliseconds(); int numSlots(); Granularity coarser(); Granularity finer(); boolean isCoarser(Granularity other); long snapMillis(long millis); int slot(long millis); int slotFromFinerSlot(int finerSlot); Range deriveRange(int slot, long referenceMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis); static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock); @Override int hashCode(); @Override boolean equals(Object obj); static Granularity[] granularities(); static Granularity[] rollupGranularities(); static Granularity fromString(String s); static Granularity getRollupGranularity(String s); @Override String toString(); static final int MILLISECONDS_IN_SLOT; static final Granularity FULL; static final Granularity MIN_5; static final Granularity MIN_20; static final Granularity MIN_60; static final Granularity MIN_240; static final Granularity MIN_1440; static final Granularity LAST; static final int MAX_NUM_SLOTS; } |
@Test public void testExtrapolate() { int shard = 1; assertEquals("Invalid extrapolation - scenario 0", SlotKey.of(Granularity.MIN_5, 1, shard), SlotKey.of(Granularity.FULL, 1, shard).extrapolate(Granularity.MIN_5)); assertEquals("Invalid extrapolation - scenario 1", SlotKey.of(Granularity.MIN_5, 43, shard), SlotKey.of(Granularity.FULL, 43, shard).extrapolate(Granularity.MIN_5)); assertEquals("Invalid extrapolation - scenario 2", SlotKey.of(Granularity.MIN_5, 24, shard), SlotKey.of(Granularity.MIN_5, 24, shard).extrapolate(Granularity.MIN_5)); assertEquals("Invalid extrapolation - scenario 3", SlotKey.of(Granularity.MIN_20, 0, shard), SlotKey.of(Granularity.MIN_5, 0, shard).extrapolate(Granularity.MIN_20)); assertEquals("Invalid extrapolation - scenario 4", SlotKey.of(Granularity.MIN_20, 0, shard), SlotKey.of(Granularity.MIN_5, 3, shard).extrapolate(Granularity.MIN_20)); assertEquals("Invalid extrapolation - scenario 5", SlotKey.of(Granularity.MIN_20, 1, shard), SlotKey.of(Granularity.MIN_5, 4, shard).extrapolate(Granularity.MIN_20)); assertEquals("Invalid extrapolation - scenario 6", SlotKey.of(Granularity.MIN_20, 4032 / 4 - 1, shard), SlotKey.of(Granularity.MIN_5, 4031, shard).extrapolate(Granularity.MIN_20)); assertEquals("Invalid extrapolation - scenario 7", SlotKey.of(Granularity.MIN_60, 0, shard), SlotKey.of(Granularity.MIN_5, 3, shard).extrapolate(Granularity.MIN_60)); assertEquals("Invalid extrapolation - scenario 8", SlotKey.of(Granularity.MIN_60, 0, shard), SlotKey.of(Granularity.MIN_5, 3, shard).extrapolate(Granularity.MIN_60)); assertEquals("Invalid extrapolation - scenario 9", SlotKey.of(Granularity.MIN_60, 1, shard), SlotKey.of(Granularity.MIN_5, 12, shard).extrapolate(Granularity.MIN_60)); assertEquals("Invalid extrapolation - scenario 10", SlotKey.of(Granularity.MIN_60, 4032 / 12 - 1, shard), SlotKey.of(Granularity.MIN_5, 4031, shard).extrapolate(Granularity.MIN_60)); assertEquals("Invalid extrapolation - scenario 11", SlotKey.of(Granularity.MIN_1440, 0, shard), SlotKey.of(Granularity.MIN_5, 3, shard).extrapolate(Granularity.MIN_1440)); assertEquals("Invalid extrapolation - scenario 12", SlotKey.of(Granularity.MIN_1440, 0, shard), SlotKey.of(Granularity.MIN_5, 287, shard).extrapolate(Granularity.MIN_1440)); assertEquals("Invalid extrapolation - scenario 13", SlotKey.of(Granularity.MIN_1440, 1, shard), SlotKey.of(Granularity.MIN_5, 288, shard).extrapolate(Granularity.MIN_1440)); assertEquals("Invalid extrapolation - scenario 14", SlotKey.of(Granularity.MIN_60, 0, shard), SlotKey.of(Granularity.MIN_20, 1, shard).extrapolate(Granularity.MIN_60)); assertEquals("Invalid extrapolation - scenario 15", SlotKey.of(Granularity.MIN_60, 0, shard), SlotKey.of(Granularity.MIN_20, 2, shard).extrapolate(Granularity.MIN_60)); assertEquals("Invalid extrapolation - scenario 16", SlotKey.of(Granularity.MIN_60, 1, shard), SlotKey.of(Granularity.MIN_20, 3, shard).extrapolate(Granularity.MIN_60)); } | public SlotKey extrapolate(Granularity destGranularity) { if (destGranularity.equals(this.getGranularity())) { return this; } if (!destGranularity.isCoarser(getGranularity())) { throw new IllegalArgumentException("Destination granularity must be coarser than the current granularity"); } int factor = getGranularity().numSlots() / destGranularity.numSlots(); int parentSlot = getSlot() / factor; return SlotKey.of(destGranularity, parentSlot, getShard()); } | SlotKey { public SlotKey extrapolate(Granularity destGranularity) { if (destGranularity.equals(this.getGranularity())) { return this; } if (!destGranularity.isCoarser(getGranularity())) { throw new IllegalArgumentException("Destination granularity must be coarser than the current granularity"); } int factor = getGranularity().numSlots() / destGranularity.numSlots(); int parentSlot = getSlot() / factor; return SlotKey.of(destGranularity, parentSlot, getShard()); } } | SlotKey { public SlotKey extrapolate(Granularity destGranularity) { if (destGranularity.equals(this.getGranularity())) { return this; } if (!destGranularity.isCoarser(getGranularity())) { throw new IllegalArgumentException("Destination granularity must be coarser than the current granularity"); } int factor = getGranularity().numSlots() / destGranularity.numSlots(); int parentSlot = getSlot() / factor; return SlotKey.of(destGranularity, parentSlot, getShard()); } private SlotKey(Granularity granularity, int slot, int shard); } | SlotKey { public SlotKey extrapolate(Granularity destGranularity) { if (destGranularity.equals(this.getGranularity())) { return this; } if (!destGranularity.isCoarser(getGranularity())) { throw new IllegalArgumentException("Destination granularity must be coarser than the current granularity"); } int factor = getGranularity().numSlots() / destGranularity.numSlots(); int parentSlot = getSlot() / factor; return SlotKey.of(destGranularity, parentSlot, getShard()); } private SlotKey(Granularity granularity, int slot, int shard); int getShard(); int getSlot(); Granularity getGranularity(); static SlotKey of(Granularity granularity, int slot, int shard); static SlotKey parse(String string); Collection<SlotKey> getChildrenKeys(); Collection<SlotKey> getChildrenKeys(Granularity destGranularity); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); SlotKey extrapolate(Granularity destGranularity); } | SlotKey { public SlotKey extrapolate(Granularity destGranularity) { if (destGranularity.equals(this.getGranularity())) { return this; } if (!destGranularity.isCoarser(getGranularity())) { throw new IllegalArgumentException("Destination granularity must be coarser than the current granularity"); } int factor = getGranularity().numSlots() / destGranularity.numSlots(); int parentSlot = getSlot() / factor; return SlotKey.of(destGranularity, parentSlot, getShard()); } private SlotKey(Granularity granularity, int slot, int shard); int getShard(); int getSlot(); Granularity getGranularity(); static SlotKey of(Granularity granularity, int slot, int shard); static SlotKey parse(String string); Collection<SlotKey> getChildrenKeys(); Collection<SlotKey> getChildrenKeys(Granularity destGranularity); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); SlotKey extrapolate(Granularity destGranularity); } |
@Test public void singleClassYieldsThatClass() { Configuration.getInstance().setProperty( CoreConfig.DISCOVERY_MODULES, "com.rackspacecloud.blueflood.utils.DummyDiscoveryIO3"); Object loadedModule = ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Assert.assertNotNull(loadedModule); Assert.assertEquals(DummyDiscoveryIO3.class, loadedModule.getClass()); } | public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } |
@Test public void singleClassInDifferentPackageYieldsThatClass() { Configuration.getInstance().setProperty( CoreConfig.DISCOVERY_MODULES, "com.rackspacecloud.blueflood.io.DummyDiscoveryIO"); Object loadedModule = ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Assert.assertNotNull(loadedModule); Assert.assertEquals(DummyDiscoveryIO.class, loadedModule.getClass()); } | public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } |
@Test public void emptyStringYieldsNull() { Configuration.getInstance().setProperty(CoreConfig.DISCOVERY_MODULES, ""); Object loadedModule = ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Assert.assertNull(loadedModule); } | public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } |
@Test(expected=RuntimeException.class) public void multipleClassesCauseAnException() { Configuration.getInstance().setProperty( CoreConfig.DISCOVERY_MODULES, "com.rackspacecloud.blueflood.io.DummyDiscoveryIO,com.rackspacecloud.blueflood.io.DummyDiscoveryIO2"); Object loadedModule = ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); } | public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } |
@Test public void nonExistentClassYieldsNull() { Configuration.getInstance().setProperty( CoreConfig.DISCOVERY_MODULES, "com.rackspacecloud.blueflood.NonExistentClass"); Object loadedModule = ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Assert.assertNull(loadedModule); } | public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } |
@Test public void callingTwiceYieldsTheSameObjectBothTimes() { Configuration.getInstance().setProperty( CoreConfig.DISCOVERY_MODULES, "com.rackspacecloud.blueflood.io.DummyDiscoveryIO"); Object loadedModule1 = ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Assert.assertNotNull(loadedModule1); Assert.assertEquals(DummyDiscoveryIO.class, loadedModule1.getClass()); Object loadedModule2 = ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Assert.assertNotNull(loadedModule2); Assert.assertSame(loadedModule1, loadedModule2); } | public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } |
@Test public void givingDifferentKeysButSameClassYieldsTwoSeparateObjects() { Configuration.getInstance().setProperty( CoreConfig.DISCOVERY_MODULES, "com.rackspacecloud.blueflood.io.DummyDiscoveryIO"); Object loadedModule1 = ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Assert.assertNotNull(loadedModule1); Assert.assertEquals(DummyDiscoveryIO.class, loadedModule1.getClass()); Assert.assertEquals(DummyDiscoveryIO.class, loadedModule1.getClass()); } | public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } |
@Test public void setServerTimeSetsContextTime() { service.setServerTime(1234L); verify(context).setCurrentTimeMillis(anyLong()); verifyNoMoreInteractions(context); verifyZeroInteractions(shardStateManager); verifyZeroInteractions(locatorFetchExecutors); verifyZeroInteractions(rollupReadExecutors); verifyZeroInteractions(rollupWriteExecutors); } | public synchronized void setServerTime(long millis) { log.info("Manually setting server time to {} {}", millis, new java.util.Date(millis)); context.setCurrentTimeMillis(millis); } | RollupService implements Runnable, RollupServiceMBean { public synchronized void setServerTime(long millis) { log.info("Manually setting server time to {} {}", millis, new java.util.Date(millis)); context.setCurrentTimeMillis(millis); } } | RollupService implements Runnable, RollupServiceMBean { public synchronized void setServerTime(long millis) { log.info("Manually setting server time to {} {}", millis, new java.util.Date(millis)); context.setCurrentTimeMillis(millis); } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
ThreadPoolExecutor locatorFetchExecutors,
ThreadPoolExecutor rollupReadExecutors,
ThreadPoolExecutor rollupWriteExecutors,
long rollupDelayMillis,
long rollupDelayForMetricsWithShortDelay,
long rollupWaitForMetricsWithLongDelay,
long pollerPeriod,
long configRefreshInterval); } | RollupService implements Runnable, RollupServiceMBean { public synchronized void setServerTime(long millis) { log.info("Manually setting server time to {} {}", millis, new java.util.Date(millis)); context.setCurrentTimeMillis(millis); } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
ThreadPoolExecutor locatorFetchExecutors,
ThreadPoolExecutor rollupReadExecutors,
ThreadPoolExecutor rollupWriteExecutors,
long rollupDelayMillis,
long rollupDelayForMetricsWithShortDelay,
long rollupWaitForMetricsWithLongDelay,
long pollerPeriod,
long configRefreshInterval); void initializeGauges(); void forcePoll(); void run(); synchronized void setServerTime(long millis); synchronized long getServerTime(); synchronized void setKeepingServerTime(boolean b); synchronized boolean getKeepingServerTime(); synchronized void setPollerPeriod(long l); synchronized long getPollerPeriod(); synchronized int getScheduledSlotCheckCount(); synchronized int getSecondsSinceLastSlotCheck(); synchronized int getSlotCheckConcurrency(); synchronized void setSlotCheckConcurrency(int i); synchronized int getRollupConcurrency(); synchronized void setRollupConcurrency(int i); synchronized int getQueuedRollupCount(); synchronized int getInFlightRollupCount(); synchronized boolean getActive(); synchronized void setActive(boolean b); void addShard(Integer shard); void removeShard(Integer shard); Collection<Integer> getManagedShards(); synchronized Collection<Integer> getRecentlyScheduledShards(); synchronized Collection<String> getOldestUnrolledSlotPerGranularity(int shard); } | RollupService implements Runnable, RollupServiceMBean { public synchronized void setServerTime(long millis) { log.info("Manually setting server time to {} {}", millis, new java.util.Date(millis)); context.setCurrentTimeMillis(millis); } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
ThreadPoolExecutor locatorFetchExecutors,
ThreadPoolExecutor rollupReadExecutors,
ThreadPoolExecutor rollupWriteExecutors,
long rollupDelayMillis,
long rollupDelayForMetricsWithShortDelay,
long rollupWaitForMetricsWithLongDelay,
long pollerPeriod,
long configRefreshInterval); void initializeGauges(); void forcePoll(); void run(); synchronized void setServerTime(long millis); synchronized long getServerTime(); synchronized void setKeepingServerTime(boolean b); synchronized boolean getKeepingServerTime(); synchronized void setPollerPeriod(long l); synchronized long getPollerPeriod(); synchronized int getScheduledSlotCheckCount(); synchronized int getSecondsSinceLastSlotCheck(); synchronized int getSlotCheckConcurrency(); synchronized void setSlotCheckConcurrency(int i); synchronized int getRollupConcurrency(); synchronized void setRollupConcurrency(int i); synchronized int getQueuedRollupCount(); synchronized int getInFlightRollupCount(); synchronized boolean getActive(); synchronized void setActive(boolean b); void addShard(Integer shard); void removeShard(Integer shard); Collection<Integer> getManagedShards(); synchronized Collection<Integer> getRecentlyScheduledShards(); synchronized Collection<String> getOldestUnrolledSlotPerGranularity(int shard); } |
@Test public void testSlotFromSlotKey() { int expectedSlot = 1; int slot = SlotKeySerDes.slotFromSlotKey(SlotKey.of(Granularity.MIN_5, expectedSlot, 10).toString()); Assert.assertEquals(expectedSlot, slot); } | protected static int slotFromSlotKey(String s) { return Integer.parseInt(s.split(",", -1)[1]); } | SlotKeySerDes { protected static int slotFromSlotKey(String s) { return Integer.parseInt(s.split(",", -1)[1]); } } | SlotKeySerDes { protected static int slotFromSlotKey(String s) { return Integer.parseInt(s.split(",", -1)[1]); } } | SlotKeySerDes { protected static int slotFromSlotKey(String s) { return Integer.parseInt(s.split(",", -1)[1]); } static SlotKey deserialize(String stateStr); String serialize(SlotKey slotKey); String serialize(Granularity gran, int slot, int shard); } | SlotKeySerDes { protected static int slotFromSlotKey(String s) { return Integer.parseInt(s.split(",", -1)[1]); } static SlotKey deserialize(String stateStr); String serialize(SlotKey slotKey); String serialize(Granularity gran, int slot, int shard); } |
@Test public void callingTwiceWithSameKeyButDifferentClassesYieldsTheSameObjectBothTimes() { Configuration.getInstance().setProperty( CoreConfig.DISCOVERY_MODULES, "com.rackspacecloud.blueflood.io.DummyDiscoveryIO"); Object loadedModule1 = ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Assert.assertNotNull(loadedModule1); Assert.assertEquals(DummyDiscoveryIO.class, loadedModule1.getClass()); Configuration.getInstance().setProperty( CoreConfig.DISCOVERY_MODULES, "com.rackspacecloud.blueflood.io.DummyDiscoveryIO2"); Object loadedModule2 = ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Assert.assertNotNull(loadedModule2); Assert.assertSame(loadedModule1, loadedModule2); } | public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } |
@Test public void specifyingAnInterfaceYieldsNull() { Configuration.getInstance().setProperty( CoreConfig.DISCOVERY_MODULES, "com.rackspacecloud.blueflood.io.DiscoveryIO"); Object loadedModule = ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Assert.assertNull(loadedModule); } | public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } |
@Test public void classWithNoParameterlessConstructorYieldsNull() { Configuration.getInstance().setProperty( CoreConfig.DISCOVERY_MODULES, "com.rackspacecloud.blueflood.io.DummyDiscoveryIO4"); Object loadedModule = ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Assert.assertNull(loadedModule); } | public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } |
@Test public void packagePrivateClassYieldsNull() { Configuration.getInstance().setProperty( CoreConfig.DISCOVERY_MODULES, "com.rackspacecloud.blueflood.io.DummyDiscoveryIO5"); Object loadedModule = ModuleLoader.getInstance(DiscoveryIO.class, CoreConfig.DISCOVERY_MODULES); Assert.assertNull(loadedModule); } | public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } | ModuleLoader { public static Object getInstance(Class c, CoreConfig moduleName) { Object moduleInstance = loadedModules.get(moduleName.name().toString()); if (moduleInstance != null) return moduleInstance; List<String> modules = Configuration.getInstance().getListProperty(moduleName); if (modules.isEmpty()) return null; if (modules.size() != 1) { throw new RuntimeException("Cannot load service with more than one "+moduleName+" module"); } String module = modules.get(0); log.info("Loading the module " + module); try { ClassLoader loader = c.getClassLoader(); Class genericClass = loader.loadClass(module); moduleInstance = genericClass.newInstance(); loadedModules.put(moduleName.name().toString(), moduleInstance); log.info("Registering the module " + module); } catch (InstantiationException e) { log.error(String.format("Unable to create instance of %s class for %s", c.getName(), module), e); } catch (IllegalAccessException e) { log.error("Error starting module: " + module, e); } catch (ClassNotFoundException e) { log.error("Unable to locate module: " + module, e); } catch (RuntimeException e) { log.error("Error starting module: " + module, e); } catch (Throwable e) { log.error("Error starting module: " + module, e); } return moduleInstance; } static Object getInstance(Class c, CoreConfig moduleName); @VisibleForTesting static void clearCache(); } |
@Test public void testGlobMatchingAnyChar() { String glob = "*"; String expectedRegex = ".*"; GlobPattern pattern = new GlobPattern(glob); Assert.assertEquals(expectedRegex, pattern.compiled().toString()); } | public Pattern compiled() { return compiled; } | GlobPattern { public Pattern compiled() { return compiled; } } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } |
@Test public void testEmptyGlob() { String glob = ""; String expectedRegex = ""; GlobPattern pattern = new GlobPattern(glob); Assert.assertEquals(expectedRegex, pattern.compiled().toString()); } | public Pattern compiled() { return compiled; } | GlobPattern { public Pattern compiled() { return compiled; } } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } |
@Test public void testGlobWithWildcards1() { String glob = "foo.bar$1.(cat).baz|qux.dog+"; String expectedRegex = "foo\\.bar\\$1\\.\\(cat\\)\\.baz\\|qux\\.dog\\+"; GlobPattern pattern = new GlobPattern(glob); Assert.assertEquals(expectedRegex, pattern.compiled().toString()); } | public Pattern compiled() { return compiled; } | GlobPattern { public Pattern compiled() { return compiled; } } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } |
@Test public void testMetricNameGlob() { String glob = "foo.bar.*"; String expectedRegex = "foo\\.bar\\..*"; GlobPattern pattern = new GlobPattern(glob); Assert.assertEquals(expectedRegex, pattern.compiled().toString()); } | public Pattern compiled() { return compiled; } | GlobPattern { public Pattern compiled() { return compiled; } } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } |
@Test public void testMetricNameGlobWithWildCards() { String glob = "f*.bar.*"; String expectedRegex = "f.*\\.bar\\..*"; GlobPattern pattern = new GlobPattern(glob); Assert.assertEquals(expectedRegex, pattern.compiled().toString()); } | public Pattern compiled() { return compiled; } | GlobPattern { public Pattern compiled() { return compiled; } } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } |
@Test public void testMetricNameWithMatchingSingleChar() { String glob = "foo?"; String expectedRegex = "foo."; GlobPattern pattern = new GlobPattern(glob); Assert.assertEquals(expectedRegex, pattern.compiled().toString()); } | public Pattern compiled() { return compiled; } | GlobPattern { public Pattern compiled() { return compiled; } } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } |
@Test public void getServerTimeGetsContextTime() { long expected = 1234L; doReturn(expected).when(context).getCurrentTimeMillis(); long actual = service.getServerTime(); assertEquals(expected, actual); verify(context).getCurrentTimeMillis(); verifyNoMoreInteractions(context); verifyZeroInteractions(shardStateManager); verifyZeroInteractions(locatorFetchExecutors); verifyZeroInteractions(rollupReadExecutors); verifyZeroInteractions(rollupWriteExecutors); } | public synchronized long getServerTime() { return context.getCurrentTimeMillis(); } | RollupService implements Runnable, RollupServiceMBean { public synchronized long getServerTime() { return context.getCurrentTimeMillis(); } } | RollupService implements Runnable, RollupServiceMBean { public synchronized long getServerTime() { return context.getCurrentTimeMillis(); } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
ThreadPoolExecutor locatorFetchExecutors,
ThreadPoolExecutor rollupReadExecutors,
ThreadPoolExecutor rollupWriteExecutors,
long rollupDelayMillis,
long rollupDelayForMetricsWithShortDelay,
long rollupWaitForMetricsWithLongDelay,
long pollerPeriod,
long configRefreshInterval); } | RollupService implements Runnable, RollupServiceMBean { public synchronized long getServerTime() { return context.getCurrentTimeMillis(); } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
ThreadPoolExecutor locatorFetchExecutors,
ThreadPoolExecutor rollupReadExecutors,
ThreadPoolExecutor rollupWriteExecutors,
long rollupDelayMillis,
long rollupDelayForMetricsWithShortDelay,
long rollupWaitForMetricsWithLongDelay,
long pollerPeriod,
long configRefreshInterval); void initializeGauges(); void forcePoll(); void run(); synchronized void setServerTime(long millis); synchronized long getServerTime(); synchronized void setKeepingServerTime(boolean b); synchronized boolean getKeepingServerTime(); synchronized void setPollerPeriod(long l); synchronized long getPollerPeriod(); synchronized int getScheduledSlotCheckCount(); synchronized int getSecondsSinceLastSlotCheck(); synchronized int getSlotCheckConcurrency(); synchronized void setSlotCheckConcurrency(int i); synchronized int getRollupConcurrency(); synchronized void setRollupConcurrency(int i); synchronized int getQueuedRollupCount(); synchronized int getInFlightRollupCount(); synchronized boolean getActive(); synchronized void setActive(boolean b); void addShard(Integer shard); void removeShard(Integer shard); Collection<Integer> getManagedShards(); synchronized Collection<Integer> getRecentlyScheduledShards(); synchronized Collection<String> getOldestUnrolledSlotPerGranularity(int shard); } | RollupService implements Runnable, RollupServiceMBean { public synchronized long getServerTime() { return context.getCurrentTimeMillis(); } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
ThreadPoolExecutor locatorFetchExecutors,
ThreadPoolExecutor rollupReadExecutors,
ThreadPoolExecutor rollupWriteExecutors,
long rollupDelayMillis,
long rollupDelayForMetricsWithShortDelay,
long rollupWaitForMetricsWithLongDelay,
long pollerPeriod,
long configRefreshInterval); void initializeGauges(); void forcePoll(); void run(); synchronized void setServerTime(long millis); synchronized long getServerTime(); synchronized void setKeepingServerTime(boolean b); synchronized boolean getKeepingServerTime(); synchronized void setPollerPeriod(long l); synchronized long getPollerPeriod(); synchronized int getScheduledSlotCheckCount(); synchronized int getSecondsSinceLastSlotCheck(); synchronized int getSlotCheckConcurrency(); synchronized void setSlotCheckConcurrency(int i); synchronized int getRollupConcurrency(); synchronized void setRollupConcurrency(int i); synchronized int getQueuedRollupCount(); synchronized int getInFlightRollupCount(); synchronized boolean getActive(); synchronized void setActive(boolean b); void addShard(Integer shard); void removeShard(Integer shard); Collection<Integer> getManagedShards(); synchronized Collection<Integer> getRecentlyScheduledShards(); synchronized Collection<String> getOldestUnrolledSlotPerGranularity(int shard); } |
@Test public void testMetricNameWithMatchingAnyChar() { String glob = "foo*"; String expectedRegex = "foo.*"; GlobPattern pattern = new GlobPattern(glob); Assert.assertEquals(expectedRegex, pattern.compiled().toString()); } | public Pattern compiled() { return compiled; } | GlobPattern { public Pattern compiled() { return compiled; } } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } |
@Test public void testMetricNameWithGlobSyntax() { String glob = "foo.{*}"; String expectedRegex = "foo\\.(.*)"; GlobPattern pattern = new GlobPattern(glob); Assert.assertEquals(expectedRegex, pattern.compiled().toString()); } | public Pattern compiled() { return compiled; } | GlobPattern { public Pattern compiled() { return compiled; } } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } |
@Test public void testVariousGlobSyntax2() { String glob = "[!abc]oo.*]"; String expectedRegex = "[^abc]oo\\..*]"; GlobPattern pattern = new GlobPattern(glob); Assert.assertEquals(expectedRegex, pattern.compiled().toString()); } | public Pattern compiled() { return compiled; } | GlobPattern { public Pattern compiled() { return compiled; } } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } |
@Test public void testMetricNameWithVariousGlobSyntax() { String glob = "foo.[bz]*.*"; String expectedRegex = "foo\\.[bz].*\\..*"; GlobPattern pattern = new GlobPattern(glob); Assert.assertEquals(expectedRegex, pattern.compiled().toString()); } | public Pattern compiled() { return compiled; } | GlobPattern { public Pattern compiled() { return compiled; } } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } |
@Test public void testMetricNameGlobWithoutWildCard() { String glob = "foo.bar"; String expectedRegex = "foo\\.bar"; GlobPattern pattern = new GlobPattern(glob); Assert.assertEquals(expectedRegex, pattern.compiled().toString()); } | public Pattern compiled() { return compiled; } | GlobPattern { public Pattern compiled() { return compiled; } } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } | GlobPattern { public Pattern compiled() { return compiled; } GlobPattern(String globPattern); Pattern compiled(); static Pattern compile(String globPattern); boolean matches(CharSequence s); void set(String glob); boolean hasWildcard(); } |
@Test public void testAlwaysPresent() { Assert.assertTrue(ttlProvider.getTTL("test", Granularity.FULL, RollupType.NOT_A_ROLLUP).isPresent()); } | @Override public Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType) { return getSafeTTL(gran, rollupType); } | SafetyTtlProvider implements TenantTtlProvider { @Override public Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType) { return getSafeTTL(gran, rollupType); } } | SafetyTtlProvider implements TenantTtlProvider { @Override public Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType) { return getSafeTTL(gran, rollupType); } SafetyTtlProvider(); } | SafetyTtlProvider implements TenantTtlProvider { @Override public Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType) { return getSafeTTL(gran, rollupType); } SafetyTtlProvider(); @Override Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType); Optional<TimeValue> getSafeTTL(Granularity gran, RollupType rollupType); } | SafetyTtlProvider implements TenantTtlProvider { @Override public Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType) { return getSafeTTL(gran, rollupType); } SafetyTtlProvider(); @Override Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType); Optional<TimeValue> getSafeTTL(Granularity gran, RollupType rollupType); } |
@Test public void testSetLocatorCurrentInBatchLayer() throws InterruptedException { locatorCache.setLocatorCurrentInBatchLayer(LOCATOR); assertTrue("locator not stored in cache", locatorCache.isLocatorCurrentInBatchLayer(LOCATOR)); Thread.sleep(2000L); assertTrue("locator not expired from cache", !locatorCache.isLocatorCurrentInBatchLayer(LOCATOR)); } | public synchronized void setLocatorCurrentInBatchLayer(Locator loc) { getOrCreateInsertedLocatorEntry(loc).setBatchCurrent(); } | LocatorCache { public synchronized void setLocatorCurrentInBatchLayer(Locator loc) { getOrCreateInsertedLocatorEntry(loc).setBatchCurrent(); } } | LocatorCache { public synchronized void setLocatorCurrentInBatchLayer(Locator loc) { getOrCreateInsertedLocatorEntry(loc).setBatchCurrent(); } protected LocatorCache(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); } | LocatorCache { public synchronized void setLocatorCurrentInBatchLayer(Locator loc) { getOrCreateInsertedLocatorEntry(loc).setBatchCurrent(); } protected LocatorCache(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); static LocatorCache getInstance(); @VisibleForTesting static LocatorCache getInstance(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); long getCurrentLocatorCount(); long getCurrentDelayedLocatorCount(); synchronized boolean isLocatorCurrentInBatchLayer(Locator loc); synchronized boolean isLocatorCurrentInDiscoveryLayer(Locator loc); synchronized boolean isLocatorCurrentInTokenDiscoveryLayer(Locator loc); synchronized boolean isDelayedLocatorForASlotCurrent(int slot, Locator locator); synchronized void setLocatorCurrentInBatchLayer(Locator loc); synchronized void setLocatorCurrentInDiscoveryLayer(Locator loc); synchronized void setLocatorCurrentInTokenDiscoveryLayer(Locator loc); synchronized void setDelayedLocatorForASlotCurrent(int slot, Locator locator); @VisibleForTesting synchronized void resetCache(); @VisibleForTesting synchronized void resetInsertedLocatorsCache(); } | LocatorCache { public synchronized void setLocatorCurrentInBatchLayer(Locator loc) { getOrCreateInsertedLocatorEntry(loc).setBatchCurrent(); } protected LocatorCache(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); static LocatorCache getInstance(); @VisibleForTesting static LocatorCache getInstance(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); long getCurrentLocatorCount(); long getCurrentDelayedLocatorCount(); synchronized boolean isLocatorCurrentInBatchLayer(Locator loc); synchronized boolean isLocatorCurrentInDiscoveryLayer(Locator loc); synchronized boolean isLocatorCurrentInTokenDiscoveryLayer(Locator loc); synchronized boolean isDelayedLocatorForASlotCurrent(int slot, Locator locator); synchronized void setLocatorCurrentInBatchLayer(Locator loc); synchronized void setLocatorCurrentInDiscoveryLayer(Locator loc); synchronized void setLocatorCurrentInTokenDiscoveryLayer(Locator loc); synchronized void setDelayedLocatorForASlotCurrent(int slot, Locator locator); @VisibleForTesting synchronized void resetCache(); @VisibleForTesting synchronized void resetInsertedLocatorsCache(); } |
@Test public void testIsLocatorCurrentInBatchLayer() throws InterruptedException { assertTrue("locator which was never set is present in cache", !locatorCache.isLocatorCurrentInBatchLayer(LOCATOR)); locatorCache.setLocatorCurrentInBatchLayer(LOCATOR); assertTrue("locator not stored in cache", locatorCache.isLocatorCurrentInBatchLayer(LOCATOR)); } | public synchronized boolean isLocatorCurrentInBatchLayer(Locator loc) { LocatorCacheEntry entry = insertedLocators.getIfPresent(loc.toString()); return entry != null && entry.isBatchCurrent(); } | LocatorCache { public synchronized boolean isLocatorCurrentInBatchLayer(Locator loc) { LocatorCacheEntry entry = insertedLocators.getIfPresent(loc.toString()); return entry != null && entry.isBatchCurrent(); } } | LocatorCache { public synchronized boolean isLocatorCurrentInBatchLayer(Locator loc) { LocatorCacheEntry entry = insertedLocators.getIfPresent(loc.toString()); return entry != null && entry.isBatchCurrent(); } protected LocatorCache(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); } | LocatorCache { public synchronized boolean isLocatorCurrentInBatchLayer(Locator loc) { LocatorCacheEntry entry = insertedLocators.getIfPresent(loc.toString()); return entry != null && entry.isBatchCurrent(); } protected LocatorCache(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); static LocatorCache getInstance(); @VisibleForTesting static LocatorCache getInstance(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); long getCurrentLocatorCount(); long getCurrentDelayedLocatorCount(); synchronized boolean isLocatorCurrentInBatchLayer(Locator loc); synchronized boolean isLocatorCurrentInDiscoveryLayer(Locator loc); synchronized boolean isLocatorCurrentInTokenDiscoveryLayer(Locator loc); synchronized boolean isDelayedLocatorForASlotCurrent(int slot, Locator locator); synchronized void setLocatorCurrentInBatchLayer(Locator loc); synchronized void setLocatorCurrentInDiscoveryLayer(Locator loc); synchronized void setLocatorCurrentInTokenDiscoveryLayer(Locator loc); synchronized void setDelayedLocatorForASlotCurrent(int slot, Locator locator); @VisibleForTesting synchronized void resetCache(); @VisibleForTesting synchronized void resetInsertedLocatorsCache(); } | LocatorCache { public synchronized boolean isLocatorCurrentInBatchLayer(Locator loc) { LocatorCacheEntry entry = insertedLocators.getIfPresent(loc.toString()); return entry != null && entry.isBatchCurrent(); } protected LocatorCache(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); static LocatorCache getInstance(); @VisibleForTesting static LocatorCache getInstance(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); long getCurrentLocatorCount(); long getCurrentDelayedLocatorCount(); synchronized boolean isLocatorCurrentInBatchLayer(Locator loc); synchronized boolean isLocatorCurrentInDiscoveryLayer(Locator loc); synchronized boolean isLocatorCurrentInTokenDiscoveryLayer(Locator loc); synchronized boolean isDelayedLocatorForASlotCurrent(int slot, Locator locator); synchronized void setLocatorCurrentInBatchLayer(Locator loc); synchronized void setLocatorCurrentInDiscoveryLayer(Locator loc); synchronized void setLocatorCurrentInTokenDiscoveryLayer(Locator loc); synchronized void setDelayedLocatorForASlotCurrent(int slot, Locator locator); @VisibleForTesting synchronized void resetCache(); @VisibleForTesting synchronized void resetInsertedLocatorsCache(); } |
@Test public void testSetLocatorCurrentInDiscoveryLayer() throws InterruptedException { locatorCache.setLocatorCurrentInDiscoveryLayer(LOCATOR); assertTrue("locator not stored in cache", locatorCache.isLocatorCurrentInDiscoveryLayer(LOCATOR)); Thread.sleep(2000L); assertTrue("locator not expired from cache", !locatorCache.isLocatorCurrentInDiscoveryLayer(LOCATOR)); } | public synchronized void setLocatorCurrentInDiscoveryLayer(Locator loc) { getOrCreateInsertedLocatorEntry(loc).setDiscoveryCurrent(); } | LocatorCache { public synchronized void setLocatorCurrentInDiscoveryLayer(Locator loc) { getOrCreateInsertedLocatorEntry(loc).setDiscoveryCurrent(); } } | LocatorCache { public synchronized void setLocatorCurrentInDiscoveryLayer(Locator loc) { getOrCreateInsertedLocatorEntry(loc).setDiscoveryCurrent(); } protected LocatorCache(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); } | LocatorCache { public synchronized void setLocatorCurrentInDiscoveryLayer(Locator loc) { getOrCreateInsertedLocatorEntry(loc).setDiscoveryCurrent(); } protected LocatorCache(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); static LocatorCache getInstance(); @VisibleForTesting static LocatorCache getInstance(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); long getCurrentLocatorCount(); long getCurrentDelayedLocatorCount(); synchronized boolean isLocatorCurrentInBatchLayer(Locator loc); synchronized boolean isLocatorCurrentInDiscoveryLayer(Locator loc); synchronized boolean isLocatorCurrentInTokenDiscoveryLayer(Locator loc); synchronized boolean isDelayedLocatorForASlotCurrent(int slot, Locator locator); synchronized void setLocatorCurrentInBatchLayer(Locator loc); synchronized void setLocatorCurrentInDiscoveryLayer(Locator loc); synchronized void setLocatorCurrentInTokenDiscoveryLayer(Locator loc); synchronized void setDelayedLocatorForASlotCurrent(int slot, Locator locator); @VisibleForTesting synchronized void resetCache(); @VisibleForTesting synchronized void resetInsertedLocatorsCache(); } | LocatorCache { public synchronized void setLocatorCurrentInDiscoveryLayer(Locator loc) { getOrCreateInsertedLocatorEntry(loc).setDiscoveryCurrent(); } protected LocatorCache(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); static LocatorCache getInstance(); @VisibleForTesting static LocatorCache getInstance(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); long getCurrentLocatorCount(); long getCurrentDelayedLocatorCount(); synchronized boolean isLocatorCurrentInBatchLayer(Locator loc); synchronized boolean isLocatorCurrentInDiscoveryLayer(Locator loc); synchronized boolean isLocatorCurrentInTokenDiscoveryLayer(Locator loc); synchronized boolean isDelayedLocatorForASlotCurrent(int slot, Locator locator); synchronized void setLocatorCurrentInBatchLayer(Locator loc); synchronized void setLocatorCurrentInDiscoveryLayer(Locator loc); synchronized void setLocatorCurrentInTokenDiscoveryLayer(Locator loc); synchronized void setDelayedLocatorForASlotCurrent(int slot, Locator locator); @VisibleForTesting synchronized void resetCache(); @VisibleForTesting synchronized void resetInsertedLocatorsCache(); } |
@Test public void testIsLocatorCurrentInDiscoveryLayer() throws InterruptedException { assertTrue("locator which was never set is present in cache", !locatorCache.isLocatorCurrentInDiscoveryLayer(LOCATOR)); locatorCache.setLocatorCurrentInDiscoveryLayer(LOCATOR); assertTrue("locator not stored in cache", locatorCache.isLocatorCurrentInDiscoveryLayer(LOCATOR)); } | public synchronized boolean isLocatorCurrentInDiscoveryLayer(Locator loc) { LocatorCacheEntry entry = insertedLocators.getIfPresent(loc.toString()); return entry != null && entry.isDiscoveryCurrent(); } | LocatorCache { public synchronized boolean isLocatorCurrentInDiscoveryLayer(Locator loc) { LocatorCacheEntry entry = insertedLocators.getIfPresent(loc.toString()); return entry != null && entry.isDiscoveryCurrent(); } } | LocatorCache { public synchronized boolean isLocatorCurrentInDiscoveryLayer(Locator loc) { LocatorCacheEntry entry = insertedLocators.getIfPresent(loc.toString()); return entry != null && entry.isDiscoveryCurrent(); } protected LocatorCache(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); } | LocatorCache { public synchronized boolean isLocatorCurrentInDiscoveryLayer(Locator loc) { LocatorCacheEntry entry = insertedLocators.getIfPresent(loc.toString()); return entry != null && entry.isDiscoveryCurrent(); } protected LocatorCache(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); static LocatorCache getInstance(); @VisibleForTesting static LocatorCache getInstance(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); long getCurrentLocatorCount(); long getCurrentDelayedLocatorCount(); synchronized boolean isLocatorCurrentInBatchLayer(Locator loc); synchronized boolean isLocatorCurrentInDiscoveryLayer(Locator loc); synchronized boolean isLocatorCurrentInTokenDiscoveryLayer(Locator loc); synchronized boolean isDelayedLocatorForASlotCurrent(int slot, Locator locator); synchronized void setLocatorCurrentInBatchLayer(Locator loc); synchronized void setLocatorCurrentInDiscoveryLayer(Locator loc); synchronized void setLocatorCurrentInTokenDiscoveryLayer(Locator loc); synchronized void setDelayedLocatorForASlotCurrent(int slot, Locator locator); @VisibleForTesting synchronized void resetCache(); @VisibleForTesting synchronized void resetInsertedLocatorsCache(); } | LocatorCache { public synchronized boolean isLocatorCurrentInDiscoveryLayer(Locator loc) { LocatorCacheEntry entry = insertedLocators.getIfPresent(loc.toString()); return entry != null && entry.isDiscoveryCurrent(); } protected LocatorCache(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); static LocatorCache getInstance(); @VisibleForTesting static LocatorCache getInstance(long expireAfterAccessDuration, TimeUnit expireAfterAccessTimeUnit,
long expireAfterWriteDuration, TimeUnit expireAfterWriteTimeUnit); long getCurrentLocatorCount(); long getCurrentDelayedLocatorCount(); synchronized boolean isLocatorCurrentInBatchLayer(Locator loc); synchronized boolean isLocatorCurrentInDiscoveryLayer(Locator loc); synchronized boolean isLocatorCurrentInTokenDiscoveryLayer(Locator loc); synchronized boolean isDelayedLocatorForASlotCurrent(int slot, Locator locator); synchronized void setLocatorCurrentInBatchLayer(Locator loc); synchronized void setLocatorCurrentInDiscoveryLayer(Locator loc); synchronized void setLocatorCurrentInTokenDiscoveryLayer(Locator loc); synchronized void setDelayedLocatorForASlotCurrent(int slot, Locator locator); @VisibleForTesting synchronized void resetCache(); @VisibleForTesting synchronized void resetInsertedLocatorsCache(); } |
@Test public void getKeepingServerTimeGetsKeepingServerTime() { assertEquals(true, service.getKeepingServerTime()); } | public synchronized boolean getKeepingServerTime() { return keepingServerTime; } | RollupService implements Runnable, RollupServiceMBean { public synchronized boolean getKeepingServerTime() { return keepingServerTime; } } | RollupService implements Runnable, RollupServiceMBean { public synchronized boolean getKeepingServerTime() { return keepingServerTime; } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
ThreadPoolExecutor locatorFetchExecutors,
ThreadPoolExecutor rollupReadExecutors,
ThreadPoolExecutor rollupWriteExecutors,
long rollupDelayMillis,
long rollupDelayForMetricsWithShortDelay,
long rollupWaitForMetricsWithLongDelay,
long pollerPeriod,
long configRefreshInterval); } | RollupService implements Runnable, RollupServiceMBean { public synchronized boolean getKeepingServerTime() { return keepingServerTime; } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
ThreadPoolExecutor locatorFetchExecutors,
ThreadPoolExecutor rollupReadExecutors,
ThreadPoolExecutor rollupWriteExecutors,
long rollupDelayMillis,
long rollupDelayForMetricsWithShortDelay,
long rollupWaitForMetricsWithLongDelay,
long pollerPeriod,
long configRefreshInterval); void initializeGauges(); void forcePoll(); void run(); synchronized void setServerTime(long millis); synchronized long getServerTime(); synchronized void setKeepingServerTime(boolean b); synchronized boolean getKeepingServerTime(); synchronized void setPollerPeriod(long l); synchronized long getPollerPeriod(); synchronized int getScheduledSlotCheckCount(); synchronized int getSecondsSinceLastSlotCheck(); synchronized int getSlotCheckConcurrency(); synchronized void setSlotCheckConcurrency(int i); synchronized int getRollupConcurrency(); synchronized void setRollupConcurrency(int i); synchronized int getQueuedRollupCount(); synchronized int getInFlightRollupCount(); synchronized boolean getActive(); synchronized void setActive(boolean b); void addShard(Integer shard); void removeShard(Integer shard); Collection<Integer> getManagedShards(); synchronized Collection<Integer> getRecentlyScheduledShards(); synchronized Collection<String> getOldestUnrolledSlotPerGranularity(int shard); } | RollupService implements Runnable, RollupServiceMBean { public synchronized boolean getKeepingServerTime() { return keepingServerTime; } RollupService(ScheduleContext context); @VisibleForTesting RollupService(ScheduleContext context,
ShardStateManager shardStateManager,
ThreadPoolExecutor locatorFetchExecutors,
ThreadPoolExecutor rollupReadExecutors,
ThreadPoolExecutor rollupWriteExecutors,
long rollupDelayMillis,
long rollupDelayForMetricsWithShortDelay,
long rollupWaitForMetricsWithLongDelay,
long pollerPeriod,
long configRefreshInterval); void initializeGauges(); void forcePoll(); void run(); synchronized void setServerTime(long millis); synchronized long getServerTime(); synchronized void setKeepingServerTime(boolean b); synchronized boolean getKeepingServerTime(); synchronized void setPollerPeriod(long l); synchronized long getPollerPeriod(); synchronized int getScheduledSlotCheckCount(); synchronized int getSecondsSinceLastSlotCheck(); synchronized int getSlotCheckConcurrency(); synchronized void setSlotCheckConcurrency(int i); synchronized int getRollupConcurrency(); synchronized void setRollupConcurrency(int i); synchronized int getQueuedRollupCount(); synchronized int getInFlightRollupCount(); synchronized boolean getActive(); synchronized void setActive(boolean b); void addShard(Integer shard); void removeShard(Integer shard); Collection<Integer> getManagedShards(); synchronized Collection<Integer> getRecentlyScheduledShards(); synchronized Collection<String> getOldestUnrolledSlotPerGranularity(int shard); } |
@Test public void testConfigTtl_invalid() { Assert.assertFalse(ttlProvider.getTTL("acBar", Granularity.FULL, RollupType.SET).isPresent()); } | @Override public Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType) { final TimeValue ttl = ttlMapper.get(gran, rollupType); if (ttl == null) { log.trace("No valid TTL entry for granularity: {}, rollup type: {}" + " in config. Resorting to safe TTL values.", gran.name(), rollupType.name()); return Optional.absent(); } return Optional.of(ttl); } | ConfigTtlProvider implements TenantTtlProvider { @Override public Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType) { final TimeValue ttl = ttlMapper.get(gran, rollupType); if (ttl == null) { log.trace("No valid TTL entry for granularity: {}, rollup type: {}" + " in config. Resorting to safe TTL values.", gran.name(), rollupType.name()); return Optional.absent(); } return Optional.of(ttl); } } | ConfigTtlProvider implements TenantTtlProvider { @Override public Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType) { final TimeValue ttl = ttlMapper.get(gran, rollupType); if (ttl == null) { log.trace("No valid TTL entry for granularity: {}, rollup type: {}" + " in config. Resorting to safe TTL values.", gran.name(), rollupType.name()); return Optional.absent(); } return Optional.of(ttl); } @VisibleForTesting ConfigTtlProvider(); } | ConfigTtlProvider implements TenantTtlProvider { @Override public Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType) { final TimeValue ttl = ttlMapper.get(gran, rollupType); if (ttl == null) { log.trace("No valid TTL entry for granularity: {}, rollup type: {}" + " in config. Resorting to safe TTL values.", gran.name(), rollupType.name()); return Optional.absent(); } return Optional.of(ttl); } @VisibleForTesting ConfigTtlProvider(); static ConfigTtlProvider getInstance(); @Override Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType); TimeValue getConfigTTLForIngestion(); boolean areTTLsForced(); } | ConfigTtlProvider implements TenantTtlProvider { @Override public Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType) { final TimeValue ttl = ttlMapper.get(gran, rollupType); if (ttl == null) { log.trace("No valid TTL entry for granularity: {}, rollup type: {}" + " in config. Resorting to safe TTL values.", gran.name(), rollupType.name()); return Optional.absent(); } return Optional.of(ttl); } @VisibleForTesting ConfigTtlProvider(); static ConfigTtlProvider getInstance(); @Override Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType); TimeValue getConfigTTLForIngestion(); boolean areTTLsForced(); } |
@Test public void testGetTTL() throws Exception { assertTrue(combinedProvider.getTTL("foo", Granularity.FULL, RollupType.BF_BASIC).isPresent()); assertTrue(combinedProvider.getTTL("foo", Granularity.MIN_5, RollupType.BF_BASIC).isPresent()); assertFalse(configProvider.getTTL("foo", Granularity.MIN_5, RollupType.BF_BASIC).isPresent()); assertEquals(combinedProvider.getTTL("foo", Granularity.MIN_5, RollupType.BF_BASIC).get(), SafetyTtlProvider.getInstance().getTTL("foo", Granularity.MIN_5, RollupType.BF_BASIC).get()); } | @Override public Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType) { Optional<TimeValue> primaryValue = primary.getTTL(tenantId, gran, rollupType); Optional<TimeValue> safetyValue = safety.getTTL(tenantId, gran, rollupType); return getTimeValue(primaryValue, safetyValue); } | CombinedTtlProvider implements TenantTtlProvider { @Override public Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType) { Optional<TimeValue> primaryValue = primary.getTTL(tenantId, gran, rollupType); Optional<TimeValue> safetyValue = safety.getTTL(tenantId, gran, rollupType); return getTimeValue(primaryValue, safetyValue); } } | CombinedTtlProvider implements TenantTtlProvider { @Override public Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType) { Optional<TimeValue> primaryValue = primary.getTTL(tenantId, gran, rollupType); Optional<TimeValue> safetyValue = safety.getTTL(tenantId, gran, rollupType); return getTimeValue(primaryValue, safetyValue); } @VisibleForTesting CombinedTtlProvider(ConfigTtlProvider primary, SafetyTtlProvider safety); } | CombinedTtlProvider implements TenantTtlProvider { @Override public Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType) { Optional<TimeValue> primaryValue = primary.getTTL(tenantId, gran, rollupType); Optional<TimeValue> safetyValue = safety.getTTL(tenantId, gran, rollupType); return getTimeValue(primaryValue, safetyValue); } @VisibleForTesting CombinedTtlProvider(ConfigTtlProvider primary, SafetyTtlProvider safety); static CombinedTtlProvider getInstance(); @Override Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType); long getFinalTTL(String tenantid, Granularity gran); } | CombinedTtlProvider implements TenantTtlProvider { @Override public Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType) { Optional<TimeValue> primaryValue = primary.getTTL(tenantId, gran, rollupType); Optional<TimeValue> safetyValue = safety.getTTL(tenantId, gran, rollupType); return getTimeValue(primaryValue, safetyValue); } @VisibleForTesting CombinedTtlProvider(ConfigTtlProvider primary, SafetyTtlProvider safety); static CombinedTtlProvider getInstance(); @Override Optional<TimeValue> getTTL(String tenantId, Granularity gran, RollupType rollupType); long getFinalTTL(String tenantid, Granularity gran); } |
@Test public void testTTL() { Locator locator = Locator.createLocatorFromPathComponents("tenantId", "metricName"); Metric metric = new Metric(locator, 134891734L, System.currentTimeMillis(), new TimeValue(5, TimeUnit.HOURS), "Unknown"); try { metric.setTtl(new TimeValue(Long.MAX_VALUE, TimeUnit.SECONDS)); fail(); } catch (Exception e) { Assert.assertTrue(e instanceof RuntimeException); } } | public void setTtl(TimeValue ttl) { if (!isValidTTL(ttl.toSeconds())) { throw new InvalidDataException("TTL supplied for metric is invalid. Required: 0 < ttl < " + Integer.MAX_VALUE + ", provided: " + ttl.toSeconds()); } ttlInSeconds = (int) ttl.toSeconds(); } | Metric implements IMetric { public void setTtl(TimeValue ttl) { if (!isValidTTL(ttl.toSeconds())) { throw new InvalidDataException("TTL supplied for metric is invalid. Required: 0 < ttl < " + Integer.MAX_VALUE + ", provided: " + ttl.toSeconds()); } ttlInSeconds = (int) ttl.toSeconds(); } } | Metric implements IMetric { public void setTtl(TimeValue ttl) { if (!isValidTTL(ttl.toSeconds())) { throw new InvalidDataException("TTL supplied for metric is invalid. Required: 0 < ttl < " + Integer.MAX_VALUE + ", provided: " + ttl.toSeconds()); } ttlInSeconds = (int) ttl.toSeconds(); } Metric(Locator locator, Object metricValue, long collectionTime, TimeValue ttl, String unit); } | Metric implements IMetric { public void setTtl(TimeValue ttl) { if (!isValidTTL(ttl.toSeconds())) { throw new InvalidDataException("TTL supplied for metric is invalid. Required: 0 < ttl < " + Integer.MAX_VALUE + ", provided: " + ttl.toSeconds()); } ttlInSeconds = (int) ttl.toSeconds(); } Metric(Locator locator, Object metricValue, long collectionTime, TimeValue ttl, String unit); Locator getLocator(); Object getMetricValue(); int getTtlInSeconds(); long getCollectionTime(); String getUnit(); void setTtl(TimeValue ttl); void setTtlInSeconds(int ttlInSeconds); RollupType getRollupType(); @Override String toString(); @Override boolean equals(Object o); } | Metric implements IMetric { public void setTtl(TimeValue ttl) { if (!isValidTTL(ttl.toSeconds())) { throw new InvalidDataException("TTL supplied for metric is invalid. Required: 0 < ttl < " + Integer.MAX_VALUE + ", provided: " + ttl.toSeconds()); } ttlInSeconds = (int) ttl.toSeconds(); } Metric(Locator locator, Object metricValue, long collectionTime, TimeValue ttl, String unit); Locator getLocator(); Object getMetricValue(); int getTtlInSeconds(); long getCollectionTime(); String getUnit(); void setTtl(TimeValue ttl); void setTtlInSeconds(int ttlInSeconds); RollupType getRollupType(); @Override String toString(); @Override boolean equals(Object o); } |
@Test public void publicConstructorDoesNotSetStringRepresentation() { Locator locator = new Locator(); assertNotNull(locator); assertNull(locator.toString()); } | public String toString() { return stringRep; } | Locator implements Comparable<Locator> { public String toString() { return stringRep; } } | Locator implements Comparable<Locator> { public String toString() { return stringRep; } Locator(); private Locator(String fullyQualifiedMetricName); } | Locator implements Comparable<Locator> { public String toString() { return stringRep; } Locator(); private Locator(String fullyQualifiedMetricName); @Override int hashCode(); @Override boolean equals(Object obj); String toString(); String getTenantId(); String getMetricName(); boolean equals(Locator other); static Locator createLocatorFromPathComponents(String tenantId, String... parts); static Locator createLocatorFromDbKey(String fullyQualifiedMetricName); @Override int compareTo(Locator o); } | Locator implements Comparable<Locator> { public String toString() { return stringRep; } Locator(); private Locator(String fullyQualifiedMetricName); @Override int hashCode(); @Override boolean equals(Object obj); String toString(); String getTenantId(); String getMetricName(); boolean equals(Locator other); static Locator createLocatorFromPathComponents(String tenantId, String... parts); static Locator createLocatorFromDbKey(String fullyQualifiedMetricName); @Override int compareTo(Locator o); static final String METRIC_TOKEN_SEPARATOR; static final String METRIC_TOKEN_SEPARATOR_REGEX; } |
@Test public void publicConstructorDoesNotSetTenant() { Locator locator = new Locator(); assertNotNull(locator); assertNull(locator.getTenantId()); } | public String getTenantId() { return this.tenantId; } | Locator implements Comparable<Locator> { public String getTenantId() { return this.tenantId; } } | Locator implements Comparable<Locator> { public String getTenantId() { return this.tenantId; } Locator(); private Locator(String fullyQualifiedMetricName); } | Locator implements Comparable<Locator> { public String getTenantId() { return this.tenantId; } Locator(); private Locator(String fullyQualifiedMetricName); @Override int hashCode(); @Override boolean equals(Object obj); String toString(); String getTenantId(); String getMetricName(); boolean equals(Locator other); static Locator createLocatorFromPathComponents(String tenantId, String... parts); static Locator createLocatorFromDbKey(String fullyQualifiedMetricName); @Override int compareTo(Locator o); } | Locator implements Comparable<Locator> { public String getTenantId() { return this.tenantId; } Locator(); private Locator(String fullyQualifiedMetricName); @Override int hashCode(); @Override boolean equals(Object obj); String toString(); String getTenantId(); String getMetricName(); boolean equals(Locator other); static Locator createLocatorFromPathComponents(String tenantId, String... parts); static Locator createLocatorFromDbKey(String fullyQualifiedMetricName); @Override int compareTo(Locator o); static final String METRIC_TOKEN_SEPARATOR; static final String METRIC_TOKEN_SEPARATOR_REGEX; } |
@Test public void publicConstructorDoesNotSetMetricName() { Locator locator = new Locator(); assertNotNull(locator); assertNull(locator.getMetricName()); } | public String getMetricName() { return this.metricName; } | Locator implements Comparable<Locator> { public String getMetricName() { return this.metricName; } } | Locator implements Comparable<Locator> { public String getMetricName() { return this.metricName; } Locator(); private Locator(String fullyQualifiedMetricName); } | Locator implements Comparable<Locator> { public String getMetricName() { return this.metricName; } Locator(); private Locator(String fullyQualifiedMetricName); @Override int hashCode(); @Override boolean equals(Object obj); String toString(); String getTenantId(); String getMetricName(); boolean equals(Locator other); static Locator createLocatorFromPathComponents(String tenantId, String... parts); static Locator createLocatorFromDbKey(String fullyQualifiedMetricName); @Override int compareTo(Locator o); } | Locator implements Comparable<Locator> { public String getMetricName() { return this.metricName; } Locator(); private Locator(String fullyQualifiedMetricName); @Override int hashCode(); @Override boolean equals(Object obj); String toString(); String getTenantId(); String getMetricName(); boolean equals(Locator other); static Locator createLocatorFromPathComponents(String tenantId, String... parts); static Locator createLocatorFromDbKey(String fullyQualifiedMetricName); @Override int compareTo(Locator o); static final String METRIC_TOKEN_SEPARATOR; static final String METRIC_TOKEN_SEPARATOR_REGEX; } |
@Test(expected = NullPointerException.class) public void isValidDBKeyThrowsExceptionOnNullDbKey() { Locator locator = new Locator(); locator.isValidDBKey(null, "a"); } | protected boolean isValidDBKey(String dbKey, String delim) { return dbKey.contains(delim); } | Locator implements Comparable<Locator> { protected boolean isValidDBKey(String dbKey, String delim) { return dbKey.contains(delim); } } | Locator implements Comparable<Locator> { protected boolean isValidDBKey(String dbKey, String delim) { return dbKey.contains(delim); } Locator(); private Locator(String fullyQualifiedMetricName); } | Locator implements Comparable<Locator> { protected boolean isValidDBKey(String dbKey, String delim) { return dbKey.contains(delim); } Locator(); private Locator(String fullyQualifiedMetricName); @Override int hashCode(); @Override boolean equals(Object obj); String toString(); String getTenantId(); String getMetricName(); boolean equals(Locator other); static Locator createLocatorFromPathComponents(String tenantId, String... parts); static Locator createLocatorFromDbKey(String fullyQualifiedMetricName); @Override int compareTo(Locator o); } | Locator implements Comparable<Locator> { protected boolean isValidDBKey(String dbKey, String delim) { return dbKey.contains(delim); } Locator(); private Locator(String fullyQualifiedMetricName); @Override int hashCode(); @Override boolean equals(Object obj); String toString(); String getTenantId(); String getMetricName(); boolean equals(Locator other); static Locator createLocatorFromPathComponents(String tenantId, String... parts); static Locator createLocatorFromDbKey(String fullyQualifiedMetricName); @Override int compareTo(Locator o); static final String METRIC_TOKEN_SEPARATOR; static final String METRIC_TOKEN_SEPARATOR_REGEX; } |
@Test(expected = NullPointerException.class) public void isValidDBKeyThrowsExceptionOnNullDelim() { Locator locator = new Locator(); locator.isValidDBKey("a.b.c", null); } | protected boolean isValidDBKey(String dbKey, String delim) { return dbKey.contains(delim); } | Locator implements Comparable<Locator> { protected boolean isValidDBKey(String dbKey, String delim) { return dbKey.contains(delim); } } | Locator implements Comparable<Locator> { protected boolean isValidDBKey(String dbKey, String delim) { return dbKey.contains(delim); } Locator(); private Locator(String fullyQualifiedMetricName); } | Locator implements Comparable<Locator> { protected boolean isValidDBKey(String dbKey, String delim) { return dbKey.contains(delim); } Locator(); private Locator(String fullyQualifiedMetricName); @Override int hashCode(); @Override boolean equals(Object obj); String toString(); String getTenantId(); String getMetricName(); boolean equals(Locator other); static Locator createLocatorFromPathComponents(String tenantId, String... parts); static Locator createLocatorFromDbKey(String fullyQualifiedMetricName); @Override int compareTo(Locator o); } | Locator implements Comparable<Locator> { protected boolean isValidDBKey(String dbKey, String delim) { return dbKey.contains(delim); } Locator(); private Locator(String fullyQualifiedMetricName); @Override int hashCode(); @Override boolean equals(Object obj); String toString(); String getTenantId(); String getMetricName(); boolean equals(Locator other); static Locator createLocatorFromPathComponents(String tenantId, String... parts); static Locator createLocatorFromDbKey(String fullyQualifiedMetricName); @Override int compareTo(Locator o); static final String METRIC_TOKEN_SEPARATOR; static final String METRIC_TOKEN_SEPARATOR_REGEX; } |
@Test public void isValidDBKeyUndelimitedStringReturnsFalse() { Locator locator = new Locator(); assertFalse(locator.isValidDBKey("abc", ".")); } | protected boolean isValidDBKey(String dbKey, String delim) { return dbKey.contains(delim); } | Locator implements Comparable<Locator> { protected boolean isValidDBKey(String dbKey, String delim) { return dbKey.contains(delim); } } | Locator implements Comparable<Locator> { protected boolean isValidDBKey(String dbKey, String delim) { return dbKey.contains(delim); } Locator(); private Locator(String fullyQualifiedMetricName); } | Locator implements Comparable<Locator> { protected boolean isValidDBKey(String dbKey, String delim) { return dbKey.contains(delim); } Locator(); private Locator(String fullyQualifiedMetricName); @Override int hashCode(); @Override boolean equals(Object obj); String toString(); String getTenantId(); String getMetricName(); boolean equals(Locator other); static Locator createLocatorFromPathComponents(String tenantId, String... parts); static Locator createLocatorFromDbKey(String fullyQualifiedMetricName); @Override int compareTo(Locator o); } | Locator implements Comparable<Locator> { protected boolean isValidDBKey(String dbKey, String delim) { return dbKey.contains(delim); } Locator(); private Locator(String fullyQualifiedMetricName); @Override int hashCode(); @Override boolean equals(Object obj); String toString(); String getTenantId(); String getMetricName(); boolean equals(Locator other); static Locator createLocatorFromPathComponents(String tenantId, String... parts); static Locator createLocatorFromDbKey(String fullyQualifiedMetricName); @Override int compareTo(Locator o); static final String METRIC_TOKEN_SEPARATOR; static final String METRIC_TOKEN_SEPARATOR_REGEX; } |
Subsets and Splits