Browse Source

Merge branch 'master' into feature/time-series-comparison

pull/10562/head
Igor Kulikov 2 years ago
parent
commit
15be7312ca
  1. 32
      application/src/test/java/org/thingsboard/server/transport/lwm2m/security/diffPort/AbstractLwM2MIntegrationDiffPortTest.java
  2. 3
      application/src/test/resources/logback-test.xml
  3. 1
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/store/TbInMemoryRegistrationStore.java
  4. 1
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/store/TbLwM2mRedisRegistrationStore.java

32
application/src/test/java/org/thingsboard/server/transport/lwm2m/security/diffPort/AbstractLwM2MIntegrationDiffPortTest.java

@ -22,8 +22,6 @@ import org.eclipse.leshan.core.peer.SocketIdentity;
import org.eclipse.leshan.server.registration.RegistrationStore; import org.eclipse.leshan.server.registration.RegistrationStore;
import org.eclipse.leshan.server.registration.RegistrationUpdate; import org.eclipse.leshan.server.registration.RegistrationUpdate;
import org.junit.Assert; import org.junit.Assert;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.boot.test.mock.mockito.SpyBean;
import org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration; import org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration;
import org.thingsboard.server.dao.service.DaoSqlTest; import org.thingsboard.server.dao.service.DaoSqlTest;
@ -50,6 +48,17 @@ public abstract class AbstractLwM2MIntegrationDiffPortTest extends AbstractSecur
protected void basicTestConnectionDifferentPort(Lwm2mDeviceProfileTransportConfiguration transportConfiguration, protected void basicTestConnectionDifferentPort(Lwm2mDeviceProfileTransportConfiguration transportConfiguration,
String awaitAlias) throws Exception { String awaitAlias) throws Exception {
doAnswer((invocation) -> {
Object[] arguments = invocation.getArguments();
log.trace("doAnswer for registrationStoreTest.updateRegistration with args {}", arguments);
int portOld = ((RegistrationUpdate) arguments[0]).getPort();
int portValueChange = 5;
arguments[0] = registrationUpdateNewPort((RegistrationUpdate) arguments[0], portValueChange);
int portNew = ((RegistrationUpdate) arguments[0]).getPort();
Assert.assertEquals((portNew - portOld), portValueChange);
return invocation.callRealMethod();
}).when(registrationStoreTest).updateRegistration(any(RegistrationUpdate.class));
createDeviceProfile(transportConfiguration); createDeviceProfile(transportConfiguration);
createDevice(deviceCredentials, clientEndpoint); createDevice(deviceCredentials, clientEndpoint);
createNewClient(security, null, true, clientEndpoint); createNewClient(security, null, true, clientEndpoint);
@ -61,23 +70,8 @@ public abstract class AbstractLwM2MIntegrationDiffPortTest extends AbstractSecur
await(awaitAlias) await(awaitAlias)
.atMost(40, TimeUnit.SECONDS) .atMost(40, TimeUnit.SECONDS)
.until(() -> { .until(() -> lwM2MTestClient.getClientStates().contains(ON_UPDATE_SUCCESS));
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] arguments = invocation.getArguments();
if (arguments.length > 0 && arguments[0] instanceof RegistrationUpdate) {
int portOld = ((RegistrationUpdate) arguments[0]).getPort();
int portValueChange = 5;
arguments[0] = registrationUpdateNewPort((RegistrationUpdate) arguments[0], portValueChange);
int portNew = ((RegistrationUpdate) arguments[0]).getPort();
Assert.assertEquals((portNew - portOld), portValueChange);
}
return invocation.callRealMethod();
}
}).when(registrationStoreTest).updateRegistration(any(RegistrationUpdate.class));
return lwM2MTestClient.getClientStates().contains(ON_UPDATE_SUCCESS);
});
Assert.assertTrue(lwM2MTestClient.getClientStates().containsAll(expectedStatusesRegistrationLwm2mSuccessUpdate)); Assert.assertTrue(lwM2MTestClient.getClientStates().containsAll(expectedStatusesRegistrationLwm2mSuccessUpdate));
} }

3
application/src/test/resources/logback-test.xml

@ -37,6 +37,9 @@
<!-- Device actor message processor debug for the test scope --> <!-- Device actor message processor debug for the test scope -->
<!-- <logger name="org.thingsboard.server.actors.device.DeviceActorMessageProcessor" level="DEBUG" />--> <!-- <logger name="org.thingsboard.server.actors.device.DeviceActorMessageProcessor" level="DEBUG" />-->
<!-- <logger name="org.thingsboard.server.transport.lwm2m.server.store.TbInMemoryRegistrationStore" level="TRACE"/>-->
<!-- <logger name="org.thingsboard.server.transport.lwm2m.server.store.TbLwM2mRedisRegistrationStore" level="TRACE"/>-->
<!-- <logger name="org.thingsboard.server.transport.lwm2m.security.diffPort" level="TRACE"/>-->
<root level="WARN"> <root level="WARN">
<appender-ref ref="console"/> <appender-ref ref="console"/>

1
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/store/TbInMemoryRegistrationStore.java

@ -147,6 +147,7 @@ public class TbInMemoryRegistrationStore implements RegistrationStore, Startable
@Override @Override
public UpdatedRegistration updateRegistration(RegistrationUpdate update) { public UpdatedRegistration updateRegistration(RegistrationUpdate update) {
log.trace("updateRegistration [{}]", update);
try { try {
lock.writeLock().lock(); lock.writeLock().lock();

1
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/store/TbLwM2mRedisRegistrationStore.java

@ -222,6 +222,7 @@ public class TbLwM2mRedisRegistrationStore implements RegistrationStore, Startab
@Override @Override
public UpdatedRegistration updateRegistration(RegistrationUpdate update) { public UpdatedRegistration updateRegistration(RegistrationUpdate update) {
log.trace("updateRegistration [{}]", update);
Lock lock = null; Lock lock = null;
try (var connection = connectionFactory.getConnection()) { try (var connection = connectionFactory.getConnection()) {

Loading…
Cancel
Save