use of org.thingsboard.server.queue.discovery.HashPartitionService 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);
}
Aggregations