Search in sources :

Example 1 with Query

use of com.datastax.oss.simulacron.common.request.Query in project pulsar-sink by datastax.

the class SimpleEndToEndSimulacronIT method should_not_record_failure_offsets_for_mapping_errors_if_ignore_errors_all.

@Test
void should_not_record_failure_offsets_for_mapping_errors_if_ignore_errors_all() {
    SimulacronUtils.primeTables(simulacron, schema);
    Query good1 = makeQuery(42, "the answer", 153000987000L);
    simulacron.prime(when(good1).then(noRows()));
    Query good2 = makeQuery(43, "another answer", 153000987000L);
    simulacron.prime(when(good2).then(noRows()));
    Map<String, Object> connectorPropertiesIgnoreErrors = new ImmutableMap.Builder<String, Object>().putAll(connectorProperties).put("ignoreErrors", "All").build();
    taskConfigs.add(connectorPropertiesIgnoreErrors);
    Record<GenericRecord> record1 = makeRecord(0, "42", "the answer", 153000987L, 1234);
    Record<GenericRecord> record2 = makeRecord(0, "bad key", "will fail", 153000987L, 1235);
    Record<GenericRecord> record3 = makeRecord(0, "43", "another answer", 153000987L, 1236);
    runTaskWithRecords(record1, record2, record3);
    assertThat(logs.getAllMessagesAsString()).contains("Error decoding/mapping Pulsar record PulsarSinkRecord{PulsarRecordImpl{topic=persistent://tenant/namespace/mytopic, value=GenericRecordImpl{values={field1=will fail}}").contains("Could not parse 'bad key'");
    InstanceState instanceState = task.getInstanceState();
    assertThat(instanceState.getFailedRecordCounter("mytopic", "ks1.table1")).isEqualTo(1);
    assertThat(instanceState.getRecordCounter("mytopic", "ks1.table1")).isEqualTo(2);
}
Also used : InstanceState(com.datastax.oss.common.sink.state.InstanceState) Query(com.datastax.oss.simulacron.common.request.Query) GenericRecord(org.apache.pulsar.client.api.schema.GenericRecord) ImmutableMap(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap) Test(org.junit.jupiter.api.Test)

Example 2 with Query

use of com.datastax.oss.simulacron.common.request.Query in project pulsar-sink by datastax.

the class SimpleEndToEndSimulacronIT method fail_prepare.

@Test
void fail_prepare() {
    SimulacronUtils.primeTables(simulacron, schema);
    Query bad1 = makeQuery(32, "fail", 153000987000L);
    simulacron.prime(when(bad1).then(serverError("bad thing")).applyToPrepare());
    assertThatThrownBy(() -> task.open(connectorProperties, sinkContext)).isInstanceOf(RuntimeException.class).hasMessageStartingWith("Prepare failed for statement: " + INSERT_STATEMENT + " or " + DELETE_STATEMENT);
}
Also used : Query(com.datastax.oss.simulacron.common.request.Query) Test(org.junit.jupiter.api.Test)

Example 3 with Query

use of com.datastax.oss.simulacron.common.request.Query in project dsbulk by datastax.

the class EndToEndUtils method validateQueryCount.

