Search in sources :

Example 1 with SetVariablesRequest

use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest in project zeebe by camunda.

the class SetVariablesTest method shouldCommandWithVariablesAsMap.

@Test
public void shouldCommandWithVariablesAsMap() {
    // given
    final Map<String, Object> variablesMap = Collections.singletonMap("key", "val");
    // when
    client.newSetVariablesCommand(123).variables(variablesMap).send().join();
    // then
    final SetVariablesRequest request = gatewayService.getLastRequest();
    assertThat(fromJsonAsMap(request.getVariables())).containsOnly(entry("key", "val"));
}
Also used : SetVariablesRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest) ClientTest(io.camunda.zeebe.client.util.ClientTest) Test(org.junit.Test)

Example 2 with SetVariablesRequest

use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest in project zeebe by camunda.

the class SetVariablesTest method shouldCommandWithVariablesAsStream.

@Test
public void shouldCommandWithVariablesAsStream() {
    // given
    final String variables = "{\"key\": \"val\"}";
    final InputStream variablesStream = new ByteArrayInputStream(StringUtil.getBytes(variables));
    // when
    client.newSetVariablesCommand(123).variables(variablesStream).send().join();
    // then
    final SetVariablesRequest request = gatewayService.getLastRequest();
    assertThat(fromJsonAsMap(request.getVariables())).containsOnly(entry("key", "val"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SetVariablesRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest) ClientTest(io.camunda.zeebe.client.util.ClientTest) Test(org.junit.Test)

Example 3 with SetVariablesRequest

use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest in project zeebe by camunda.

the class SetVariablesTest method shouldCommandWithVariablesAsString.

@Test
public void shouldCommandWithVariablesAsString() {
    // given
    gatewayService.onSetVariablesRequest(345);
    final String variables = "{\"key\": \"val\"}";
    // when
    final SetVariablesResponse response = client.newSetVariablesCommand(123).variables(variables).send().join();
    // then
    assertThat(response).isNotNull();
    assertThat(response.getKey()).isEqualTo(345);
    final SetVariablesRequest request = gatewayService.getLastRequest();
    assertThat(request.getElementInstanceKey()).isEqualTo(123);
    assertThat(fromJsonAsMap(request.getVariables())).containsOnly(entry("key", "val"));
    rule.verifyDefaultRequestTimeout();
}
Also used : SetVariablesRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest) SetVariablesResponse(io.camunda.zeebe.client.api.response.SetVariablesResponse) ClientTest(io.camunda.zeebe.client.util.ClientTest) Test(org.junit.Test)

Example 4 with SetVariablesRequest

use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest in project zeebe by zeebe-io.

the class SetVariablesTest method shouldMapRequestAndResponse.

@Test
public void shouldMapRequestAndResponse() {
    // given
    final SetVariablesStub stub = new SetVariablesStub();
    stub.registerWith(brokerClient);
    final String variables = JsonUtil.toJson(Collections.singletonMap("key", "value"));
    final int partitionId = 1;
    final long elementInstanceKey = Protocol.encodePartitionId(partitionId, 1);
    final SetVariablesRequest request = SetVariablesRequest.newBuilder().setElementInstanceKey(elementInstanceKey).setVariables(variables).build();
    // when
    final SetVariablesResponse response = client.setVariables(request);
    // then
    assertThat(response).isNotNull();
    assertThat(response.getKey()).isEqualTo(stub.getKey());
    final BrokerSetVariablesRequest brokerRequest = brokerClient.getSingleBrokerRequest();
    assertThat(brokerRequest.getKey()).isEqualTo(-1);
    assertThat(brokerRequest.getIntent()).isEqualTo(VariableDocumentIntent.UPDATE);
    assertThat(brokerRequest.getValueType()).isEqualTo(ValueType.VARIABLE_DOCUMENT);
    assertThat(brokerRequest.getPartitionId()).isEqualTo(partitionId);
    final VariableDocumentRecord brokerRequestValue = brokerRequest.getRequestWriter();
    MsgPackUtil.assertEqualityExcluding(brokerRequestValue.getVariablesBuffer(), variables);
    assertThat(brokerRequestValue.getScopeKey()).isEqualTo(elementInstanceKey);
}
Also used : BrokerSetVariablesRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerSetVariablesRequest) SetVariablesRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest) BrokerSetVariablesRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerSetVariablesRequest) VariableDocumentRecord(io.camunda.zeebe.protocol.impl.record.value.variable.VariableDocumentRecord) SetVariablesResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesResponse) GatewayTest(io.camunda.zeebe.gateway.api.util.GatewayTest) Test(org.junit.Test)

Example 5 with SetVariablesRequest

use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest in project zeebe by zeebe-io.

the class SetVariablesTest method shouldCommandWithVariablesAsString.

@Test
public void shouldCommandWithVariablesAsString() {
    // given
    gatewayService.onSetVariablesRequest(345);
    final String variables = "{\"key\": \"val\"}";
    // when
    final SetVariablesResponse response = client.newSetVariablesCommand(123).variables(variables).send().join();
    // then
    assertThat(response).isNotNull();
    assertThat(response.getKey()).isEqualTo(345);
    final SetVariablesRequest request = gatewayService.getLastRequest();
    assertThat(request.getElementInstanceKey()).isEqualTo(123);
    assertThat(fromJsonAsMap(request.getVariables())).containsOnly(entry("key", "val"));
    rule.verifyDefaultRequestTimeout();
}
Also used : SetVariablesRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest) SetVariablesResponse(io.camunda.zeebe.client.api.response.SetVariablesResponse) ClientTest(io.camunda.zeebe.client.util.ClientTest) Test(org.junit.Test)

Aggregations

SetVariablesRequest (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesRequest)18 Test (org.junit.Test)15 ClientTest (io.camunda.zeebe.client.util.ClientTest)12 SetVariablesResponse (io.camunda.zeebe.client.api.response.SetVariablesResponse)6 RetriableClientFutureImpl (io.camunda.zeebe.client.impl.RetriableClientFutureImpl)3 SetVariablesResponseImpl (io.camunda.zeebe.client.impl.response.SetVariablesResponseImpl)3 GatewayTest (io.camunda.zeebe.gateway.api.util.GatewayTest)3 BrokerSetVariablesRequest (io.camunda.zeebe.gateway.impl.broker.request.BrokerSetVariablesRequest)3 SetVariablesResponse (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.SetVariablesResponse)3 VariableDocumentRecord (io.camunda.zeebe.protocol.impl.record.value.variable.VariableDocumentRecord)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3