Search in sources :

Example 1 with ErrorRecord

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"));
}
Also used : ErrorRecord(com.datastax.oss.dsbulk.connectors.api.ErrorRecord) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ErrorRecord

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"));
}
Also used : ErrorRecord(com.datastax.oss.dsbulk.connectors.api.ErrorRecord) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with ErrorRecord

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Config(com.typesafe.config.Config) DefaultRecord(com.datastax.oss.dsbulk.connectors.api.DefaultRecord) Record(com.datastax.oss.dsbulk.connectors.api.Record) ErrorRecord(com.datastax.oss.dsbulk.connectors.api.ErrorRecord) ErrorRecord(com.datastax.oss.dsbulk.connectors.api.ErrorRecord) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ErrorRecord (com.datastax.oss.dsbulk.connectors.api.ErrorRecord)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 DefaultRecord (com.datastax.oss.dsbulk.connectors.api.DefaultRecord)1 Record (com.datastax.oss.dsbulk.connectors.api.Record)1 Config (com.typesafe.config.Config)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 Test (org.junit.jupiter.api.Test)1