-
Notifications
You must be signed in to change notification settings - Fork 8
/
ReceiveAndLockMessageTest.java
79 lines (67 loc) · 2.73 KB
/
ReceiveAndLockMessageTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.messaging.servicebus.perf;
import com.azure.core.util.IterableStream;
import com.azure.core.util.logging.ClientLogger;
import com.azure.messaging.servicebus.ServiceBusMessage;
import com.azure.messaging.servicebus.ServiceBusReceivedMessage;
import com.azure.messaging.servicebus.models.ServiceBusReceiveMode;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* Performance test.
*/
public class ReceiveAndLockMessageTest extends ServiceTest<ServiceBusStressOptions> {
private final ClientLogger logger = new ClientLogger(ReceiveAndLockMessageTest.class);
private final ServiceBusStressOptions options;
private final Flux<ServiceBusReceivedMessage> receivedMessageFlux;
/**
* Creates test object
* @param options to set performance test options.
*/
public ReceiveAndLockMessageTest(ServiceBusStressOptions options) {
super(options, ServiceBusReceiveMode.PEEK_LOCK);
this.options = options;
this.receivedMessageFlux = receiverAsync.receiveMessages().publish().autoConnect();
}
@Override
public Mono<Void> setupAsync() {
// Since test does warm up and test many times, we are sending many messages, so we will have them available.
return Mono.defer(() -> {
int total = options.getMessagesToSend() * TOTAL_MESSAGE_MULTIPLIER;
List<ServiceBusMessage> messages = new ArrayList<>();
for (int i = 0; i < total; ++i) {
ServiceBusMessage message = new ServiceBusMessage(CONTENTS);
message.setMessageId(UUID.randomUUID().toString());
messages.add(message);
}
return senderAsync.sendMessages(messages);
});
}
@Override
public void run() {
int count = 0;
while(count < options.getMessagesToReceive()) {
IterableStream<ServiceBusReceivedMessage> messages = receiver
.receiveMessages(options.getMessagesToReceive());
for (ServiceBusReceivedMessage message : messages) {
receiver.complete(message);
count++;
}
if (count <= 0) {
throw logger.logExceptionAsWarning(new RuntimeException("Error. Should have received some messages."));
}
}
}
@Override
public Mono<Void> runAsync() {
return receivedMessageFlux
.take(options.getMessagesToReceive())
.flatMap(message -> {
return receiverAsync.complete(message).thenReturn(true);
}, 1).then();
}
}