|
17 | 17 |
|
18 | 18 | import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; |
19 | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
20 | | - |
21 | 20 | import org.apache.kafka.connect.data.Decimal; |
22 | 21 | import org.apache.kafka.connect.data.Schema; |
23 | 22 | import org.apache.kafka.connect.data.SchemaBuilder; |
24 | 23 | import org.apache.kafka.connect.data.Struct; |
25 | 24 | import org.apache.kafka.connect.errors.ConnectException; |
26 | 25 | import org.apache.kafka.connect.errors.DataException; |
27 | 26 | import org.apache.kafka.connect.sink.SinkRecord; |
28 | | -import org.junit.Rule; |
| 27 | +import org.hamcrest.MatcherAssert; |
29 | 28 | import org.junit.Before; |
30 | 29 | import org.junit.Test; |
31 | 30 |
|
|
41 | 40 | import java.util.Map; |
42 | 41 | import java.util.Set; |
43 | 42 |
|
44 | | -import org.junit.rules.ExpectedException; |
45 | | - |
46 | 43 | import static io.confluent.connect.elasticsearch.DataConverter.BehaviorOnNullValues; |
| 44 | +import static org.hamcrest.Matchers.containsString; |
47 | 45 |
|
48 | 46 | @ThreadLeakScope(ThreadLeakScope.Scope.NONE) |
49 | 47 | public class ElasticsearchWriterTest extends ElasticsearchSinkTestBase { |
@@ -458,6 +456,32 @@ public void testDropInvalidRecord() throws Exception { |
458 | 456 | verifySearchResults(outputRecords, ignoreKey, ignoreSchema); |
459 | 457 | } |
460 | 458 |
|
| 459 | + @Test |
| 460 | + public void testDropInvalidRecordThrowsOnOtherErrors() throws Exception { |
| 461 | + ignoreSchema = true; |
| 462 | + Collection<SinkRecord> inputRecords = new ArrayList<>(); |
| 463 | + |
| 464 | + Schema structSchema = SchemaBuilder.struct().name("struct") |
| 465 | + .field("bytes", SchemaBuilder.BYTES_SCHEMA) |
| 466 | + .build(); |
| 467 | + |
| 468 | + Struct struct = new Struct(structSchema); |
| 469 | + struct.put("bytes", new byte[]{42}); |
| 470 | + |
| 471 | + SinkRecord validRecord = new SinkRecord(TOPIC, PARTITION, Schema.STRING_SCHEMA, key, structSchema, struct, 1); |
| 472 | + |
| 473 | + inputRecords.add(validRecord); |
| 474 | + |
| 475 | + final ElasticsearchWriter nonStrictWriter = initWriter(client, true); |
| 476 | + // stop the bulk processor |
| 477 | + nonStrictWriter.stop(); |
| 478 | + |
| 479 | + // try to write on a stopped writer, should throw |
| 480 | + ConnectException e = assertThrows(ConnectException.class, |
| 481 | + () -> nonStrictWriter.write(inputRecords)); |
| 482 | + MatcherAssert.assertThat(e.getMessage(), containsString("Stopping")); |
| 483 | + } |
| 484 | + |
461 | 485 | private Collection<SinkRecord> prepareData(int numRecords) { |
462 | 486 | Collection<SinkRecord> records = new ArrayList<>(); |
463 | 487 | for (int i = 0; i < numRecords; ++i) { |
|
0 commit comments