use of org.apache.kafka.common.header.internals.RecordHeaders in project kafka by apache.
the class BufferValueTest method shouldSerializeOld.
@Test
public void shouldSerializeOld() {
final ProcessorRecordContext context = new ProcessorRecordContext(0L, 0L, 0, "topic", new RecordHeaders());
final byte[] serializedContext = context.serialize();
final byte[] oldValue = { (byte) 5 };
final byte[] bytes = new BufferValue(null, oldValue, null, context).serialize(0).array();
final byte[] withoutContext = Arrays.copyOfRange(bytes, serializedContext.length, bytes.length);
assertThat(withoutContext, is(ByteBuffer.allocate(Integer.BYTES * 3 + 1).putInt(-1).putInt(1).put(oldValue).putInt(-1).array()));
}
use of org.apache.kafka.common.header.internals.RecordHeaders in project kafka by apache.
the class BufferValueTest method shouldDeserializeNew.
@Test
public void shouldDeserializeNew() {
final ProcessorRecordContext context = new ProcessorRecordContext(0L, 0L, 0, "topic", new RecordHeaders());
final byte[] serializedContext = context.serialize();
final byte[] newValue = { (byte) 5 };
final ByteBuffer serialValue = ByteBuffer.allocate(serializedContext.length + Integer.BYTES * 3 + newValue.length).put(serializedContext).putInt(-1).putInt(-1).putInt(1).put(newValue);
serialValue.position(0);
assertThat(BufferValue.deserialize(serialValue), is(new BufferValue(null, null, newValue, context)));
}
use of org.apache.kafka.common.header.internals.RecordHeaders in project kafka by apache.
the class BufferValueTest method shouldSerializeNew.
@Test
public void shouldSerializeNew() {
final ProcessorRecordContext context = new ProcessorRecordContext(0L, 0L, 0, "topic", new RecordHeaders());
final byte[] serializedContext = context.serialize();
final byte[] newValue = { (byte) 5 };
final byte[] bytes = new BufferValue(null, null, newValue, context).serialize(0).array();
final byte[] withoutContext = Arrays.copyOfRange(bytes, serializedContext.length, bytes.length);
assertThat(withoutContext, is(ByteBuffer.allocate(Integer.BYTES * 3 + 1).putInt(-1).putInt(-1).putInt(1).put(newValue).array()));
}
use of org.apache.kafka.common.header.internals.RecordHeaders in project kafka by apache.
the class BufferValueTest method shouldSerializeNulls.
@Test
public void shouldSerializeNulls() {
final ProcessorRecordContext context = new ProcessorRecordContext(0L, 0L, 0, "topic", new RecordHeaders());
final byte[] serializedContext = context.serialize();
final byte[] bytes = new BufferValue(null, null, null, context).serialize(0).array();
final byte[] withoutContext = Arrays.copyOfRange(bytes, serializedContext.length, bytes.length);
assertThat(withoutContext, is(ByteBuffer.allocate(Integer.BYTES * 3).putInt(-1).putInt(-1).putInt(-1).array()));
}
use of org.apache.kafka.common.header.internals.RecordHeaders in project kafka by apache.
the class BufferValueTest method shouldSerializePrior.
@Test
public void shouldSerializePrior() {
final ProcessorRecordContext context = new ProcessorRecordContext(0L, 0L, 0, "topic", new RecordHeaders());
final byte[] serializedContext = context.serialize();
final byte[] priorValue = { (byte) 5 };
final byte[] bytes = new BufferValue(priorValue, null, null, context).serialize(0).array();
final byte[] withoutContext = Arrays.copyOfRange(bytes, serializedContext.length, bytes.length);
assertThat(withoutContext, is(ByteBuffer.allocate(Integer.BYTES * 3 + 1).putInt(1).put(priorValue).putInt(-1).putInt(-1).array()));
}
Aggregations