|
@@ -17,6 +17,7 @@ package org.thingsboard.server.service.cluster.routing; |
|
@@ -17,6 +17,7 @@ package org.thingsboard.server.service.cluster.routing; |
17
|
|
17
|
|
18
|
import com.datastax.driver.core.utils.UUIDs;
|
18
|
import com.datastax.driver.core.utils.UUIDs;
|
19
|
import lombok.extern.slf4j.Slf4j;
|
19
|
import lombok.extern.slf4j.Slf4j;
|
|
|
20
|
+import org.junit.Assert;
|
20
|
import org.junit.Before;
|
21
|
import org.junit.Before;
|
21
|
import org.junit.Test;
|
22
|
import org.junit.Test;
|
22
|
import org.junit.runner.RunWith;
|
23
|
import org.junit.runner.RunWith;
|
|
@@ -31,6 +32,8 @@ import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
|
@@ -31,6 +32,8 @@ import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
31
|
import org.thingsboard.server.common.msg.queue.TopicPartitionInfo;
|
32
|
import org.thingsboard.server.common.msg.queue.TopicPartitionInfo;
|
32
|
import org.thingsboard.server.gen.transport.TransportProtos;
|
33
|
import org.thingsboard.server.gen.transport.TransportProtos;
|
33
|
import org.thingsboard.server.queue.discovery.TenantRoutingInfoService;
|
34
|
import org.thingsboard.server.queue.discovery.TenantRoutingInfoService;
|
|
|
35
|
+import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings;
|
|
|
36
|
+import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration;
|
34
|
|
37
|
|
35
|
import java.util.ArrayList;
|
38
|
import java.util.ArrayList;
|
36
|
import java.util.Collections;
|
39
|
import java.util.Collections;
|
|
@@ -41,6 +44,7 @@ import java.util.Map; |
|
@@ -41,6 +44,7 @@ import java.util.Map; |
41
|
import java.util.stream.Collectors;
|
44
|
import java.util.stream.Collectors;
|
42
|
|
45
|
|
43
|
import static org.mockito.Mockito.mock;
|
46
|
import static org.mockito.Mockito.mock;
|
|
|
47
|
+import static org.mockito.Mockito.when;
|
44
|
|
48
|
|
45
|
@Slf4j
|
49
|
@Slf4j
|
46
|
@RunWith(MockitoJUnitRunner.class)
|
50
|
@RunWith(MockitoJUnitRunner.class)
|
|
@@ -52,6 +56,7 @@ public class ConsistentHashParitionServiceTest { |
|
@@ -52,6 +56,7 @@ public class ConsistentHashParitionServiceTest { |
52
|
private TbServiceInfoProvider discoveryService;
|
56
|
private TbServiceInfoProvider discoveryService;
|
53
|
private TenantRoutingInfoService routingInfoService;
|
57
|
private TenantRoutingInfoService routingInfoService;
|
54
|
private ApplicationEventPublisher applicationEventPublisher;
|
58
|
private ApplicationEventPublisher applicationEventPublisher;
|
|
|
59
|
+ private TbQueueRuleEngineSettings ruleEngineSettings;
|
55
|
|
60
|
|
56
|
private String hashFunctionName = "murmur3_128";
|
61
|
private String hashFunctionName = "murmur3_128";
|
57
|
private Integer virtualNodesSize = 16;
|
62
|
private Integer virtualNodesSize = 16;
|
|
@@ -62,12 +67,15 @@ public class ConsistentHashParitionServiceTest { |
|
@@ -62,12 +67,15 @@ public class ConsistentHashParitionServiceTest { |
62
|
discoveryService = mock(TbServiceInfoProvider.class);
|
67
|
discoveryService = mock(TbServiceInfoProvider.class);
|
63
|
applicationEventPublisher = mock(ApplicationEventPublisher.class);
|
68
|
applicationEventPublisher = mock(ApplicationEventPublisher.class);
|
64
|
routingInfoService = mock(TenantRoutingInfoService.class);
|
69
|
routingInfoService = mock(TenantRoutingInfoService.class);
|
65
|
- clusterRoutingService = new ConsistentHashPartitionService(discoveryService, routingInfoService, applicationEventPublisher);
|
70
|
+ ruleEngineSettings = mock(TbQueueRuleEngineSettings.class);
|
|
|
71
|
+ clusterRoutingService = new ConsistentHashPartitionService(discoveryService,
|
|
|
72
|
+ routingInfoService,
|
|
|
73
|
+ applicationEventPublisher,
|
|
|
74
|
+ ruleEngineSettings
|
|
|
75
|
+ );
|
|
|
76
|
+ when(ruleEngineSettings.getQueues()).thenReturn(Collections.emptyList());
|
66
|
ReflectionTestUtils.setField(clusterRoutingService, "coreTopic", "tb.core");
|
77
|
ReflectionTestUtils.setField(clusterRoutingService, "coreTopic", "tb.core");
|
67
|
ReflectionTestUtils.setField(clusterRoutingService, "corePartitions", 3);
|
78
|
ReflectionTestUtils.setField(clusterRoutingService, "corePartitions", 3);
|
68
|
- ReflectionTestUtils.setField(clusterRoutingService, "ruleEngineTopic", "tb.rule-engine");
|
|
|
69
|
- ReflectionTestUtils.setField(clusterRoutingService, "ruleEnginePartitions", 100);
|
|
|
70
|
-
|
|
|
71
|
ReflectionTestUtils.setField(clusterRoutingService, "hashFunctionName", hashFunctionName);
|
79
|
ReflectionTestUtils.setField(clusterRoutingService, "hashFunctionName", hashFunctionName);
|
72
|
ReflectionTestUtils.setField(clusterRoutingService, "virtualNodesSize", virtualNodesSize);
|
80
|
ReflectionTestUtils.setField(clusterRoutingService, "virtualNodesSize", virtualNodesSize);
|
73
|
TransportProtos.ServiceInfo currentServer = TransportProtos.ServiceInfo.newBuilder()
|
81
|
TransportProtos.ServiceInfo currentServer = TransportProtos.ServiceInfo.newBuilder()
|
|
@@ -107,8 +115,9 @@ public class ConsistentHashParitionServiceTest { |
|
@@ -107,8 +115,9 @@ public class ConsistentHashParitionServiceTest { |
107
|
List<Map.Entry<Integer, Integer>> data = map.entrySet().stream().sorted(Comparator.comparingInt(Map.Entry::getValue)).collect(Collectors.toList());
|
115
|
List<Map.Entry<Integer, Integer>> data = map.entrySet().stream().sorted(Comparator.comparingInt(Map.Entry::getValue)).collect(Collectors.toList());
|
108
|
long end = System.currentTimeMillis();
|
116
|
long end = System.currentTimeMillis();
|
109
|
double diff = (data.get(data.size() - 1).getValue() - data.get(0).getValue());
|
117
|
double diff = (data.get(data.size() - 1).getValue() - data.get(0).getValue());
|
110
|
- System.out.println("Size: " + virtualNodesSize + " Time: " + (end - start) + " Diff: " + diff + "(" + String.format("%f", (diff / ITERATIONS) * 100.0) + "%)");
|
|
|
111
|
-
|
118
|
+ double diffPercent = (diff / ITERATIONS) * 100.0;
|
|
|
119
|
+ System.out.println("Size: " + virtualNodesSize + " Time: " + (end - start) + " Diff: " + diff + "(" + String.format("%f", diffPercent) + "%)");
|
|
|
120
|
+ Assert.assertTrue(diffPercent < 0.5);
|
112
|
for (Map.Entry<Integer, Integer> entry : data) {
|
121
|
for (Map.Entry<Integer, Integer> entry : data) {
|
113
|
System.out.println(entry.getKey() + ": " + entry.getValue());
|
122
|
System.out.println(entry.getKey() + ": " + entry.getValue());
|
114
|
}
|
123
|
}
|