Browse Source

Merge pull request #5079 from thingsboard/smatvienko-tb-cache-caffeine-zero-size-fix

Cache caffeine zero size fix
pull/5082/head
Igor Kulikov 5 years ago
committed by GitHub
parent
commit
b0be356fe5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      application/pom.xml
  2. 20
      application/src/main/resources/thingsboard.yml
  3. 55
      application/src/test/java/org/thingsboard/server/cache/CaffeineCacheDefaultConfigurationTestSuite.java
  4. 2
      application/src/test/java/org/thingsboard/server/controller/AbstractRuleEngineControllerTest.java
  5. 2
      application/src/test/java/org/thingsboard/server/controller/BaseEdgeEventControllerTest.java
  6. 2
      application/src/test/java/org/thingsboard/server/controller/BaseWebsocketApiTest.java
  7. 2
      application/src/test/java/org/thingsboard/server/service/ServiceSqlTestSuite.java
  8. 3
      application/src/test/java/org/thingsboard/server/service/resource/sql/BaseTbResourceServiceTest.java
  9. 2
      application/src/test/java/org/thingsboard/server/transport/TransportSqlTestSuite.java
  10. 2
      application/src/test/java/org/thingsboard/server/transport/lwm2m/AbstractLwM2MIntegrationTest.java
  11. 5
      application/src/test/java/org/thingsboard/server/transport/lwm2m/sql/NoSecLwM2MIntegrationTest.java
  12. 3
      application/src/test/java/org/thingsboard/server/transport/lwm2m/sql/PskLwm2mIntegrationTest.java
  13. 3
      application/src/test/java/org/thingsboard/server/transport/lwm2m/sql/RpkLwM2MIntegrationTest.java
  14. 3
      application/src/test/java/org/thingsboard/server/transport/lwm2m/sql/X509LwM2MIntegrationTest.java
  15. 25
      dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java

5
application/pom.xml

