Search in sources :

Example 1 with QueueService

use of org.thingsboard.server.queue.QueueService in project thingsboard by thingsboard.

the class HashPartitionServiceTest method setup.

@Before
public void setup() throws Exception {
    discoveryService = mock(TbServiceInfoProvider.class);
    applicationEventPublisher = mock(ApplicationEventPublisher.class);
    routingInfoService = mock(TenantRoutingInfoService.class);
    ruleEngineSettings = mock(TbQueueRuleEngineSettings.class);
    queueService = mock(QueueService.class);
    clusterRoutingService = new HashPartitionService(discoveryService, routingInfoService, applicationEventPublisher, ruleEngineSettings, queueService);
    when(ruleEngineSettings.getQueues()).thenReturn(Collections.emptyList());
    ReflectionTestUtils.setField(clusterRoutingService, "coreTopic", "tb.core");
    ReflectionTestUtils.setField(clusterRoutingService, "corePartitions", 10);
    ReflectionTestUtils.setField(clusterRoutingService, "hashFunctionName", hashFunctionName);
    TransportProtos.ServiceInfo currentServer = TransportProtos.ServiceInfo.newBuilder().setServiceId("tb-core-0").setTenantIdMSB(TenantId.NULL_UUID.getMostSignificantBits()).setTenantIdLSB(TenantId.NULL_UUID.getLeastSignificantBits()).addAllServiceTypes(Collections.singletonList(ServiceType.TB_CORE.name())).build();
    // when(queueService.resolve(Mockito.any(), Mockito.anyString())).thenAnswer(i -> i.getArguments()[1]);
    // when(discoveryService.getServiceInfo()).thenReturn(currentServer);
    List<TransportProtos.ServiceInfo> otherServers = new ArrayList<>();
    for (int i = 1; i < SERVER_COUNT; i++) {
        otherServers.add(TransportProtos.ServiceInfo.newBuilder().setServiceId("tb-rule-" + i).setTenantIdMSB(TenantId.NULL_UUID.getMostSignificantBits()).setTenantIdLSB(TenantId.NULL_UUID.getLeastSignificantBits()).addAllServiceTypes(Collections.singletonList(ServiceType.TB_CORE.name())).build());
    }
    clusterRoutingService.init();
    clusterRoutingService.recalculatePartitions(currentServer, otherServers);
}
Also used : TbServiceInfoProvider(org.thingsboard.server.queue.discovery.TbServiceInfoProvider) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) TenantRoutingInfoService(org.thingsboard.server.queue.discovery.TenantRoutingInfoService) ArrayList(java.util.ArrayList) HashPartitionService(org.thingsboard.server.queue.discovery.HashPartitionService) QueueService(org.thingsboard.server.queue.QueueService) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) TbQueueRuleEngineSettings(org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings) Before(org.junit.Before)

Aggregations

ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)1 TransportProtos (org.thingsboard.server.gen.transport.TransportProtos)1 QueueService (org.thingsboard.server.queue.QueueService)1 HashPartitionService (org.thingsboard.server.queue.discovery.HashPartitionService)1 TbServiceInfoProvider (org.thingsboard.server.queue.discovery.TbServiceInfoProvider)1 TenantRoutingInfoService (org.thingsboard.server.queue.discovery.TenantRoutingInfoService)1 TbQueueRuleEngineSettings (org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings)1