use of com.google.api.services.dataflow.model.MetricShortId in project beam by apache.
the class CounterShortIdCacheTest method createMetricShortId.
private MetricShortId createMetricShortId(int index, Long shortId) {
MetricShortId id = new MetricShortId();
id.setMetricIndex(index);
id.setShortId(shortId);
return id;
}
use of com.google.api.services.dataflow.model.MetricShortId in project beam by apache.
the class CounterShortIdCacheTest method testValidateNumberStatusesAndStates.
@Test
public void testValidateNumberStatusesAndStates() {
CounterShortIdCache cache = new CounterShortIdCache();
ReportWorkItemStatusRequest request = new ReportWorkItemStatusRequest();
ReportWorkItemStatusResponse reply = new ReportWorkItemStatusResponse();
request.setWorkItemStatuses(createWorkStatusNameAndKind(new String[] { "counter" }, new String[] { "counter2" }));
reply.setWorkItemServiceStates(createWorkServiceState(new MetricShortId[] { createMetricShortId(0, 1000L) }));
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("RequestWorkItemStatus request and response are unbalanced");
cache.storeNewShortIds(request, reply);
}
use of com.google.api.services.dataflow.model.MetricShortId in project beam by apache.
the class CounterShortIdCacheTest method testValidateAggregateIndexOutOfRange.
@Test
public void testValidateAggregateIndexOutOfRange() {
CounterShortIdCache cache = new CounterShortIdCache();
ReportWorkItemStatusRequest request = new ReportWorkItemStatusRequest();
ReportWorkItemStatusResponse reply = new ReportWorkItemStatusResponse();
request.setWorkItemStatuses(createWorkStatusNameAndKind(new String[] { "counter" }));
reply.setWorkItemServiceStates(createWorkServiceState(new MetricShortId[] { createMetricShortId(1000, 1000L) }));
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Received aggregate index outside range of sent update");
cache.storeNewShortIds(request, reply);
}
use of com.google.api.services.dataflow.model.MetricShortId in project beam by apache.
the class CounterShortIdCache method storeNewShortIds.
/**
* Add any new short ids received to the table. The outgoing request will have the full counter
* updates, and the incoming responses have the associated short ids. By matching up short ids
* with the counters in order we can build a mapping of name -> short_id for future use.
*/
public void storeNewShortIds(final ReportWorkItemStatusRequest request, final ReportWorkItemStatusResponse reply) {
checkArgument(request.getWorkItemStatuses() != null && reply.getWorkItemServiceStates() != null && request.getWorkItemStatuses().size() == reply.getWorkItemServiceStates().size(), "RequestWorkItemStatus request and response are unbalanced, status: %s, states: %s", request.getWorkItemStatuses(), reply.getWorkItemServiceStates());
for (int i = 0; i < request.getWorkItemStatuses().size(); i++) {
WorkItemServiceState state = reply.getWorkItemServiceStates().get(i);
WorkItemStatus status = request.getWorkItemStatuses().get(i);
if (state.getMetricShortId() == null) {
continue;
}
checkArgument(status.getCounterUpdates() != null, "Response has shortids but no corresponding CounterUpdate");
for (MetricShortId shortIdMsg : state.getMetricShortId()) {
int metricIndex = MoreObjects.firstNonNull(shortIdMsg.getMetricIndex(), 0);
checkArgument(metricIndex < status.getCounterUpdates().size(), "Received aggregate index outside range of sent update %s >= %s", shortIdMsg.getMetricIndex(), status.getCounterUpdates().size());
CounterUpdate update = status.getCounterUpdates().get(metricIndex);
cache.insert(update, checkNotNull(shortIdMsg.getShortId(), "Shortid should be non-null"));
}
}
}
use of com.google.api.services.dataflow.model.MetricShortId in project beam by apache.
the class CounterShortIdCacheTest method createWorkServiceState.
private List<WorkItemServiceState> createWorkServiceState(Long[]... counterIds) {
List<WorkItemServiceState> states = new ArrayList<>();
for (Long[] ids : counterIds) {
WorkItemServiceState state = new WorkItemServiceState();
List<MetricShortId> shortIds = new ArrayList<>();
for (int i = 0; i < ids.length; i++) {
shortIds.add(createMetricShortId(i, ids[i]));
}
state.setMetricShortId(shortIds);
states.add(state);
}
return states;
}
Aggregations