@Test
  public void testGettersAndSetters() {
    ActiveMQConnectionFactory cf =
        ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, liveTC);

    long clientFailureCheckPeriod = RandomUtil.randomPositiveLong();
    long connectionTTL = RandomUtil.randomPositiveLong();
    long callTimeout = RandomUtil.randomPositiveLong();
    int minLargeMessageSize = RandomUtil.randomPositiveInt();
    int consumerWindowSize = RandomUtil.randomPositiveInt();
    int consumerMaxRate = RandomUtil.randomPositiveInt();
    int confirmationWindowSize = RandomUtil.randomPositiveInt();
    int producerMaxRate = RandomUtil.randomPositiveInt();
    boolean blockOnAcknowledge = RandomUtil.randomBoolean();
    boolean blockOnDurableSend = RandomUtil.randomBoolean();
    boolean blockOnNonDurableSend = RandomUtil.randomBoolean();
    boolean autoGroup = RandomUtil.randomBoolean();
    boolean preAcknowledge = RandomUtil.randomBoolean();
    String loadBalancingPolicyClassName = RandomUtil.randomString();
    boolean useGlobalPools = RandomUtil.randomBoolean();
    int scheduledThreadPoolMaxSize = RandomUtil.randomPositiveInt();
    int threadPoolMaxSize = RandomUtil.randomPositiveInt();
    long retryInterval = RandomUtil.randomPositiveLong();
    double retryIntervalMultiplier = RandomUtil.randomDouble();
    int reconnectAttempts = RandomUtil.randomPositiveInt();
    cf.setClientFailureCheckPeriod(clientFailureCheckPeriod);
    cf.setConnectionTTL(connectionTTL);
    cf.setCallTimeout(callTimeout);
    cf.setMinLargeMessageSize(minLargeMessageSize);
    cf.setConsumerWindowSize(consumerWindowSize);
    cf.setConsumerMaxRate(consumerMaxRate);
    cf.setConfirmationWindowSize(confirmationWindowSize);
    cf.setProducerMaxRate(producerMaxRate);
    cf.setBlockOnAcknowledge(blockOnAcknowledge);
    cf.setBlockOnDurableSend(blockOnDurableSend);
    cf.setBlockOnNonDurableSend(blockOnNonDurableSend);
    cf.setAutoGroup(autoGroup);
    cf.setPreAcknowledge(preAcknowledge);
    cf.setConnectionLoadBalancingPolicyClassName(loadBalancingPolicyClassName);
    cf.setUseGlobalPools(useGlobalPools);
    cf.setScheduledThreadPoolMaxSize(scheduledThreadPoolMaxSize);
    cf.setThreadPoolMaxSize(threadPoolMaxSize);
    cf.setRetryInterval(retryInterval);
    cf.setRetryIntervalMultiplier(retryIntervalMultiplier);
    cf.setReconnectAttempts(reconnectAttempts);
    Assert.assertEquals(clientFailureCheckPeriod, cf.getClientFailureCheckPeriod());
    Assert.assertEquals(connectionTTL, cf.getConnectionTTL());
    Assert.assertEquals(callTimeout, cf.getCallTimeout());
    Assert.assertEquals(minLargeMessageSize, cf.getMinLargeMessageSize());
    Assert.assertEquals(consumerWindowSize, cf.getConsumerWindowSize());
    Assert.assertEquals(consumerMaxRate, cf.getConsumerMaxRate());
    Assert.assertEquals(confirmationWindowSize, cf.getConfirmationWindowSize());
    Assert.assertEquals(producerMaxRate, cf.getProducerMaxRate());
    Assert.assertEquals(blockOnAcknowledge, cf.isBlockOnAcknowledge());
    Assert.assertEquals(blockOnDurableSend, cf.isBlockOnDurableSend());
    Assert.assertEquals(blockOnNonDurableSend, cf.isBlockOnNonDurableSend());
    Assert.assertEquals(autoGroup, cf.isAutoGroup());
    Assert.assertEquals(preAcknowledge, cf.isPreAcknowledge());
    Assert.assertEquals(
        loadBalancingPolicyClassName, cf.getConnectionLoadBalancingPolicyClassName());
    Assert.assertEquals(useGlobalPools, cf.isUseGlobalPools());
    Assert.assertEquals(scheduledThreadPoolMaxSize, cf.getScheduledThreadPoolMaxSize());
    Assert.assertEquals(threadPoolMaxSize, cf.getThreadPoolMaxSize());
    Assert.assertEquals(retryInterval, cf.getRetryInterval());
    Assert.assertEquals(retryIntervalMultiplier, cf.getRetryIntervalMultiplier(), 0.0001);
    Assert.assertEquals(reconnectAttempts, cf.getReconnectAttempts());

    cf.close();
  }
  private void testSettersThrowException(final ActiveMQConnectionFactory cf) {

    String discoveryAddress = RandomUtil.randomString();
    int discoveryPort = RandomUtil.randomPositiveInt();
    long discoveryRefreshTimeout = RandomUtil.randomPositiveLong();
    String clientID = RandomUtil.randomString();
    long clientFailureCheckPeriod = RandomUtil.randomPositiveLong();
    long connectionTTL = RandomUtil.randomPositiveLong();
    long callTimeout = RandomUtil.randomPositiveLong();
    int minLargeMessageSize = RandomUtil.randomPositiveInt();
    int consumerWindowSize = RandomUtil.randomPositiveInt();
    int consumerMaxRate = RandomUtil.randomPositiveInt();
    int confirmationWindowSize = RandomUtil.randomPositiveInt();
    int producerMaxRate = RandomUtil.randomPositiveInt();
    boolean blockOnAcknowledge = RandomUtil.randomBoolean();
    boolean blockOnDurableSend = RandomUtil.randomBoolean();
    boolean blockOnNonDurableSend = RandomUtil.randomBoolean();
    boolean autoGroup = RandomUtil.randomBoolean();
    boolean preAcknowledge = RandomUtil.randomBoolean();
    String loadBalancingPolicyClassName = RandomUtil.randomString();
    int dupsOKBatchSize = RandomUtil.randomPositiveInt();
    int transactionBatchSize = RandomUtil.randomPositiveInt();
    long initialWaitTimeout = RandomUtil.randomPositiveLong();
    boolean useGlobalPools = RandomUtil.randomBoolean();
    int scheduledThreadPoolMaxSize = RandomUtil.randomPositiveInt();
    int threadPoolMaxSize = RandomUtil.randomPositiveInt();
    long retryInterval = RandomUtil.randomPositiveLong();
    double retryIntervalMultiplier = RandomUtil.randomDouble();
    int reconnectAttempts = RandomUtil.randomPositiveInt();
    boolean failoverOnServerShutdown = RandomUtil.randomBoolean();

    try {
      cf.setClientID(clientID);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setClientFailureCheckPeriod(clientFailureCheckPeriod);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setConnectionTTL(connectionTTL);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setCallTimeout(callTimeout);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setMinLargeMessageSize(minLargeMessageSize);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setConsumerWindowSize(consumerWindowSize);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setConsumerMaxRate(consumerMaxRate);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setConfirmationWindowSize(confirmationWindowSize);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setProducerMaxRate(producerMaxRate);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setBlockOnAcknowledge(blockOnAcknowledge);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setBlockOnDurableSend(blockOnDurableSend);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setBlockOnNonDurableSend(blockOnNonDurableSend);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setAutoGroup(autoGroup);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setPreAcknowledge(preAcknowledge);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setConnectionLoadBalancingPolicyClassName(loadBalancingPolicyClassName);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setDupsOKBatchSize(dupsOKBatchSize);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setTransactionBatchSize(transactionBatchSize);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setUseGlobalPools(useGlobalPools);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setScheduledThreadPoolMaxSize(scheduledThreadPoolMaxSize);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setThreadPoolMaxSize(threadPoolMaxSize);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setRetryInterval(retryInterval);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setRetryIntervalMultiplier(retryIntervalMultiplier);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }
    try {
      cf.setReconnectAttempts(reconnectAttempts);
      Assert.fail("Should throw exception");
    } catch (IllegalStateException e) {
      // OK
    }

    cf.getStaticConnectors();
    cf.getClientID();
    cf.getClientFailureCheckPeriod();
    cf.getConnectionTTL();
    cf.getCallTimeout();
    cf.getMinLargeMessageSize();
    cf.getConsumerWindowSize();
    cf.getConsumerMaxRate();
    cf.getConfirmationWindowSize();
    cf.getProducerMaxRate();
    cf.isBlockOnAcknowledge();
    cf.isBlockOnDurableSend();
    cf.isBlockOnNonDurableSend();
    cf.isAutoGroup();
    cf.isPreAcknowledge();
    cf.getConnectionLoadBalancingPolicyClassName();
    cf.getDupsOKBatchSize();
    cf.getTransactionBatchSize();
    cf.isUseGlobalPools();
    cf.getScheduledThreadPoolMaxSize();
    cf.getThreadPoolMaxSize();
    cf.getRetryInterval();
    cf.getRetryIntervalMultiplier();
    cf.getReconnectAttempts();

    cf.close();
  }
  /**
   * @param sf
   * @param NMSGS
   * @throws ActiveMQException
   * @throws InterruptedException
   * @throws Throwable
   */
  private void produceMessages(final ClientSessionFactory sf, final int NMSGS) throws Throwable {

    final int TIMEOUT = 5000;

    System.out.println("sending " + NMSGS + " messages");

    final ClientSession sessionSend = sf.createSession(true, true);

    ClientProducer prod2 = sessionSend.createProducer("slow-queue");

    try {
      sessionSend.createQueue("Queue", "Queue", true);
    } catch (Exception ignored) {
    }

    final ClientSession sessionReceive = sf.createSession(true, true);
    sessionReceive.start();

    final ArrayList<Throwable> errors = new ArrayList<>();

    Thread tReceive =
        new Thread() {
          @Override
          public void run() {
            try {
              ClientConsumer consumer = sessionReceive.createConsumer("Queue");

              for (int i = 0; i < NMSGS; i++) {
                if (i % 500 == 0) {
                  double percent = (double) i / (double) NMSGS;
                  System.out.println(
                      "msgs " + i + " of " + NMSGS + ", " + (int) (percent * 100) + "%");
                  Thread.sleep(100);
                }

                ClientMessage msg = consumer.receive(TIMEOUT);
                if (msg == null) {
                  errors.add(new Exception("Didn't receive msgs"));
                  break;
                }
                msg.acknowledge();
              }
            } catch (Exception e) {
              errors.add(e);
            }
          }
        };

    tReceive.start();

    ClientProducer prod = sessionSend.createProducer("Queue");

    Random random = new Random();

    for (int i = 0; i < NMSGS; i++) {
      ClientMessage msg = sessionSend.createMessage(true);

      int size = RandomUtil.randomPositiveInt() % 10024;

      if (size == 0) {
        size = 10 * 1024;
      }

      byte[] buffer = new byte[size];

      random.nextBytes(buffer);

      msg.getBodyBuffer().writeBytes(buffer);

      prod.send(msg);

      if (i % 5000 == 0) {
        prod2.send(msg);
        System.out.println("Sending slow message");
      }
    }

    tReceive.join();

    sessionReceive.close();
    sessionSend.close();
    sf.close();

    for (Throwable e : errors) {
      throw e;
    }
  }