Package org.hornetq.core.server

Examples of org.hornetq.core.server.HornetQServer


      Configuration config = createDefaultConfig();

      config.setJournalSyncNonTransactional(false);

      HornetQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());

      server.start();

      final int messageSize = 1024;

      final int numberOfMessages = 500;

      try
      {
         ServerLocator locator = createInVMNonHALocator();

         locator.setClientFailureCheckPeriod(1000);
         locator.setConnectionTTL(2000);
         locator.setReconnectAttempts(0);

         locator.setBlockOnNonDurableSend(true);
         locator.setBlockOnDurableSend(true);
         locator.setBlockOnAcknowledge(true);
         locator.setConsumerWindowSize(1024 * 1024);

         ClientSessionFactory sf = locator.createSessionFactory();

         ClientSession session = sf.createSession(false, false, false);

         Queue queue = server.createQueue(ADDRESS, ADDRESS, null, true, false);

         ClientProducer producer = session.createProducer(PagingTest.ADDRESS);

         byte[] body = new byte[messageSize];

         ByteBuffer bb = ByteBuffer.wrap(body);

         for (int j = 1; j <= messageSize; j++)
         {
            bb.put(getSamplebyte(j));
         }

         for (int i = 0; i < numberOfMessages; i++)
         {
            ClientMessage message = session.createMessage(persistentMessages);

            HornetQBuffer bodyLocal = message.getBodyBuffer();

            bodyLocal.writeBytes(body);

            message.putIntProperty(new SimpleString("id"), i);

            producer.send(message);
            if (i % 1000 == 0)
            {
               session.commit();
            }
         }

         session.commit();

         session.close();

         session = sf.createSession(true, true, 0);

         session.start();

         ClientConsumer consumer = session.createConsumer(ADDRESS);

         for (int i = 0; i < numberOfMessages / 2; i++)
         {
            ClientMessage message = consumer.receive(5000);
            assertNotNull(message);
            assertEquals(i, message.getIntProperty("id").intValue());

            if (i < 100)
            {
               // Do not consume the last one so we could restart
               message.acknowledge();
            }
         }

         session.close();
        
         session = null;

         sf.close();
         sf = locator.createSessionFactory();

         locator = createInVMNonHALocator();

         session = sf.createSession(true, true, 0);

         session.start();

         consumer = session.createConsumer(ADDRESS);

         for (int i = 100; i < numberOfMessages; i++)
         {
            ClientMessage message = consumer.receive(5000);
            assertNotNull(message);
            assertEquals(i, message.getIntProperty("id").intValue());
            message.acknowledge();
         }
        
         session.close();
        
         sf.close();

      }
      catch (Throwable e)
      {
         e.printStackTrace();
         throw e;
      }
      finally
      {
         try
         {
            server.stop();
         }
         catch (Throwable ignored)
         {
         }
      }
