MCPcopy
hub / github.com/OpenTSDB/opentsdb / getMock

Method getMock

test/storage/MockDataPoints.java:78–128  ·  view source on GitHub ↗

Retrieves the DataPoints object and sets up the mock calls @return A DataPoints object for iteration

()

Source from the content-addressed store, hash-verified

76 * @return A DataPoints object for iteration
77 */
78 public DataPoints getMock() {
79 when(dps.metricName()).thenReturn(metric);
80 when(dps.metricNameAsync()).thenReturn(Deferred.fromResult(metric));
81 when(dps.getTags()).thenReturn(tags);
82 when(dps.getTagsAsync()).thenReturn(Deferred.fromResult(tags));
83 when(dps.getAggregatedTags()).thenReturn(agg_tags);
84 when(dps.getAggregatedTagsAsync()).thenReturn(Deferred.fromResult(agg_tags));
85 when(dps.getTSUIDs()).thenReturn(tsuids);
86 when(dps.getAnnotations()).thenReturn(annotations);
87 when(dps.size()).thenReturn(limit);
88 when(dps.aggregatedSize()).thenReturn(limit * 2);
89 when(dps.iterator()).thenReturn(it);
90 when(dps.getQueryIndex()).thenReturn(0);
91
92 // iterator mocking
93 when(it.hasNext()).thenAnswer(new Answer<Boolean>() {
94 @Override
95 public Boolean answer(final InvocationOnMock args) throws Throwable {
96 if (value > limit) {
97 return false;
98 }
99 return true;
100 }
101 });
102 when(it.next()).thenAnswer(new Answer<DataPoint>() {
103 @Override
104 public DataPoint answer(final InvocationOnMock args) throws Throwable {
105 value++;
106 timestamp += interval;
107 return dp;
108 }
109 });
110 doThrow(new RuntimeException("OpenTSDB doesn't support remove"))
111 .when(it).remove();
112
113 // data point mocking
114 when(dp.timestamp()).thenAnswer(new Answer<Long>() {
115 @Override
116 public Long answer(final InvocationOnMock args) throws Throwable {
117 return timestamp;
118 }
119 });
120 when(dp.isInteger()).thenReturn(true);
121 when(dp.longValue()).thenAnswer(new Answer<Long>() {
122 @Override
123 public Long answer(final InvocationOnMock args) throws Throwable {
124 return value;
125 }
126 });
127 return dps;
128 }
129
130 /**
131 * Returns the DataPoint object so that the test can override the mocks.

Calls 15

metricNameMethod · 0.65
metricNameAsyncMethod · 0.65
getTagsMethod · 0.65
getTagsAsyncMethod · 0.65
getAggregatedTagsMethod · 0.65
getTSUIDsMethod · 0.65
getAnnotationsMethod · 0.65
sizeMethod · 0.65
aggregatedSizeMethod · 0.65
iteratorMethod · 0.65
getQueryIndexMethod · 0.65

Tested by

no test coverage detected