@Test
  public void testSessionClosedOnRemotingConnectionFailure() throws Exception {
    ClientSession session = addClientSession(sf.createSession());

    session.createQueue("fooaddress", "fooqueue");

    ClientProducer prod = session.createProducer("fooaddress");

    ClientConsumer cons = session.createConsumer("fooqueue");

    session.start();

    prod.send(session.createMessage(false));

    Assert.assertNotNull(cons.receive());

    // Now fail the underlying connection

    RemotingConnection connection = ((ClientSessionInternal) session).getConnection();

    connection.fail(new HornetQNotConnectedException());

    Assert.assertTrue(session.isClosed());

    Assert.assertTrue(prod.isClosed());

    Assert.assertTrue(cons.isClosed());

    // Now try and use the producer

    try {
      prod.send(session.createMessage(false));

      Assert.fail("Should throw exception");
    } catch (HornetQObjectClosedException oce) {
      // ok
    } catch (HornetQException e) {
      fail("Invalid Exception type:" + e.getType());
    }

    try {
      cons.receive();

      Assert.fail("Should throw exception");
    } catch (HornetQObjectClosedException oce) {
      // ok
    } catch (HornetQException e) {
      fail("Invalid Exception type:" + e.getType());
    }

    session.close();
  }
Exemplo n.º 2
0
    @Override
    public void run() {
      while (!closed) {
        try {
          long now = System.currentTimeMillis();

          Set<Object> idsToRemove = new HashSet<Object>();

          for (ConnectionEntry entry : connections.values()) {
            RemotingConnection conn = entry.connection;

            boolean flush = true;

            if (entry.ttl != -1) {
              if (!conn.checkDataReceived()) {
                if (now >= entry.lastCheck + entry.ttl) {
                  idsToRemove.add(conn.getID());

                  flush = false;
                }
              } else {
                entry.lastCheck = now;
              }
            }

            if (flush) {
              conn.flush();
            }
          }

          for (Object id : idsToRemove) {
            RemotingConnection conn = removeConnection(id);
            if (conn != null) {
              conn.fail(HornetQMessageBundle.BUNDLE.clientExited(conn.getRemoteAddress()));
            }
          }

          if (latch.await(pauseInterval, TimeUnit.MILLISECONDS)) return;
        } catch (Throwable e) {
          HornetQServerLogger.LOGGER.errorOnFailureCheck(e);
        }
      }
    }
Exemplo n.º 3
0
  // https://jira.jboss.org/jira/browse/JBMESSAGING-1703
  // Make sure that failing a connection removes it from the connection manager and can't be
  // returned in a subsequent
  // call
  public void testUsingDeadConnection() throws Exception {
    for (int i = 0; i < 100; i++) {
      final Connection conn1 = cf1.createConnection();

      Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
      RemotingConnection rc1 =
          ((ClientSessionInternal) ((HornetQSession) sess1).getCoreSession()).getConnection();

      rc1.fail(new HornetQException(HornetQException.NOT_CONNECTED, "blah"));

      try {
        conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        fail("should throw exception");
      } catch (JMSException e) {
        // pass
      }

      conn1.close();
    }
  }
Exemplo n.º 4
0
 @Override
 public void run() {
   conn.fail(new HornetQException(HornetQException.NOT_CONNECTED, "blah"));
 }