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);
}
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);
}
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);
}
}
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");
}
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);
}
Aggregations