158 changed files with 2588 additions and 1063 deletions
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,74 +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", |
|
||||
"left_analog_water_level_meter", |
|
||||
"right_analog_water_level_meter", |
|
||||
"leak_sensor", |
|
||||
"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", |
|
||||
"water_stop", |
|
||||
"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" |
|
||||
] |
|
||||
} |
|
||||
File diff suppressed because one or more lines are too long
@ -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,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) {} |
||||
|
} |
||||
@ -0,0 +1,81 @@ |
|||||
|
/** |
||||
|
* 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.dao.settings; |
||||
|
|
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import org.springframework.cache.annotation.CacheEvict; |
||||
|
import org.springframework.cache.annotation.Cacheable; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.thingsboard.common.util.JacksonUtil; |
||||
|
import org.thingsboard.server.common.data.AdminSettings; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.security.model.SecuritySettings; |
||||
|
import org.thingsboard.server.common.data.security.model.UserPasswordPolicy; |
||||
|
import org.thingsboard.server.dao.service.ConstraintValidator; |
||||
|
|
||||
|
import static org.thingsboard.server.common.data.CacheConstants.SECURITY_SETTINGS_CACHE; |
||||
|
|
||||
|
@Service |
||||
|
@RequiredArgsConstructor |
||||
|
public class DefaultSecuritySettingsService implements SecuritySettingsService { |
||||
|
|
||||
|
private final AdminSettingsService adminSettingsService; |
||||
|
|
||||
|
public static final int DEFAULT_MOBILE_SECRET_KEY_LENGTH = 64; |
||||
|
|
||||
|
@Cacheable(cacheNames = SECURITY_SETTINGS_CACHE, key = "'securitySettings'") |
||||
|
@Override |
||||
|
public SecuritySettings getSecuritySettings() { |
||||
|
AdminSettings adminSettings = adminSettingsService.findAdminSettingsByKey(TenantId.SYS_TENANT_ID, "securitySettings"); |
||||
|
SecuritySettings securitySettings; |
||||
|
if (adminSettings != null) { |
||||
|
try { |
||||
|
securitySettings = JacksonUtil.convertValue(adminSettings.getJsonValue(), SecuritySettings.class); |
||||
|
} catch (Exception e) { |
||||
|
throw new RuntimeException("Failed to load security settings!", e); |
||||
|
} |
||||
|
} else { |
||||
|
securitySettings = new SecuritySettings(); |
||||
|
securitySettings.setPasswordPolicy(new UserPasswordPolicy()); |
||||
|
securitySettings.getPasswordPolicy().setMinimumLength(6); |
||||
|
securitySettings.getPasswordPolicy().setMaximumLength(72); |
||||
|
securitySettings.setMobileSecretKeyLength(DEFAULT_MOBILE_SECRET_KEY_LENGTH); |
||||
|
securitySettings.setPasswordResetTokenTtl(24); |
||||
|
securitySettings.setUserActivationTokenTtl(24); |
||||
|
} |
||||
|
return securitySettings; |
||||
|
} |
||||
|
|
||||
|
@CacheEvict(cacheNames = SECURITY_SETTINGS_CACHE, key = "'securitySettings'") |
||||
|
@Override |
||||
|
public SecuritySettings saveSecuritySettings(SecuritySettings securitySettings) { |
||||
|
ConstraintValidator.validateFields(securitySettings); |
||||
|
AdminSettings adminSettings = adminSettingsService.findAdminSettingsByKey(TenantId.SYS_TENANT_ID, "securitySettings"); |
||||
|
if (adminSettings == null) { |
||||
|
adminSettings = new AdminSettings(); |
||||
|
adminSettings.setTenantId(TenantId.SYS_TENANT_ID); |
||||
|
adminSettings.setKey("securitySettings"); |
||||
|
} |
||||
|
adminSettings.setJsonValue(JacksonUtil.valueToTree(securitySettings)); |
||||
|
AdminSettings savedAdminSettings = adminSettingsService.saveAdminSettings(TenantId.SYS_TENANT_ID, adminSettings); |
||||
|
try { |
||||
|
return JacksonUtil.convertValue(savedAdminSettings.getJsonValue(), SecuritySettings.class); |
||||
|
} catch (Exception e) { |
||||
|
throw new RuntimeException("Failed to load security settings!", e); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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.dao.settings; |
||||
|
|
||||
|
import org.thingsboard.server.common.data.security.model.SecuritySettings; |
||||
|
|
||||
|
public interface SecuritySettingsService { |
||||
|
|
||||
|
SecuritySettings getSecuritySettings(); |
||||
|
|
||||
|
SecuritySettings saveSecuritySettings(SecuritySettings securitySettings); |
||||
|
|
||||
|
} |
||||
File diff suppressed because one or more lines are too long
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue