use of org.neo4j.unsafe.impl.batchimport.input.InputException in project neo4j by neo4j.
the class ImportPanicIT method shouldExitAndThrowExceptionOnPanic.
/**
* There was this problem where some steps and in particular parallel CSV input parsing that
* paniced would hang the import entirely.
*/
@Test
public void shouldExitAndThrowExceptionOnPanic() throws Exception {
// GIVEN
BatchImporter importer = new ParallelBatchImporter(directory.absolutePath(), fs, Configuration.DEFAULT, NullLogService.getInstance(), ExecutionMonitors.invisible(), AdditionalInitialIds.EMPTY, Config.empty(), StandardV3_0.RECORD_FORMATS);
Iterable<DataFactory<InputNode>> nodeData = nodeData(data(NO_NODE_DECORATOR, fileAsCharReadable(nodeCsvFileWithBrokenEntries())));
Input brokenCsvInput = new CsvInput(nodeData, defaultFormatNodeFileHeader(), relationshipData(), defaultFormatRelationshipFileHeader(), IdType.ACTUAL, csvConfigurationWithLowBufferSize(), new BadCollector(new NullOutputStream(), 0, 0), Runtime.getRuntime().availableProcessors());
// WHEN
try {
importer.doImport(brokenCsvInput);
fail("Should have failed properly");
} catch (InputException e) {
// THEN
assertTrue(e.getCause() instanceof DataAfterQuoteException);
// and we managed to shut down properly
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputException in project neo4j by neo4j.
the class ImportToolTest method shouldPrintUserFriendlyMessageAboutUnsupportedMultilineFields.
@Test
public void shouldPrintUserFriendlyMessageAboutUnsupportedMultilineFields() throws Exception {
// GIVEN
File data = data(":ID,name", "1,\"one\ntwo\nthree\"", "2,four");
try {
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", data.getAbsolutePath(), "--multiline-fields", "false");
fail("Should have failed");
} catch (InputException e) {
// THEN
assertTrue(suppressOutput.getErrorVoice().containsMessage("Detected field which spanned multiple lines"));
assertTrue(suppressOutput.getErrorVoice().containsMessage("multiline-fields"));
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputException in project neo4j by neo4j.
the class ImportToolTest method shouldPrintStackTraceOnInputExceptionIfToldTo.
@Test
public void shouldPrintStackTraceOnInputExceptionIfToldTo() throws Exception {
// GIVEN
List<String> nodeIds = nodeIds();
Configuration config = Configuration.TABS;
// WHEN data file contains more columns than header file
int extraColumns = 3;
try {
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", nodeHeader(config).getAbsolutePath() + MULTI_FILE_DELIMITER + nodeData(false, config, nodeIds, TRUE, Charset.defaultCharset(), extraColumns).getAbsolutePath(), "--stacktrace");
fail("Should have thrown exception");
} catch (InputException e) {
// THEN
assertTrue(suppressOutput.getErrorVoice().containsMessage(e.getClass().getName()));
assertTrue(e.getMessage().contains("Extra column not present in header on line"));
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputException in project neo4j by neo4j.
the class InputEntityDeserializer method close.
@Override
public void close() {
try {
decorator.close();
data.close();
} catch (IOException e) {
throw new InputException("Unable to close data iterator", e);
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputException in project neo4j by neo4j.
the class InputEntityDeserializer method fetchNextOrNull.
@Override
protected ENTITY fetchNextOrNull() {
// Read a CSV "line" and convert the values into what they semantically mean.
try {
if (!deserializeNextFromSource()) {
return null;
}
// When we have everything, create an input entity out of it
ENTITY entity = deserialization.materialize();
// less columns than the data. Prints in close() so it only happens once per file.
while (!mark.isEndOfLine()) {
long lineNumber = data.lineNumber();
data.seek(mark, delimiter);
data.tryExtract(mark, stringExtractor);
badCollector.collectExtraColumns(data.sourceDescription(), lineNumber, stringExtractor.value());
}
entity = decorator.apply(entity);
validator.validate(entity);
return entity;
} catch (IOException e) {
throw new InputException("Unable to read more data from input stream", e);
} finally {
deserialization.clear();
}
}
Aggregations