public static void validateQueryCount(BoundCluster simulacron, int numOfQueries, String query, ConsistencyLevel level) {
    List<QueryLog> logs = simulacron.getLogs().getQueryLogs();
    List<QueryLog> ipLogs = logs.stream().filter(l -> !l.getType().equals("PREPARE") && l.getQuery() != null && l.getQuery().startsWith(query)).collect(Collectors.toList());
    assertThat(ipLogs.size()).isEqualTo(numOfQueries);
    for (QueryLog log : ipLogs) {
        Assertions.assertThat(log.getConsistency()).isEqualTo(level);
    }
}
Also used : SimulacronUtils(com.datastax.oss.dsbulk.tests.simulacron.SimulacronUtils) BoundCluster(com.datastax.oss.simulacron.server.BoundCluster) URL(java.net.URL) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) URISyntaxException(java.net.URISyntaxException) BIGINT(com.datastax.oss.driver.api.core.type.DataTypes.BIGINT) ArrayList(java.util.ArrayList) RequestPrime(com.datastax.oss.simulacron.common.cluster.RequestPrime) LinkedHashMap(java.util.LinkedHashMap) ErrorResult(com.datastax.oss.simulacron.common.result.ErrorResult) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Map(java.util.Map) PathMatcher(java.nio.file.PathMatcher) Assertions(org.assertj.core.api.Assertions) INET(com.datastax.oss.driver.api.core.type.DataTypes.INET) URI(java.net.URI) Result(com.datastax.oss.simulacron.common.result.Result) Path(java.nio.file.Path) FileUtils(com.datastax.oss.dsbulk.tests.utils.FileUtils) Query(com.datastax.oss.simulacron.common.request.Query) PrintWriter(java.io.PrintWriter) QueryLog(com.datastax.oss.simulacron.common.cluster.QueryLog) OperationDirectory(com.datastax.oss.dsbulk.workflow.api.log.OperationDirectory) SuccessResult(com.datastax.oss.simulacron.common.result.SuccessResult) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Stream(java.util.stream.Stream) ExitStatus(com.datastax.oss.dsbulk.runner.ExitStatus) ConsistencyLevel(com.datastax.oss.simulacron.common.codec.ConsistencyLevel) Entry(java.util.Map.Entry) Collections(java.util.Collections) FileSystems(java.nio.file.FileSystems) TEXT(com.datastax.oss.driver.api.core.type.DataTypes.TEXT) QueryLog(com.datastax.oss.simulacron.common.cluster.QueryLog)

Example 4 with Query

use of com.datastax.oss.simulacron.common.request.Query in project pulsar-sink by datastax.

the class SimpleEndToEndSimulacronIT method fail_prepare_counter_table.

@Test
void fail_prepare_counter_table() {
    SimulacronUtils.primeTables(simulacron, schema);
    ImmutableMap<String, String> paramTypes = ImmutableMap.<String, String>builder().put("a", "int").put("b", "varchar").put("c", "counter").build();
    String query = "UPDATE ks1.mycounter SET c = c + :c WHERE a = :a AND b = :b";
    Query bad1 = new Query(query, Collections.emptyList(), makeParams(32, "fail", 2), paramTypes);
    simulacron.prime(when(bad1).then(serverError("bad thing")).applyToPrepare());
    ImmutableMap<String, Object> props = ImmutableMap.<String, Object>builder().put("name", INSTANCE_NAME).put("contactPoints", (String) connectorProperties.get("contactPoints")).put("port", (String) connectorProperties.get("port")).put("loadBalancing.localDc", "dc1").put("topic.mytopic.ks1.mycounter.mapping", "a=key, b=value, c=value.f2").build();
    assertThatThrownBy(() -> task.open(props, sinkContext)).isInstanceOf(RuntimeException.class).hasMessageStartingWith("Prepare failed for statement: " + query + " or " + "DELETE FROM ks1.mycounter WHERE a = :a AND b = :b");
}
Also used : Query(com.datastax.oss.simulacron.common.request.Query) Test(org.junit.jupiter.api.Test)

Example 5 with Query

use of com.datastax.oss.simulacron.common.request.Query in project pulsar-sink by datastax.

the class SimpleEndToEndSimulacronIT method failure_offsets.

