use of org.apache.kafka.test.MockInternalProcessorContext in project kafka by apache.
the class TimeOrderedKeyValueBufferTest method makeContext.
private static MockInternalProcessorContext makeContext() {
final Properties properties = new Properties();
properties.setProperty(StreamsConfig.APPLICATION_ID_CONFIG, APP_ID);
properties.setProperty(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "");
final TaskId taskId = new TaskId(0, 0);
final MockInternalProcessorContext context = new MockInternalProcessorContext(properties, taskId, TestUtils.tempDirectory());
context.setRecordCollector(new MockRecordCollector());
return context;
}
use of org.apache.kafka.test.MockInternalProcessorContext in project kafka by apache.
the class TimeOrderedKeyValueBufferTest method shouldEvictOldestAndUpdateSizeAndCountAndMinTimestamp.
@Test
public void shouldEvictOldestAndUpdateSizeAndCountAndMinTimestamp() {
final TimeOrderedKeyValueBuffer<String, String> buffer = bufferSupplier.apply(testName);
final MockInternalProcessorContext context = makeContext();
buffer.init((StateStoreContext) context, buffer);
putRecord(buffer, context, 1L, 0L, "zxcv", "o23i4");
assertThat(buffer.numRecords(), is(1));
assertThat(buffer.bufferSize(), is(42L));
assertThat(buffer.minTimestamp(), is(1L));
putRecord(buffer, context, 0L, 0L, "asdf", "3ng");
assertThat(buffer.numRecords(), is(2));
assertThat(buffer.bufferSize(), is(82L));
assertThat(buffer.minTimestamp(), is(0L));
final AtomicInteger callbackCount = new AtomicInteger(0);
buffer.evictWhile(() -> true, kv -> {
switch(callbackCount.incrementAndGet()) {
case 1:
{
assertThat(kv.key(), is("asdf"));
assertThat(buffer.numRecords(), is(2));
assertThat(buffer.bufferSize(), is(82L));
assertThat(buffer.minTimestamp(), is(0L));
break;
}
case 2:
{
assertThat(kv.key(), is("zxcv"));
assertThat(buffer.numRecords(), is(1));
assertThat(buffer.bufferSize(), is(42L));
assertThat(buffer.minTimestamp(), is(1L));
break;
}
default:
{
fail("too many invocations");
break;
}
}
});
assertThat(callbackCount.get(), is(2));
assertThat(buffer.numRecords(), is(0));
assertThat(buffer.bufferSize(), is(0L));
assertThat(buffer.minTimestamp(), is(Long.MAX_VALUE));
cleanup(context, buffer);
}
use of org.apache.kafka.test.MockInternalProcessorContext in project kafka by apache.
the class TimeOrderedKeyValueBufferTest method shouldRejectNullValues.
@Test
public void shouldRejectNullValues() {
final TimeOrderedKeyValueBuffer<String, String> buffer = bufferSupplier.apply(testName);
final MockInternalProcessorContext context = makeContext();
buffer.init((StateStoreContext) context, buffer);
try {
buffer.put(0, new Record<>("asdf", null, 0L), getContext(0));
fail("expected an exception");
} catch (final NullPointerException expected) {
// expected
}
cleanup(context, buffer);
}
use of org.apache.kafka.test.MockInternalProcessorContext in project kafka by apache.
the class TimeOrderedKeyValueBufferTest method shouldRemoveData.
@Test
public void shouldRemoveData() {
final TimeOrderedKeyValueBuffer<String, String> buffer = bufferSupplier.apply(testName);
final MockInternalProcessorContext context = makeContext();
buffer.init((StateStoreContext) context, buffer);
putRecord(buffer, context, 0L, 0L, "asdf", "qwer");
assertThat(buffer.numRecords(), is(1));
buffer.evictWhile(() -> true, kv -> {
});
assertThat(buffer.numRecords(), is(0));
cleanup(context, buffer);
}
use of org.apache.kafka.test.MockInternalProcessorContext in project kafka by apache.
the class TimeOrderedKeyValueBufferTest method shouldReturnUndefinedOnPriorValueForNotBufferedKey.
@Test
public void shouldReturnUndefinedOnPriorValueForNotBufferedKey() {
final TimeOrderedKeyValueBuffer<String, String> buffer = bufferSupplier.apply(testName);
final MockInternalProcessorContext context = makeContext();
buffer.init((StateStoreContext) context, buffer);
assertThat(buffer.priorValueForBuffered("ASDF"), is(Maybe.undefined()));
}
Aggregations