Skip to content

Commit 4533442

Browse files
committed
[#2029] Use Command Router in adapters and integration tests.
This adds a org.eclipse.hono.adapter.client.command.CommandConsumerFactory implementation that uses the new Command Router component. For the integration tests, a new maven profile 'command-router' is added to let the tests run using the Command Router component. The GitHub action workflow has been adapted to use that profile in the test-run that uses the jdbc device registry (so that the other test-runs still use the old command routing mechanism). Signed-off-by: Carsten Lohmann <[email protected]>
1 parent 2394c91 commit 4533442

27 files changed

+860
-151
lines changed

.github/workflows/ci.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# The job uses a matrix for the distinct device registry implementations. Thus,
1515
# for each registry implementation, the workflow is run on a separate VM.
1616

17-
name: Build Hono's 'container images and run integration tests
17+
name: Build and run integration tests
1818

1919
on: [push,pull_request]
2020

@@ -25,7 +25,12 @@ jobs:
2525
strategy:
2626
matrix:
2727
device-registry: [file,jdbc,mongodb]
28+
include:
29+
# let the jdbc test-run use the command-router component
30+
- device-registry: jdbc
31+
commandrouting-mode: commandrouter
2832

33+
name: Use ${{ matrix.device-registry }}-registry [${{ matrix.commandrouting-mode }}]
2934
steps:
3035
- uses: actions/checkout@v2
3136
- name: Cache local Maven repository
@@ -47,4 +52,4 @@ jobs:
4752
with:
4853
java-version: '11'
4954
- name: Build all components (incl. unit tests) and run integration tests
50-
run: mvn install -B -e -DcreateJavadoc=true -DCI=$CI -Dhono.deviceregistry.type=${{ matrix.device-registry }} -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -Pbuild-docker-image,run-tests
55+
run: mvn install -B -e -DcreateJavadoc=true -DCI=$CI -Dhono.deviceregistry.type=${{ matrix.device-registry }} -Dhono.commandrouting.mode=${{ matrix.commandrouting-mode }} -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -Pbuild-docker-image,run-tests
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2020 Contributors to the Eclipse Foundation
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*******************************************************************************/
13+
14+
package org.eclipse.hono.adapter.client.command.amqp;
15+
16+
import java.util.Objects;
17+
18+
import org.apache.qpid.proton.amqp.transport.ErrorCondition;
19+
import org.eclipse.hono.adapter.client.command.Command;
20+
import org.eclipse.hono.adapter.client.command.CommandContext;
21+
import org.eclipse.hono.util.Constants;
22+
23+
import io.opentracing.Span;
24+
import io.opentracing.SpanContext;
25+
import io.vertx.proton.ProtonHelper;
26+
27+
/**
28+
* A wrapper around a legacy {@link org.eclipse.hono.client.CommandContext}.
29+
*/
30+
public class ProtonBasedCommandContext implements CommandContext {
31+
32+
private final org.eclipse.hono.client.CommandContext ctx;
33+
private final ProtonBasedCommand command;
34+
35+
/**
36+
* Creates a new command context.
37+
*
38+
* @param context The legacy command context to wrap.
39+
* @throws NullPointerException if context is {@code null}.
40+
*/
41+
public ProtonBasedCommandContext(final org.eclipse.hono.client.CommandContext context) {
42+
this.ctx = Objects.requireNonNull(context);
43+
this.command = new ProtonBasedCommand(context.getCommand());
44+
}
45+
46+
@Override
47+
public void logCommandToSpan(final Span span) {
48+
command.logToSpan(span);
49+
}
50+
51+
@Override
52+
public Command getCommand() {
53+
return command;
54+
}
55+
56+
@Override
57+
public void accept() {
58+
ctx.accept();
59+
}
60+
61+
@Override
62+
public void release() {
63+
ctx.release();
64+
}
65+
66+
@Override
67+
public void modify(final boolean deliveryFailed, final boolean undeliverableHere) {
68+
ctx.modify(deliveryFailed, undeliverableHere);
69+
}
70+
71+
@Override
72+
public void reject(final String cause) {
73+
final ErrorCondition error = ProtonHelper.condition(Constants.AMQP_BAD_REQUEST, cause);
74+
ctx.reject(error);
75+
}
76+
77+
@Override
78+
public <T> T get(final String key) {
79+
return ctx.get(key);
80+
}
81+
82+
@Override
83+
public <T> T get(final String key, final T defaultValue) {
84+
return ctx.get(key, defaultValue);
85+
}
86+
87+
@Override
88+
public void put(final String key, final Object value) {
89+
ctx.put(key, value);
90+
}
91+
92+
@Override
93+
public SpanContext getTracingContext() {
94+
return ctx.getTracingContext();
95+
}
96+
97+
@Override
98+
public Span getTracingSpan() {
99+
return ctx.getTracingSpan();
100+
}
101+
}

0 commit comments

Comments
 (0)