Search in sources :

Example 1 with KsqlTimestampExtractor

use of io.confluent.ksql.execution.streams.timestamp.KsqlTimestampExtractor in project ksql by confluentinc.

the class SinkBuilderTest method shouldCallProcessingLoggerOnTimestampExtractorError.

@Test
public void shouldCallProcessingLoggerOnTimestampExtractorError() {
    // Given
    final KsqlTimestampExtractor timestampExtractor = mock(KsqlTimestampExtractor.class);
    doThrow(KsqlException.class).when(timestampExtractor).extract(key, row);
    // When
    final Transformer<Struct, GenericRow, KeyValue<Struct, GenericRow>> transformer = getTransformer(timestampExtractor, processingLogger);
    transformer.init(processorContext);
    final KeyValue<Struct, GenericRow> kv = transformer.transform(key, row);
    // Then
    assertNull(kv);
    verify(timestampExtractor).extract(key, row);
    verify(processingLogger, Mockito.times(1)).error(any());
    verifyNoMoreInteractions(processorContext);
}
Also used : GenericRow(io.confluent.ksql.GenericRow) KeyValue(org.apache.kafka.streams.KeyValue) KsqlTimestampExtractor(io.confluent.ksql.execution.streams.timestamp.KsqlTimestampExtractor) Struct(org.apache.kafka.connect.data.Struct) Test(org.junit.Test)

Example 2 with KsqlTimestampExtractor

use of io.confluent.ksql.execution.streams.timestamp.KsqlTimestampExtractor in project ksql by confluentinc.

the class SinkBuilderTest method shouldTransformTimestampRow.

@Test
public void shouldTransformTimestampRow() {
    // Given
    final long timestampColumnValue = 10001;
    final KsqlTimestampExtractor timestampExtractor = mock(KsqlTimestampExtractor.class);
    when(timestampExtractor.extract(any(), any())).thenReturn(timestampColumnValue);
    // When
    final Transformer<Struct, GenericRow, KeyValue<Struct, GenericRow>> transformer = getTransformer(timestampExtractor, processingLogger);
    transformer.init(processorContext);
    final KeyValue<Struct, GenericRow> kv = transformer.transform(key, row);
    // Then
    assertNull(kv);
    verify(timestampExtractor).extract(key, row);
    verify(processorContext, Mockito.times(1)).forward(eq(key), eq(row), toCaptor.capture());
    assertEquals(toCaptor.getValue(), To.all().withTimestamp(timestampColumnValue));
    verifyNoMoreInteractions(processingLogger);
}
Also used : GenericRow(io.confluent.ksql.GenericRow) KeyValue(org.apache.kafka.streams.KeyValue) KsqlTimestampExtractor(io.confluent.ksql.execution.streams.timestamp.KsqlTimestampExtractor) Struct(org.apache.kafka.connect.data.Struct) Test(org.junit.Test)

Example 3 with KsqlTimestampExtractor

use of io.confluent.ksql.execution.streams.timestamp.KsqlTimestampExtractor in project ksql by confluentinc.

the class SinkBuilderTest method shouldThrowOnNullProcessorContext.

@Test(expected = NullPointerException.class)
public void shouldThrowOnNullProcessorContext() {
    // Given
    final KsqlTimestampExtractor timestampExtractor = mock(KsqlTimestampExtractor.class);
    // When/Then
    getTransformer(timestampExtractor, processingLogger).init(null);
}
Also used : KsqlTimestampExtractor(io.confluent.ksql.execution.streams.timestamp.KsqlTimestampExtractor) Test(org.junit.Test)

Example 4 with KsqlTimestampExtractor

use of io.confluent.ksql.execution.streams.timestamp.KsqlTimestampExtractor in project ksql by confluentinc.

the class SinkBuilderTest method shouldThrowOnNullProcessingLogger.

@Test(expected = NullPointerException.class)
public void shouldThrowOnNullProcessingLogger() {
    // Given
    final KsqlTimestampExtractor timestampExtractor = mock(KsqlTimestampExtractor.class);
    // When/Then
    getTransformer(timestampExtractor, null);
}
Also used : KsqlTimestampExtractor(io.confluent.ksql.execution.streams.timestamp.KsqlTimestampExtractor) Test(org.junit.Test)

Example 5 with KsqlTimestampExtractor

use of io.confluent.ksql.execution.streams.timestamp.KsqlTimestampExtractor in project ksql by confluentinc.

the class SinkBuilderTest method shouldCallProcessingLoggerOnForwardError.

@Test
public void shouldCallProcessingLoggerOnForwardError() {
    // Given
    final long timestampColumnValue = 10001;
    final KsqlTimestampExtractor timestampExtractor = mock(KsqlTimestampExtractor.class);
    when(timestampExtractor.extract(any(), any())).thenReturn(timestampColumnValue);
    doThrow(KsqlException.class).when(processorContext).forward(any(), any(), any(To.class));
    // When
    final Transformer<Struct, GenericRow, KeyValue<Struct, GenericRow>> transformer = getTransformer(timestampExtractor, processingLogger);
    transformer.init(processorContext);
    final KeyValue<Struct, GenericRow> kv = transformer.transform(key, row);
    // Then
    assertNull(kv);
    verify(timestampExtractor).extract(key, row);
    verify(processorContext, Mockito.times(1)).forward(eq(key), eq(row), toCaptor.capture());
    verify(processingLogger, Mockito.times(1)).error(any());
}
Also used : GenericRow(io.confluent.ksql.GenericRow) KeyValue(org.apache.kafka.streams.KeyValue) To(org.apache.kafka.streams.processor.To) KsqlTimestampExtractor(io.confluent.ksql.execution.streams.timestamp.KsqlTimestampExtractor) Struct(org.apache.kafka.connect.data.Struct) Test(org.junit.Test)

Aggregations

KsqlTimestampExtractor (io.confluent.ksql.execution.streams.timestamp.KsqlTimestampExtractor)5 Test (org.junit.Test)5 GenericRow (io.confluent.ksql.GenericRow)3 Struct (org.apache.kafka.connect.data.Struct)3 KeyValue (org.apache.kafka.streams.KeyValue)3 To (org.apache.kafka.streams.processor.To)1