@@ -56,9 +56,17 @@ public class HonoServerIntegrationTest {
56
56
private static final String NAME_HONO_CONNECTION_FACTORY = "hono" ;
57
57
private static final Logger LOG = LoggerFactory .getLogger (HonoServerIntegrationTest .class );
58
58
private static final String BIND_ADDRESS = InetAddress .getLoopbackAddress ().getHostAddress ();
59
+ private Connection connection ;
60
+ private Vertx vertx ;
59
61
60
62
@ After
61
- public void disconnect (final TestContext ctx ) {
63
+ public void disconnect (final TestContext ctx ) throws JMSException {
64
+ if (connection != null ) {
65
+ connection .close ();
66
+ }
67
+ if (vertx != null ) {
68
+ vertx .close (ctx .asyncAssertSuccess ());
69
+ }
62
70
}
63
71
64
72
private static HonoServer createServer (final Endpoint telemetryEndpoint ) {
@@ -72,14 +80,18 @@ private static HonoServer createServer(final Endpoint telemetryEndpoint) {
72
80
@ Test
73
81
public void testTelemetryUpload (final TestContext ctx ) throws Exception {
74
82
75
- Vertx vertx = Vertx .vertx ();
83
+ vertx = Vertx .vertx ();
76
84
LOG .debug ("starting telemetry upload test" );
77
85
int count = 110 ;
86
+ final Async messagesReceived = ctx .async (count );
78
87
final Async deployed = ctx .async ();
79
88
80
89
TelemetryEndpoint telemetryEndpoint = new TelemetryEndpoint (vertx , false );
81
90
HonoServer server = createServer (telemetryEndpoint );
82
- vertx .deployVerticle (new MessageDiscardingTelemetryAdapter ());
91
+ vertx .deployVerticle (new MessageDiscardingTelemetryAdapter (msg -> {
92
+ messagesReceived .countDown ();
93
+ LOG .debug ("Received message [id: {}]" , msg .getMessageId ());
94
+ }));
83
95
vertx .deployVerticle (InMemoryAuthorizationService .class .getName ());
84
96
vertx .deployVerticle (server , res -> {
85
97
ctx .assertTrue (res .succeeded ());
@@ -91,7 +103,7 @@ public void testTelemetryUpload(final TestContext ctx) throws Exception {
91
103
ConnectionFactory factory = (ConnectionFactory ) context .lookup (NAME_HONO_CONNECTION_FACTORY );
92
104
Destination telemetryAddress = (Destination ) context .lookup (TelemetryConstants .TELEMETRY_ENDPOINT );
93
105
94
- Connection connection = factory .createConnection ();
106
+ connection = factory .createConnection ();
95
107
connection .setExceptionListener (new ExceptionListener () {
96
108
97
109
@ Override
@@ -105,7 +117,6 @@ public void onException(JMSException exception) {
105
117
MessageProducer messageProducer = session .createProducer (telemetryAddress );
106
118
messageProducer .setDeliveryMode (DeliveryMode .NON_PERSISTENT );
107
119
108
- long start = System .currentTimeMillis ();
109
120
for (int i = 1 ; i <= count ; i ++) {
110
121
BytesMessage message = createTelemetryMessage (session , i );
111
122
messageProducer .send (message );
@@ -114,12 +125,7 @@ public void onException(JMSException exception) {
114
125
LOG .debug ("Sent message {}" , i );
115
126
}
116
127
}
117
-
118
- long finish = System .currentTimeMillis ();
119
- long taken = finish - start ;
120
- LOG .info ("Sent {} messages in {}ms" , count , taken );
121
-
122
- connection .close ();
128
+ messagesReceived .awaitSuccess (2000 );
123
129
}
124
130
125
131
private static Context createInitialContext (final HonoServer server ) throws NamingException {
0 commit comments