use of org.apache.activemq.artemis.utils.collections.LinkedListIterator in project activemq-artemis by apache.
the class BridgeTest method testWithDuplicates.
@Test
public void testWithDuplicates() throws Exception {
Map<String, Object> server0Params = new HashMap<>();
server0 = createClusteredServerWithParams(isNetty(), 0, true, server0Params);
Map<String, Object> server1Params = new HashMap<>();
addTargetParameters(server1Params);
server1 = createClusteredServerWithParams(isNetty(), 1, true, server1Params);
final String testAddress = "testAddress";
final String queueName0 = "queue0";
final String forwardAddress = "forwardAddress";
final String queueName1 = "forwardQueue";
Map<String, TransportConfiguration> connectors = new HashMap<>();
TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params);
TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params);
connectors.put(server1tc.getName(), server1tc);
server0.getConfiguration().setConnectorConfigurations(connectors);
ArrayList<String> staticConnectors = new ArrayList<>();
staticConnectors.add(server1tc.getName());
BridgeConfiguration bridgeConfiguration = new BridgeConfiguration().setName("bridge1").setQueueName(queueName0).setForwardingAddress(forwardAddress).setRetryInterval(100).setReconnectAttemptsOnSameNode(-1).setConfirmationWindowSize(0).setStaticConnectors(staticConnectors);
List<BridgeConfiguration> bridgeConfigs = new ArrayList<>();
bridgeConfigs.add(bridgeConfiguration);
server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);
CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName0);
List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<>();
queueConfigs0.add(queueConfig0);
server0.getConfiguration().setQueueConfigurations(queueConfigs0);
server0.start();
locator = addServerLocator(ActiveMQClient.createServerLocatorWithoutHA(server0tc, server1tc));
ClientSessionFactory sf0 = locator.createSessionFactory(server0tc);
ClientSession session0 = sf0.createSession(false, true, true);
ClientProducer producer0 = session0.createProducer(new SimpleString(testAddress));
final int numMessages = 1000;
final SimpleString propKey = new SimpleString("testkey");
final SimpleString selectorKey = new SimpleString("animal");
for (int i = 0; i < numMessages; i++) {
ClientMessage message = session0.createMessage(true);
message.getBodyBuffer().writeBytes(new byte[1024]);
message.putIntProperty(propKey, i);
message.putStringProperty(selectorKey, new SimpleString("monkey" + i));
producer0.send(message);
}
server1.start();
// Inserting the duplicateIDs so the bridge will fail in a few
{
long[] ids = new long[100];
Queue queue = server0.locateQueue(new SimpleString(queueName0));
LinkedListIterator<MessageReference> iterator = queue.iterator();
for (int i = 0; i < 100; i++) {
iterator.hasNext();
ids[i] = iterator.next().getMessage().getMessageID();
}
iterator.close();
DuplicateIDCache duplicateTargetCache = server1.getPostOffice().getDuplicateIDCache(PostOfficeImpl.BRIDGE_CACHE_STR.concat(forwardAddress));
TransactionImpl tx = new TransactionImpl(server1.getStorageManager());
for (long id : ids) {
byte[] duplicateArray = BridgeImpl.getDuplicateBytes(server0.getNodeManager().getUUID(), id);
duplicateTargetCache.addToCache(duplicateArray, tx);
}
tx.commit();
}
Thread.sleep(1000);
ClientSessionFactory sf1 = locator.createSessionFactory(server1tc);
ClientSession session1 = sf1.createSession(false, true, true);
try {
session1.createQueue(forwardAddress, RoutingType.ANYCAST, queueName1);
} catch (Throwable ignored) {
ignored.printStackTrace();
}
ClientConsumer consumer1 = session1.createConsumer(queueName1);
session1.start();
for (int i = 100; i < numMessages; i++) {
ClientMessage message = consumer1.receive(5000);
assertNotNull(message);
assertEquals(i, message.getIntProperty(propKey).intValue());
message.acknowledge();
}
session1.commit();
Assert.assertNull(consumer1.receiveImmediate());
consumer1.close();
session1.deleteQueue(queueName1);
session1.close();
sf1.close();
server1.stop();
session0.close();
sf0.close();
closeFields();
assertEquals(0, loadQueues(server0).size());
}
Aggregations