Search in sources :

Example 1 with JsonConnector

use of com.datastax.oss.dsbulk.connectors.json.JsonConnector in project dsbulk by datastax.

the class JsonEndToEndSimulacronIT method unload_write_error.

@Test
void unload_write_error() {
    Path file1 = unloadDir.resolve("output-000001.json");
    Path file2 = unloadDir.resolve("output-000002.json");
    Path file3 = unloadDir.resolve("output-000003.json");
    Path file4 = unloadDir.resolve("output-000004.json");
    MockConnector.setDelegate(new JsonConnector() {

        @Override
        public void configure(@NonNull Config settings, boolean read, boolean retainRecordSources) {
            settings = ConfigFactory.parseString("url = " + StringUtils.quoteJson(unloadDir) + ", maxConcurrentFiles = 4").withFallback(ConfigUtils.createReferenceConfig().getConfig("dsbulk.connector.json"));
            super.configure(settings, read, retainRecordSources);
        }

        @NonNull
        @Override
        public Function<Publisher<Record>, Publisher<Record>> write() {
            // will cause the write workers to fail because the files already exist
            try {
                Files.createFile(file1);
                Files.createFile(file2);
                Files.createFile(file3);
                Files.createFile(file4);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return super.write();
        }

        @Override
        public boolean supports(@NonNull ConnectorFeature feature) {
            return true;
        }
    });
    primeIpByCountryTable(simulacron);
    RequestPrime prime = createQueryWithResultSet(SELECT_FROM_IP_BY_COUNTRY, 10);
    simulacron.prime(new Prime(prime));
    String[] args = { "unload", "--connector.name", "mock", "--schema.keyspace", "ks1", "--schema.query", SELECT_FROM_IP_BY_COUNTRY, "--schema.mapping", IP_BY_COUNTRY_MAPPING_NAMED };
    ExitStatus status = new DataStaxBulkLoader(addCommonSettings(args)).run();
    assertStatus(status, STATUS_ABORTED_FATAL_ERROR);
    assertThat(stdErr.getStreamAsString()).contains("failed").containsPattern("output-00000[1-4].json");
    assertThat(logs.getAllMessagesAsString()).contains("failed").containsPattern("output-00000[1-4].json");
}
Also used : Path(java.nio.file.Path) Prime(com.datastax.oss.simulacron.common.stubbing.Prime) RequestPrime(com.datastax.oss.simulacron.common.cluster.RequestPrime) Config(com.typesafe.config.Config) UncheckedIOException(java.io.UncheckedIOException) DataStaxBulkLoader(com.datastax.oss.dsbulk.runner.DataStaxBulkLoader) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ConnectorFeature(com.datastax.oss.dsbulk.connectors.api.ConnectorFeature) ExitStatus(com.datastax.oss.dsbulk.runner.ExitStatus) Function(java.util.function.Function) JsonConnector(com.datastax.oss.dsbulk.connectors.json.JsonConnector) RequestPrime(com.datastax.oss.simulacron.common.cluster.RequestPrime) NonNull(edu.umd.cs.findbugs.annotations.NonNull) Record(com.datastax.oss.dsbulk.connectors.api.Record) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ConnectorFeature (com.datastax.oss.dsbulk.connectors.api.ConnectorFeature)1 Record (com.datastax.oss.dsbulk.connectors.api.Record)1 JsonConnector (com.datastax.oss.dsbulk.connectors.json.JsonConnector)1 DataStaxBulkLoader (com.datastax.oss.dsbulk.runner.DataStaxBulkLoader)1 ExitStatus (com.datastax.oss.dsbulk.runner.ExitStatus)1 RequestPrime (com.datastax.oss.simulacron.common.cluster.RequestPrime)1 Prime (com.datastax.oss.simulacron.common.stubbing.Prime)1 Config (com.typesafe.config.Config)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Path (java.nio.file.Path)1 Function (java.util.function.Function)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1