Search in sources :

Example 21 with Record

use of com.datastax.oss.dsbulk.connectors.api.Record in project dsbulk by datastax.

the class JsonConnectorTest method should_read_single_file_multi_doc.

@ParameterizedTest(name = "[{index}] read multi doc file {0} with compression {1} (sources: {2})")
@MethodSource
@DisplayName("Should read multidoc file with given compression")
void should_read_single_file_multi_doc(String fileName, String compression, boolean retainRecordSources) throws Exception {
    JsonConnector connector = new JsonConnector();
    Config settings = TestConfigUtils.createTestConfig("dsbulk.connector.json", "url", url("/" + fileName), "parserFeatures", "{ALLOW_COMMENTS:true}", "deserializationFeatures", "{USE_BIG_DECIMAL_FOR_FLOATS : false}", "compression", quoteJson(compression));
    connector.configure(settings, true, retainRecordSources);
    connector.init();
    assertThat(connector.readConcurrency()).isOne();
    List<Record> actual = Flux.merge(connector.read()).collectList().block();
    verifyRecords(actual, retainRecordSources, rawURL("/" + fileName).toURI());
    connector.close();
}
Also used : Config(com.typesafe.config.Config) DefaultRecord(com.datastax.oss.dsbulk.connectors.api.DefaultRecord) Record(com.datastax.oss.dsbulk.connectors.api.Record) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) DisplayName(org.junit.jupiter.api.DisplayName)

Example 22 with Record

use of com.datastax.oss.dsbulk.connectors.api.Record in project dsbulk by datastax.

the class JsonConnectorTest method should_read_single_empty_file_single_doc.

@Test
void should_read_single_empty_file_single_doc() throws Exception {
    JsonConnector connector = new JsonConnector();
    Config settings = TestConfigUtils.createTestConfig("dsbulk.connector.json", "url", url("/empty.json"), "parserFeatures", "{ALLOW_COMMENTS:true}", "mode", "SINGLE_DOCUMENT");
    connector.configure(settings, true, true);
    connector.init();
    assertThat(connector.readConcurrency()).isOne();
    // should complete with 0 records.
    List<Record> actual = Flux.merge(connector.read()).collectList().block();
    assertThat(actual).hasSize(0);
    connector.close();
}
Also used : Config(com.typesafe.config.Config) DefaultRecord(com.datastax.oss.dsbulk.connectors.api.DefaultRecord) Record(com.datastax.oss.dsbulk.connectors.api.Record) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with Record

use of com.datastax.oss.dsbulk.connectors.api.Record in project dsbulk by datastax.

the class LogManagerTest method should_stop_when_max_connector_errors_reached.

@Test
void should_stop_when_max_connector_errors_reached() throws Exception {
    Path outputDir = Files.createTempDirectory("test");
    LogManager logManager = new LogManager(session, outputDir, ErrorThreshold.forAbsoluteValue(2), ErrorThreshold.forAbsoluteValue(0), true, statementFormatter, EXTENDED, rowFormatter);
    logManager.init();
    Flux<Record> records = Flux.just(csvRecord1, csvRecord2, csvRecord3);
    try {
        records.transform(logManager.newFailedRecordsHandler()).blockLast();
        fail("Expecting TooManyErrorsException to be thrown");
    } catch (TooManyErrorsException e) {
        assertThat(e).hasMessage("Too many errors, the maximum allowed is 2.");
        assertThat(((AbsoluteErrorThreshold) e.getThreshold()).getMaxErrors()).isEqualTo(2);
    }
    logManager.close();
    Path bad = logManager.getOperationDirectory().resolve("connector.bad");
    Path errors = logManager.getOperationDirectory().resolve("connector-errors.log");
    Path positions = logManager.getOperationDirectory().resolve("positions.txt");
    assertThat(bad.toFile()).exists();
    assertThat(errors.toFile()).exists();
    assertThat(positions.toFile()).exists();
    assertThat(FileUtils.listAllFilesInDirectory(logManager.getOperationDirectory())).containsOnly(bad, errors, positions);
    List<String> lines = Files.readAllLines(errors, UTF_8);
    String content = String.join("\n", lines);
    assertThat(content).containsOnlyOnce("Resource: " + resource1).containsOnlyOnce("Position: 1").containsOnlyOnce("Source: " + LogManagerUtils.formatSingleLine(source1)).containsOnlyOnce("java.lang.RuntimeException: error 1").containsOnlyOnce("Resource: " + resource2).containsOnlyOnce("Position: 2").containsOnlyOnce("Source: " + LogManagerUtils.formatSingleLine(source2)).containsOnlyOnce("java.lang.RuntimeException: error 2").containsOnlyOnce("Resource: " + resource3).containsOnlyOnce("Position: 3").containsOnlyOnce("Source: " + LogManagerUtils.formatSingleLine(source3)).containsOnlyOnce("java.lang.RuntimeException: error 3");
}
Also used : Path(java.nio.file.Path) TooManyErrorsException(com.datastax.oss.dsbulk.workflow.api.error.TooManyErrorsException) DefaultErrorRecord(com.datastax.oss.dsbulk.connectors.api.DefaultErrorRecord) DefaultRecord(com.datastax.oss.dsbulk.connectors.api.DefaultRecord) Record(com.datastax.oss.dsbulk.connectors.api.Record) Test(org.junit.jupiter.api.Test)

