30
30
import javax .jms .Session ;
31
31
import javax .jms .TextMessage ;
32
32
import java .io .File ;
33
- import java .util .ArrayList ;
34
- import java .util .Collection ;
35
- import java .util .List ;
33
+ import java .util .concurrent .CountDownLatch ;
36
34
import java .util .concurrent .ExecutorService ;
37
35
import java .util .concurrent .Executors ;
38
36
import java .util .concurrent .TimeUnit ;
39
37
import java .util .concurrent .atomic .AtomicInteger ;
40
38
41
39
import org .apache .activemq .artemis .tests .soak .SoakTestBase ;
42
40
import org .apache .activemq .artemis .tests .util .CFUtil ;
41
+ import org .apache .activemq .artemis .util .ServerUtil ;
42
+ import org .apache .activemq .artemis .utils .FileUtil ;
43
43
import org .apache .activemq .artemis .utils .RandomUtil ;
44
- import org .apache .activemq .artemis .utils .ReusableLatch ;
45
44
import org .apache .activemq .artemis .utils .TestParameters ;
46
45
import org .apache .activemq .artemis .cli .commands .helper .HelperCreate ;
47
46
import org .junit .jupiter .api .BeforeAll ;
@@ -61,18 +60,19 @@ public class HorizontalPagingTest extends SoakTestBase {
61
60
private static final String TEST_NAME = "HORIZONTAL" ;
62
61
63
62
private static final boolean TEST_ENABLED = Boolean .parseBoolean (testProperty (TEST_NAME , "TEST_ENABLED" , "true" ));
64
- private static final int SERVER_START_TIMEOUT = testProperty (TEST_NAME , "SERVER_START_TIMEOUT" , 300_000 );
65
- private static final int TIMEOUT_MINUTES = testProperty (TEST_NAME , "TIMEOUT_MINUTES" , 120 );
66
- private static final String PROTOCOL_LIST = testProperty (TEST_NAME , "PROTOCOL_LIST" , "OPENWIRE,CORE,AMQP" );
63
+ private static final int SERVER_START_TIMEOUT = testProperty (TEST_NAME , "SERVER_START_TIMEOUT" , 20_000 );
64
+ private static final int TIMEOUT_MINUTES = testProperty (TEST_NAME , "TIMEOUT_MINUTES" , 5 );
67
65
private static final int PRINT_INTERVAL = testProperty (TEST_NAME , "PRINT_INTERVAL" , 100 );
66
+ // This property is useful if you want to validate a setup on a different data folder, for example a remote directory on a NFS server or anything like that
67
+ private static final String DATA_FOLDER = testProperty (TEST_NAME , "DATA_FOLDER" , null );
68
+ private static final int EXECUTOR_SIZE = testProperty (TEST_NAME , "EXECUTOR_SIZE" , 50 );
68
69
69
70
private final int DESTINATIONS ;
70
71
private final int MESSAGES ;
71
72
private final int COMMIT_INTERVAL ;
72
73
// if 0 will use AUTO_ACK
73
74
private final int RECEIVE_COMMIT_INTERVAL ;
74
75
private final int MESSAGE_SIZE ;
75
- private final int PARALLEL_SENDS ;
76
76
77
77
private static final Logger logger = LoggerFactory .getLogger (MethodHandles .lookup ().lookupClass ());
78
78
@@ -84,35 +84,34 @@ public static void createServers() throws Exception {
84
84
File serverLocation = getFileServerLocation (SERVER_NAME_0 );
85
85
deleteDirectory (serverLocation );
86
86
87
+ File dataFolder = null ;
88
+ if (DATA_FOLDER != null ) {
89
+ dataFolder = new File (DATA_FOLDER );
90
+ if (dataFolder .exists ()) {
91
+ deleteDirectory (dataFolder );
92
+ }
93
+ }
94
+
87
95
HelperCreate cliCreateServer = helperCreate ();
88
96
cliCreateServer .setRole ("amq" ).setUser ("admin" ).setPassword ("admin" ).setAllowAnonymous (true ).setNoWeb (false ).setArtemisInstance (serverLocation );
89
- // some limited memory to make it more likely to fail
90
97
cliCreateServer .setArgs ("--java-memory" , "2g" );
91
- cliCreateServer .setConfiguration ("./src/main/resources/servers/subscriptionPaging " );
98
+ cliCreateServer .setConfiguration ("./src/main/resources/servers/horizontalPaging " );
92
99
cliCreateServer .createServer ();
93
- }
94
- }
95
100
96
- public static List <String > parseProtocolList () {
97
- String [] protocols = PROTOCOL_LIST .split ("," );
98
-
99
- List <String > protocolList = new ArrayList <>();
100
- for (String str : protocols ) {
101
- logger .info ("Adding {} to the list for the test" , str );
102
- protocolList .add (str );
101
+ if (dataFolder != null ) {
102
+ assertTrue (FileUtil .findReplace (new File (getFileServerLocation (SERVER_NAME_0 ), "/etc/broker.xml" ), "data/" , dataFolder .getAbsolutePath () + "/" ));
103
+ }
103
104
}
104
-
105
- return protocolList ;
106
105
}
107
106
108
107
public HorizontalPagingTest () {
109
- DESTINATIONS = TestParameters .testProperty (TEST_NAME , "DESTINATIONS" , 5 );
110
- MESSAGES = TestParameters .testProperty (TEST_NAME , "MESSAGES" , 1000 );
108
+ DESTINATIONS = TestParameters .testProperty (TEST_NAME , "DESTINATIONS" , 100 );
109
+ MESSAGES = TestParameters .testProperty (TEST_NAME , "MESSAGES" , 100 );
111
110
COMMIT_INTERVAL = TestParameters .testProperty (TEST_NAME , "COMMIT_INTERVAL" , 100 );
112
111
// if 0 will use AUTO_ACK
113
112
RECEIVE_COMMIT_INTERVAL = TestParameters .testProperty (TEST_NAME , "RECEIVE_COMMIT_INTERVAL" , 100 );
114
113
MESSAGE_SIZE = TestParameters .testProperty (TEST_NAME , "MESSAGE_SIZE" , 10_000 );
115
- PARALLEL_SENDS = TestParameters . testProperty ( TEST_NAME , "PARALLEL_SENDS" , 5 );
114
+
116
115
}
117
116
118
117
Process serverProcess ;
@@ -125,29 +124,43 @@ public void before() throws Exception {
125
124
serverProcess = startServer (SERVER_NAME_0 , 0 , SERVER_START_TIMEOUT );
126
125
}
127
126
127
+ /// ///////////////////////////////////////////////////
128
+ /// It is important to keep separate tests here
129
+ /// as the server has to be killed within the timeframe of protocol being executed
130
+ /// to validate proper callbacks are in place
131
+ @ Test
132
+ public void testHorizontalAMQP () throws Exception {
133
+ testHorizontal ("AMQP" );
134
+ }
135
+
136
+ @ Test
137
+ public void testHorizontalCORE () throws Exception {
138
+ testHorizontal ("CORE" );
139
+ }
140
+
128
141
@ Test
129
- public void testHorizontal () throws Exception {
130
- Collection <String > protocolList = parseProtocolList ();
142
+ public void testHorizontalOPENWIRE () throws Exception {
143
+ testHorizontal ("OPENWIRE" );
144
+ }
145
+
146
+ private void testHorizontal (String protocol ) throws Exception {
131
147
AtomicInteger errors = new AtomicInteger (0 );
132
148
133
- ExecutorService service = Executors .newFixedThreadPool (DESTINATIONS * protocolList . size () );
149
+ ExecutorService service = Executors .newFixedThreadPool (EXECUTOR_SIZE );
134
150
runAfter (service ::shutdownNow );
135
151
136
152
String text = RandomUtil .randomAlphaNumericString (MESSAGE_SIZE );
137
153
138
- ReusableLatch latchDone = new ReusableLatch (0 );
139
-
140
- for (String protocol : protocolList ) {
141
- String protocolUsed = protocol ;
154
+ {
155
+ CountDownLatch latchDone = new CountDownLatch (DESTINATIONS );
142
156
143
157
ConnectionFactory factory = CFUtil .createConnectionFactory (protocol , "tcp://localhost:61616" );
144
158
Connection connection = factory .createConnection ();
145
159
runAfter (connection ::close );
146
160
147
161
for (int i = 0 ; i < DESTINATIONS ; i ++) {
148
- latchDone .countUp ();
149
162
Session session = connection .createSession (true , Session .SESSION_TRANSACTED );
150
- Queue queue = session .createQueue ("queue_" + i + protocolUsed );
163
+ Queue queue = session .createQueue ("queue_" + i + "_" + protocol );
151
164
service .execute (() -> {
152
165
try {
153
166
logger .info ("*******************************************************************************************************************************\n destination {}" , queue .getQueueName ());
@@ -172,25 +185,24 @@ public void testHorizontal() throws Exception {
172
185
}
173
186
});
174
187
}
188
+ assertTrue (latchDone .await (TIMEOUT_MINUTES , TimeUnit .MINUTES ));
175
189
}
176
190
177
- assertTrue (latchDone .await (TIMEOUT_MINUTES , TimeUnit .MINUTES ));
178
-
179
191
killServer (serverProcess , true );
180
-
181
- serverProcess = startServer (SERVER_NAME_0 , 0 , SERVER_START_TIMEOUT );
192
+ serverProcess = startServer (SERVER_NAME_0 , 0 , -1 );
193
+ assertTrue (ServerUtil .waitForServerToStart (0 , SERVER_START_TIMEOUT ));
194
+ assertEquals (0 , errors .get ());
182
195
183
196
AtomicInteger completedFine = new AtomicInteger (0 );
184
197
185
- for ( String protocol : protocolList ) {
186
- String protocolUsed = protocol ;
198
+ {
199
+ CountDownLatch latchDone = new CountDownLatch ( DESTINATIONS ) ;
187
200
188
201
ConnectionFactory factory = CFUtil .createConnectionFactory (protocol , "tcp://localhost:61616" );
189
202
Connection connectionConsumer = factory .createConnection ();
190
203
runAfter (connectionConsumer ::close );
191
204
192
205
for (int i = 0 ; i < DESTINATIONS ; i ++) {
193
- latchDone .countUp ();
194
206
int destination = i ;
195
207
service .execute (() -> {
196
208
try {
@@ -202,10 +214,13 @@ public void testHorizontal() throws Exception {
202
214
sessionConsumer = connectionConsumer .createSession (true , Session .SESSION_TRANSACTED );
203
215
}
204
216
205
- MessageConsumer messageConsumer = sessionConsumer .createConsumer (sessionConsumer .createQueue ("queue_" + destination + protocolUsed ));
217
+ String queueName = "queue_" + destination + "_" + protocol ;
218
+
219
+ MessageConsumer messageConsumer = sessionConsumer .createConsumer (sessionConsumer .createQueue (queueName ));
206
220
for (int m = 0 ; m < MESSAGES ; m ++) {
207
- TextMessage message = (TextMessage ) messageConsumer .receive (50_000 );
221
+ TextMessage message = (TextMessage ) messageConsumer .receive (1_000 );
208
222
if (message == null ) {
223
+ logger .info ("message is null on {}, m={}" , queueName , m );
209
224
m --;
210
225
continue ;
211
226
}
@@ -238,14 +253,18 @@ public void testHorizontal() throws Exception {
238
253
}
239
254
240
255
connectionConsumer .start ();
241
- }
242
256
243
- assertTrue (latchDone .await (TIMEOUT_MINUTES , TimeUnit .MINUTES ));
257
+ assertTrue (latchDone .await (TIMEOUT_MINUTES , TimeUnit .MINUTES ));
258
+ }
244
259
245
260
service .shutdown ();
246
261
assertTrue (service .awaitTermination (TIMEOUT_MINUTES , TimeUnit .MINUTES ), "Test Timed Out" );
247
262
assertEquals (0 , errors .get ());
248
- assertEquals (DESTINATIONS * protocolList .size (), completedFine .get ());
263
+ assertEquals (DESTINATIONS , completedFine .get ());
264
+
265
+ killServer (serverProcess , true );
266
+ serverProcess = startServer (SERVER_NAME_0 , 0 , -1 );
267
+ assertTrue (ServerUtil .waitForServerToStart (0 , SERVER_START_TIMEOUT ));
249
268
}
250
269
251
270
}
0 commit comments