@ -21,6 +21,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement ;
import lombok.extern.slf4j.Slf4j ;
import org.apache.commons.io.IOUtils ;
import org.awaitility.core.ConditionTimeoutException ;
import org.eclipse.leshan.client.LeshanClient ;
import org.eclipse.leshan.client.object.Security ;
import org.eclipse.leshan.client.servers.LwM2mServer ;
@ -94,6 +95,7 @@ import java.util.Map;
import java.util.Set ;
import java.util.concurrent.ScheduledExecutorService ;
import java.util.concurrent.TimeUnit ;
import java.util.concurrent.atomic.AtomicLong ;
import static org.awaitility.Awaitility.await ;
import static org.eclipse.leshan.client.object.Security.noSec ;
@ -118,6 +120,7 @@ import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.LwM2MClient
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.LwM2MClientState.ON_UPDATE_SUCCESS ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.LwM2MProfileBootstrapConfigType ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.LwM2MProfileBootstrapConfigType.NONE ;
import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.lwm2mClientResources ;
import static org.thingsboard.server.transport.lwm2m.ota.AbstractOtaLwM2MIntegrationTest.CLIENT_LWM2M_SETTINGS_19 ;
@TestPropertySource ( properties = {
@ -306,7 +309,7 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractTransportInte
protected final Set < Lwm2mTestHelper . LwM2MClientState > expectedStatusesRegistrationBsSuccess = new HashSet < > ( Arrays . asList ( ON_BOOTSTRAP_STARTED , ON_BOOTSTRAP_SUCCESS , ON_REGISTRATION_STARTED , ON_REGISTRATION_SUCCESS ) ) ;
protected ScheduledExecutorService executor ;
protected LwM2MTestClient lwM2MTestClient ;
private String [ ] resources ;
private String [ ] resources = lwm2mClientResources ;
protected String deviceId ;
protected boolean supportFormatOnly_SenMLJSON_SenMLCBOR = false ;
@ -548,7 +551,9 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractTransportInte
}
public void setResources ( String [ ] resources ) {
this . resources = resources ;
if ( this . resources = = null | | ! Arrays . equals ( this . resources , resources ) ) {
this . resources = resources ;
}
}
public void createNewClient ( Security security , Security securityBs , boolean isRpc ,
@ -726,11 +731,19 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractTransportInte
return credentials ;
}
protected void awaitObserveReadAll ( int cntObserve , String deviceIdStr ) throws Exception {
await ( "ObserveReadAll: countObserve " + cntObserve )
. atMost ( 40 , TimeUnit . SECONDS )
. until ( ( ) - > cntObserve = = getCntObserveAll ( deviceIdStr ) ) ;
protected void awaitObserveReadAll ( int cntObserve , String deviceIdStr ) throws Exception {
try {
await ( "ObserveReadAll: countObserve " + cntObserve )
. atMost ( 40 , TimeUnit . SECONDS )
. until ( ( ) - > cntObserve = = getCntObserveAll ( deviceIdStr ) ) ;
} catch ( ConditionTimeoutException e ) {
int current = getCntObserveAll ( deviceIdStr ) ;
log . error ( "Condition or device {} with alias 'ObserveReadAll: countObserve {}, but received {}" , deviceIdStr , cntObserve , current ) ;
throw e ;
}
}
protected void awaitDeleteDevice ( String deviceIdStr ) throws Exception {
await ( "Delete device with id: " + deviceIdStr )
. atMost ( 40 , TimeUnit . SECONDS )
@ -741,6 +754,19 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractTransportInte
} ) ;
}
protected void updateRegAtLeastOnceAfterAction ( ) {
long initialInvocationCount = countUpdateReg ( ) ;
AtomicLong newInvocationCount = new AtomicLong ( initialInvocationCount ) ;
log . trace ( "updateRegAtLeastOnceAfterAction: initialInvocationCount [{}]" , initialInvocationCount ) ;
await ( "Update Registration at-least-once after action" )
. atMost ( 50 , TimeUnit . SECONDS )
. until ( ( ) - > {
newInvocationCount . set ( countUpdateReg ( ) ) ;
return newInvocationCount . get ( ) > initialInvocationCount ;
} ) ;
log . trace ( "updateRegAtLeastOnceAfterAction: newInvocationCount [{}]" , newInvocationCount . get ( ) ) ;
}
protected Integer getCntObserveAll ( String deviceIdStr ) throws Exception {
String actualResult = sendObserveOK ( "ObserveReadAll" , null , deviceIdStr ) ;
ObjectNode rpcActualResult = JacksonUtil . fromString ( actualResult , ObjectNode . class ) ;