/**
 * 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.transport.discovery;

import javax.jms.Connection;
import javax.jms.JMSException;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.CombinationTestSupport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class DiscoveryTransportNoBrokerTest extends CombinationTestSupport {

    private static final Log LOG = LogFactory.getLog(DiscoveryTransportNoBrokerTest.class);
    
    public void testMaxReconnectAttempts() throws JMSException {
        try {
            ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("discovery:(multicast://doesNOTexist)");
            LOG.info("Connecting.");
            Connection connection = factory.createConnection();
            connection.setClientID("test");
            fail("Did not fail to connect as expected.");
        } catch ( JMSException expected ) { 
            assertTrue("reason is java.io.IOException, was: " + expected.getCause(), expected.getCause() instanceof java.io.IOException);
        }
    }
}

@@ -1684,16 +1684,24 @@
        %7D
+%0A       
  catch (
@@ -1882,10 +1882,1349 @@
 %7D%0A    %7D%0A
+    %0A    public void testInitialConnectDelayWithNoBroker() throws Exception %7B%0A        // the initialReconnectDelay only kicks in once a set of connect URL have%0A        // been returned from the discovery agent.%0A        // Up to that point the reconnectDelay is used which has a default value of 10%0A        //%0A        long initialReconnectDelay = 4000;%0A        long startT = System.currentTimeMillis();%0A        String groupId = %22WillNotMatch%22 + startT;%0A        try %7B%0A            String urlStr = %22discovery:(multicast://default?group=%22 + groupId + %0A                %22)?useExponentialBackOff=false&maxReconnectAttempts=2&reconnectDelay=%22 + initialReconnectDelay;          %0A            ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(urlStr);%0A            LOG.info(%22Connecting.%22);%0A            Connection connection = factory.createConnection();%0A            connection.setClientID(%22test%22);%0A            fail(%22Did not fail to connect as expected.%22);%0A        %7D catch ( JMSException expected ) %7B %0A            assertTrue(%22reason is java.io.IOException, was: %22 + expected.getCause(), expected.getCause() instanceof java.io.IOException);%0A            long duration = System.currentTimeMillis() - startT;%0A            assertTrue(%22took at least initialReconnectDelay time: %22 + duration, duration %3E= initialReconnectDelay);%0A        %7D%0A    %7D%0A
 %7D%0A

test for https://issues.apache.org/activemq/browse/AMQ-2080 that shows use of reconnectDelay