fixed AlarmTypes redis cache serialization

This commit is contained in:
YevhenBondarenko 2023-09-29 11:49:41 +02:00 committed by Andrii Shvaika
parent 7c174de71d
commit 28b23ba9b4
3 changed files with 60 additions and 71 deletions

View File

@ -15,80 +15,17 @@
*/
package org.thingsboard.server.common.data;
import lombok.Data;
import org.thingsboard.server.common.data.id.TenantId;
public class EntitySubtype {
import java.io.Serializable;
@Data
public class EntitySubtype implements Serializable {
private static final long serialVersionUID = 8057240243059922101L;
private TenantId tenantId;
private EntityType entityType;
private String type;
public EntitySubtype() {
super();
}
public EntitySubtype(TenantId tenantId, EntityType entityType, String type) {
this.tenantId = tenantId;
this.entityType = entityType;
this.type = type;
}
public TenantId getTenantId() {
return tenantId;
}
public void setTenantId(TenantId tenantId) {
this.tenantId = tenantId;
}
public EntityType getEntityType() {
return entityType;
}
public void setEntityType(EntityType entityType) {
this.entityType = entityType;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
EntitySubtype that = (EntitySubtype) o;
if (tenantId != null ? !tenantId.equals(that.tenantId) : that.tenantId != null) return false;
if (entityType != that.entityType) return false;
return type != null ? type.equals(that.type) : that.type == null;
}
@Override
public int hashCode() {
int result = tenantId != null ? tenantId.hashCode() : 0;
result = 31 * result + (entityType != null ? entityType.hashCode() : 0);
result = 31 * result + (type != null ? type.hashCode() : 0);
return result;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("EntitySubtype{");
sb.append("tenantId=").append(tenantId);
sb.append(", entityType=").append(entityType);
sb.append(", type='").append(type).append('\'');
sb.append('}');
return sb.toString();
}
private final TenantId tenantId;
private final EntityType entityType;
private final String type;
}

View File

@ -19,6 +19,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.util.Collections;
@ -27,6 +28,7 @@ import java.util.function.Function;
import java.util.stream.Collectors;
@ApiModel
@EqualsAndHashCode
public class PageData<T> implements Serializable {
public static final PageData EMPTY_PAGE_DATA = new PageData<>();

View File

@ -0,0 +1,50 @@
/**
* Copyright © 2016-2023 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.service;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.cache.TbTransactionalCache;
import org.thingsboard.server.common.data.EntitySubtype;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.PageData;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@DaoSqlTest
public class TbCacheSerializationTest extends AbstractServiceTest {
@Autowired
TbTransactionalCache<TenantId, PageData<EntitySubtype>> alarmTypesCache;
@Test
public void AlarmTypesSerializationTest() {
var typesCount = 13;
TenantId tenantId = new TenantId(UUID.randomUUID());
List<EntitySubtype> types = new ArrayList<>(typesCount);
for (int i = 0; i < typesCount; i++) {
types.add(new EntitySubtype(tenantId, EntityType.ALARM, "alarm_type_" + i));
}
PageData<EntitySubtype> alarmTypesPage = new PageData<>(types, 1, typesCount, false);
alarmTypesCache.put(tenantId, alarmTypesPage);
PageData<EntitySubtype> foundAlarmTypes = alarmTypesCache.get(tenantId).get();
Assert.assertEquals(alarmTypesPage, foundAlarmTypes);
}
}