File tree Expand file tree Collapse file tree 3 files changed +72
-1
lines changed
main/java/org/reactivecommons/async/rabbit
test/java/org/reactivecommons/async/rabbit Expand file tree Collapse file tree 3 files changed +72
-1
lines changed Original file line number Diff line number Diff line change 3
3
import lombok .AccessLevel ;
4
4
import lombok .NoArgsConstructor ;
5
5
6
+ import java .util .UUID ;
7
+
6
8
@ NoArgsConstructor (access = AccessLevel .PRIVATE )
7
9
public class InstanceIdentifier {
10
+ private static final String INSTANCE_ID = UUID .randomUUID ().toString ().replace ("-" , "" );
11
+
8
12
public static String getInstanceId (String kind ) {
13
+ return getInstanceId (kind , INSTANCE_ID );
14
+ }
15
+
16
+ public static String getInstanceId (String kind , String defaultHost ) {
9
17
String host = System .getenv ("HOSTNAME" );
10
18
if (host == null || host .isEmpty ()) {
11
- return kind ;
19
+ return defaultHost + "-" + kind ;
12
20
}
13
21
return host + "-" + kind ;
14
22
}
Original file line number Diff line number Diff line change
1
+ package org .reactivecommons .async .rabbit ;
2
+
3
+ import org .junit .jupiter .api .Test ;
4
+
5
+ import static org .assertj .core .api .Assertions .assertThat ;
6
+
7
+ class InstanceIdentifierTest {
8
+
9
+ @ Test
10
+ void shouldGetInstanceIdFromUuid () {
11
+ String instanceId = InstanceIdentifier .getInstanceId ("events" );
12
+ var expectedLength = 39 ;
13
+ assertThat (instanceId ).endsWith ("-events" ).hasSize (expectedLength );
14
+ }
15
+
16
+ @ Test
17
+ void shouldGetInstanceIdFromEnv () {
18
+ String instanceId = InstanceIdentifier .getInstanceId ("events" , "host123" );
19
+ assertThat (instanceId ).isEqualTo ("host123-events" );
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ package org .reactivecommons .async .rabbit .communications ;
2
+
3
+ import org .junit .jupiter .api .BeforeEach ;
4
+ import org .junit .jupiter .api .Test ;
5
+ import org .junit .jupiter .api .extension .ExtendWith ;
6
+ import org .mockito .Mock ;
7
+ import org .mockito .junit .jupiter .MockitoExtension ;
8
+ import reactor .rabbitmq .QueueSpecification ;
9
+ import reactor .rabbitmq .Sender ;
10
+
11
+ import static org .assertj .core .api .Assertions .assertThat ;
12
+
13
+ @ ExtendWith (MockitoExtension .class )
14
+ class TopologyCreatorTest {
15
+ @ Mock
16
+ private Sender sender ;
17
+
18
+ private TopologyCreator creator ;
19
+
20
+ @ BeforeEach
21
+ void setUp () {
22
+ creator = new TopologyCreator (sender , "quorum" );
23
+ }
24
+
25
+ @ Test
26
+ void shouldInjectQueueType () {
27
+ QueueSpecification spec = creator .fillQueueType (QueueSpecification .queue ("durable" ));
28
+ assertThat (spec .getArguments ()).containsEntry ("x-queue-type" , "quorum" );
29
+ }
30
+
31
+ @ Test
32
+ void shouldForceClassicQueueTypeWhenAutodelete () {
33
+ QueueSpecification spec = creator .fillQueueType (QueueSpecification .queue ("autodelete" ).autoDelete (true ));
34
+ assertThat (spec .getArguments ()).containsEntry ("x-queue-type" , "classic" );
35
+ }
36
+
37
+ @ Test
38
+ void shouldForceClassicQueueTypeWhenExclusive () {
39
+ QueueSpecification spec = creator .fillQueueType (QueueSpecification .queue ("exclusive" ).exclusive (true ));
40
+ assertThat (spec .getArguments ()).containsEntry ("x-queue-type" , "classic" );
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments