Search in sources :

Example 1 with PartitionsResponse

use of io.zeebe.broker.system.log.PartitionsResponse in project zeebe by zeebe-io.

the class PartitionsResponseTest method shouldEncodePartitions.

@Test
public void shouldEncodePartitions() throws Exception {
    // given
    final PartitionsResponse response = new PartitionsResponse();
    response.addPartition(1, BufferUtil.wrapString("default-topic"));
    response.addPartition(2, BufferUtil.wrapString("foo"));
    response.addPartition(3, BufferUtil.wrapString("foo"));
    // when
    final UnsafeBuffer buf = new UnsafeBuffer(new byte[response.getLength()]);
    response.write(buf, 0);
    // then
    final ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
    final JsonNode deserializedResponse = objectMapper.readTree(new DirectBufferInputStream(buf));
    assertThat(deserializedResponse.isObject()).isTrue();
    assertThat(deserializedResponse.fieldNames()).containsExactly("partitions");
    final JsonNode partitions = deserializedResponse.get("partitions");
    assertThat(partitions.isArray()).isTrue();
    assertThat(partitions.size()).isEqualTo(3);
    final JsonNode partition3 = partitions.get(0);
    assertThat(partition3.isObject()).isTrue();
    assertThat(partition3.get("topic").textValue()).isEqualTo("default-topic");
    assertThat(partition3.get("id").numberValue()).isEqualTo(1);
    final JsonNode partition1 = partitions.get(1);
    assertThat(partition1.isObject()).isTrue();
    assertThat(partition1.get("topic").textValue()).isEqualTo("foo");
    assertThat(partition1.get("id").numberValue()).isEqualTo(2);
    final JsonNode partition2 = partitions.get(2);
    assertThat(partition2.isObject()).isTrue();
    assertThat(partition2.get("topic").textValue()).isEqualTo("foo");
    assertThat(partition2.get("id").numberValue()).isEqualTo(3);
}
Also used : MessagePackFactory(org.msgpack.jackson.dataformat.MessagePackFactory) DirectBufferInputStream(org.agrona.io.DirectBufferInputStream) PartitionsResponse(io.zeebe.broker.system.log.PartitionsResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 PartitionsResponse (io.zeebe.broker.system.log.PartitionsResponse)1 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)1 DirectBufferInputStream (org.agrona.io.DirectBufferInputStream)1 Test (org.junit.Test)1 MessagePackFactory (org.msgpack.jackson.dataformat.MessagePackFactory)1