Browse Source

Add comment explaining why EntityViewControllerTest owns its MQTT port

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
pull/15199/head
Sergey Matvienko 6 months ago
parent
commit
42179bddf8
  1. 6
      application/src/test/java/org/thingsboard/server/controller/EntityViewControllerTest.java

6
application/src/test/java/org/thingsboard/server/controller/EntityViewControllerTest.java

@ -97,6 +97,12 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
@ContextConfiguration(classes = {EntityViewControllerTest.Config.class})
@DaoSqlTest
public class EntityViewControllerTest extends AbstractControllerTest {
// Must NOT be imported from AbstractMqttIntegrationTest. That field is a static final initialized
// once per JVM. Other test classes (e.g. MqttGatewayRateLimitsTest, DeviceEdgeTest) share the same
// constant but produce a different Spring context cache key, so Spring creates a separate
// ApplicationContext for each of them. Every context starts its own MqttTransportService and tries
// to bind the same port, causing BindException when tests run in the same Surefire JVM fork.
// Declaring the port here gives this context its own independently allocated port.
static final int MQTT_PORT = TestSocketUtils.findAvailableTcpPort();
static final String MQTT_URL = "tcp://localhost:" + MQTT_PORT;

Loading…
Cancel
Save