@ -360,7 +360,12 @@
<systemPropertyVariables>
<spring.config.name>thingsboard</spring.config.name>
</systemPropertyVariables>
<excludes>
<exclude>**/sql/*Test.java</exclude>
<exclude>**/nosql/*Test.java</exclude>
</excludes>
<includes>
<include>**/*Test.java</include>
<include>**/*TestSuite.java</include>
</includes>
</configuration>

20
application/src/main/resources/thingsboard.yml

@ -344,34 +344,34 @@ caffeine:
specs:
relations:
timeToLiveInMinutes: 1440
maxSize: 0
maxSize: 10000 # maxSize: 0 means the cache is disabled
deviceCredentials:
timeToLiveInMinutes: 1440
maxSize: 0
maxSize: 10000
devices:
timeToLiveInMinutes: 1440
maxSize: 0
maxSize: 10000
sessions:
timeToLiveInMinutes: 1440
maxSize: 0
maxSize: 10000
assets:
timeToLiveInMinutes: 1440
maxSize: 0
maxSize: 10000
entityViews:
timeToLiveInMinutes: 1440
maxSize: 0
maxSize: 10000
claimDevices:
timeToLiveInMinutes: 1440
maxSize: 1000
securitySettings:
timeToLiveInMinutes: 1440
maxSize: 0
maxSize: 10000
tenantProfiles:
timeToLiveInMinutes: 1440
maxSize: 0
maxSize: 10000
deviceProfiles:
timeToLiveInMinutes: 1440
maxSize: 0
maxSize: 10000
attributes:
timeToLiveInMinutes: 1440
maxSize: 100000
@ -386,7 +386,7 @@ caffeine:
maxSize: 10
edges:
timeToLiveInMinutes: 1440
maxSize: 0
maxSize: 10000
redis:
# standalone or cluster

55
application/src/test/java/org/thingsboard/server/cache/CaffeineCacheDefaultConfigurationTestSuite.java

@ -0,0 +1,55 @@
/**
* Copyright © 2016-2021 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.cache;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootContextLoader;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static org.assertj.core.api.Assertions.assertThat;
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = CaffeineCacheDefaultConfigurationTestSuite.class, loader = SpringBootContextLoader.class)
@ComponentScan({"org.thingsboard.server.cache"})
@EnableConfigurationProperties
@Slf4j
public class CaffeineCacheDefaultConfigurationTestSuite {
@Autowired
CaffeineCacheConfiguration caffeineCacheConfiguration;
@Test
public void verifyTransactionAwareCacheManagerProxy() {
assertThat(caffeineCacheConfiguration.getSpecs()).as("specs").isNotNull();
caffeineCacheConfiguration.getSpecs().forEach((name, cacheSpecs)->assertThat(cacheSpecs).as("cache %s specs", name).isNotNull());
SoftAssertions softly = new SoftAssertions();
caffeineCacheConfiguration.getSpecs().forEach((name, cacheSpecs)->{
softly.assertThat(name).as("cache name").isNotEmpty();
softly.assertThat(cacheSpecs.getTimeToLiveInMinutes()).as("cache %s time to live", name).isGreaterThan(0);
softly.assertThat(cacheSpecs.getMaxSize()).as("cache %s max size", name).isGreaterThan(0);
});
softly.assertAll();
}
}

2
application/src/test/java/org/thingsboard/server/controller/AbstractRuleEngineControllerTest.java

@ -35,7 +35,7 @@ import java.util.function.Predicate;
/**
* Created by ashvayka on 20.03.18.
*/
public class AbstractRuleEngineControllerTest extends AbstractControllerTest {
public abstract class AbstractRuleEngineControllerTest extends AbstractControllerTest {
@Autowired
protected RuleChainService ruleChainService;

2
application/src/test/java/org/thingsboard/server/controller/BaseEdgeEventControllerTest.java

@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@Slf4j
public class BaseEdgeEventControllerTest extends AbstractControllerTest {
public abstract class BaseEdgeEventControllerTest extends AbstractControllerTest {
private Tenant savedTenant;
private User tenantAdmin;

2
application/src/test/java/org/thingsboard/server/controller/BaseWebsocketApiTest.java

@ -68,7 +68,7 @@ import java.util.concurrent.TimeUnit;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@Slf4j
public class BaseWebsocketApiTest extends AbstractWebsocketTest {
public abstract class BaseWebsocketApiTest extends AbstractWebsocketTest {
private Tenant savedTenant;
private User tenantAdmin;

2
application/src/test/java/org/thingsboard/server/service/ServiceSqlTestSuite.java

@ -26,7 +26,7 @@ import java.util.Arrays;
@RunWith(ClasspathSuite.class)
@ClasspathSuite.ClassnameFilters({
"org.thingsboard.server.service.resource.*Test",
"org.thingsboard.server.service.resource.sql.*Test",
})
public class ServiceSqlTestSuite {

3
application/src/test/java/org/thingsboard/server/service/resource/BaseTbResourceServiceTest.java → application/src/test/java/org/thingsboard/server/service/resource/sql/BaseTbResourceServiceTest.java

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* 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 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.dao.exception.DataValidationException;
import org.thingsboard.server.dao.service.DaoSqlTest;
import org.thingsboard.server.service.resource.TbResourceService;
import java.util.ArrayList;
import java.util.Base64;

2
application/src/test/java/org/thingsboard/server/transport/TransportSqlTestSuite.java

@ -33,7 +33,7 @@ import java.util.Arrays;
"org.thingsboard.server.transport.*.attributes.request.sql.*Test",
"org.thingsboard.server.transport.*.claim.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 {

2
application/src/test/java/org/thingsboard/server/transport/lwm2m/AbstractLwM2MIntegrationTest.java

@ -88,7 +88,7 @@ import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE;
import static org.thingsboard.server.common.data.ota.OtaPackageType.SOFTWARE;
@DaoSqlTest
public class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest {
public abstract class AbstractLwM2MIntegrationTest extends AbstractWebsocketTest {
protected final String TRANSPORT_CONFIGURATION = "{\n" +
" \"type\": \"LWM2M\",\n" +

5
application/src/test/java/org/thingsboard/server/transport/lwm2m/NoSecLwM2MIntegrationTest.java → application/src/test/java/org/thingsboard/server/transport/lwm2m/sql/NoSecLwM2MIntegrationTest.java

@ -13,18 +13,20 @@
* See the License for the specific language governing permissions and
* 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 lombok.extern.slf4j.Slf4j;
import org.junit.After;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.device.credentials.lwm2m.NoSecClientCredentials;
import org.thingsboard.server.common.data.kv.KvEntry;
import org.thingsboard.server.common.data.kv.TsKvEntry;
import org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus;
import org.thingsboard.server.transport.lwm2m.AbstractLwM2MIntegrationTest;
import org.thingsboard.server.transport.lwm2m.client.LwM2MTestClient;
import java.util.Arrays;
@ -217,6 +219,7 @@ public class NoSecLwM2MIntegrationTest extends AbstractLwM2MIntegrationTest {
* Check the detailed log output to learn how Awaitility polling the API and when exactly expected result appears
* */
@Test
@Ignore
public void testSoftwareUpdateByObject9() throws Exception {
//given
final List<OtaPackageUpdateStatus> expectedStatuses = Collections.unmodifiableList(Arrays.asList(

3
application/src/test/java/org/thingsboard/server/transport/lwm2m/PskLwm2mIntegrationTest.java → application/src/test/java/org/thingsboard/server/transport/lwm2m/sql/PskLwm2mIntegrationTest.java

@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* 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.core.util.Hex;
import org.junit.Test;
import org.thingsboard.server.common.data.device.credentials.lwm2m.PSKClientCredentials;
import org.thingsboard.server.transport.lwm2m.AbstractLwM2MIntegrationTest;
import java.nio.charset.StandardCharsets;

3
application/src/test/java/org/thingsboard/server/transport/lwm2m/RpkLwM2MIntegrationTest.java → application/src/test/java/org/thingsboard/server/transport/lwm2m/sql/RpkLwM2MIntegrationTest.java

@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* 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.core.util.Hex;
import org.junit.Test;
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;

3
application/src/test/java/org/thingsboard/server/transport/lwm2m/X509LwM2MIntegrationTest.java → application/src/test/java/org/thingsboard/server/transport/lwm2m/sql/X509LwM2MIntegrationTest.java

@ -13,13 +13,14 @@
* See the License for the specific language governing permissions and
* 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.junit.Ignore;
import org.junit.Test;
import org.thingsboard.server.common.data.device.credentials.lwm2m.X509ClientCredentials;
import org.thingsboard.server.common.transport.util.SslUtil;
import org.thingsboard.server.transport.lwm2m.AbstractLwM2MIntegrationTest;
import static org.eclipse.leshan.client.object.Security.x509;

25
dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java

@ -314,14 +314,20 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
public Device assignDeviceToCustomer(TenantId tenantId, DeviceId deviceId, CustomerId customerId) {
Device device = findDeviceById(tenantId, deviceId);
device.setCustomerId(customerId);
return saveDevice(device);
Device savedDevice = saveDevice(device);
removeDeviceFromCacheByName(tenantId, device.getName());
removeDeviceFromCacheById(tenantId, device.getId());
return savedDevice;
}
@Override
public Device unassignDeviceFromCustomer(TenantId tenantId, DeviceId deviceId) {
Device device = findDeviceById(tenantId, deviceId);
device.setCustomerId(null);
return saveDevice(device);
Device savedDevice = saveDevice(device);
removeDeviceFromCacheByName(tenantId, device.getName());
removeDeviceFromCacheById(tenantId, device.getId());
return savedDevice;
}
@Override
@ -550,10 +556,6 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
}
@Transactional
@Caching(evict= {
@CacheEvict(cacheNames = DEVICE_CACHE, key = "{#device.tenantId, #device.name}"),
@CacheEvict(cacheNames = DEVICE_CACHE, key = "{#device.tenantId, #device.id}")
})
@Override
public Device assignDeviceToTenant(TenantId tenantId, Device device) {
log.trace("Executing assignDeviceToTenant [{}][{}]", tenantId, device);
@ -572,9 +574,18 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
relationService.removeRelations(device.getTenantId(), device.getId());
TenantId oldTenantId = device.getTenantId();
device.setTenantId(tenantId);
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

Loading…
Cancel
Save