Skip to content

Commit

Permalink
[#2029] Use Command Router in adapters and integration tests.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
calohmn committed Nov 26, 2020
1 parent 275332b commit 4a7863d
Show file tree
Hide file tree
Showing 27 changed files with 860 additions and 151 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# The job uses a matrix for the distinct device registry implementations. Thus,
# for each registry implementation, the workflow is run on a separate VM.

name: Build Hono's 'container images and run integration tests
name: Build and run integration tests

on: [push,pull_request]

Expand All @@ -25,7 +25,12 @@ jobs:
strategy:
matrix:
device-registry: [file,jdbc,mongodb]
include:
# let the jdbc test-run use the command-router component
- device-registry: jdbc
commandrouting-mode: commandrouter

name: Use ${{ matrix.device-registry }}-registry [${{ matrix.commandrouting-mode }}]
steps:
- uses: actions/checkout@v2
- name: Cache local Maven repository
Expand All @@ -47,4 +52,4 @@ jobs:
with:
java-version: '11'
- name: Build all components (incl. unit tests) and run integration tests
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
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 number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*******************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/

package org.eclipse.hono.adapter.client.command.amqp;

import java.util.Objects;

import org.apache.qpid.proton.amqp.transport.ErrorCondition;
import org.eclipse.hono.adapter.client.command.Command;
import org.eclipse.hono.adapter.client.command.CommandContext;
import org.eclipse.hono.util.Constants;

import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.vertx.proton.ProtonHelper;

/**
* A wrapper around a legacy {@link org.eclipse.hono.client.CommandContext}.
*/
public class ProtonBasedCommandContext implements CommandContext {

private final org.eclipse.hono.client.CommandContext ctx;
private final ProtonBasedCommand command;

/**
* Creates a new command context.
*
* @param context The legacy command context to wrap.
* @throws NullPointerException if context is {@code null}.
*/
public ProtonBasedCommandContext(final org.eclipse.hono.client.CommandContext context) {
this.ctx = Objects.requireNonNull(context);
this.command = new ProtonBasedCommand(context.getCommand());
}

@Override
public void logCommandToSpan(final Span span) {
command.logToSpan(span);
}

@Override
public Command getCommand() {
return command;
}

@Override
public void accept() {
ctx.accept();
}

@Override
public void release() {
ctx.release();
}

@Override
public void modify(final boolean deliveryFailed, final boolean undeliverableHere) {
ctx.modify(deliveryFailed, undeliverableHere);
}

@Override
public void reject(final String cause) {
final ErrorCondition error = ProtonHelper.condition(Constants.AMQP_BAD_REQUEST, cause);
ctx.reject(error);
}

@Override
public <T> T get(final String key) {
return ctx.get(key);
}

@Override
public <T> T get(final String key, final T defaultValue) {
return ctx.get(key, defaultValue);
}

@Override
public void put(final String key, final Object value) {
ctx.put(key, value);
}

@Override
public SpanContext getTracingContext() {
return ctx.getTracingContext();
}

@Override
public Span getTracingSpan() {
return ctx.getTracingSpan();
}
}
Loading

0 comments on commit 4a7863d

Please sign in to comment.