5 changed files with 69 additions and 5 deletions
@ -0,0 +1,59 @@ |
|||||
|
/** |
||||
|
* 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.sql.rpc; |
||||
|
|
||||
|
import org.junit.Test; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.thingsboard.common.util.JacksonUtil; |
||||
|
import org.thingsboard.server.common.data.id.DeviceId; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.rpc.Rpc; |
||||
|
import org.thingsboard.server.common.data.rpc.RpcStatus; |
||||
|
import org.thingsboard.server.dao.AbstractJpaDaoTest; |
||||
|
|
||||
|
import java.util.UUID; |
||||
|
|
||||
|
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
|
||||
|
public class JpaRpcDaoTest extends AbstractJpaDaoTest { |
||||
|
|
||||
|
@Autowired |
||||
|
JpaRpcDao rpcDao; |
||||
|
|
||||
|
@Test |
||||
|
public void deleteOutdated() { |
||||
|
Rpc rpc = new Rpc(); |
||||
|
rpc.setTenantId(TenantId.SYS_TENANT_ID); |
||||
|
rpc.setDeviceId(new DeviceId(UUID.randomUUID())); |
||||
|
rpc.setStatus(RpcStatus.QUEUED); |
||||
|
rpc.setRequest(JacksonUtil.toJsonNode("{}")); |
||||
|
rpcDao.saveAndFlush(rpc.getTenantId(), rpc); |
||||
|
|
||||
|
rpc.setId(null); |
||||
|
rpcDao.saveAndFlush(rpc.getTenantId(), rpc); |
||||
|
|
||||
|
TenantId tenantId = TenantId.fromUUID(UUID.fromString("3d193a7a-774b-4c05-84d5-f7fdcf7a37cf")); |
||||
|
rpc.setId(null); |
||||
|
rpc.setTenantId(tenantId); |
||||
|
rpc.setDeviceId(new DeviceId(UUID.randomUUID())); |
||||
|
rpcDao.saveAndFlush(rpc.getTenantId(), rpc); |
||||
|
|
||||
|
assertThat(rpcDao.deleteOutdatedRpcByTenantId(TenantId.SYS_TENANT_ID, 0L)).isEqualTo(0); |
||||
|
assertThat(rpcDao.deleteOutdatedRpcByTenantId(TenantId.SYS_TENANT_ID, Long.MAX_VALUE)).isEqualTo(2); |
||||
|
assertThat(rpcDao.deleteOutdatedRpcByTenantId(tenantId, System.currentTimeMillis() + 1)).isEqualTo(1); |
||||
|
} |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue