@Test
 public void testMaxSessions() throws Exception {
   HornetQResourceAdapter qResourceAdapter = newResourceAdapter();
   MyBootstrapContext ctx = new MyBootstrapContext();
   qResourceAdapter.start(ctx);
   HornetQActivationSpec spec = new HornetQActivationSpec();
   spec.setMaxSession(1);
   spec.setResourceAdapter(qResourceAdapter);
   spec.setUseJNDI(false);
   spec.setDestinationType("javax.jms.Queue");
   spec.setDestination(MDBQUEUE);
   qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
   CountDownLatch latch = new CountDownLatch(1);
   DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
   DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
   qResourceAdapter.endpointActivation(endpointFactory, spec);
   Binding binding = server.getPostOffice().getBinding(MDBQUEUEPREFIXEDSIMPLE);
   assertEquals(((LocalQueueBinding) binding).getQueue().getConsumerCount(), 1);
   qResourceAdapter.endpointDeactivation(endpointFactory, spec);
   qResourceAdapter.stop();
 }
  @Test
  public void testXARollback() throws Exception {
    setupDLQ(10);
    HornetQResourceAdapter qResourceAdapter = newResourceAdapter();
    qResourceAdapter.setConnectorClassName(UnitTestCase.INVM_CONNECTOR_FACTORY);
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);
    HornetQActivationSpec spec = new HornetQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setMaxSession(1);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Queue");
    spec.setDestination(MDBQUEUE);
    qResourceAdapter.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    CountDownLatch latch = new CountDownLatch(1);
    XADummyEndpoint endpoint = new XADummyEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, true);
    qResourceAdapter.endpointActivation(endpointFactory, spec);
    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer(MDBQUEUEPREFIXED);
    ClientMessage message = session.createMessage(true);
    message.getBodyBuffer().writeString("teststring");
    clientProducer.send(message);
    session.close();
    latch.await(5, TimeUnit.SECONDS);

    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
    latch = new CountDownLatch(1);
    endpoint.reset(latch);
    endpoint.rollback();
    latch.await(5, TimeUnit.SECONDS);

    assertNotNull(endpoint.lastMessage);
    assertEquals(endpoint.lastMessage.getCoreMessage().getBodyBuffer().readString(), "teststring");
    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.stop();
  }
  @Test
  public void testSharedSubscription() throws Exception {
    HornetQResourceAdapter qResourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    qResourceAdapter.start(ctx);

    HornetQActivationSpec spec = new HornetQActivationSpec();
    spec.setResourceAdapter(qResourceAdapter);
    spec.setUseJNDI(false);
    spec.setDestinationType("javax.jms.Topic");
    spec.setDestination("mdbTopic");
    spec.setSubscriptionDurability("Durable");
    spec.setSubscriptionName("durable-mdb");
    spec.setClientID("id-1");
    spec.setSetupAttempts(1);
    spec.setShareSubscriptions(true);
    spec.setMaxSession(1);

    HornetQActivationSpec spec2 = new HornetQActivationSpec();
    spec2.setResourceAdapter(qResourceAdapter);
    spec2.setUseJNDI(false);
    spec2.setDestinationType("javax.jms.Topic");
    spec2.setDestination("mdbTopic");
    spec2.setSubscriptionDurability("Durable");
    spec2.setSubscriptionName("durable-mdb");
    spec2.setClientID("id-1");
    spec2.setSetupAttempts(1);
    spec2.setShareSubscriptions(true);
    spec2.setMaxSession(1);

    CountDownLatch latch = new CountDownLatch(5);
    DummyMessageEndpoint endpoint = new DummyMessageEndpoint(latch);
    DummyMessageEndpointFactory endpointFactory = new DummyMessageEndpointFactory(endpoint, false);
    qResourceAdapter.endpointActivation(endpointFactory, spec);

    CountDownLatch latch2 = new CountDownLatch(5);
    DummyMessageEndpoint endpoint2 = new DummyMessageEndpoint(latch2);
    DummyMessageEndpointFactory endpointFactory2 =
        new DummyMessageEndpointFactory(endpoint2, false);
    qResourceAdapter.endpointActivation(endpointFactory2, spec2);

    ClientSession session = locator.createSessionFactory().createSession();
    ClientProducer clientProducer = session.createProducer("jms.topic.mdbTopic");

    for (int i = 0; i < 10; i++) {
      ClientMessage message = session.createMessage(true);
      message.getBodyBuffer().writeString("" + i);
      clientProducer.send(message);
    }
    session.commit();

    assertTrue(latch.await(5, TimeUnit.SECONDS));
    assertTrue(latch2.await(5, TimeUnit.SECONDS));

    assertNotNull(endpoint.lastMessage);
    assertNotNull(endpoint2.lastMessage);

    qResourceAdapter.endpointDeactivation(endpointFactory, spec);
    qResourceAdapter.endpointDeactivation(endpointFactory2, spec2);
    qResourceAdapter.stop();
  }