// create a live/backup pair. protected ServerGroup createServerGroup(String name) throws Exception { ServerGroup server = groups.get(name); if (server == null) { server = new ServerGroup(name, groups.size()); server.create(); groups.put(name, server); } return server; }
@Override @Before public void setUp() throws Exception { super.setUp(); sourceServer = createServerGroup("source-server"); targetServer = createServerGroup("target-server"); sourceServer.start(); targetServer.start(); sourceServer.createQueue(sourceQueueName); targetServer.createQueue(targetQueueName); }
/** Builds {@link ServerGroup} instances and populates the map {@link #serverGroups} */ private SortedSet<ServerGroup> deriveGroups(List<HostInfo> hosts) { serverGroups.clear(); for (HostInfo host : hosts) { List<ServerInstance> serverInstances = host.getServerInstances(); for (ServerInstance server : serverInstances) { String group = server.getGroup(); String profile = server.getProfile(); ServerGroup serverGroup = serverGroups.get(group); if (serverGroup == null) { serverGroup = new ServerGroup(group, profile); serverGroup.fill(hosts); serverGroups.put(group, serverGroup); } } } return new TreeSet<ServerGroup>(serverGroups.values()); }
private void receiveMessages(ServerGroup server, String queueName, int num) throws ActiveMQException { try { server.receiveMessages(queueName, num, false); } catch (ActiveMQException e) { e.printStackTrace(); throw e; } }
/* * (non-Javadoc) * * @see * org.owasp.proxy.daemon.TargetedConnectionHandler#handleConnection(java * .net.Socket, java.net.InetSocketAddress) */ public void handleConnection(Socket socket, InetSocketAddress target) throws IOException { if (serverGroup.wouldAccept(target)) throw new IOException("Loop detected! Target " + target + " is handled by a local server"); next.handleConnection(socket, target); }
// test messages are correctly bridged when failover happens during a batch send. // first send some messages, make sure bridge doesn't send it (below batch size) // then crash the live // then send more messages // then receive those messages, no more, no less. // this test are valid for ONCE_AND_ONLY_ONCE and AT_MOST_ONCE. // with DUPS_OK the test failed because some messages are delivered again // after failover, which is fine as in this mode duplication is allowed. public void performSourceAndTargetCrashAndFailoverWithMessages(QualityOfServiceMode mode) throws Exception { JMSBridgeImpl bridge = null; TransactionManager txMgr = null; try { ConnectionFactoryFactory sourceCFF = sourceServer.getConnectionFactoryFactory(); ConnectionFactoryFactory targetCFF = targetServer.getConnectionFactoryFactory(); DestinationFactory sourceQueueFactory = sourceServer.getDestinationFactory(sourceQueueName); DestinationFactory targetQueueFactory = targetServer.getDestinationFactory(targetQueueName); // even number final int batchSize = 4; bridge = new JMSBridgeImpl( "test-bridge", sourceCFF, targetCFF, sourceQueueFactory, targetQueueFactory, null, null, null, null, null, 1000, -1, mode, batchSize, -1, null, null, false); txMgr = newTransactionManager(); bridge.setTransactionManager(txMgr); // start the bridge bridge.start(); System.out.println("started bridge"); final int NUM_MESSAGES = batchSize / 2; // send some messages to source sendMessages(sourceServer, sourceQueueName, NUM_MESSAGES); // receive from target, no message should be received. receiveMessages(targetServer, targetQueueName, 0); // now crash target server targetServer.crashLive(); // send more sendMessages(sourceServer, sourceQueueName, NUM_MESSAGES); receiveMessages(targetServer, targetQueueName, batchSize); // send some again sendMessages(sourceServer, sourceQueueName, NUM_MESSAGES); // check no messages arrived. receiveMessages(targetServer, targetQueueName, 0); // now crash source server sourceServer.crashLive(); // verify bridge still work sendMessages(sourceServer, sourceQueueName, NUM_MESSAGES); receiveMessages(targetServer, targetQueueName, batchSize); } finally { if (bridge != null) { bridge.stop(); } } }
private void sendMessages(ServerGroup server, String queueName, int num) throws ActiveMQException { server.sendMessages(queueName, num); }
/* * Deploy a bridge, source and target queues are in * separate live/backup pairs. Source and Target CF are ha. * Test the bridge work when the live servers crash. */ private void performSourceAndTargetCrashAndFailover(QualityOfServiceMode mode) throws Exception { JMSBridgeImpl bridge = null; TransactionManager txMgr = null; try { ConnectionFactoryFactory sourceCFF = sourceServer.getConnectionFactoryFactory(); ConnectionFactoryFactory targetCFF = targetServer.getConnectionFactoryFactory(); DestinationFactory sourceQueueFactory = sourceServer.getDestinationFactory(sourceQueueName); DestinationFactory targetQueueFactory = targetServer.getDestinationFactory(targetQueueName); bridge = new JMSBridgeImpl( "test-bridge", sourceCFF, targetCFF, sourceQueueFactory, targetQueueFactory, null, null, null, null, null, 1000, -1, mode, 10, 1000, null, null, false); txMgr = newTransactionManager(); bridge.setTransactionManager(txMgr); // start the bridge bridge.start(); final int NUM_MESSAGES = 10; // send some messages to source sendMessages(sourceServer, sourceQueueName, NUM_MESSAGES); // receive from target receiveMessages(targetServer, targetQueueName, NUM_MESSAGES); // now crash target server targetServer.crashLive(); // verify bridge still works sendMessages(sourceServer, sourceQueueName, NUM_MESSAGES); receiveMessages(targetServer, targetQueueName, NUM_MESSAGES); // now crash source server sourceServer.crashLive(); // verify bridge still work sendMessages(sourceServer, sourceQueueName, NUM_MESSAGES); receiveMessages( targetServer, targetQueueName, NUM_MESSAGES, mode == QualityOfServiceMode.ONCE_AND_ONLY_ONCE); } finally { if (bridge != null) { bridge.stop(); } } }