View Full Code Here


      Configuration config = createDefaultConfig();

      config.setJournalSyncNonTransactional(false);

      HornetQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());

      server.start();

      final int messageSize = 1024;

      final int numberOfMessages = 500;

      try
      {
         ServerLocator locator = createInVMNonHALocator();

         locator.setClientFailureCheckPeriod(1000);
         locator.setConnectionTTL(2000);
         locator.setReconnectAttempts(0);

         locator.setBlockOnNonDurableSend(true);
         locator.setBlockOnDurableSend(true);
         locator.setBlockOnAcknowledge(true);
         locator.setConsumerWindowSize(1024 * 1024);

         ClientSessionFactory sf = locator.createSessionFactory();

         ClientSession session = sf.createSession(false, false, false);

         Queue q1 = server.createQueue(ADDRESS, ADDRESS, null, true, false);

         Queue q2 = server.createQueue(ADDRESS, new SimpleString("inactive"), null, true, false);

         ClientProducer producer = session.createProducer(PagingTest.ADDRESS);

         byte[] body = new byte[messageSize];

         ByteBuffer bb = ByteBuffer.wrap(body);

         for (int j = 1; j <= messageSize; j++)
         {
            bb.put(getSamplebyte(j));
         }

         final AtomicInteger errors = new AtomicInteger(0);

         Thread t1 = new Thread()
         {
            public void run()
            {
               try
               {
                  ServerLocator sl = createInVMNonHALocator();
                  ClientSessionFactory sf = sl.createSessionFactory();
                  ClientSession sess = sf.createSession(true, true, 0);
                  sess.start();
                  ClientConsumer cons = sess.createConsumer(ADDRESS);
                  for (int i = 0; i < numberOfMessages; i++)
                  {
                     ClientMessage msg = cons.receive(5000);
                     assertNotNull(msg);
                     assertEquals(i, msg.getIntProperty("id").intValue());
                     msg.acknowledge();
                  }

                  assertNull(cons.receiveImmediate());
                  sess.close();
                  sl.close();
               }
               catch (Throwable e)
               {
                  e.printStackTrace();
                  errors.incrementAndGet();
               }

            }
         };

         t1.start();

         for (int i = 0; i < numberOfMessages; i++)
         {
            ClientMessage message = session.createMessage(persistentMessages);

            HornetQBuffer bodyLocal = message.getBodyBuffer();

            bodyLocal.writeBytes(body);

            message.putIntProperty(new SimpleString("id"), i);

            producer.send(message);
            if (i % 20 == 0)
            {
               session.commit();
            }
         }

         session.commit();

         t1.join();

         assertEquals(0, errors.get());

         assertEquals(numberOfMessages, q2.getMessageCount());
         assertEquals(numberOfMessages, q2.getMessagesAdded());
         assertEquals(0, q1.getMessageCount());
         assertEquals(numberOfMessages, q1.getMessagesAdded());

         session.close();
         sf.close();
         locator.close();

         server.stop();

         server.start();

         Bindings bindings = server.getPostOffice().getBindingsForAddress(ADDRESS);

         q1 = null;
         q2 = null;

         for (Binding bind : bindings.getBindings())
         {
            if (bind instanceof LocalQueueBinding)
            {
               LocalQueueBinding qb = (LocalQueueBinding)bind;
               if (qb.getQueue().getName().equals(ADDRESS))
               {
                  q1 = qb.getQueue();
               }

               if (qb.getQueue().getName().equals(new SimpleString("inactive")))
               {
                  q2 = qb.getQueue();
               }
            }
         }

         assertNotNull(q1);

         assertNotNull(q2);

         assertEquals(numberOfMessages, q2.getMessageCount());
         assertEquals(numberOfMessages, q2.getMessagesAdded());
         assertEquals(0, q1.getMessageCount());
         // 0, since nothing was sent to the queue after the server was restarted
         assertEquals(0, q1.getMessagesAdded());

      }
      catch (Throwable e)
      {
         e.printStackTrace();
         throw e;
      }
      finally
      {
         try
         {
            server.stop();
         }
         catch (Throwable ignored)
         {
         }
      }
View Full Code Here

      Configuration config = createDefaultConfig();

      config.setJournalSyncNonTransactional(false);

      HornetQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());

      server.start();

      final int messageSize = 1024;

      final int numberOfMessages = 500;

      try
      {
         ServerLocator locator = createInVMNonHALocator();

         locator.setClientFailureCheckPeriod(1000);
         locator.setConnectionTTL(2000);
         locator.setReconnectAttempts(0);

         locator.setBlockOnNonDurableSend(true);
         locator.setBlockOnDurableSend(true);
         locator.setBlockOnAcknowledge(true);
         locator.setConsumerWindowSize(1024 * 1024);

         ClientSessionFactory sf = locator.createSessionFactory();

         ClientSession session = sf.createSession(false, false, false);

         Queue q1 = server.createQueue(ADDRESS, ADDRESS, null, true, false);

         Queue q2 = server.createQueue(ADDRESS, new SimpleString("inactive"), null, true, false);

         ClientProducer producer = session.createProducer(PagingTest.ADDRESS);

         byte[] body = new byte[messageSize];

         ByteBuffer bb = ByteBuffer.wrap(body);

         for (int j = 1; j <= messageSize; j++)
         {
            bb.put(getSamplebyte(j));
         }

         final AtomicInteger errors = new AtomicInteger(0);

         Thread t1 = new Thread()
         {
            public void run()
            {
               try
               {
                  ServerLocator sl = createInVMNonHALocator();
                  ClientSessionFactory sf = sl.createSessionFactory();
                  ClientSession sess = sf.createSession(true, true, 0);
                  sess.start();
                  ClientConsumer cons = sess.createConsumer(ADDRESS);
                  for (int i = 0; i < 100; i++)
                  {
                     ClientMessage msg = cons.receive(5000);
                     assertNotNull(msg);
                     assertEquals(i, msg.getIntProperty("id").intValue());
                     msg.acknowledge();
                  }
                  sess.close();
                  sl.close();
               }
               catch (Throwable e)
               {
                  e.printStackTrace();
                  errors.incrementAndGet();
               }

            }
         };

         for (int i = 0; i < numberOfMessages; i++)
         {
            ClientMessage message = session.createMessage(persistentMessages);

            HornetQBuffer bodyLocal = message.getBodyBuffer();

            bodyLocal.writeBytes(body);

            message.putIntProperty(new SimpleString("id"), i);

            producer.send(message);
            if (i % 20 == 0)
            {
               session.commit();
            }
         }

         session.commit();

         t1.start();
         t1.join();

         assertEquals(0, errors.get());
         long timeout = System.currentTimeMillis() + 10000;
         while (numberOfMessages - 100 != q1.getMessageCount() && System.currentTimeMillis() < timeout)
         {
            Thread.sleep(500);

         }

         assertEquals(numberOfMessages, q2.getMessageCount());
         assertEquals(numberOfMessages, q2.getMessagesAdded());
         assertEquals(numberOfMessages - 100, q1.getMessageCount());
         assertEquals(numberOfMessages, q2.getMessagesAdded());

      }
      catch (Throwable e)
      {
         e.printStackTrace();
         throw e;
      }
      finally
      {
         try
         {
            server.stop();
         }
         catch (Throwable ignored)
         {
         }
      }
