Fix device service cache. Configure maven surefire plugin to execute both test suits and single tests.
This commit is contained in:
parent
6c4c4a2211
commit
82a66a9421
@ -360,7 +360,12 @@
|
|||||||
<systemPropertyVariables>
|
<systemPropertyVariables>
|
||||||
<spring.config.name>thingsboard</spring.config.name>
|
<spring.config.name>thingsboard</spring.config.name>
|
||||||
</systemPropertyVariables>
|
</systemPropertyVariables>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/sql/*Test.java</exclude>
|
||||||
|
<exclude>**/nosql/*Test.java</exclude>
|
||||||
|
</excludes>
|
||||||
<includes>
|
<includes>
|
||||||
|
<include>**/*Test.java</include>
|
||||||
<include>**/*TestSuite.java</include>
|
<include>**/*TestSuite.java</include>
|
||||||
</includes>
|
</includes>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
@ -35,7 +35,7 @@ import java.util.function.Predicate;
|
|||||||
/**
|
/**
|
||||||
* Created by ashvayka on 20.03.18.
|
* Created by ashvayka on 20.03.18.
|
||||||
*/
|
*/
|
||||||
public class AbstractRuleEngineControllerTest extends AbstractControllerTest {
|
public abstract class AbstractRuleEngineControllerTest extends AbstractControllerTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
protected RuleChainService ruleChainService;
|
protected RuleChainService ruleChainService;
|
||||||
|
|||||||
@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class BaseEdgeEventControllerTest extends AbstractControllerTest {
|
public abstract class BaseEdgeEventControllerTest extends AbstractControllerTest {
|
||||||
|
|
||||||
private Tenant savedTenant;
|
private Tenant savedTenant;
|
||||||
private User tenantAdmin;
|
private User tenantAdmin;
|
||||||
|
|||||||
@ -68,7 +68,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class BaseWebsocketApiTest extends AbstractWebsocketTest {
|
public abstract class BaseWebsocketApiTest extends AbstractWebsocketTest {
|
||||||
|
|
||||||
private Tenant savedTenant;
|
private Tenant savedTenant;
|
||||||
private User tenantAdmin;
|
private User tenantAdmin;
|
||||||
|
|||||||
@ -26,7 +26,7 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
@RunWith(ClasspathSuite.class)
|
@RunWith(ClasspathSuite.class)
|
||||||
@ClasspathSuite.ClassnameFilters({
|
@ClasspathSuite.ClassnameFilters({
|
||||||
"org.thingsboard.server.service.resource.*Test",
|
"org.thingsboard.server.service.resource.sql.*Test",
|
||||||
})
|
})
|
||||||
public class ServiceSqlTestSuite {
|
public class ServiceSqlTestSuite {
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.thingsboard.server.service.resource;
|
package org.thingsboard.server.service.resource.sql;
|
||||||
|
|
||||||
import com.datastax.oss.driver.api.core.uuid.Uuids;
|
import com.datastax.oss.driver.api.core.uuid.Uuids;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
@ -40,6 +40,7 @@ import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileCon
|
|||||||
import org.thingsboard.server.controller.AbstractControllerTest;
|
import org.thingsboard.server.controller.AbstractControllerTest;
|
||||||
import org.thingsboard.server.dao.exception.DataValidationException;
|
import org.thingsboard.server.dao.exception.DataValidationException;
|
||||||
import org.thingsboard.server.dao.service.DaoSqlTest;
|
import org.thingsboard.server.dao.service.DaoSqlTest;
|
||||||
|
import org.thingsboard.server.service.resource.TbResourceService;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
@ -33,7 +33,7 @@ import java.util.Arrays;
|
|||||||
"org.thingsboard.server.transport.*.attributes.request.sql.*Test",
|
"org.thingsboard.server.transport.*.attributes.request.sql.*Test",
|
||||||
"org.thingsboard.server.transport.*.claim.sql.*Test",
|
"org.thingsboard.server.transport.*.claim.sql.*Test",
|
||||||
"org.thingsboard.server.transport.*.provision.sql.*Test",
|
"org.thingsboard.server.transport.*.provision.sql.*Test",
|
||||||
"org.thingsboard.server.transport.lwm2m.*Test"
|
"org.thingsboard.server.transport.lwm2m.sql.*Test"
|
||||||
})
|
})
|
||||||
public class TransportSqlTestSuite {
|
public class TransportSqlTestSuite {
|
||||||
|
|
||||||
|
|||||||
@ -88,7 +88,7 @@ import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE;
|
|||||||
import static org.thingsboard.server.common.data.ota.OtaPackageType.SOFTWARE;
|
import static org.thingsboard.server.common.data.ota.OtaPackageType.SOFTWARE;
|
||||||
|
|
||||||
@DaoSqlTest
|
@DaoSqlTest
|
||||||
public class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest {
|
public abstract class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest {
|
||||||
|
|
||||||
protected final String TRANSPORT_CONFIGURATION = "{\n" +
|
protected final String TRANSPORT_CONFIGURATION = "{\n" +
|
||||||
" \"type\": \"LWM2M\",\n" +
|
" \"type\": \"LWM2M\",\n" +
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.thingsboard.server.transport.lwm2m;
|
package org.thingsboard.server.transport.lwm2m.sql;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -25,6 +25,7 @@ import org.thingsboard.server.common.data.device.credentials.lwm2m.NoSecClientCr
|
|||||||
import org.thingsboard.server.common.data.kv.KvEntry;
|
import org.thingsboard.server.common.data.kv.KvEntry;
|
||||||
import org.thingsboard.server.common.data.kv.TsKvEntry;
|
import org.thingsboard.server.common.data.kv.TsKvEntry;
|
||||||
import org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus;
|
import org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus;
|
||||||
|
import org.thingsboard.server.transport.lwm2m.AbstractLwM2MIntegrationTest;
|
||||||
import org.thingsboard.server.transport.lwm2m.client.LwM2MTestClient;
|
import org.thingsboard.server.transport.lwm2m.client.LwM2MTestClient;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -13,12 +13,13 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.thingsboard.server.transport.lwm2m;
|
package org.thingsboard.server.transport.lwm2m.sql;
|
||||||
|
|
||||||
import org.eclipse.leshan.client.object.Security;
|
import org.eclipse.leshan.client.object.Security;
|
||||||
import org.eclipse.leshan.core.util.Hex;
|
import org.eclipse.leshan.core.util.Hex;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.thingsboard.server.common.data.device.credentials.lwm2m.PSKClientCredentials;
|
import org.thingsboard.server.common.data.device.credentials.lwm2m.PSKClientCredentials;
|
||||||
|
import org.thingsboard.server.transport.lwm2m.AbstractLwM2MIntegrationTest;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
@ -13,12 +13,13 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.thingsboard.server.transport.lwm2m;
|
package org.thingsboard.server.transport.lwm2m.sql;
|
||||||
|
|
||||||
import org.eclipse.leshan.client.object.Security;
|
import org.eclipse.leshan.client.object.Security;
|
||||||
import org.eclipse.leshan.core.util.Hex;
|
import org.eclipse.leshan.core.util.Hex;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.thingsboard.server.common.data.device.credentials.lwm2m.RPKClientCredentials;
|
import org.thingsboard.server.common.data.device.credentials.lwm2m.RPKClientCredentials;
|
||||||
|
import org.thingsboard.server.transport.lwm2m.AbstractLwM2MIntegrationTest;
|
||||||
|
|
||||||
import static org.eclipse.leshan.client.object.Security.rpk;
|
import static org.eclipse.leshan.client.object.Security.rpk;
|
||||||
|
|
||||||
@ -13,13 +13,14 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.thingsboard.server.transport.lwm2m;
|
package org.thingsboard.server.transport.lwm2m.sql;
|
||||||
|
|
||||||
import org.eclipse.leshan.client.object.Security;
|
import org.eclipse.leshan.client.object.Security;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.thingsboard.server.common.data.device.credentials.lwm2m.X509ClientCredentials;
|
import org.thingsboard.server.common.data.device.credentials.lwm2m.X509ClientCredentials;
|
||||||
import org.thingsboard.server.common.transport.util.SslUtil;
|
import org.thingsboard.server.common.transport.util.SslUtil;
|
||||||
|
import org.thingsboard.server.transport.lwm2m.AbstractLwM2MIntegrationTest;
|
||||||
|
|
||||||
import static org.eclipse.leshan.client.object.Security.x509;
|
import static org.eclipse.leshan.client.object.Security.x509;
|
||||||
|
|
||||||
@ -314,14 +314,20 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
|
|||||||
public Device assignDeviceToCustomer(TenantId tenantId, DeviceId deviceId, CustomerId customerId) {
|
public Device assignDeviceToCustomer(TenantId tenantId, DeviceId deviceId, CustomerId customerId) {
|
||||||
Device device = findDeviceById(tenantId, deviceId);
|
Device device = findDeviceById(tenantId, deviceId);
|
||||||
device.setCustomerId(customerId);
|
device.setCustomerId(customerId);
|
||||||
return saveDevice(device);
|
Device savedDevice = saveDevice(device);
|
||||||
|
removeDeviceFromCacheByName(tenantId, device.getName());
|
||||||
|
removeDeviceFromCacheById(tenantId, device.getId());
|
||||||
|
return savedDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Device unassignDeviceFromCustomer(TenantId tenantId, DeviceId deviceId) {
|
public Device unassignDeviceFromCustomer(TenantId tenantId, DeviceId deviceId) {
|
||||||
Device device = findDeviceById(tenantId, deviceId);
|
Device device = findDeviceById(tenantId, deviceId);
|
||||||
device.setCustomerId(null);
|
device.setCustomerId(null);
|
||||||
return saveDevice(device);
|
Device savedDevice = saveDevice(device);
|
||||||
|
removeDeviceFromCacheByName(tenantId, device.getName());
|
||||||
|
removeDeviceFromCacheById(tenantId, device.getId());
|
||||||
|
return savedDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -550,10 +556,6 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Caching(evict= {
|
|
||||||
@CacheEvict(cacheNames = DEVICE_CACHE, key = "{#device.tenantId, #device.name}"),
|
|
||||||
@CacheEvict(cacheNames = DEVICE_CACHE, key = "{#device.tenantId, #device.id}")
|
|
||||||
})
|
|
||||||
@Override
|
@Override
|
||||||
public Device assignDeviceToTenant(TenantId tenantId, Device device) {
|
public Device assignDeviceToTenant(TenantId tenantId, Device device) {
|
||||||
log.trace("Executing assignDeviceToTenant [{}][{}]", tenantId, device);
|
log.trace("Executing assignDeviceToTenant [{}][{}]", tenantId, device);
|
||||||
@ -572,9 +574,18 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
|
|||||||
|
|
||||||
relationService.removeRelations(device.getTenantId(), device.getId());
|
relationService.removeRelations(device.getTenantId(), device.getId());
|
||||||
|
|
||||||
|
TenantId oldTenantId = device.getTenantId();
|
||||||
|
|
||||||
device.setTenantId(tenantId);
|
device.setTenantId(tenantId);
|
||||||
device.setCustomerId(null);
|
device.setCustomerId(null);
|
||||||
return doSaveDevice(device, null, true);
|
Device savedDevice = doSaveDevice(device, null, true);
|
||||||
|
|
||||||
|
// explicitly remove device with previous tenant id from cache
|
||||||
|
// result device object will have different tenant id and will not remove entity from cache
|
||||||
|
removeDeviceFromCacheByName(oldTenantId, device.getName());
|
||||||
|
removeDeviceFromCacheById(oldTenantId, device.getId());
|
||||||
|
|
||||||
|
return savedDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user