-
Notifications
You must be signed in to change notification settings - Fork 912
/
BridgeTransferingTest.java
190 lines (165 loc) · 7.25 KB
/
BridgeTransferingTest.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.artemis.tests.smoke.bridgeTransfer;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import java.util.Arrays;
import java.util.Collection;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.tests.smoke.common.SmokeTestBase;
import org.apache.activemq.artemis.utils.Wait;
import org.apache.qpid.jms.JmsConnectionFactory;
import org.jboss.logging.Logger;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class BridgeTransferingTest extends SmokeTestBase {
public static final String SERVER_NAME_0 = "bridgeTransfer/serverA";
public static final String SERVER_NAME_1 = "bridgeTransfer/serverB";
private static final Logger logger = Logger.getLogger(BridgeTransferingTest.class);
private static final String JMX_SERVER_HOSTNAME = "localhost";
private static final int JMX_SERVER_PORT = 11099;
final String theprotocol;
// As the produces sends messages, a client will be killed every X messages. This is it!
final int killServerInterval;
final int numberOfMessages;
final int commitInterval;
final int messageSize;
final boolean killBothServers;
final int minlargeMessageSize;
Process serverProcess;
Process serverProcess2;
public BridgeTransferingTest(String protocol, int commitInterval, int killServerInterval, int numberOfMessages, int messageSize, int minlargeMessageSize, boolean killBothServers) {
this.theprotocol = protocol;
this.killServerInterval = killServerInterval;
this.messageSize = messageSize;
this.commitInterval = commitInterval;
this.numberOfMessages = numberOfMessages;
this.killBothServers = killBothServers;
this.minlargeMessageSize = minlargeMessageSize;
}
@Parameterized.Parameters(name = "protocol={0}, commitInterval={1}, killInterval={2}, numberOfMessages={3}, messageSize={4}, minLargeMessageSize={5}, KillBothServers={6}")
public static Collection<Object[]> parameters() {
return Arrays.asList(new Object[][]{{"CORE", 200, 1000, 10000, 15_000, 5000, true}, {"CORE", 200, 1000, 10000, 15_000, 5000, false}});
}
public static ConnectionFactory createConnectionFactory(String protocol, String uri) {
if (protocol.toUpperCase().equals("OPENWIRE")) {
return new org.apache.activemq.ActiveMQConnectionFactory(uri);
} else if (protocol.toUpperCase().equals("AMQP")) {
if (uri.startsWith("tcp://")) {
// replacing tcp:// by amqp://
uri = "amqp" + uri.substring(3);
}
return new JmsConnectionFactory(uri);
} else if (protocol.toUpperCase().equals("CORE") || protocol.toUpperCase().equals("ARTEMIS")) {
return new org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory(uri);
} else {
throw new IllegalStateException("Unknown:" + protocol);
}
}
@Before
public void before() throws Exception {
cleanupData(SERVER_NAME_0);
cleanupData(SERVER_NAME_1);
disableCheckThread();
serverProcess = startServer(SERVER_NAME_0, 0, 30000);
serverProcess2 = startServer(SERVER_NAME_1, 1, 30000);
}
@After
public void stopServers() throws Exception {
serverProcess2.destroyForcibly();
serverProcess.destroyForcibly();
}
@Test
public void testTransfer() throws Exception {
ConnectionFactory cf = createConnectionFactory(theprotocol, "tcp://localhost:61616");
((ActiveMQConnectionFactory) cf).setMinLargeMessageSize(minlargeMessageSize);
String body;
{
StringBuffer buffer = new StringBuffer();
while (buffer.length() < messageSize) {
buffer.append(" ");
}
body = buffer.toString();
}
{
Connection connection = cf.createConnection();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
Queue queue = session.createQueue("bridgeQueue");
MessageProducer producer = session.createProducer(queue);
int txElement = 0;
int killElement = 0;
for (int i = 0; i < numberOfMessages; i++) {
producer.send(session.createTextMessage(body + " " + i));
if (++txElement == commitInterval) {
logger.debug("Sent " + (i + 1) + " messages");
txElement = 0;
session.commit();
}
if (++killElement == killServerInterval) {
logger.debug("Killing server at " + (i + 1));
killElement = 0;
if (killBothServers) {
serverProcess.destroyForcibly();
Wait.assertFalse(serverProcess::isAlive);
}
serverProcess2.destroyForcibly();
Wait.assertFalse(serverProcess2::isAlive);
serverProcess2 = startServer(SERVER_NAME_1, 1, 30000);
if (killBothServers) {
serverProcess = startServer(SERVER_NAME_0, 0, 30000);
}
if (killBothServers) {
connection.close();
connection = cf.createConnection();
session = connection.createSession(true, Session.SESSION_TRANSACTED);
queue = session.createQueue("bridgeQueue");
producer = session.createProducer(queue);
}
}
}
if (txElement > 0) {
session.commit();
}
}
ConnectionFactory cf2 = createConnectionFactory(theprotocol, "tcp://localhost:61617");
try (Connection connection = cf2.createConnection()) {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("bridgeQueue");
MessageConsumer consumer = session.createConsumer(queue);
connection.start();
for (int i = 0; i < numberOfMessages; i++) {
if (i % 100 == 0) {
logger.debug("consuming " + i);
}
TextMessage message = (TextMessage) consumer.receive(5000);
Assert.assertNotNull(message);
Assert.assertEquals(body + " " + i, message.getText());
}
Assert.assertNull(consumer.receiveNoWait());
}
}
}