All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.camunda.zeebe.process.test.engine.GatewayRequestStore Maven / Gradle / Ivy

Go to download

Test engine for running process tests. This a minimized version of the real Zeebe engine and should be used for testing purposes only.

There is a newer version: 8.7.0-alpha1
Show newest version
/*
 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
 * one or more contributor license agreements. See the NOTICE file distributed
 * with this work for additional information regarding copyright ownership.
 * Licensed under the Zeebe Community License 1.1. You may not use this file
 * except in compliance with the Zeebe Community License 1.1.
 */

package io.camunda.zeebe.process.test.engine;

import com.google.protobuf.GeneratedMessageV3;
import io.grpc.stub.StreamObserver;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

/**
 * This class stores gateway requests in a thread-safe manner. These requests will be accessed by
 * the {@link GrpcResponseWriter} in order to send the responses
 */
class GatewayRequestStore {

  private final Map requestMap = new ConcurrentHashMap<>();
  private final AtomicLong requestIdGenerator = new AtomicLong();

  Long registerNewRequest(
      final Class requestType,
      final StreamObserver responseObserver) {
    final long currentRequestId = requestIdGenerator.incrementAndGet();
    requestMap.put(currentRequestId, new Request(requestType, responseObserver));
    return currentRequestId;
  }

  Request removeRequest(final Long requestId) {
    return requestMap.remove(requestId);
  }

  record Request(
      Class requestType, StreamObserver responseObserver) {}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy