|
After Width: | Height: | Size: 6.0 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 12 KiB |
@ -1,70 +0,0 @@ |
|||
{ |
|||
"widgetsBundle": { |
|||
"alias": "scada_water_system_symbols", |
|||
"title": "SCADA water system symbols", |
|||
"scada": true, |
|||
"image": null, |
|||
"description": "Bundle with SCADA symbols for water system", |
|||
"order": 9300, |
|||
"name": "SCADA water system symbols" |
|||
}, |
|||
"widgetTypeFqns": [ |
|||
"horizontal_pipe", |
|||
"long_horizontal_pipe", |
|||
"vertical_pipe", |
|||
"long_vertical_pipe", |
|||
"left_bottom_elbow_pipe", |
|||
"bottom_right_elbow_pipe", |
|||
"top_right_elbow_pipe", |
|||
"left_top_elbow_pipe", |
|||
"cross_pipe", |
|||
"left_tee_pipe", |
|||
"bottom_tee_pipe", |
|||
"right_tee_pipe", |
|||
"top_tee_pipe", |
|||
"right_elbow_drain_pipe", |
|||
"left_elbow_drain_pipe", |
|||
"left_drain_pipe", |
|||
"right_drain_pipe", |
|||
"short_left_drain_pipe", |
|||
"short_right_drain_pipe", |
|||
"top_flow_meter", |
|||
"right_flow_meter", |
|||
"bottom_flow_meter", |
|||
"left_flow_meter", |
|||
"horizontal_inline_flow_meter", |
|||
"vertical_inline_flow_meter", |
|||
"centrifugal_pump", |
|||
"small_right_motor_pump", |
|||
"small_left_motor_pump", |
|||
"right_motor_pump", |
|||
"left_motor_pump", |
|||
"right_heat_pump", |
|||
"left_heat_pump", |
|||
"short_bottom_filter", |
|||
"long_bottom_filter", |
|||
"short_top_filter", |
|||
"long_top_filter", |
|||
"stand_filter", |
|||
"horizontal_wheel_valve", |
|||
"vertical_wheel_valve", |
|||
"horizontal_ball_valve", |
|||
"vertical_ball_valve", |
|||
"vertical_tank", |
|||
"stand_vertical_tank", |
|||
"cylindrical_tank", |
|||
"stand_cylindrical_tank", |
|||
"vertical_short_tank", |
|||
"stand_vertical_short_tank", |
|||
"large_cylindrical_tank", |
|||
"large_stand_cylindrical_tank", |
|||
"large_vertical_tank", |
|||
"large_stand_vertical_tank", |
|||
"horizontal_tank", |
|||
"stand_horizontal_tank", |
|||
"spherical_tank", |
|||
"small_spherical_tank", |
|||
"elevated_tank", |
|||
"pool" |
|||
] |
|||
} |
|||
@ -0,0 +1,93 @@ |
|||
/** |
|||
* Copyright © 2016-2024 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.service.notification.channels; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
import org.thingsboard.server.dao.util.ImageUtils; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @link <a href="https://adaptivecards.io/designer/">AdaptiveCard Designer</a> |
|||
*/ |
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class TeamsAdaptiveCard { |
|||
private String type = "message"; |
|||
private List<Attachment> attachments; |
|||
|
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public static class Attachment { |
|||
private String contentType = "application/vnd.microsoft.card.adaptive"; |
|||
private AdaptiveCard content; |
|||
} |
|||
|
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public static class AdaptiveCard { |
|||
@JsonProperty("$schema") |
|||
private final String schema = "http://adaptivecards.io/schemas/adaptive-card.json"; |
|||
private final String type = "AdaptiveCard"; |
|||
private BackgroundImage backgroundImage; |
|||
@JsonProperty("body") |
|||
private List<TextBlock> textBlocks = new ArrayList<>(); |
|||
private List<ActionOpenUrl> actions = new ArrayList<>(); |
|||
} |
|||
|
|||
@Data |
|||
@NoArgsConstructor |
|||
public static class BackgroundImage { |
|||
private String url; |
|||
private final String fillMode = "repeat"; |
|||
|
|||
public BackgroundImage(String color) { |
|||
// This is the only one way how to specify color the custom color for the card
|
|||
url = ImageUtils.getEmbeddedBase64EncodedImg(color); |
|||
} |
|||
|
|||
} |
|||
|
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public static class TextBlock { |
|||
private final String type = "TextBlock"; |
|||
private String text; |
|||
private String weight = "Normal"; |
|||
private String size = "Medium"; |
|||
private String spacing = "None"; |
|||
private String color = "#FFFFFF"; |
|||
private final boolean wrap = true; |
|||
} |
|||
|
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public static class ActionOpenUrl { |
|||
private final String type = "Action.OpenUrl"; |
|||
private String title; |
|||
private String url; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,92 @@ |
|||
/** |
|||
* Copyright © 2016-2024 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.service.notification.channels; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonInclude; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Data |
|||
public class TeamsMessageCard { |
|||
@JsonProperty("@type") |
|||
private final String type = "MessageCard"; |
|||
@JsonProperty("@context") |
|||
private final String context = "http://schema.org/extensions"; |
|||
private String themeColor; |
|||
private String summary; |
|||
private String text; |
|||
private List<Section> sections; |
|||
private List<ActionCard> potentialAction; |
|||
|
|||
@Data |
|||
public static class Section { |
|||
private String activityTitle; |
|||
private String activitySubtitle; |
|||
private String activityImage; |
|||
private List<Fact> facts; |
|||
private boolean markdown; |
|||
|
|||
@Data |
|||
public static class Fact { |
|||
private final String name; |
|||
private final String value; |
|||
} |
|||
} |
|||
|
|||
@Data |
|||
@JsonInclude(JsonInclude.Include.NON_NULL) |
|||
public static class ActionCard { |
|||
@JsonProperty("@type") |
|||
private String type; // ActionCard, OpenUri
|
|||
private String name; |
|||
private List<Input> inputs; // for ActionCard
|
|||
private List<Action> actions; // for ActionCard
|
|||
private List<Target> targets; |
|||
|
|||
@Data |
|||
public static class Input { |
|||
@JsonProperty("@type") |
|||
private String type; // TextInput, DateInput, MultichoiceInput
|
|||
private String id; |
|||
private boolean isMultiple; |
|||
private String title; |
|||
private boolean isMultiSelect; |
|||
|
|||
@Data |
|||
public static class Choice { |
|||
private final String display; |
|||
private final String value; |
|||
} |
|||
} |
|||
|
|||
@Data |
|||
public static class Action { |
|||
@JsonProperty("@type") |
|||
private final String type; // HttpPOST
|
|||
private final String name; |
|||
private final String target; // url
|
|||
} |
|||
|
|||
@Data |
|||
public static class Target { |
|||
private final String os; |
|||
private final String uri; |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,148 @@ |
|||
/** |
|||
* Copyright © 2016-2024 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.transport.mqtt.mqttv3.rpc; |
|||
|
|||
import io.netty.handler.codec.mqtt.MqttQoS; |
|||
import org.junit.Test; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.TenantProfile; |
|||
import org.thingsboard.server.common.data.TransportPayloadType; |
|||
import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration; |
|||
import org.thingsboard.server.dao.service.DaoSqlTest; |
|||
import org.thingsboard.server.transport.mqtt.AbstractMqttIntegrationTest; |
|||
import org.thingsboard.server.transport.mqtt.MqttTestConfigProperties; |
|||
import org.thingsboard.server.transport.mqtt.limits.GatewaySessionLimits; |
|||
import org.thingsboard.server.transport.mqtt.limits.SessionLimits; |
|||
import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestCallback; |
|||
import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestClient; |
|||
import org.thingsboard.server.transport.mqtt.mqttv3.MqttTestSubscribeOnTopicCallback; |
|||
|
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
import static org.assertj.core.api.Assertions.assertThat; |
|||
import static org.junit.jupiter.api.Assertions.assertEquals; |
|||
import static org.junit.jupiter.api.Assertions.assertTrue; |
|||
import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVICE_RPC_REQUESTS_TOPIC; |
|||
import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVICE_RPC_RESPONSE_SUB_TOPIC; |
|||
import static org.thingsboard.server.common.data.device.profile.MqttTopics.DEVICE_RPC_RESPONSE_TOPIC; |
|||
|
|||
@DaoSqlTest |
|||
public class MqttClientSideRpcIntegrationTest extends AbstractMqttIntegrationTest { |
|||
|
|||
@Value("${transport.mqtt.netty.max_payload_size}") |
|||
private Integer maxPayloadSize; |
|||
|
|||
@Value("${transport.mqtt.msg_queue_size_per_device_limit}") |
|||
private int maxInflightMessages; |
|||
|
|||
@Test |
|||
public void getSessionLimitsRpcForDeviceTest() throws Exception { |
|||
loginSysAdmin(); |
|||
TenantProfile tenantProfile = doGet("/api/tenantProfile/" + tenantProfileId, TenantProfile.class); |
|||
DefaultTenantProfileConfiguration profileConfiguration = tenantProfile.getDefaultProfileConfiguration(); |
|||
|
|||
profileConfiguration.setTransportDeviceMsgRateLimit("20:600"); |
|||
profileConfiguration.setTransportDeviceTelemetryMsgRateLimit("10:600"); |
|||
profileConfiguration.setTransportDeviceTelemetryDataPointsRateLimit("40:600"); |
|||
|
|||
doPost("/api/tenantProfile", tenantProfile); |
|||
|
|||
var expectedLimits = new SessionLimits(); |
|||
var deviceLimits = new SessionLimits.SessionRateLimits(profileConfiguration.getTransportDeviceMsgRateLimit(), |
|||
profileConfiguration.getTransportDeviceTelemetryMsgRateLimit(), |
|||
profileConfiguration.getTransportDeviceTelemetryDataPointsRateLimit()); |
|||
expectedLimits.setRateLimits(deviceLimits); |
|||
expectedLimits.setMaxPayloadSize(maxPayloadSize); |
|||
expectedLimits.setMaxInflightMessages(maxInflightMessages); |
|||
|
|||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder() |
|||
.deviceName("Test Get Service Configuration") |
|||
.transportPayloadType(TransportPayloadType.JSON) |
|||
.build(); |
|||
processBeforeTest(configProperties); |
|||
|
|||
MqttTestClient client = new MqttTestClient(); |
|||
client.connectAndWait(accessToken); |
|||
|
|||
MqttTestCallback callback = new MqttTestSubscribeOnTopicCallback(DEVICE_RPC_RESPONSE_TOPIC + "1"); |
|||
client.setCallback(callback); |
|||
client.subscribeAndWait(DEVICE_RPC_RESPONSE_SUB_TOPIC, MqttQoS.AT_MOST_ONCE); |
|||
|
|||
client.publishAndWait(DEVICE_RPC_REQUESTS_TOPIC + "1", "{\"method\":\"getSessionLimits\",\"params\":{}}".getBytes()); |
|||
|
|||
assertThat(callback.getSubscribeLatch().await(DEFAULT_WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS)) |
|||
.as("await callback").isTrue(); |
|||
|
|||
var payload = callback.getPayloadBytes(); |
|||
SessionLimits actualLimits = JacksonUtil.fromBytes(payload, SessionLimits.class); |
|||
assertEquals(expectedLimits, actualLimits); |
|||
|
|||
client.disconnect(); |
|||
} |
|||
|
|||
@Test |
|||
public void getSessionLimitsRpcForGatewayTest() throws Exception { |
|||
loginSysAdmin(); |
|||
TenantProfile tenantProfile = doGet("/api/tenantProfile/" + tenantProfileId, TenantProfile.class); |
|||
DefaultTenantProfileConfiguration profileConfiguration = tenantProfile.getDefaultProfileConfiguration(); |
|||
|
|||
profileConfiguration.setTransportGatewayMsgRateLimit("100:600"); |
|||
profileConfiguration.setTransportGatewayTelemetryMsgRateLimit("50:600"); |
|||
profileConfiguration.setTransportGatewayTelemetryDataPointsRateLimit("200:600"); |
|||
|
|||
profileConfiguration.setTransportGatewayDeviceMsgRateLimit("20:600"); |
|||
profileConfiguration.setTransportGatewayDeviceTelemetryMsgRateLimit("10:600"); |
|||
profileConfiguration.setTransportGatewayDeviceTelemetryDataPointsRateLimit("40:600"); |
|||
|
|||
doPost("/api/tenantProfile", tenantProfile); |
|||
|
|||
var expectedLimits = new GatewaySessionLimits(); |
|||
var gatewayLimits = new SessionLimits.SessionRateLimits(profileConfiguration.getTransportGatewayMsgRateLimit(), |
|||
profileConfiguration.getTransportGatewayTelemetryMsgRateLimit(), |
|||
profileConfiguration.getTransportGatewayTelemetryDataPointsRateLimit()); |
|||
var gatewayDeviceLimits = new SessionLimits.SessionRateLimits(profileConfiguration.getTransportGatewayDeviceMsgRateLimit(), |
|||
profileConfiguration.getTransportGatewayDeviceTelemetryMsgRateLimit(), |
|||
profileConfiguration.getTransportGatewayDeviceTelemetryDataPointsRateLimit()); |
|||
expectedLimits.setGatewayRateLimits(gatewayLimits); |
|||
expectedLimits.setRateLimits(gatewayDeviceLimits); |
|||
expectedLimits.setMaxPayloadSize(maxPayloadSize); |
|||
expectedLimits.setMaxInflightMessages(maxInflightMessages); |
|||
|
|||
MqttTestConfigProperties configProperties = MqttTestConfigProperties.builder() |
|||
.gatewayName("Test Get Service Configuration Gateway") |
|||
.transportPayloadType(TransportPayloadType.JSON) |
|||
.build(); |
|||
processBeforeTest(configProperties); |
|||
|
|||
MqttTestClient client = new MqttTestClient(); |
|||
client.connectAndWait(gatewayAccessToken); |
|||
|
|||
MqttTestCallback callback = new MqttTestSubscribeOnTopicCallback(DEVICE_RPC_RESPONSE_TOPIC + "1"); |
|||
client.setCallback(callback); |
|||
client.subscribeAndWait(DEVICE_RPC_RESPONSE_SUB_TOPIC, MqttQoS.AT_MOST_ONCE); |
|||
|
|||
client.publishAndWait(DEVICE_RPC_REQUESTS_TOPIC + "1", "{\"method\":\"getSessionLimits\",\"params\":{}}".getBytes()); |
|||
|
|||
assertTrue(callback.getSubscribeLatch().await(DEFAULT_WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS)); |
|||
|
|||
var payload = callback.getPayloadBytes(); |
|||
SessionLimits actualLimits = JacksonUtil.fromBytes(payload, GatewaySessionLimits.class); |
|||
assertEquals(expectedLimits, actualLimits); |
|||
|
|||
client.disconnect(); |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
/** |
|||
* Copyright © 2016-2024 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.cache; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
public interface VersionedCacheKey extends Serializable { |
|||
|
|||
default boolean isVersioned() { |
|||
return false; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
/** |
|||
* Copyright © 2016-2024 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data; |
|||
|
|||
public record UserActivationLink(String value, long ttlMs) { |
|||
} |
|||
@ -0,0 +1,128 @@ |
|||
/** |
|||
* Copyright © 2016-2024 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.queue.rabbitmq; |
|||
|
|||
import static org.assertj.core.api.Assertions.assertThat; |
|||
import static org.mockito.ArgumentMatchers.anyBoolean; |
|||
import static org.mockito.ArgumentMatchers.anyString; |
|||
import static org.mockito.Mockito.times; |
|||
import static org.mockito.Mockito.verify; |
|||
import static org.mockito.Mockito.when; |
|||
|
|||
import com.rabbitmq.client.Channel; |
|||
import com.rabbitmq.client.Connection; |
|||
import com.rabbitmq.client.ConnectionFactory; |
|||
import com.rabbitmq.client.GetResponse; |
|||
import java.nio.charset.StandardCharsets; |
|||
import java.util.Set; |
|||
import java.util.UUID; |
|||
import org.junit.jupiter.api.Test; |
|||
import org.junit.jupiter.api.extension.ExtendWith; |
|||
import org.mockito.Mock; |
|||
import org.mockito.junit.jupiter.MockitoExtension; |
|||
import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; |
|||
import org.thingsboard.server.queue.TbQueueAdmin; |
|||
import org.thingsboard.server.queue.TbQueueMsgDecoder; |
|||
import org.thingsboard.server.queue.common.DefaultTbQueueMsg; |
|||
|
|||
@ExtendWith(MockitoExtension.class) |
|||
class TbRabbitMqConsumerTemplateTest { |
|||
|
|||
private static final String TOPIC = "some-topic"; |
|||
|
|||
@Mock |
|||
private TbQueueAdmin admin; |
|||
|
|||
@Mock |
|||
private ConnectionFactory connectionFactory; |
|||
|
|||
@Mock |
|||
private TbQueueMsgDecoder<DefaultTbQueueMsg> decoder; |
|||
|
|||
@Mock |
|||
private Connection connection; |
|||
|
|||
@Mock |
|||
private Channel channel; |
|||
|
|||
@Mock |
|||
private TopicPartitionInfo partition; |
|||
|
|||
@Mock |
|||
private GetResponse getResponse; |
|||
|
|||
private TbRabbitMqConsumerTemplate<DefaultTbQueueMsg> consumer; |
|||
|
|||
private void setUpConsumerWithMaxPollMessages(int maxPollMessages) throws Exception { |
|||
when(connectionFactory.newConnection()).thenReturn(connection); |
|||
when(connection.createChannel()).thenReturn(channel); |
|||
TbRabbitMqSettings settings = new TbRabbitMqSettings(); |
|||
settings.setMaxPollMessages(maxPollMessages); |
|||
settings.setConnectionFactory(connectionFactory); |
|||
|
|||
consumer = new TbRabbitMqConsumerTemplate<>(admin, settings, TOPIC, decoder); |
|||
when(partition.getFullTopicName()).thenReturn(TOPIC); |
|||
consumer.subscribe(Set.of(partition)); |
|||
} |
|||
|
|||
@Test |
|||
void pollWithMax5PollMessagesReturnsEmptyListIfNoMessages() throws Exception { |
|||
setUpConsumerWithMaxPollMessages(5); |
|||
when(channel.basicGet(anyString(), anyBoolean())).thenReturn(null); |
|||
|
|||
assertThat(consumer.poll(0L)).isEmpty(); |
|||
|
|||
verify(channel).basicGet(anyString(), anyBoolean()); |
|||
} |
|||
|
|||
@Test |
|||
void pollWithMax5PollMessagesReturns5MessagesIfQueueContains5() throws Exception { |
|||
setUpConsumerWithMaxPollMessages(5); |
|||
when(getResponse.getBody()).thenReturn(newMessageBody()); |
|||
when(channel.basicGet(anyString(), anyBoolean())).thenReturn(getResponse); |
|||
|
|||
assertThat(consumer.poll(0L)).hasSize(5); |
|||
|
|||
verify(channel, times(5)).basicGet(anyString(), anyBoolean()); |
|||
} |
|||
|
|||
@Test |
|||
void pollWithMax1PollMessageReturns1MessageIfQueueContainsMore() throws Exception { |
|||
setUpConsumerWithMaxPollMessages(1); |
|||
when(getResponse.getBody()).thenReturn(newMessageBody()); |
|||
when(channel.basicGet(anyString(), anyBoolean())).thenReturn(getResponse); |
|||
|
|||
assertThat(consumer.poll(0L)).hasSize(1); |
|||
|
|||
verify(channel).basicGet(anyString(), anyBoolean()); |
|||
} |
|||
|
|||
@Test |
|||
void pollWithMax3PollMessagesReturns2MessagesIfQueueContains2() throws Exception { |
|||
setUpConsumerWithMaxPollMessages(3); |
|||
when(getResponse.getBody()).thenReturn(newMessageBody()); |
|||
when(channel.basicGet(anyString(), anyBoolean())).thenReturn(getResponse, getResponse, null); |
|||
|
|||
assertThat(consumer.poll(0L)).hasSize(2); |
|||
|
|||
verify(channel, times(3)).basicGet(anyString(), anyBoolean()); |
|||
} |
|||
|
|||
private byte[] newMessageBody() { |
|||
return ("{\"key\": \"" + UUID.randomUUID() + "\"}").getBytes(StandardCharsets.UTF_8); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,95 @@ |
|||
/** |
|||
* Copyright © 2016-2024 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.queue.scheduler; |
|||
|
|||
import org.awaitility.Awaitility; |
|||
import org.junit.jupiter.api.AfterEach; |
|||
import org.junit.jupiter.api.BeforeEach; |
|||
import org.junit.jupiter.api.DisplayName; |
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
import java.util.concurrent.ScheduledFuture; |
|||
import java.util.concurrent.TimeUnit; |
|||
import java.util.concurrent.atomic.AtomicBoolean; |
|||
|
|||
import static org.assertj.core.api.Assertions.assertThat; |
|||
|
|||
class DefaultSchedulerComponentTest { |
|||
|
|||
DefaultSchedulerComponent schedulerComponent; |
|||
|
|||
@BeforeEach |
|||
void setup() { |
|||
schedulerComponent = new DefaultSchedulerComponent(); |
|||
schedulerComponent.init(); |
|||
} |
|||
|
|||
@AfterEach |
|||
void cleanup() { |
|||
schedulerComponent.destroy(); |
|||
} |
|||
|
|||
@Test |
|||
@DisplayName("scheduleAtFixedRate() should continue periodic execution even if command throws exception") |
|||
void scheduleAtFixedRateShouldNotStopPeriodicExecutionWhenCommandThrowsException() { |
|||
// GIVEN
|
|||
var wasExecutedAtLeastOnce = new AtomicBoolean(false); |
|||
|
|||
Runnable exceptionThrowingCommand = () -> { |
|||
try { |
|||
throw new RuntimeException("Unexpected exception"); |
|||
} finally { |
|||
wasExecutedAtLeastOnce.set(true); |
|||
} |
|||
}; |
|||
|
|||
// WHEN
|
|||
ScheduledFuture<?> future = schedulerComponent.scheduleAtFixedRate(exceptionThrowingCommand, 0, 200, TimeUnit.MILLISECONDS); |
|||
|
|||
// THEN
|
|||
Awaitility.await().alias("Wait until command is executed at least once") |
|||
.atMost(5, TimeUnit.SECONDS) |
|||
.until(wasExecutedAtLeastOnce::get); |
|||
|
|||
assertThat(future.isDone()).as("Periodic execution should not stop after unhandled exception is thrown by the command").isFalse(); |
|||
} |
|||
|
|||
@Test |
|||
@DisplayName("scheduleWithFixedDelay() should continue periodic execution even if command throws exception") |
|||
void scheduleWithFixedDelayShouldNotStopPeriodicExecutionWhenCommandThrowsException() { |
|||
// GIVEN
|
|||
var wasExecutedAtLeastOnce = new AtomicBoolean(false); |
|||
|
|||
Runnable exceptionThrowingCommand = () -> { |
|||
try { |
|||
throw new RuntimeException("Unexpected exception"); |
|||
} finally { |
|||
wasExecutedAtLeastOnce.set(true); |
|||
} |
|||
}; |
|||
|
|||
// WHEN
|
|||
ScheduledFuture<?> future = schedulerComponent.scheduleWithFixedDelay(exceptionThrowingCommand, 0, 200, TimeUnit.MILLISECONDS); |
|||
|
|||
// THEN
|
|||
Awaitility.await().alias("Wait until command is executed at least once") |
|||
.atMost(5, TimeUnit.SECONDS) |
|||
.until(wasExecutedAtLeastOnce::get); |
|||
|
|||
assertThat(future.isDone()).as("Periodic execution should not stop after unhandled exception is thrown by the command").isFalse(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
/** |
|||
* Copyright © 2016-2024 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.transport.mqtt.limits; |
|||
|
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class GatewaySessionLimits extends SessionLimits { |
|||
|
|||
private SessionRateLimits gatewayRateLimits; |
|||
|
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
/** |
|||
* Copyright © 2016-2024 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.transport.mqtt.limits; |
|||
|
|||
import lombok.Data; |
|||
import org.thingsboard.server.common.data.TransportPayloadType; |
|||
|
|||
@Data |
|||
public class SessionLimits { |
|||
|
|||
private int maxPayloadSize; |
|||
private int maxInflightMessages; |
|||
private SessionRateLimits rateLimits; |
|||
|
|||
public record SessionRateLimits(String messages, String telemetryMessages, String telemetryDataPoints) {} |
|||
} |
|||