Example 24 with Record

use of com.datastax.oss.dsbulk.connectors.api.Record in project dsbulk by datastax.

the class MetricsManagerTest method should_increment_records.

@Test
void should_increment_records(@LogCapture(value = MetricsManager.class, level = INFO) LogInterceptor logs, @StreamCapture(STDERR) StreamInterceptor stderr) {
    try (MetricsManager manager = new MetricsManager(new MetricRegistry(), false, "test", Executors.newSingleThreadScheduledExecutor(), SECONDS, MILLISECONDS, -1, -1, true, false, false, true, null, null, LogSettings.Verbosity.normal, Duration.ofSeconds(5), false, protocolVersion, codecRegistry, RowType.REGULAR)) {
        manager.init();
        manager.start();
        Flux<Record> records = Flux.just(record1, record2, record3);
        records.transform(manager.newTotalItemsMonitor()).transform(manager.newFailedItemsMonitor()).blockLast();
        manager.stop(Duration.ofSeconds(123), true);
        MetricRegistry registry = (MetricRegistry) ReflectionUtils.getInternalState(manager, "registry");
        assertThat(registry.counter("records/total").getCount()).isEqualTo(3);
        assertThat(registry.counter("records/failed").getCount()).isEqualTo(1);
        assertThat(logs.getLoggedEvents()).isEmpty();
        assertThat(stderr.getStreamLinesPlain()).anySatisfy(line -> assertThat(line).startsWith("    3 |      1 |"));
    }
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) DefaultErrorRecord(com.datastax.oss.dsbulk.connectors.api.DefaultErrorRecord) DefaultRecord(com.datastax.oss.dsbulk.connectors.api.DefaultRecord) Record(com.datastax.oss.dsbulk.connectors.api.Record) Test(org.junit.jupiter.api.Test)

Example 25 with Record

use of com.datastax.oss.dsbulk.connectors.api.Record in project dsbulk by datastax.

the class PrometheusEndToEndSimulacronIT method newConnectorDelegate.

