|
|
|
@ -20,28 +20,32 @@ import com.google.protobuf.Descriptors; |
|
|
|
import com.google.protobuf.DynamicMessage; |
|
|
|
import com.squareup.wire.schema.internal.parser.ProtoFileElement; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.eclipse.paho.client.mqttv3.MqttAsyncClient; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Test; |
|
|
|
import org.thingsboard.server.common.data.Device; |
|
|
|
import org.thingsboard.server.common.data.TransportPayloadType; |
|
|
|
import org.thingsboard.server.common.data.device.profile.DeviceProfileTransportConfiguration; |
|
|
|
import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration; |
|
|
|
import org.thingsboard.server.common.data.device.profile.MqttTopics; |
|
|
|
import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration; |
|
|
|
import org.thingsboard.server.common.data.device.profile.TransportPayloadTypeConfiguration; |
|
|
|
import org.thingsboard.server.gen.transport.TransportApiProtos; |
|
|
|
import org.thingsboard.server.gen.transport.TransportProtos; |
|
|
|
import org.thingsboard.server.transport.mqtt.MqttTestCallback; |
|
|
|
import org.thingsboard.server.transport.mqtt.MqttTestClient; |
|
|
|
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.concurrent.CountDownLatch; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
import static org.junit.Assert.assertFalse; |
|
|
|
import static org.junit.Assert.assertNotNull; |
|
|
|
import static org.junit.Assert.assertTrue; |
|
|
|
import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVICE_TELEMETRY_SHORT_JSON_TOPIC; |
|
|
|
import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVICE_TELEMETRY_SHORT_PROTO_TOPIC; |
|
|
|
import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVICE_TELEMETRY_SHORT_TOPIC; |
|
|
|
import static org.thingsboard.server.common.data.device.profile.MqttTopics.GATEWAY_CONNECT_TOPIC; |
|
|
|
import static org.thingsboard.server.common.data.device.profile.MqttTopics.GATEWAY_TELEMETRY_TOPIC; |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends AbstractMqttTimeseriesIntegrationTest { |
|
|
|
@ -272,7 +276,7 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac |
|
|
|
.build(); |
|
|
|
processBeforeTest(configProperties); |
|
|
|
DynamicMessage postTelemetryMsg = getDefaultDynamicMessage(); |
|
|
|
processTelemetryTest(MqttTopics.DEVICE_TELEMETRY_SHORT_TOPIC, Arrays.asList("key1", "key2", "key3", "key4", "key5"), postTelemetryMsg.toByteArray(), false, false); |
|
|
|
processTelemetryTest(DEVICE_TELEMETRY_SHORT_TOPIC, Arrays.asList("key1", "key2", "key3", "key4", "key5"), postTelemetryMsg.toByteArray(), false, false); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -283,7 +287,7 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac |
|
|
|
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC) |
|
|
|
.build(); |
|
|
|
processBeforeTest(configProperties); |
|
|
|
processJsonPayloadTelemetryTest(MqttTopics.DEVICE_TELEMETRY_SHORT_JSON_TOPIC, Arrays.asList("key1", "key2", "key3", "key4", "key5"), PAYLOAD_VALUES_STR.getBytes(), false); |
|
|
|
processJsonPayloadTelemetryTest(DEVICE_TELEMETRY_SHORT_JSON_TOPIC, Arrays.asList("key1", "key2", "key3", "key4", "key5"), PAYLOAD_VALUES_STR.getBytes(), false); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -295,7 +299,7 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac |
|
|
|
.build(); |
|
|
|
processBeforeTest(configProperties); |
|
|
|
DynamicMessage postTelemetryMsg = getDefaultDynamicMessage(); |
|
|
|
processTelemetryTest(MqttTopics.DEVICE_TELEMETRY_SHORT_PROTO_TOPIC, Arrays.asList("key1", "key2", "key3", "key4", "key5"), postTelemetryMsg.toByteArray(), false, false); |
|
|
|
processTelemetryTest(DEVICE_TELEMETRY_SHORT_PROTO_TOPIC, Arrays.asList("key1", "key2", "key3", "key4", "key5"), postTelemetryMsg.toByteArray(), false, false); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -315,7 +319,7 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac |
|
|
|
TransportApiProtos.TelemetryMsg deviceBTelemetryMsgProto = getDeviceTelemetryMsgProto(deviceName2, expectedKeys, 10000, 20000); |
|
|
|
gatewayTelemetryMsgProtoBuilder.addAllMsg(Arrays.asList(deviceATelemetryMsgProto, deviceBTelemetryMsgProto)); |
|
|
|
TransportApiProtos.GatewayTelemetryMsg gatewayTelemetryMsg = gatewayTelemetryMsgProtoBuilder.build(); |
|
|
|
processGatewayTelemetryTest(MqttTopics.GATEWAY_TELEMETRY_TOPIC, expectedKeys, gatewayTelemetryMsg.toByteArray(), deviceName1, deviceName2); |
|
|
|
processGatewayTelemetryTest(GATEWAY_TELEMETRY_TOPIC, expectedKeys, gatewayTelemetryMsg.toByteArray(), deviceName1, deviceName2); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -329,14 +333,16 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac |
|
|
|
processBeforeTest(configProperties); |
|
|
|
String deviceName = "Device A"; |
|
|
|
TransportApiProtos.ConnectMsg connectMsgProto = getConnectProto(deviceName); |
|
|
|
MqttAsyncClient client = getMqttAsyncClient(gatewayAccessToken); |
|
|
|
publishMqttMsg(client, connectMsgProto.toByteArray(), MqttTopics.GATEWAY_CONNECT_TOPIC); |
|
|
|
MqttTestClient client = new MqttTestClient(); |
|
|
|
client.connectAndWait(gatewayAccessToken); |
|
|
|
client.publish(GATEWAY_CONNECT_TOPIC, connectMsgProto.toByteArray()); |
|
|
|
|
|
|
|
Device device = doExecuteWithRetriesAndInterval(() -> doGet("/api/tenant/devices?deviceName=" + deviceName, Device.class), |
|
|
|
20, |
|
|
|
100); |
|
|
|
|
|
|
|
assertNotNull(device); |
|
|
|
client.disconnect(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -349,13 +355,14 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac |
|
|
|
.sendAckOnValidationException(true) |
|
|
|
.build(); |
|
|
|
processBeforeTest(configProperties); |
|
|
|
CountDownLatch latch = new CountDownLatch(1); |
|
|
|
MqttAsyncClient client = getMqttAsyncClient(accessToken); |
|
|
|
TestMqttPublishCallback callback = new TestMqttPublishCallback(latch); |
|
|
|
MqttTestClient client = new MqttTestClient(); |
|
|
|
client.connectAndWait(accessToken); |
|
|
|
MqttTestCallback callback = new MqttTestCallback(); |
|
|
|
client.setCallback(callback); |
|
|
|
publishMqttMsg(client, MALFORMED_PROTO_PAYLOAD.getBytes(), POST_DATA_TELEMETRY_TOPIC); |
|
|
|
latch.await(3, TimeUnit.SECONDS); |
|
|
|
client.publish(POST_DATA_TELEMETRY_TOPIC, MALFORMED_PROTO_PAYLOAD.getBytes()); |
|
|
|
callback.getDeliveryLatch().await(3, TimeUnit.SECONDS); |
|
|
|
assertTrue(callback.isPubAckReceived()); |
|
|
|
client.disconnect(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -366,12 +373,12 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac |
|
|
|
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC) |
|
|
|
.build(); |
|
|
|
processBeforeTest(configProperties); |
|
|
|
CountDownLatch latch = new CountDownLatch(1); |
|
|
|
MqttAsyncClient client = getMqttAsyncClient(accessToken); |
|
|
|
TestMqttPublishCallback callback = new TestMqttPublishCallback(latch); |
|
|
|
MqttTestClient client = new MqttTestClient(); |
|
|
|
client.connectAndWait(accessToken); |
|
|
|
MqttTestCallback callback = new MqttTestCallback(); |
|
|
|
client.setCallback(callback); |
|
|
|
publishMqttMsg(client, MALFORMED_PROTO_PAYLOAD.getBytes(), POST_DATA_TELEMETRY_TOPIC); |
|
|
|
latch.await(3, TimeUnit.SECONDS); |
|
|
|
client.publish(POST_DATA_TELEMETRY_TOPIC, MALFORMED_PROTO_PAYLOAD.getBytes()); |
|
|
|
callback.getDeliveryLatch().await(3, TimeUnit.SECONDS); |
|
|
|
assertFalse(callback.isPubAckReceived()); |
|
|
|
} |
|
|
|
|
|
|
|
@ -385,13 +392,14 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac |
|
|
|
.sendAckOnValidationException(true) |
|
|
|
.build(); |
|
|
|
processBeforeTest(configProperties); |
|
|
|
CountDownLatch latch = new CountDownLatch(1); |
|
|
|
MqttAsyncClient client = getMqttAsyncClient(accessToken); |
|
|
|
TestMqttPublishCallback callback = new TestMqttPublishCallback(latch); |
|
|
|
MqttTestClient client = new MqttTestClient(); |
|
|
|
client.connectAndWait(accessToken); |
|
|
|
MqttTestCallback callback = new MqttTestCallback(); |
|
|
|
client.setCallback(callback); |
|
|
|
publishMqttMsg(client, MALFORMED_JSON_PAYLOAD.getBytes(), POST_DATA_TELEMETRY_TOPIC); |
|
|
|
latch.await(3, TimeUnit.SECONDS); |
|
|
|
client.publish(POST_DATA_TELEMETRY_TOPIC, MALFORMED_JSON_PAYLOAD.getBytes()); |
|
|
|
callback.getDeliveryLatch().await(3, TimeUnit.SECONDS); |
|
|
|
assertTrue(callback.isPubAckReceived()); |
|
|
|
client.disconnect(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -403,12 +411,12 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac |
|
|
|
.enableCompatibilityWithJsonPayloadFormat(true) |
|
|
|
.build(); |
|
|
|
processBeforeTest(configProperties); |
|
|
|
CountDownLatch latch = new CountDownLatch(1); |
|
|
|
MqttAsyncClient client = getMqttAsyncClient(accessToken); |
|
|
|
TestMqttPublishCallback callback = new TestMqttPublishCallback(latch); |
|
|
|
MqttTestClient client = new MqttTestClient(); |
|
|
|
client.connectAndWait(accessToken); |
|
|
|
MqttTestCallback callback = new MqttTestCallback(); |
|
|
|
client.setCallback(callback); |
|
|
|
publishMqttMsg(client, MALFORMED_JSON_PAYLOAD.getBytes(), POST_DATA_TELEMETRY_TOPIC); |
|
|
|
latch.await(3, TimeUnit.SECONDS); |
|
|
|
client.publish(POST_DATA_TELEMETRY_TOPIC, MALFORMED_JSON_PAYLOAD.getBytes()); |
|
|
|
callback.getDeliveryLatch().await(3, TimeUnit.SECONDS); |
|
|
|
assertFalse(callback.isPubAckReceived()); |
|
|
|
} |
|
|
|
|
|
|
|
@ -422,13 +430,14 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac |
|
|
|
.sendAckOnValidationException(true) |
|
|
|
.build(); |
|
|
|
processBeforeTest(configProperties); |
|
|
|
CountDownLatch latch = new CountDownLatch(1); |
|
|
|
MqttAsyncClient client = getMqttAsyncClient(gatewayAccessToken); |
|
|
|
TestMqttPublishCallback callback = new TestMqttPublishCallback(latch); |
|
|
|
MqttTestClient client = new MqttTestClient(); |
|
|
|
client.connectAndWait(gatewayAccessToken); |
|
|
|
MqttTestCallback callback = new MqttTestCallback(); |
|
|
|
client.setCallback(callback); |
|
|
|
publishMqttMsg(client, MALFORMED_PROTO_PAYLOAD.getBytes(), POST_DATA_TELEMETRY_TOPIC); |
|
|
|
latch.await(3, TimeUnit.SECONDS); |
|
|
|
client.publish(POST_DATA_TELEMETRY_TOPIC, MALFORMED_PROTO_PAYLOAD.getBytes()); |
|
|
|
callback.getDeliveryLatch().await(3, TimeUnit.SECONDS); |
|
|
|
assertTrue(callback.isPubAckReceived()); |
|
|
|
client.disconnect(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -440,12 +449,12 @@ public abstract class AbstractMqttTimeseriesProtoIntegrationTest extends Abstrac |
|
|
|
.telemetryTopicFilter(POST_DATA_TELEMETRY_TOPIC) |
|
|
|
.build(); |
|
|
|
processBeforeTest(configProperties); |
|
|
|
CountDownLatch latch = new CountDownLatch(1); |
|
|
|
MqttAsyncClient client = getMqttAsyncClient(gatewayAccessToken); |
|
|
|
TestMqttPublishCallback callback = new TestMqttPublishCallback(latch); |
|
|
|
MqttTestClient client = new MqttTestClient(); |
|
|
|
client.connectAndWait(gatewayAccessToken); |
|
|
|
MqttTestCallback callback = new MqttTestCallback(); |
|
|
|
client.setCallback(callback); |
|
|
|
publishMqttMsg(client, MALFORMED_PROTO_PAYLOAD.getBytes(), POST_DATA_TELEMETRY_TOPIC); |
|
|
|
latch.await(3, TimeUnit.SECONDS); |
|
|
|
client.publish(POST_DATA_TELEMETRY_TOPIC, MALFORMED_PROTO_PAYLOAD.getBytes()); |
|
|
|
callback.getDeliveryLatch().await(3, TimeUnit.SECONDS); |
|
|
|
assertFalse(callback.isPubAckReceived()); |
|
|
|
} |
|
|
|
|
|
|
|
|