Skip to content

Commit 5935a39

Browse files
committed
Count the number of TooManyDatapointsFoundException
1 parent 16094d7 commit 5935a39

File tree

1 file changed

+47
-33
lines changed

1 file changed

+47
-33
lines changed

carbonj.service/src/test/java/com/demandware/carbonj/service/db/TimeSeriesStoreImplDatapointsLimitTest.java

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -44,43 +44,57 @@ public void incrementsMeterWhenTooManyDatapointsAreMatched() throws Exception {
4444
when(nameIndex.findMetrics(any(String.class), anyBoolean(), anyBoolean(), anyBoolean()))
4545
.thenReturn(List.of(m));
4646

47-
ThreadPoolExecutor main = TimeSeriesStoreImpl.newMainTaskQueue(1, 10);
48-
ThreadPoolExecutor heavy = TimeSeriesStoreImpl.newMainTaskQueue(1, 10);
49-
ThreadPoolExecutor serial = TimeSeriesStoreImpl.newSerialTaskQueue(10);
47+
ThreadPoolExecutor main = null;
48+
ThreadPoolExecutor heavy = null;
49+
ThreadPoolExecutor serial = null;
5050

5151
// Create store with a non-existent config file, then override thresholds via reflection-free path:
5252
// Create a temp properties file with a very low datapoints threshold to force the exception
53-
File tmpProps = File.createTempFile("tsstore", ".properties");
54-
try (FileWriter fw = new FileWriter(tmpProps)) {
55-
fw.write("metrics.store.maxDataPointsPerRequest=10\n");
53+
File tmpProps = null;
54+
55+
try {
56+
main = TimeSeriesStoreImpl.newMainTaskQueue(1, 10);
57+
heavy = TimeSeriesStoreImpl.newMainTaskQueue(1, 10);
58+
serial = TimeSeriesStoreImpl.newSerialTaskQueue(10);
59+
60+
tmpProps = File.createTempFile("tsstore", ".properties");
61+
try (FileWriter fw = new FileWriter(tmpProps)) {
62+
fw.write("metrics.store.maxDataPointsPerRequest=10\n");
63+
}
64+
65+
TimeSeriesStoreImpl store = new TimeSeriesStoreImpl(metricRegistry, nameIndex, new NoOpLogger<>(),
66+
main, heavy, serial,
67+
mock(com.demandware.carbonj.service.db.model.DataPointStore.class), dbMetrics,
68+
true, 10, false, new File("/tmp/idx.out"), 10,
69+
tmpProps.getAbsolutePath(), false);
70+
71+
// Manually set thresholds via internal fields to avoid filesystem config
72+
// dataPointsThreshold is private, but enforced via selectThreadPoolExecutor; we can choose query that exceeds
73+
int now = (int) (System.currentTimeMillis() / 1000);
74+
Query q = new Query("foo", now - 365 * 24 * 3600, now, now, System.currentTimeMillis());
75+
76+
long before = metricRegistry.meter("db.datapointsLimitExceeded").getCount();
77+
78+
assertThrows(TooManyDatapointsFoundException.class, () -> store.fetchSeriesData(q));
79+
80+
long after = metricRegistry.meter("db.datapointsLimitExceeded").getCount();
81+
// Ensure the meter was incremented once
82+
assertEquals(before + 1, after);
83+
} finally {
84+
if (main != null) {
85+
main.shutdownNow();
86+
}
87+
if (heavy != null) {
88+
heavy.shutdownNow();
89+
}
90+
if (serial != null) {
91+
serial.shutdownNow();
92+
}
93+
if (tmpProps != null) {
94+
//noinspection ResultOfMethodCallIgnored
95+
tmpProps.delete();
96+
}
5697
}
57-
58-
TimeSeriesStoreImpl store = new TimeSeriesStoreImpl(metricRegistry, nameIndex, new NoOpLogger<>(),
59-
main, heavy, serial,
60-
mock(com.demandware.carbonj.service.db.model.DataPointStore.class), dbMetrics,
61-
true, 10, false, new File("/tmp/idx.out"), 10,
62-
tmpProps.getAbsolutePath(), false);
63-
64-
// Manually set thresholds via internal fields to avoid filesystem config
65-
// dataPointsThreshold is private, but enforced via selectThreadPoolExecutor; we can choose query that exceeds
66-
int now = (int) (System.currentTimeMillis() / 1000);
67-
Query q = new Query("foo", now - 365 * 24 * 3600, now, now, System.currentTimeMillis());
68-
69-
long before = metricRegistry.meter("db.datapointsLimitExceeded").getCount();
70-
71-
assertThrows(TooManyDatapointsFoundException.class, () -> store.fetchSeriesData(q));
72-
73-
long after = metricRegistry.meter("db.datapointsLimitExceeded").getCount();
74-
// Ensure the meter was incremented once
75-
assertEquals(before + 1, after);
76-
77-
// Cleanup executors
78-
main.shutdownNow();
79-
heavy.shutdownNow();
80-
serial.shutdownNow();
81-
// cleanup temp
82-
//noinspection ResultOfMethodCallIgnored
83-
tmpProps.delete();
8498
}
8599
}
86100

0 commit comments

Comments
 (0)