View Full Code Here

      Configuration config = createDefaultConfig();

      config.setJournalSyncNonTransactional(false);

      HornetQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());

      server.start();

      final int messageSize = 1024;

      final int numberOfMessages = 3000;

      try
      {
         ServerLocator locator = createInVMNonHALocator();

         locator.setClientFailureCheckPeriod(1000);
         locator.setConnectionTTL(2000);
         locator.setReconnectAttempts(0);

         locator.setBlockOnNonDurableSend(true);
         locator.setBlockOnDurableSend(true);
         locator.setBlockOnAcknowledge(true);
         locator.setConsumerWindowSize(1024 * 1024);

         ClientSessionFactory sf = locator.createSessionFactory();

         ClientSession session = sf.createSession(false, false, false);

         QueueImpl queue = (QueueImpl)server.createQueue(ADDRESS, ADDRESS, null, true, false);

         ClientProducer producer = session.createProducer(PagingTest.ADDRESS);

         byte[] body = new byte[messageSize];

         ByteBuffer bb = ByteBuffer.wrap(body);

         for (int j = 1; j <= messageSize; j++)
         {
            bb.put(getSamplebyte(j));
         }

         for (int i = 0; i < numberOfMessages; i++)
         {
            ClientMessage message = session.createMessage(persistentMessages);

            HornetQBuffer bodyLocal = message.getBodyBuffer();

            bodyLocal.writeBytes(body);

            message.putIntProperty(new SimpleString("id"), i);

            producer.send(message);
            if (i % 1000 == 0)
            {
               session.commit();
            }
         }

         session.commit();

         session.close();

         session = sf.createSession(false, false, 0);

         session.start();

         ClientConsumer consumer = session.createConsumer(ADDRESS);

         for (int i = 0; i < numberOfMessages / 2; i++)
         {
            ClientMessage message = consumer.receive(5000);
            assertNotNull(message);
            assertEquals(i, message.getIntProperty("id").intValue());
            message.acknowledge();
         }

         session.rollback();

         session.close();

         session = sf.createSession(false, false, 0);

         session.start();

         consumer = session.createConsumer(ADDRESS);

         for (int i = 0; i < numberOfMessages; i++)
         {
            ClientMessage message = consumer.receive(5000);
            assertNotNull(message);
            assertEquals(i, message.getIntProperty("id").intValue());
            message.acknowledge();
         }

         session.commit();

      }
      catch (Throwable e)
      {
         e.printStackTrace();
         throw e;
      }
      finally
      {
         try
         {
            server.stop();
         }
         catch (Throwable ignored)
         {
         }
      }
