use of org.apache.druid.java.util.common.parsers.ParseException in project druid by druid-io.
the class IncrementalIndexAddResultTest method testIsRowAdded.
@Test
public void testIsRowAdded() {
Assert.assertTrue(new IncrementalIndexAddResult(0, 0L).isRowAdded());
Assert.assertFalse(new IncrementalIndexAddResult(0, 0L, "test").isRowAdded());
Assert.assertFalse(new IncrementalIndexAddResult(0, 0L, new ParseException(null, "test")).isRowAdded());
}
use of org.apache.druid.java.util.common.parsers.ParseException in project druid by druid-io.
the class ParseExceptionHandlerTest method testLogParseExceptions.
@Test
public void testLogParseExceptions() {
final ParseException parseException = new ParseException(null, "test");
final RowIngestionMeters rowIngestionMeters = new SimpleRowIngestionMeters();
final ParseExceptionHandler parseExceptionHandler = new ParseExceptionHandler(rowIngestionMeters, true, Integer.MAX_VALUE, 0);
parseExceptionHandler.handle(parseException);
List<LogEvent> logEvents = logger.getLogEvents();
Assert.assertEquals(1, logEvents.size());
String logMessage = logEvents.get(0).getMessage().getFormattedMessage();
Assert.assertTrue(logMessage.contains("Encountered parse exception"));
}
use of org.apache.druid.java.util.common.parsers.ParseException in project druid by druid-io.
the class ParseExceptionHandlerTest method testMaxAllowedParseExceptionsThrowExceptionWhenItHitsMax.
@Test
public void testMaxAllowedParseExceptionsThrowExceptionWhenItHitsMax() {
final ParseException parseException = new ParseException(null, "test");
final int maxAllowedParseExceptions = 3;
final RowIngestionMeters rowIngestionMeters = new SimpleRowIngestionMeters();
final ParseExceptionHandler parseExceptionHandler = new ParseExceptionHandler(rowIngestionMeters, false, maxAllowedParseExceptions, 0);
IntStream.range(0, maxAllowedParseExceptions).forEach(i -> parseExceptionHandler.handle(parseException));
Assert.assertEquals(3, rowIngestionMeters.getUnparseable());
expectedException.expect(RuntimeException.class);
expectedException.expectMessage("Max parse exceptions[3] exceeded");
try {
parseExceptionHandler.handle(parseException);
} catch (RuntimeException e) {
Assert.assertEquals(4, rowIngestionMeters.getUnparseable());
throw e;
}
}
use of org.apache.druid.java.util.common.parsers.ParseException in project druid by druid-io.
the class ParseExceptionHandlerTest method testGetSavedParseExceptionsReturnMostRecentParseExceptions.
@Test
public void testGetSavedParseExceptionsReturnMostRecentParseExceptions() {
final int maxSavedParseExceptions = 3;
final RowIngestionMeters rowIngestionMeters = new SimpleRowIngestionMeters();
final ParseExceptionHandler parseExceptionHandler = new ParseExceptionHandler(rowIngestionMeters, false, Integer.MAX_VALUE, maxSavedParseExceptions);
Assert.assertNotNull(parseExceptionHandler.getSavedParseExceptionReports());
int exceptionCounter = 0;
for (; exceptionCounter < maxSavedParseExceptions; exceptionCounter++) {
parseExceptionHandler.handle(new ParseException(null, StringUtils.format("test %d", exceptionCounter)));
}
Assert.assertEquals(3, rowIngestionMeters.getUnparseable());
Assert.assertEquals(maxSavedParseExceptions, parseExceptionHandler.getSavedParseExceptionReports().size());
for (int i = 0; i < maxSavedParseExceptions; i++) {
Assert.assertEquals(StringUtils.format("test %d", i), parseExceptionHandler.getSavedParseExceptionReports().get(i).getDetails().get(0));
}
for (; exceptionCounter < 5; exceptionCounter++) {
parseExceptionHandler.handle(new ParseException(null, StringUtils.format("test %d", exceptionCounter)));
}
Assert.assertEquals(5, rowIngestionMeters.getUnparseable());
Assert.assertEquals(maxSavedParseExceptions, parseExceptionHandler.getSavedParseExceptionReports().size());
for (int i = 0; i < maxSavedParseExceptions; i++) {
Assert.assertEquals(StringUtils.format("test %d", i + 2), parseExceptionHandler.getSavedParseExceptionReports().get(i).getDetails().get(0));
}
}
use of org.apache.druid.java.util.common.parsers.ParseException in project druid by druid-io.
the class FileBasedProtobufBytesDecoder method getDescriptor.
private Descriptors.Descriptor getDescriptor(String descriptorFilePath) {
InputStream fin;
fin = this.getClass().getClassLoader().getResourceAsStream(descriptorFilePath);
if (fin == null) {
URL url;
try {
url = new URL(descriptorFilePath);
} catch (MalformedURLException e) {
throw new ParseException(descriptorFilePath, e, "Descriptor not found in class path or malformed URL:" + descriptorFilePath);
}
try {
fin = url.openConnection().getInputStream();
} catch (IOException e) {
throw new ParseException(url.toString(), e, "Cannot read descriptor file: " + url);
}
}
DynamicSchema dynamicSchema;
try {
dynamicSchema = DynamicSchema.parseFrom(fin);
} catch (Descriptors.DescriptorValidationException e) {
throw new ParseException(null, e, "Invalid descriptor file: " + descriptorFilePath);
} catch (IOException e) {
throw new ParseException(null, e, "Cannot read descriptor file: " + descriptorFilePath);
}
Set<String> messageTypes = dynamicSchema.getMessageTypes();
if (messageTypes.size() == 0) {
throw new ParseException(null, "No message types found in the descriptor: " + descriptorFilePath);
}
String messageType = protoMessageType == null ? (String) messageTypes.toArray()[0] : protoMessageType;
Descriptors.Descriptor desc = dynamicSchema.getMessageDescriptor(messageType);
if (desc == null) {
throw new ParseException(null, StringUtils.format("Protobuf message type %s not found in the specified descriptor. Available messages types are %s", protoMessageType, messageTypes));
}
return desc;
}
Aggregations