use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.InvalidProtocolBufferException in project heron by twitter.
the class MetricsCacheMetricsProvider method getMetricsFromMetricsCache.
@VisibleForTesting
TopologyManager.MetricResponse getMetricsFromMetricsCache(String metric, String component, Instant start, Duration duration) {
LOG.log(Level.FINE, "MetricsCache Query request metric name : {0}", metric);
TopologyManager.MetricRequest request = TopologyManager.MetricRequest.newBuilder().setComponentName(component).setExplicitInterval(MetricInterval.newBuilder().setStart(start.minus(duration).getEpochSecond()).setEnd(start.getEpochSecond()).build()).addMetric(metric).build();
LOG.log(Level.FINE, "MetricsCache Query request: \n{0}", request);
HttpURLConnection connection = NetworkUtils.getHttpConnection(getCacheLocation());
try {
boolean result = NetworkUtils.sendHttpPostRequest(connection, "X", request.toByteArray());
if (!result) {
LOG.warning("Failed to get response from metrics cache. Resetting connection...");
resetCacheLocation();
return null;
}
byte[] responseData = NetworkUtils.readHttpResponse(connection);
try {
TopologyManager.MetricResponse response = TopologyManager.MetricResponse.parseFrom(responseData);
LOG.log(Level.FINE, "MetricsCache Query response: \n{0}", response);
return response;
} catch (InvalidProtocolBufferException e) {
LOG.log(Level.SEVERE, "protobuf cannot parse the reply from MetricsCache ", e);
return null;
}
} finally {
if (connection != null) {
connection.disconnect();
}
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.InvalidProtocolBufferException in project j2objc by google.
the class CompatibilityTest method testParseFromInvalidProtocolBufferException.
public void testParseFromInvalidProtocolBufferException() throws Exception {
try {
@SuppressWarnings("unused") TypicalData output = TypicalData.parseFrom(new byte[] { 0x08 });
fail("Expected InvalidProtocolBufferException to be thrown.");
} catch (InvalidProtocolBufferException e) {
// Expected
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.InvalidProtocolBufferException in project j2objc by google.
the class CompatibilityTest method testParseDelimitedFromInvalidProtocolBufferException.
public void testParseDelimitedFromInvalidProtocolBufferException() throws Exception {
try {
ByteArrayInputStream in = new ByteArrayInputStream(new byte[] { 0x03, 0x01, 0x02 });
@SuppressWarnings("unused") TypicalData output = TypicalData.parseDelimitedFrom(in);
fail("Expected InvalidProtocolBufferException to be thrown.");
} catch (InvalidProtocolBufferException e) {
// Expected
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.InvalidProtocolBufferException in project j2objc by google.
the class TrailingZerosTest method testFailsToReadMessageWithTooManyTrailingZeros.
public void testFailsToReadMessageWithTooManyTrailingZeros() throws Exception {
TypicalData data = TypicalData.newBuilder().build();
byte[] serializedData = data.toByteArray();
byte[] paddedSerializedData = Arrays.copyOf(serializedData, serializedData.length + 8);
try {
TypicalData.parseFrom(paddedSerializedData);
fail("should not have parsed a buffer with too many trailing zeros");
} catch (InvalidProtocolBufferException e) {
// expected
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.InvalidProtocolBufferException in project j2objc by google.
the class CompatibilityTest method testMergeDelimitedFromInvalidProtocolBufferException.
public void testMergeDelimitedFromInvalidProtocolBufferException() throws Exception {
try {
ByteArrayInputStream in = new ByteArrayInputStream(new byte[] { 0x03, 0x01, 0x02 });
TypicalData.Builder builder = TypicalData.newBuilder();
builder.mergeDelimitedFrom(in, ExtensionRegistry.getEmptyRegistry());
builder.build();
fail("Expected InvalidProtocolBufferException to be thrown.");
} catch (InvalidProtocolBufferException e) {
// Expected
}
}
Aggregations