View Full Code Here

      Configuration config = createDefaultConfig();

      config.setJournalSyncNonTransactional(false);

      HornetQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());

      server.start();

      final int messageSize = 1024;

      final int numberOfMessages = 200;

      try
      {
         ServerLocator locator = createInVMNonHALocator();

         locator.setClientFailureCheckPeriod(1000);
         locator.setConnectionTTL(2000);
         locator.setReconnectAttempts(0);

         locator.setBlockOnNonDurableSend(true);
         locator.setBlockOnDurableSend(true);
         locator.setBlockOnAcknowledge(true);
         locator.setConsumerWindowSize(0);

         ClientSessionFactory sf = locator.createSessionFactory();

         ClientSession session = sf.createSession(false, false, false);

         QueueImpl queue = (QueueImpl)server.createQueue(ADDRESS, ADDRESS, null, true, false);

         ClientProducer producer = session.createProducer(PagingTest.ADDRESS);

         byte[] body = new byte[messageSize];

         ByteBuffer bb = ByteBuffer.wrap(body);

         for (int j = 1; j <= messageSize; j++)
         {
            bb.put(getSamplebyte(j));
         }

         for (int i = 0; i < numberOfMessages; i++)
         {
            ClientMessage message = session.createMessage(persistentMessages);

            HornetQBuffer bodyLocal = message.getBodyBuffer();

            bodyLocal.writeBytes(body);

            message.putIntProperty(new SimpleString("id"), i);

            producer.send(message);
            if (i % 1000 == 0)
            {
               session.commit();
            }
         }

         session.commit();

         session.close();

         session = sf.createSession(false, false, 0);

         session.start();

         ClientConsumer consumer = session.createConsumer(ADDRESS);

         // number of references without paging
         int numberOfRefs = queue.getNumberOfReferences();

         // consume all non-paged references
         for (int ref = 0; ref < numberOfRefs; ref++)
         {
            ClientMessage msg = consumer.receive(5000);
            assertNotNull(msg);
            msg.acknowledge();
         }

         session.commit();

         session.close();

         session = sf.createSession(false, false, 0);

         session.start();

         consumer = session.createConsumer(ADDRESS);

         ClientMessage msg = consumer.receive(5000);
         assertNotNull(msg);
         int msgIDRolledBack = msg.getIntProperty("id").intValue();
         msg.acknowledge();

         session.rollback();

         msg = consumer.receive(5000);

         assertNotNull(msg);

         assertEquals(msgIDRolledBack, msg.getIntProperty("id").intValue());

         session.rollback();

         session.close();

         sf.close();
         locator.close();

         server.stop();

         server.start();

         locator = createInVMNonHALocator();

         locator.setClientFailureCheckPeriod(1000);
         locator.setConnectionTTL(2000);
         locator.setReconnectAttempts(0);

         locator.setBlockOnNonDurableSend(true);
         locator.setBlockOnDurableSend(true);
         locator.setBlockOnAcknowledge(true);
         locator.setConsumerWindowSize(0);

         sf = locator.createSessionFactory();

         session = sf.createSession(false, false, 0);

         session.start();

         consumer = session.createConsumer(ADDRESS);

         for (int i = msgIDRolledBack; i < numberOfMessages; i++)
         {
            ClientMessage message = consumer.receive(5000);
            assertNotNull(message);
            assertEquals(i, message.getIntProperty("id").intValue());
            message.acknowledge();
         }

         session.commit();

         session.close();

         locator.close();

      }
      catch (Throwable e)
      {
         e.printStackTrace();
         throw e;
      }
      finally
      {
         try
         {
            server.stop();
         }
         catch (Throwable ignored)
         {
         }
      }
View Full Code Here

      Configuration config = createDefaultConfig();

      config.setJournalSyncNonTransactional(false);

      HornetQServer server = createServer(true, config, PAGE_SIZE, -1, new HashMap<String, AddressSettings>());

      JMSServerManagerImpl jmsServer = new JMSServerManagerImpl(server);
      InVMContext context = new InVMContext();
      jmsServer.setContext(context);
      jmsServer.start();

      jmsServer.createTopic(true, "tt", "/topic/TT");

      server.getHornetQServerControl().addAddressSettings("jms.topic.TT",
                                                          "DLQ",
                                                          "DLQ",
                                                          false,
                                                          5,
                                                          1024 * 1024,
                                                          1024 * 10,
                                                          5,
                                                          5,
                                                          0,
                                                          false,
                                                          "PAGE");

      HornetQJMSConnectionFactory cf = (HornetQJMSConnectionFactory)HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF,
                                                                                                                      new TransportConfiguration(INVM_CONNECTOR_FACTORY));

      Connection conn = cf.createConnection();
      conn.setClientID("tst");
      Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Topic topic = (Topic)context.lookup("/topic/TT");
      sess.createDurableSubscriber(topic, "t1");
     
      MessageProducer prod = sess.createProducer(topic);
      prod.setDeliveryMode(DeliveryMode.PERSISTENT);
      TextMessage txt = sess.createTextMessage("TST");
      prod.send(txt);
     
      PagingStore store = server.getPagingManager().getPageStore(new SimpleString("jms.topic.TT"));

      assertEquals(1024 * 1024, store.getMaxSize());
      assertEquals(10 * 1024, store.getPageSizeBytes());

      jmsServer.stop();

      server = createServer(true, config, PAGE_SIZE, -1, new HashMap<String, AddressSettings>());

      jmsServer = new JMSServerManagerImpl(server);
      context = new InVMContext();
      jmsServer.setContext(context);
      jmsServer.start();

      AddressSettings settings = server.getAddressSettingsRepository().getMatch("jms.topic.TT");

      assertEquals(1024 * 1024, settings.getMaxSizeBytes());
      assertEquals(10 * 1024, settings.getPageSizeBytes());
      assertEquals(AddressFullMessagePolicy.PAGE, settings.getAddressFullMessagePolicy());

      store = server.getPagingManager().getPageStore(new SimpleString("TT"));
     
      conn.close();

      server.stop();

   }
