Search in sources :

Example 1 with TopologyException

use of org.apache.kafka.streams.errors.TopologyException in project apache-kafka-on-k8s by banzaicloud.

the class KStreamsFineGrainedAutoResetIntegrationTest method shouldThrowExceptionOverlappingPattern.

@Test
public void shouldThrowExceptionOverlappingPattern() throws Exception {
    final KStreamBuilder builder = new KStreamBuilder();
    // NOTE this would realistically get caught when building topology, the test is for completeness
    builder.stream(KStreamBuilder.AutoOffsetReset.EARLIEST, Pattern.compile("topic-[A-D]_1"));
    builder.stream(KStreamBuilder.AutoOffsetReset.LATEST, Pattern.compile("topic-[A-D]_1"));
    // instead of at runtime. See KAFKA-5660
    try {
        builder.earliestResetTopicsPattern();
        fail("Should have thrown TopologyException");
    } catch (final TopologyException expected) {
    // do nothing
    }
}
Also used : KStreamBuilder(org.apache.kafka.streams.kstream.KStreamBuilder) TopologyException(org.apache.kafka.streams.errors.TopologyException) IntegrationTest(org.apache.kafka.test.IntegrationTest) Test(org.junit.Test)

Example 2 with TopologyException

use of org.apache.kafka.streams.errors.TopologyException in project apache-kafka-on-k8s by banzaicloud.

the class KStreamsFineGrainedAutoResetIntegrationTest method shouldThrowExceptionOverlappingTopic.

@Test
public void shouldThrowExceptionOverlappingTopic() throws Exception {
    final StreamsBuilder builder = new StreamsBuilder();
    // NOTE this would realistically get caught when building topology, the test is for completeness
    builder.stream(Pattern.compile("topic-[A-D]_1"), Consumed.with(Topology.AutoOffsetReset.EARLIEST));
    try {
        builder.stream(Arrays.asList(TOPIC_A_1, TOPIC_Z_1), Consumed.with(Topology.AutoOffsetReset.LATEST));
        fail("Should have thrown TopologyException");
    } catch (final TopologyException expected) {
    // do nothing
    }
}
Also used : StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) TopologyException(org.apache.kafka.streams.errors.TopologyException) IntegrationTest(org.apache.kafka.test.IntegrationTest) Test(org.junit.Test)

Example 3 with TopologyException

use of org.apache.kafka.streams.errors.TopologyException in project apache-kafka-on-k8s by banzaicloud.

the class TopologyTest method shouldNotAllowToAddProcessorWithSameName.

@Test
public void shouldNotAllowToAddProcessorWithSameName() {
    topology.addSource("source", "topic-1");
    topology.addProcessor("processor", new MockProcessorSupplier(), "source");
    try {
        topology.addProcessor("processor", new MockProcessorSupplier(), "source");
        fail("Should throw TopologyException for duplicate processor name");
    } catch (TopologyException expected) {
    }
}
Also used : MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) TopologyException(org.apache.kafka.streams.errors.TopologyException) Test(org.junit.Test)

Example 4 with TopologyException

use of org.apache.kafka.streams.errors.TopologyException in project apache-kafka-on-k8s by banzaicloud.

the class KTableImpl method writeAsText.

/**
 * @throws TopologyException if file is not found
 */
@SuppressWarnings({ "unchecked", "deprecation" })
@Override
public void writeAsText(final String filePath, final String label, final Serde<K> keySerde, final Serde<V> valSerde) {
    Objects.requireNonNull(filePath, "filePath can't be null");
    Objects.requireNonNull(label, "label can't be null");
    if (filePath.trim().isEmpty()) {
        throw new TopologyException("filePath can't be an empty string");
    }
    final String name = builder.newProcessorName(PRINTING_NAME);
    try {
        builder.internalTopologyBuilder.addProcessor(name, new KStreamPrint<>(new PrintForeachAction<>(new FileOutputStream(filePath), defaultKeyValueMapper, label)), this.name);
    } catch (final FileNotFoundException e) {
        throw new TopologyException(String.format("Unable to write stream to file at [%s] %s", filePath, e.getMessage()));
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) TopologyException(org.apache.kafka.streams.errors.TopologyException)

Example 5 with TopologyException

use of org.apache.kafka.streams.errors.TopologyException in project apache-kafka-on-k8s by banzaicloud.

the class InternalTopologyBuilderTest method testAddStateStoreWithSource.

@Test
public void testAddStateStoreWithSource() {
    builder.addSource(null, "source-1", null, null, null, "topic-1");
    try {
        builder.addStateStore(new MockStateStoreSupplier("store", false), "source-1");
        fail("Should throw TopologyException with store cannot be added to source");
    } catch (final TopologyException expected) {
    /* ok */
    }
}
Also used : MockStateStoreSupplier(org.apache.kafka.test.MockStateStoreSupplier) TopologyException(org.apache.kafka.streams.errors.TopologyException) Test(org.junit.Test)

Aggregations

TopologyException (org.apache.kafka.streams.errors.TopologyException)8 Test (org.junit.Test)7 MockStateStoreSupplier (org.apache.kafka.test.MockStateStoreSupplier)3 IntegrationTest (org.apache.kafka.test.IntegrationTest)2 MockProcessorSupplier (org.apache.kafka.test.MockProcessorSupplier)2 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)1 KStreamBuilder (org.apache.kafka.streams.kstream.KStreamBuilder)1