Search in sources :

Example 1 with ZeebeProtocolModule

use of io.camunda.zeebe.protocol.jackson.ZeebeProtocolModule in project zeebe-process-test by camunda-cloud.

the class ContainerizedEngine method getRecords.

/**
 * Gets a list of all records that have occurred on the test engine.
 *
 * @return a list of records
 */
public List<Record<?>> getRecords() {
    final ManagedChannel channel = getChannel();
    final EngineControlBlockingStub stub = getStub(channel);
    final ObjectMapper mapper = new ObjectMapper().registerModule(new ZeebeProtocolModule());
    final List<Record<?>> mappedRecords = new ArrayList<>();
    final GetRecordsRequest request = GetRecordsRequest.newBuilder().build();
    final Iterator<RecordResponse> response = stub.getRecords(request);
    while (response.hasNext()) {
        final RecordResponse recordResponse = response.next();
        try {
            final Record<?> record = mapper.readValue(recordResponse.getRecordJson(), new TypeReference<Record<?>>() {
            });
            mappedRecords.add(record);
        } catch (final JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
    closeChannel(channel);
    return mappedRecords;
}
Also used : ArrayList(java.util.ArrayList) RecordResponse(io.camunda.zeebe.process.test.engine.protocol.EngineControlOuterClass.RecordResponse) EngineControlBlockingStub(io.camunda.zeebe.process.test.engine.protocol.EngineControlGrpc.EngineControlBlockingStub) GetRecordsRequest(io.camunda.zeebe.process.test.engine.protocol.EngineControlOuterClass.GetRecordsRequest) ZeebeProtocolModule(io.camunda.zeebe.protocol.jackson.ZeebeProtocolModule) StatusRuntimeException(io.grpc.StatusRuntimeException) ManagedChannel(io.grpc.ManagedChannel) Record(io.camunda.zeebe.protocol.record.Record) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 EngineControlBlockingStub (io.camunda.zeebe.process.test.engine.protocol.EngineControlGrpc.EngineControlBlockingStub)1 GetRecordsRequest (io.camunda.zeebe.process.test.engine.protocol.EngineControlOuterClass.GetRecordsRequest)1 RecordResponse (io.camunda.zeebe.process.test.engine.protocol.EngineControlOuterClass.RecordResponse)1 ZeebeProtocolModule (io.camunda.zeebe.protocol.jackson.ZeebeProtocolModule)1 Record (io.camunda.zeebe.protocol.record.Record)1 ManagedChannel (io.grpc.ManagedChannel)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 ArrayList (java.util.ArrayList)1