View Full Code Here

      Configuration config = createDefaultConfig();

      config.setJournalSyncNonTransactional(false);

      HornetQServer server = createServer(true, config, -1, -1, AddressFullMessagePolicy.BLOCK, new HashMap<String, AddressSettings>());

      JMSServerManagerImpl jmsServer = new JMSServerManagerImpl(server);
      InVMContext context = new InVMContext();
      jmsServer.setContext(context);
      jmsServer.start();

      server.getHornetQServerControl().addAddressSettings("jms.queue.Q1",
                                                          "DLQ",
                                                          "DLQ",
                                                          false,
                                                          5,
                                                          100 * 1024,
                                                          10 * 1024,
                                                          5,
                                                          5,
                                                          0,
                                                          false,
                                                          "PAGE");

      jmsServer.createQueue(true, "Q1", null, true, "/queue/Q1");

      HornetQJMSConnectionFactory cf = (HornetQJMSConnectionFactory)HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF,
                                                                                                                      new TransportConfiguration(INVM_CONNECTOR_FACTORY));

      Connection conn = cf.createConnection();
      conn.setClientID("tst");
      Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      javax.jms.Queue queue = (javax.jms.Queue)context.lookup("/queue/Q1");
     
      MessageProducer prod = sess.createProducer(queue);
      prod.setDeliveryMode(DeliveryMode.PERSISTENT);
      BytesMessage bmt = sess.createBytesMessage();
     
      bmt.writeBytes(new byte[1024]);
     
      for (int i = 0 ; i < 500; i++)
      {
         prod.send(bmt);
      }
     
      PagingStore store = server.getPagingManager().getPageStore(new SimpleString("jms.queue.Q1"));

      assertEquals(100 * 1024, store.getMaxSize());
      assertEquals(10 * 1024, store.getPageSizeBytes());
      assertEquals(AddressFullMessagePolicy.PAGE, store.getAddressFullMessagePolicy());

      jmsServer.stop();

      server = createServer(true, config, -1, -1, AddressFullMessagePolicy.BLOCK, new HashMap<String, AddressSettings>());

      jmsServer = new JMSServerManagerImpl(server);
      context = new InVMContext();
      jmsServer.setContext(context);
      jmsServer.start();

      AddressSettings settings = server.getAddressSettingsRepository().getMatch("jms.queue.Q1");

      assertEquals(100 * 1024, settings.getMaxSizeBytes());
      assertEquals(10 * 1024, settings.getPageSizeBytes());
      assertEquals(AddressFullMessagePolicy.PAGE, settings.getAddressFullMessagePolicy());

      store = server.getPagingManager().getPageStore(new SimpleString("jms.queue.Q1"));
      assertEquals(100 * 1024, store.getMaxSize());
      assertEquals(10 * 1024, store.getPageSizeBytes());
      assertEquals(AddressFullMessagePolicy.PAGE, store.getAddressFullMessagePolicy());


      server.stop();

   }
