|
|
@ -20,8 +20,8 @@ import lombok.extern.slf4j.Slf4j; |
|
|
import org.junit.Test; |
|
|
import org.junit.Test; |
|
|
import org.junit.runner.RunWith; |
|
|
import org.junit.runner.RunWith; |
|
|
import org.mockito.ArgumentCaptor; |
|
|
import org.mockito.ArgumentCaptor; |
|
|
import org.springframework.boot.test.mock.mockito.MockBean; |
|
|
import org.springframework.test.context.bean.override.mockito.MockitoBean; |
|
|
import org.springframework.boot.test.mock.mockito.SpyBean; |
|
|
import org.springframework.test.context.bean.override.mockito.MockitoSpyBean; |
|
|
import org.springframework.test.context.ContextConfiguration; |
|
|
import org.springframework.test.context.ContextConfiguration; |
|
|
import org.springframework.test.context.junit4.SpringRunner; |
|
|
import org.springframework.test.context.junit4.SpringRunner; |
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
@ -56,6 +56,7 @@ import org.thingsboard.server.queue.discovery.PartitionService; |
|
|
import org.thingsboard.server.queue.discovery.TopicService; |
|
|
import org.thingsboard.server.queue.discovery.TopicService; |
|
|
import org.thingsboard.server.queue.provider.TbQueueProducerProvider; |
|
|
import org.thingsboard.server.queue.provider.TbQueueProducerProvider; |
|
|
import org.thingsboard.server.service.gateway_device.GatewayNotificationsService; |
|
|
import org.thingsboard.server.service.gateway_device.GatewayNotificationsService; |
|
|
|
|
|
import org.thingsboard.server.service.ota.OtaPackageStateService; |
|
|
import org.thingsboard.server.service.profile.TbAssetProfileCache; |
|
|
import org.thingsboard.server.service.profile.TbAssetProfileCache; |
|
|
import org.thingsboard.server.service.profile.TbDeviceProfileCache; |
|
|
import org.thingsboard.server.service.profile.TbDeviceProfileCache; |
|
|
|
|
|
|
|
|
@ -67,6 +68,7 @@ import static org.mockito.ArgumentMatchers.any; |
|
|
import static org.mockito.ArgumentMatchers.eq; |
|
|
import static org.mockito.ArgumentMatchers.eq; |
|
|
import static org.mockito.ArgumentMatchers.isNull; |
|
|
import static org.mockito.ArgumentMatchers.isNull; |
|
|
import static org.mockito.Mockito.doReturn; |
|
|
import static org.mockito.Mockito.doReturn; |
|
|
|
|
|
import static org.mockito.Mockito.lenient; |
|
|
import static org.mockito.Mockito.mock; |
|
|
import static org.mockito.Mockito.mock; |
|
|
import static org.mockito.Mockito.never; |
|
|
import static org.mockito.Mockito.never; |
|
|
import static org.mockito.Mockito.times; |
|
|
import static org.mockito.Mockito.times; |
|
|
@ -87,30 +89,45 @@ public class DefaultTbClusterServiceTest { |
|
|
|
|
|
|
|
|
public static final String TRANSPORT = "transport"; |
|
|
public static final String TRANSPORT = "transport"; |
|
|
|
|
|
|
|
|
@MockBean |
|
|
@MockitoBean |
|
|
protected TbDeviceProfileCache deviceProfileCache; |
|
|
protected TbDeviceProfileCache deviceProfileCache; |
|
|
@MockBean |
|
|
@MockitoBean |
|
|
protected TbAssetProfileCache assetProfileCache; |
|
|
protected TbAssetProfileCache assetProfileCache; |
|
|
@MockBean |
|
|
@MockitoBean |
|
|
protected GatewayNotificationsService gatewayNotificationsService; |
|
|
protected GatewayNotificationsService gatewayNotificationsService; |
|
|
@MockBean |
|
|
@MockitoBean |
|
|
protected EdgeService edgeService; |
|
|
protected EdgeService edgeService; |
|
|
@MockBean |
|
|
@MockitoBean |
|
|
protected PartitionService partitionService; |
|
|
protected PartitionService partitionService; |
|
|
@MockBean |
|
|
@MockitoBean |
|
|
protected TbQueueProducerProvider producerProvider; |
|
|
protected TbQueueProducerProvider producerProvider; |
|
|
@MockBean |
|
|
@MockitoBean |
|
|
protected TbRuleEngineProducerService ruleEngineProducerService; |
|
|
protected TbRuleEngineProducerService ruleEngineProducerService; |
|
|
@MockBean |
|
|
@MockitoBean |
|
|
protected TbTransactionalCache<EdgeId, String> edgeCache; |
|
|
protected TbTransactionalCache<EdgeId, String> edgeCache; |
|
|
@MockBean |
|
|
@MockitoBean |
|
|
protected CalculatedFieldService calculatedFieldService; |
|
|
protected CalculatedFieldService calculatedFieldService; |
|
|
|
|
|
|
|
|
@SpyBean |
|
|
@MockitoBean |
|
|
protected TopicService topicService; |
|
|
protected TopicService topicService; |
|
|
@SpyBean |
|
|
@MockitoBean |
|
|
|
|
|
protected OtaPackageStateService otaPackageStateService; |
|
|
|
|
|
@MockitoSpyBean |
|
|
protected TbClusterService clusterService; |
|
|
protected TbClusterService clusterService; |
|
|
|
|
|
|
|
|
|
|
|
@org.junit.Before |
|
|
|
|
|
public void setUp() { |
|
|
|
|
|
lenient().when(topicService.getNotificationsTopic(any(), any())).thenAnswer(invocation -> { |
|
|
|
|
|
ServiceType serviceType = invocation.getArgument(0); |
|
|
|
|
|
String serviceId = invocation.getArgument(1); |
|
|
|
|
|
return new TopicPartitionInfo(serviceType.name().toLowerCase() + ".notifications." + serviceId, null, null, false); |
|
|
|
|
|
}); |
|
|
|
|
|
lenient().when(topicService.getCalculatedFieldNotificationsTopic(any())).thenAnswer(invocation -> { |
|
|
|
|
|
String serviceId = invocation.getArgument(0); |
|
|
|
|
|
return new TopicPartitionInfo("calculated_field.notifications." + serviceId, null, null, false); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Test |
|
|
@Test |
|
|
public void testOnQueueChangeSingleMonolith() { |
|
|
public void testOnQueueChangeSingleMonolith() { |
|
|
when(partitionService.getAllServiceIds(ServiceType.TB_RULE_ENGINE)).thenReturn(Sets.newHashSet(MONOLITH)); |
|
|
when(partitionService.getAllServiceIds(ServiceType.TB_RULE_ENGINE)).thenReturn(Sets.newHashSet(MONOLITH)); |
|
|
|