use of com.datastax.oss.dsbulk.connectors.api.ErrorRecord in project dsbulk by datastax.
the class DefaultReadResultMapperTest method should_map_result_to_error_record_when_mapping_fails.
@ParameterizedTest
@ValueSource(booleans = { true, false })
void should_map_result_to_error_record_when_mapping_fails(boolean retainRecordSources) {
// emulate a bad mapping (bad writetime variable) - see DefaultMapping
String msg = "Cannot create a WriteTimeCodec for int";
IllegalArgumentException error = new IllegalArgumentException(msg);
when(mapping.codec(C1, DataTypes.INT, GenericType.INTEGER)).thenThrow(error);
DefaultReadResultMapper mapper = new DefaultReadResultMapper(mapping, recordMetadata, RESOURCE, retainRecordSources);
ErrorRecord record = (ErrorRecord) mapper.map(result);
assertThat(record.getError()).isInstanceOf(IllegalArgumentException.class).hasMessage("Could not deserialize column col1 of type INT as java.lang.Integer").hasCauseInstanceOf(IllegalArgumentException.class);
Throwable cause = record.getError().getCause();
assertThat(cause).hasMessage(msg);
if (retainRecordSources) {
assertThat(record.getSource()).isSameAs(result);
} else {
assertThat(record.getSource()).isNull();
}
assertThat(record.getResource()).isEqualTo(URI.create("cql://ks1/table1"));
}
use of com.datastax.oss.dsbulk.connectors.api.ErrorRecord in project dsbulk by datastax.
the class DefaultReadResultMapperTest method should_map_result_to_error_record_when_deser_fails.
@ParameterizedTest
@ValueSource(booleans = { true, false })
void should_map_result_to_error_record_when_deser_fails(boolean retainRecordSources) {
// emulate bad byte buffer contents when deserializing a 4-byte integer
String msg = "Invalid 32-bits integer value, expecting 4 bytes but got 5";
IllegalArgumentException error = new IllegalArgumentException(msg);
when(row.get(C1.asIdentifier(), codec1)).thenThrow(error);
byte[] array = { 1, 2, 3, 4, 5 };
when(row.getBytesUnsafe(C1.asIdentifier())).thenReturn(ByteBuffer.wrap(array));
DefaultReadResultMapper mapper = new DefaultReadResultMapper(mapping, recordMetadata, RESOURCE, retainRecordSources);
ErrorRecord record = (ErrorRecord) mapper.map(result);
assertThat(record.getError()).isInstanceOf(IllegalArgumentException.class).hasMessage("Could not deserialize column col1 of type INT as java.lang.Integer").hasCauseInstanceOf(IllegalArgumentException.class);
Throwable cause = record.getError().getCause();
assertThat(cause).hasMessage(msg);
if (retainRecordSources) {
assertThat(record.getSource()).isSameAs(result);
} else {
assertThat(record.getSource()).isNull();
}
assertThat(record.getResource()).isEqualTo(URI.create("cql://ks1/table1"));
}
use of com.datastax.oss.dsbulk.connectors.api.ErrorRecord in project dsbulk by datastax.
the class CSVConnectorTest method should_return_unmappable_record_when_line_malformed.
@Test
void should_return_unmappable_record_when_line_malformed() throws Exception {
InputStream stdin = System.in;
try {
String lines = "header1,header2\nvalue1,value2,value3";
InputStream is = new ByteArrayInputStream(lines.getBytes(UTF_8));
System.setIn(is);
CSVConnector connector = new CSVConnector();
Config settings = TestConfigUtils.createTestConfig("dsbulk.connector.csv", "header", true);
connector.configure(settings, true, true);
connector.init();
List<Record> actual = Flux.merge(connector.read()).collectList().block();
assertThat(actual).hasSize(1);
assertThat(actual.get(0)).isInstanceOf(ErrorRecord.class);
assertThat(actual.get(0).getSource()).isEqualTo("value1,value2,value3");
assertThat(((ErrorRecord) actual.get(0)).getError()).isInstanceOf(IllegalArgumentException.class);
assertThat(actual.get(0).values()).isEmpty();
connector.close();
} finally {
System.setIn(stdin);
}
}
Aggregations