View Full Code Here

   // Fail bridge and reconnecting immediately
   public void testFailoverAndReconnectImmediately() throws Exception
   {
      NodeManager nodeManager = new InVMNodeManager();
      Map<String, Object> server0Params = new HashMap<String, Object>();
      HornetQServer server0 = createHornetQServer(0, server0Params, isNetty(), nodeManager);

      Map<String, Object> server1Params = new HashMap<String, Object>();
      HornetQServer server1 = createHornetQServer(1, isNetty(), server1Params);

      Map<String, Object> server2Params = new HashMap<String, Object>();
      HornetQServer service2 = createBackupHornetQServer(2, server2Params, isNetty(), 0, nodeManager);

      TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params, "server0tc");

      Map<String, TransportConfiguration> connectors = new HashMap<String, TransportConfiguration>();

      TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params, "server1tc");

      TransportConfiguration server2tc = new TransportConfiguration(getConnector(), server2Params, "server2tc");

      connectors.put(server1tc.getName(), server1tc);

      connectors.put(server2tc.getName(), server2tc);

      server0.getConfiguration().setConnectorConfigurations(connectors);
      server1.getConfiguration().setConnectorConfigurations(connectors);

      final String bridgeName = "bridge1";
      final String testAddress = "testAddress";
      final String queueName0 = "queue0";
      final String forwardAddress = "forwardAddress";

      final long retryInterval = 50;
      final double retryIntervalMultiplier = 1d;
      final int reconnectAttempts = 1;
      final int confirmationWindowSize = 1024;

      ArrayList<String> staticConnectors = new ArrayList<String>();
      staticConnectors.add(server1tc.getName());

      BridgeConfiguration bridgeConfiguration = new BridgeConfiguration(bridgeName,
                                                                        queueName0,
                                                                        forwardAddress,
                                                                        null,
                                                                        null,
                                                                        retryInterval,
                                                                        retryIntervalMultiplier,
                                                                        reconnectAttempts,
                                                                        false,
                                                                        confirmationWindowSize,
                                                                        HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
                                                                        staticConnectors,
                                                                        false,
                                                                        ConfigurationImpl.DEFAULT_CLUSTER_USER,
                                                                        ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);

      List<BridgeConfiguration> bridgeConfigs = new ArrayList<BridgeConfiguration>();
      bridgeConfigs.add(bridgeConfiguration);
      server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);

      CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration(testAddress, queueName0, null, true);
      List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<CoreQueueConfiguration>();
      queueConfigs0.add(queueConfig0);
      server0.getConfiguration().setQueueConfigurations(queueConfigs0);

      CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration(forwardAddress, queueName0, null, true);
      List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<CoreQueueConfiguration>();
      queueConfigs1.add(queueConfig1);
      server1.getConfiguration().setQueueConfigurations(queueConfigs1);
      service2.getConfiguration().setQueueConfigurations(queueConfigs1);

      ServerLocator locator = null;

      try
      {
         service2.start();
         server1.start();
         server0.start();

         BridgeReconnectTest.log.info("** failing connection");
         // Now we will simulate a failure of the bridge connection between server0 and server1
         server0.stop(true);

         waitForServerStart(service2);

         locator = HornetQClient.createServerLocatorWithoutHA(server0tc, server2tc);

         ClientSessionFactory csf0 = locator.createSessionFactory(server2tc);

         ClientSession session0 = csf0.createSession(false, true, true);

         ClientProducer prod0 = session0.createProducer(testAddress);

         ClientSessionFactory csf2 = locator.createSessionFactory(server2tc);

         ClientSession session2 = csf2.createSession(false, true, true);

         ClientConsumer cons2 = session2.createConsumer(queueName0);

         session2.start();

         final int numMessages = 10;

         SimpleString propKey = new SimpleString("propkey");

         for (int i = 0; i < numMessages; i++)
         {
            ClientMessage message = session0.createMessage(true);
            message.putIntProperty(propKey, i);

            prod0.send(message);
         }

         for (int i = 0; i < numMessages; i++)
         {
            ClientMessage r1 = cons2.receive(1500);
            Assert.assertNotNull(r1);
            Assert.assertEquals(i, r1.getObjectProperty(propKey));
         }

         session0.close();
         session2.close();
      }
      finally
      {
         if (locator != null)
         {
            locator.close();
         }

         server0.stop();
         server1.stop();
         service2.stop();
      }

      Assert.assertEquals(0, server0.getRemotingService().getConnections().size());
      Assert.assertEquals(0, server1.getRemotingService().getConnections().size());
      Assert.assertEquals(0, service2.getRemotingService().getConnections().size());
   }