@Test
void failure_offsets() {
    SimulacronUtils.primeTables(simulacron, schema);
    Query good1 = makeQuery(42, "the answer", 153000987000L);
    simulacron.prime(when(good1).then(noRows()));
    Query bad1 = makeQuery(32, "fail", 153000987000L);
    simulacron.prime(when(bad1).then(serverError("bad thing")).delay(500, TimeUnit.MILLISECONDS));
    Query good2 = makeQuery(22, "success", 153000987000L);
    simulacron.prime(when(good2).then(noRows()));
    Query bad2 = makeQuery(12, "fail2", 153000987000L);
    simulacron.prime(when(bad2).then(serverError("bad thing")));
    taskConfigs.add(connectorProperties);
    Record<GenericRecord> record1 = makeRecord(0, "42", "the answer", 153000987L, 1234);
    Record<GenericRecord> record2 = makeRecord(0, "32", "fail", 153000987L, 1235);
    Record<GenericRecord> record3 = makeRecord(0, "22", "success", 153000987L, 1236);
    Record<GenericRecord> record4 = makeRecord(0, "12", "fail2", 153000987L, 1237);
    // Make a bad record in a different partition.
    Record<GenericRecord> record5 = makeRecord(1, "bad key", "fail3", 153000987L, 1238);
    // bad record in the wrong topic. THis is probably not realistic but allows us to test the outer
    // try-catch block in mapAndQueueRecord().
    Record<GenericRecord> record6 = new PulsarRecordImpl("persistent://tenant/namespace/wrongtopic", "", new GenericRecordImpl(), recordType);
    runTaskWithRecords(record1, record2, record3, record4, record5, record6);
    assertThat(logs.getAllMessagesAsString()).contains("Error inserting/updating row for Pulsar record PulsarSinkRecord{PulsarRecordImpl{topic=persistent://tenant/namespace/mytopic, value=GenericRecordImpl{values={field1=fail2}}").contains("Error decoding/mapping Pulsar record PulsarSinkRecord{PulsarRecordImpl{topic=persistent://tenant/namespace/mytopic, value=GenericRecordImpl{values={field1=fail3}}").contains("Connector has no configuration for record topic 'wrongtopic'").contains("Could not parse 'bad key'").contains("statement: INSERT INTO ks1.table1(a,b) VALUES (:a,:b) USING TIMESTAMP :" + SinkUtil.TIMESTAMP_VARNAME);
    InstanceState instanceState = task.getInstanceState();
    assertThat(instanceState.getFailedRecordCounter("mytopic", "ks1.table1")).isEqualTo(3);
    assertThat(instanceState.getRecordCounter("mytopic", "ks1.table1")).isEqualTo(4);
    assertThat(instanceState.getFailedWithUnknownTopicCounter()).isEqualTo(1);
}
Also used : InstanceState(com.datastax.oss.common.sink.state.InstanceState) Query(com.datastax.oss.simulacron.common.request.Query) PulsarRecordImpl(com.datastax.oss.sink.pulsar.PulsarRecordImpl) GenericRecordImpl(com.datastax.oss.sink.pulsar.GenericRecordImpl) GenericRecord(org.apache.pulsar.client.api.schema.GenericRecord) Test(org.junit.jupiter.api.Test)

Aggregations

Query (com.datastax.oss.simulacron.common.request.Query)14 RequestPrime (com.datastax.oss.simulacron.common.cluster.RequestPrime)7 Test (org.junit.jupiter.api.Test)7 LinkedHashMap (java.util.LinkedHashMap)6 SuccessResult (com.datastax.oss.simulacron.common.result.SuccessResult)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 GenericRecord (org.apache.pulsar.client.api.schema.GenericRecord)4 InstanceState (com.datastax.oss.common.sink.state.InstanceState)3 ImmutableMap (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap)3 ErrorResult (com.datastax.oss.simulacron.common.result.ErrorResult)3 BoundCluster (com.datastax.oss.simulacron.server.BoundCluster)3 GenericRecordImpl (com.datastax.oss.sink.pulsar.GenericRecordImpl)3 PulsarRecordImpl (com.datastax.oss.sink.pulsar.PulsarRecordImpl)3 Collections (java.util.Collections)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 TEXT (com.datastax.oss.driver.api.core.type.DataTypes.TEXT)2 ServerErrorResult (com.datastax.oss.simulacron.common.result.ServerErrorResult)2