@NonNull
private Connector newConnectorDelegate() {
    return new Connector() {

        @Override
        public int readConcurrency() {
            return 1;
        }

        @Override
        public boolean supports(@NonNull ConnectorFeature feature) {
            return feature == CommonConnectorFeature.INDEXED_RECORDS;
        }

        @NonNull
        @Override
        public Publisher<Publisher<Record>> read() {
            AtomicInteger counter = new AtomicInteger();
            AtomicBoolean running = new AtomicBoolean(true);
            return Flux.just(Flux.generate(sink -> {
                int i = counter.getAndAdd(1);
                if (i == 0) {
                    startTimer(running);
                }
                if (running.get()) {
                    Record record = RecordUtils.indexedCSV("pk", "pk" + 1, "cc", "cc" + 1, "v", "v" + 1);
                    sink.next(record);
                } else {
                    sink.complete();
                }
            }));
        }

        @NonNull
        @Override
        public RecordMetadata getRecordMetadata() {
            return (fieldType, cqlType) -> GenericType.STRING;
        }

        @NonNull
        @Override
        public Function<Publisher<Record>, Publisher<Record>> write() {
            throw new UnsupportedOperationException();
        }

        @Override
        public int writeConcurrency() {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : SimulacronUtils(com.datastax.oss.dsbulk.tests.simulacron.SimulacronUtils) BoundCluster(com.datastax.oss.simulacron.server.BoundCluster) Connector(com.datastax.oss.dsbulk.connectors.api.Connector) DockerImageName(org.testcontainers.utility.DockerImageName) URL(java.net.URL) MockConnector(com.datastax.oss.dsbulk.runner.tests.MockConnector) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GenericType(com.datastax.oss.driver.api.core.type.reflect.GenericType) Timer(java.util.Timer) Function(java.util.function.Function) Network(org.testcontainers.containers.Network) RecordUtils(com.datastax.oss.dsbulk.runner.tests.RecordUtils) RecordMetadata(com.datastax.oss.dsbulk.connectors.api.RecordMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) Keyspace(com.datastax.oss.dsbulk.tests.simulacron.SimulacronUtils.Keyspace) NonNull(edu.umd.cs.findbugs.annotations.NonNull) EndToEndUtils.assertStatus(com.datastax.oss.dsbulk.runner.tests.EndToEndUtils.assertStatus) Resources(com.datastax.oss.driver.shaded.guava.common.io.Resources) GenericContainer(org.testcontainers.containers.GenericContainer) Tag(org.junit.jupiter.api.Tag) TimerTask(java.util.TimerTask) Record(com.datastax.oss.dsbulk.connectors.api.Record) LogInterceptor(com.datastax.oss.dsbulk.tests.logging.LogInterceptor) Container(org.testcontainers.junit.jupiter.Container) Session(com.datastax.oss.driver.api.core.session.Session) CommonConnectorFeature(com.datastax.oss.dsbulk.connectors.api.CommonConnectorFeature) WorkflowUtils(com.datastax.oss.dsbulk.workflow.api.utils.WorkflowUtils) Table(com.datastax.oss.dsbulk.tests.simulacron.SimulacronUtils.Table) TestAssertions.assertThat(com.datastax.oss.dsbulk.tests.assertions.TestAssertions.assertThat) Publisher(org.reactivestreams.Publisher) Testcontainers(org.testcontainers.junit.jupiter.Testcontainers) IOException(java.io.IOException) ConnectorFeature(com.datastax.oss.dsbulk.connectors.api.ConnectorFeature) DataStaxBulkLoader(com.datastax.oss.dsbulk.runner.DataStaxBulkLoader) LogCapture(com.datastax.oss.dsbulk.tests.logging.LogCapture) StandardCharsets(java.nio.charset.StandardCharsets) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) STATUS_OK(com.datastax.oss.dsbulk.runner.ExitStatus.STATUS_OK) Flux(reactor.core.publisher.Flux) ExitStatus(com.datastax.oss.dsbulk.runner.ExitStatus) MountableFile(org.testcontainers.utility.MountableFile) Column(com.datastax.oss.dsbulk.tests.simulacron.SimulacronUtils.Column) TEXT(com.datastax.oss.driver.api.core.type.DataTypes.TEXT) Connector(com.datastax.oss.dsbulk.connectors.api.Connector) MockConnector(com.datastax.oss.dsbulk.runner.tests.MockConnector) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NonNull(edu.umd.cs.findbugs.annotations.NonNull) Record(com.datastax.oss.dsbulk.connectors.api.Record) Publisher(org.reactivestreams.Publisher) CommonConnectorFeature(com.datastax.oss.dsbulk.connectors.api.CommonConnectorFeature) ConnectorFeature(com.datastax.oss.dsbulk.connectors.api.ConnectorFeature) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Aggregations

Record (com.datastax.oss.dsbulk.connectors.api.Record)54 DefaultRecord (com.datastax.oss.dsbulk.connectors.api.DefaultRecord)40 Config (com.typesafe.config.Config)39 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)37 Test (org.junit.jupiter.api.Test)35 ErrorRecord (com.datastax.oss.dsbulk.connectors.api.ErrorRecord)24 Path (java.nio.file.Path)24 DefaultIndexedField (com.datastax.oss.dsbulk.connectors.api.DefaultIndexedField)10 Function (java.util.function.Function)9 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 DefaultMappedField (com.datastax.oss.dsbulk.connectors.api.DefaultMappedField)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Publisher (org.reactivestreams.Publisher)8 DefaultErrorRecord (com.datastax.oss.dsbulk.connectors.api.DefaultErrorRecord)7 IOException (java.io.IOException)7 ValueSource (org.junit.jupiter.params.provider.ValueSource)7 Flux (reactor.core.publisher.Flux)7 DataStaxBulkLoader (com.datastax.oss.dsbulk.runner.DataStaxBulkLoader)6 ExitStatus (com.datastax.oss.dsbulk.runner.ExitStatus)6