View Full Code Here

   public void testFailoverAndReconnectAfterAFewTries() throws Exception
   {
      NodeManager nodeManager = new InVMNodeManager();

      Map<String, Object> server0Params = new HashMap<String, Object>();
      HornetQServer server0 = createHornetQServer(0, server0Params, isNetty(), nodeManager);

      Map<String, Object> server1Params = new HashMap<String, Object>();
      HornetQServer server1 = createHornetQServer(1, isNetty(), server1Params);

      Map<String, Object> server2Params = new HashMap<String, Object>();
      HornetQServer service2 = createBackupHornetQServer(2, server2Params, isNetty(), 0, nodeManager);

      TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params, "server0tc");

      Map<String, TransportConfiguration> connectors = new HashMap<String, TransportConfiguration>();

      TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params, "server1tc");

      TransportConfiguration server2tc = new TransportConfiguration(getConnector(), server2Params, "server2tc");

      connectors.put(server1tc.getName(), server1tc);

      connectors.put(server2tc.getName(), server2tc);

      server0.getConfiguration().setConnectorConfigurations(connectors);
      server1.getConfiguration().setConnectorConfigurations(connectors);

      final String bridgeName = "bridge1";
      final String testAddress = "testAddress";
      final String queueName0 = "queue0";
      final String forwardAddress = "forwardAddress";

      final long retryInterval = 50;
      final double retryIntervalMultiplier = 1d;
      final int reconnectAttempts = 3;
      final int confirmationWindowSize = 1024;

      ArrayList<String> staticConnectors = new ArrayList<String>();
      staticConnectors.add(server1tc.getName());

      BridgeConfiguration bridgeConfiguration = new BridgeConfiguration(bridgeName,
                                                                        queueName0,
                                                                        forwardAddress,
                                                                        null,
                                                                        null,
                                                                        retryInterval,
                                                                        retryIntervalMultiplier,
                                                                        reconnectAttempts,
                                                                        false,
                                                                        confirmationWindowSize,
                                                                        HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
                                                                        staticConnectors,
                                                                        false,
                                                                        ConfigurationImpl.DEFAULT_CLUSTER_USER,
                                                                        ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);

      List<BridgeConfiguration> bridgeConfigs = new ArrayList<BridgeConfiguration>();
      bridgeConfigs.add(bridgeConfiguration);
      server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);

      CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration(testAddress, queueName0, null, true);
      List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<CoreQueueConfiguration>();
      queueConfigs0.add(queueConfig0);
      server0.getConfiguration().setQueueConfigurations(queueConfigs0);

      CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration(forwardAddress, queueName0, null, true);
      List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<CoreQueueConfiguration>();
      queueConfigs1.add(queueConfig1);
      server1.getConfiguration().setQueueConfigurations(queueConfigs1);
      service2.getConfiguration().setQueueConfigurations(queueConfigs1);

      ServerLocator locator = null;
      try
      {
         service2.start();
         server1.start();
         server0.start();
         // Now we will simulate a failure of the bridge connection between server0 and server1
         server0.stop(true);

         locator = HornetQClient.createServerLocatorWithHA(server2tc);
         locator.setReconnectAttempts(100);
         ClientSessionFactory csf0 = locator.createSessionFactory(server2tc);
         ClientSession session0 = csf0.createSession(false, true, true);

         ClientSessionFactory csf2 = locator.createSessionFactory(server2tc);
         ClientSession session2 = csf2.createSession(false, true, true);

         ClientProducer prod0 = session0.createProducer(testAddress);

         ClientConsumer cons2 = session2.createConsumer(queueName0);

         session2.start();

         final int numMessages = 10;

         SimpleString propKey = new SimpleString("propkey");

         for (int i = 0; i < numMessages; i++)
         {
            ClientMessage message = session0.createMessage(false);
            message.putIntProperty(propKey, i);

            prod0.send(message);
         }

         for (int i = 0; i < numMessages; i++)
         {
            ClientMessage r1 = cons2.receive(1500);
            Assert.assertNotNull(r1);
            Assert.assertEquals(i, r1.getObjectProperty(propKey));
         }

         session0.close();
         session2.close();
      }
      finally
      {
         if (locator != null)
         {
            locator.close();
         }

         server0.stop();
         server1.stop();
         service2.stop();
      }

      Assert.assertEquals(0, server0.getRemotingService().getConnections().size());
      Assert.assertEquals(0, server1.getRemotingService().getConnections().size());
      Assert.assertEquals(0, service2.getRemotingService().getConnections().size());
   }
