Skip to content

Commit 43ae025

Browse files
Fix edge tests
1 parent 387dbc3 commit 43ae025

7 files changed

Lines changed: 22 additions & 7 deletions

File tree

application/src/test/java/org/thingsboard/server/client/DashboardApiClientTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import static org.junit.Assert.assertEquals;
2828
import static org.junit.Assert.assertNotNull;
29-
import static org.junit.Assert.assertTrue;
3029

3130
@DaoSqlTest
3231
public class DashboardApiClientTest extends AbstractApiClientTest {
@@ -86,6 +85,8 @@ public void testDashboardLifecycle() throws Exception {
8685
PageDataDashboardInfo dashboardsAfterUnassign = client.getCustomerDashboards(customerId, 100, 0, null, null, null, null);
8786
assertEquals(0, dashboardsAfterUnassign.getData().size());
8887

88+
/*
89+
// Edge: a dashboard can't be made public directly — the public customer is cloud-managed
8990
// make dashboard public and verify
9091
client.assignDashboardToPublicCustomer(dashboardId);
9192
DashboardInfo publicDashboard = client.getDashboardInfoById(dashboardId);
@@ -94,6 +95,7 @@ public void testDashboardLifecycle() throws Exception {
9495
9596
// remove public access
9697
client.unassignDashboardFromPublicCustomer(dashboardId);
98+
*/
9799

98100
// delete dashboard
99101
UUID dashboardToDeleteId = createdDashboards.get(0).getId().getId();

application/src/test/java/org/thingsboard/server/client/DeviceConnectivityApiClientTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ public void testGetDevicePublishTelemetryCommands() throws Exception {
3939
String deviceId = savedDevice.getId().getId().toString();
4040

4141
JsonNode commands = client.getDevicePublishTelemetryCommands(deviceId);
42-
assertEquals("curl -v -X POST http://localhost:8080/api/v1/" + token + "/telemetry --header Content-Type:application/json --data \"{temperature:25}\"", commands.get("http").get("http").asText());
42+
// Edge: the HTTP publish command reflects the live request port (DeviceConnectivityServiceImpl
43+
// overrides it with the base-URL port), not CE's configured 8080 — assert the dynamic test port.
44+
// assertEquals("curl -v -X POST http://localhost:8080/api/v1/" + token + "/telemetry --header Content-Type:application/json --data \"{temperature:25}\"", commands.get("http").get("http").asText());
45+
assertEquals("curl -v -X POST http://localhost:" + wsPort + "/api/v1/" + token + "/telemetry --header Content-Type:application/json --data \"{temperature:25}\"", commands.get("http").get("http").asText());
4346
assertEquals("mosquitto_pub -d -q 1 -h localhost -p 1883 -t v1/devices/me/telemetry -u \"" + token + "\" -m \"{temperature:25}\"", commands.get("mqtt").get("mqtt").asText());
4447
assertEquals("coap-client -v 6 -m POST -t \"application/json\" -e \"{temperature:25}\" coap://localhost:5683/api/v1/" + token + "/telemetry", commands.get("coap").get("coap").asText());
4548
}

application/src/test/java/org/thingsboard/server/controller/AlarmRuleControllerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public void testSaveAlarmRule() throws Exception {
105105
AlarmRuleDefinition updated = saveAlarmRule(saved);
106106

107107
assertThat(updated.getName()).isEqualTo("Updated Alarm Rule");
108-
assertThat(updated.getVersion()).isEqualTo(saved.getVersion() + 1);
108+
// Edge: optimistic locking mechanism is not used, so the version should be null. See the 'doSave' method in the 'JpaAbstractDao' class for more details.
109+
// assertThat(updated.getVersion()).isEqualTo(saved.getVersion() + 1);
109110

110111
doDelete("/api/alarm/rule/" + saved.getId().getId())
111112
.andExpect(status().isOk());

dao/src/main/java/org/thingsboard/server/dao/sql/rule/JpaRuleChainDetailsDao.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ public RuleChainDetails findById(TenantId tenantId, UUID key) {
5454
@Override
5555
protected RuleChainDetailsEntity doSave(RuleChainDetailsEntity entity, boolean isNew, boolean flush) {
5656
try {
57-
return super.doSave(entity, isNew, flush);
57+
RuleChainDetailsEntity saved = super.doSave(entity, isNew, flush);
58+
// Edge-only: base 'doSave' does not flush (Edge does not use JPA optimistic locking), so a DB constraint violation would otherwise surface at commit,
59+
// outside this catch. Flush here so an oversized "notes" payload ("value too long") becomes DataValidationException (-> HTTP 400).
60+
getRepository().flush();
61+
return saved;
5862
} catch (Exception e) {
5963
String rootMsg = ExceptionUtils.getRootCauseMessage(e);
6064
if (StringUtils.contains(rootMsg, "value too long")) {

dao/src/main/java/org/thingsboard/server/dao/tenant/TenantServiceImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
5656
import static org.thingsboard.server.dao.DaoUtil.toUUIDs;
5757
import static org.thingsboard.server.dao.service.Validator.validateId;
58-
import static org.thingsboard.server.dao.service.Validator.validateIds;
5958

6059
@Service("TenantDaoService")
6160
@Slf4j
@@ -142,7 +141,11 @@ public Tenant saveTenant(Tenant tenant, Consumer<TenantId> defaultEntitiesCreato
142141
}
143142
boolean create = tenant.getId() == null;
144143

145-
Tenant savedTenant = tenantDao.save(tenant.getId(), tenant);
144+
// Edge-only: base 'doSave' does not flush (Edge does not use JPA optimistic locking). On create, flush eagerly so a non-existent tenantProfileId
145+
// fails the FK constraint here (-> HTTP 400) instead of later during default-entity creation, where it gets re-wrapped as a generic 500.
146+
Tenant savedTenant = create
147+
? tenantDao.saveAndFlush(TenantId.SYS_TENANT_ID, tenant)
148+
: tenantDao.save(tenant.getId(), tenant);
146149
TenantId tenantId = savedTenant.getId();
147150
publishEvictEvent(new TenantEvictEvent(tenantId, create));
148151

@@ -239,7 +242,7 @@ public List<Tenant> findTenantsByIds(TenantId callerId, List<TenantId> tenantIds
239242
public boolean tenantExists(TenantId tenantId) {
240243
// edge-only: we cannot properly evict cache, because it's only appear on tenant creation
241244
// return existsTenantCache.getAndPutInTransaction(tenantId, () -> tenantDao.existsById(tenantId, tenantId.getId()), false);
242-
return tenantDao.existsById(tenantId, tenantId.getId());
245+
return tenantDao.existsById(tenantId, tenantId.getId());
243246
}
244247

245248
private final PaginatedRemover<TenantId, Tenant> tenantsRemover = new PaginatedRemover<>() {

msa/tb-edge-node/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
<workingDirectory>${project.build.directory}/docker-tb-edge-node</workingDirectory>
130130
<arguments>
131131
<argument>build</argument>
132+
<argument>--load</argument>
132133
<argument>-t</argument>
133134
<argument>${docker.repo}/${docker.name}:latest</argument>
134135
<argument>.</argument>

msa/tb-edge/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
<workingDirectory>${project.build.directory}/docker-tb-edge</workingDirectory>
133133
<arguments>
134134
<argument>build</argument>
135+
<argument>--load</argument>
135136
<argument>-t</argument>
136137
<argument>${docker.repo}/${docker.name}:latest</argument>
137138
<argument>.</argument>

0 commit comments

Comments
 (0)