View Full Code Here

   // Fail bridge and reconnect same node, no backup specified
   public void testReconnectSameNode() throws Exception
   {
      Map<String, Object> server0Params = new HashMap<String, Object>();
      HornetQServer server0 = createHornetQServer(0, isNetty(), server0Params);

      Map<String, Object> server1Params = new HashMap<String, Object>();
      HornetQServer server1 = createHornetQServer(1, isNetty(), server1Params);

      TransportConfiguration server0tc = new TransportConfiguration(getConnector(), server0Params, "server0tc");

      Map<String, TransportConfiguration> connectors = new HashMap<String, TransportConfiguration>();

      TransportConfiguration server1tc = new TransportConfiguration(getConnector(), server1Params, "server1tc");

      connectors.put(server1tc.getName(), server1tc);

      server0.getConfiguration().setConnectorConfigurations(connectors);
      server1.getConfiguration().setConnectorConfigurations(connectors);

      final String bridgeName = "bridge1";
      final String testAddress = "testAddress";
      final String queueName0 = "queue0";
      final String forwardAddress = "forwardAddress";

      final long retryInterval = 50;
      final double retryIntervalMultiplier = 1d;
      final int reconnectAttempts = 3;
      final int confirmationWindowSize = 1024;

      ArrayList<String> staticConnectors = new ArrayList<String>();
      staticConnectors.add(server1tc.getName());

      BridgeConfiguration bridgeConfiguration = new BridgeConfiguration(bridgeName,
                                                                        queueName0,
                                                                        forwardAddress,
                                                                        null,
                                                                        null,
                                                                        retryInterval,
                                                                        retryIntervalMultiplier,
                                                                        reconnectAttempts,
                                                                        false,
                                                                        confirmationWindowSize,
                                                                        HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
                                                                        staticConnectors,
                                                                        false,
                                                                        ConfigurationImpl.DEFAULT_CLUSTER_USER,
                                                                        ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);

      List<BridgeConfiguration> bridgeConfigs = new ArrayList<BridgeConfiguration>();
      bridgeConfigs.add(bridgeConfiguration);
      server0.getConfiguration().setBridgeConfigurations(bridgeConfigs);

      CoreQueueConfiguration queueConfig0 = new CoreQueueConfiguration(testAddress, queueName0, null, true);
      List<CoreQueueConfiguration> queueConfigs0 = new ArrayList<CoreQueueConfiguration>();
      queueConfigs0.add(queueConfig0);
      server0.getConfiguration().setQueueConfigurations(queueConfigs0);

      CoreQueueConfiguration queueConfig1 = new CoreQueueConfiguration(forwardAddress, queueName0, null, true);
      List<CoreQueueConfiguration> queueConfigs1 = new ArrayList<CoreQueueConfiguration>();
      queueConfigs1.add(queueConfig1);
      server1.getConfiguration().setQueueConfigurations(queueConfigs1);

      ServerLocator locator = null;
      try
      {
         server1.start();
         server0.start();

         locator = HornetQClient.createServerLocatorWithHA(server0tc, server1tc);
         ClientSessionFactory csf0 = locator.createSessionFactory(server0tc);
         ClientSession session0 = csf0.createSession(false, true, true);

         ClientSessionFactory csf1 = locator.createSessionFactory(server1tc);
         ClientSession session1 = csf1.createSession(false, true, true);

         ClientProducer prod0 = session0.createProducer(testAddress);

         ClientConsumer cons1 = session1.createConsumer(queueName0);

         session1.start();

         // Now we will simulate a failure of the bridge connection between server0 and server1
         Bridge bridge = server0.getClusterManager().getBridges().get(bridgeName);
         RemotingConnection forwardingConnection = getForwardingConnection(bridge);
         InVMConnector.failOnCreateConnection = true;
         InVMConnector.numberOfFailures = reconnectAttempts - 1;
         forwardingConnection.fail(new HornetQException(HornetQException.NOT_CONNECTED));

         forwardingConnection = getForwardingConnection(bridge);
         forwardingConnection.fail(new HornetQException(HornetQException.NOT_CONNECTED));

         final int numMessages = 10;

         SimpleString propKey = new SimpleString("propkey");

         for (int i = 0; i < numMessages; i++)
         {
            ClientMessage message = session0.createMessage(false);
            message.putIntProperty(propKey, i);

            prod0.send(message);
         }

         for (int i = 0; i < numMessages; i++)
         {
            ClientMessage r1 = cons1.receive(1500);
            Assert.assertNotNull(r1);
            Assert.assertEquals(i, r1.getObjectProperty(propKey));
         }

         session0.close();
         session1.close();
      }
      finally
      {
         if (locator != null)
         {
            locator.close();
         }

         server0.stop();
         server1.stop();
      }

      Assert.assertEquals(0, server0.getRemotingService().getConnections().size());
      Assert.assertEquals(0, server1.getRemotingService().getConnections().size());
   }
View Full Code Here

TOP

Related Classes of org.hornetq.core.server.HornetQServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.