Package org.hornetq.tests.integration.management

Source Code of org.hornetq.tests.integration.management.QueueControlUsingCoreTest

/*
* Copyright 2009 Red Hat, Inc.
* Red Hat 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.hornetq.tests.integration.management;

import java.util.HashMap;
import java.util.Map;

import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientSession;
import org.hornetq.api.core.client.ClientSessionFactory;
import org.hornetq.api.core.client.HornetQClient;
import org.hornetq.api.core.client.ServerLocator;
import org.hornetq.api.core.management.QueueControl;
import org.hornetq.api.core.management.ResourceNames;
import org.hornetq.core.logging.Logger;
import org.hornetq.tests.util.UnitTestCase;

/**
* A QueueControlTest
*
* @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a>
*
*/
public class QueueControlUsingCoreTest extends QueueControlTest
{

   // Constants -----------------------------------------------------

   private static final Logger log = Logger.getLogger(QueueControlUsingCoreTest.class);

   // Attributes ----------------------------------------------------

   protected ClientSession session;

   private ServerLocator locator;

   // Static --------------------------------------------------------

   // Constructors --------------------------------------------------

   // Public --------------------------------------------------------

   @Override
   protected QueueControl createManagementControl(final SimpleString address, final SimpleString queue) throws Exception
   {
      return new QueueControl()
      {
         private final CoreMessagingProxy proxy = new CoreMessagingProxy(session, ResourceNames.CORE_QUEUE + queue);

         public boolean changeMessagePriority(final long messageID, final int newPriority) throws Exception
         {
            return (Boolean)proxy.invokeOperation("changeMessagePriority", messageID, newPriority);
         }

         public int changeMessagesPriority(final String filter, final int newPriority) throws Exception
         {
            return (Integer)proxy.invokeOperation("changeMessagesPriority", filter, newPriority);
         }

         public long countMessages(final String filter) throws Exception
         {
            return ((Number)proxy.invokeOperation("countMessages", filter)).longValue();
         }

         public boolean expireMessage(final long messageID) throws Exception
         {
            return (Boolean)proxy.invokeOperation("expireMessage", messageID);
         }

         public int expireMessages(final String filter) throws Exception
         {
            return (Integer)proxy.invokeOperation("expireMessages", filter);
         }

         public String getAddress()
         {
            return (String)proxy.retrieveAttributeValue("address");
         }

         public int getConsumerCount()
         {
            return (Integer)proxy.retrieveAttributeValue("consumerCount");
         }

         public String getDeadLetterAddress()
         {
            return (String)proxy.retrieveAttributeValue("deadLetterAddress");
         }

         public int getDeliveringCount()
         {
            return (Integer)proxy.retrieveAttributeValue("deliveringCount");
         }

         public String getExpiryAddress()
         {
            return (String)proxy.retrieveAttributeValue("expiryAddress");
         }

         public String getFilter()
         {
            return (String)proxy.retrieveAttributeValue("filter");
         }

         public long getMessageCount()
         {
            return ((Number)proxy.retrieveAttributeValue("messageCount")).longValue();
         }

         public long getMessagesAdded()
         {
            return (Integer)proxy.retrieveAttributeValue("messagesAdded");
         }

         public String getName()
         {
            return (String)proxy.retrieveAttributeValue("name");
         }

         public long getID()
         {
            return (Long)proxy.retrieveAttributeValue("ID");
         }

         public long getScheduledCount()
         {
            return (Long)proxy.retrieveAttributeValue("scheduledCount", Long.class);
         }

         public boolean isDurable()
         {
            return (Boolean)proxy.retrieveAttributeValue("durable");
         }

         public boolean isTemporary()
         {
            return (Boolean)proxy.retrieveAttributeValue("temporary");
         }

         public String listMessageCounter() throws Exception
         {
            return (String)proxy.invokeOperation("listMessageCounter");
         }

         public String listMessageCounterAsHTML() throws Exception
         {
            return (String)proxy.invokeOperation("listMessageCounterAsHTML");
         }

         public String listMessageCounterHistory() throws Exception
         {
            return (String)proxy.invokeOperation("listMessageCounterHistory");
         }

         public String listMessageCounterHistoryAsHTML() throws Exception
         {
            return (String)proxy.invokeOperation("listMessageCounterHistoryAsHTML");
         }

         public Map<String, Object>[] listMessages(final String filter) throws Exception
         {
            Object[] res = (Object[])proxy.invokeOperation("listMessages", filter);
            Map<String, Object>[] results = new Map[res.length];
            for (int i = 0; i < res.length; i++)
            {
               results[i] = (Map<String, Object>)res[i];
            }
            return results;
         }

         public String listMessagesAsJSON(final String filter) throws Exception
         {
            return (String)proxy.invokeOperation("listMessagesAsJSON", filter);
         }

         public Map<String, Object>[] listScheduledMessages() throws Exception
         {
            Object[] res = (Object[])proxy.invokeOperation("listScheduledMessages");
            Map<String, Object>[] results = new Map[res.length];
            for (int i = 0; i < res.length; i++)
            {
               results[i] = (Map<String, Object>)res[i];
            }
            return results;
         }

         public String listScheduledMessagesAsJSON() throws Exception
         {
            return (String)proxy.invokeOperation("listScheduledMessagesAsJSON");
         }

         public int moveMessages(final String filter, final String otherQueueName) throws Exception
         {
            return (Integer)proxy.invokeOperation("moveMessages", filter, otherQueueName);
         }

         public int moveMessages(int flushLimit, String filter, String otherQueueName, boolean rejectDuplicates) throws Exception
         {
            return (Integer)proxy.invokeOperation("moveMessages", flushLimit, filter, otherQueueName, rejectDuplicates);
         }

         public int moveMessages(final String filter, final String otherQueueName, final boolean rejectDuplicates) throws Exception
         {
            return (Integer)proxy.invokeOperation("moveMessages", filter, otherQueueName, rejectDuplicates);
         }

         public boolean moveMessage(final long messageID, final String otherQueueName) throws Exception
         {
            return (Boolean)proxy.invokeOperation("moveMessage", messageID, otherQueueName);
         }

         public boolean moveMessage(final long messageID, final String otherQueueName, final boolean rejectDuplicates) throws Exception
         {
            return (Boolean)proxy.invokeOperation("moveMessage", messageID, otherQueueName, rejectDuplicates);
         }

         public int removeMessages(final String filter) throws Exception
         {
            return (Integer)proxy.invokeOperation("removeMessages", filter);
         }

         public int removeMessages(final int limit, final String filter) throws Exception
         {
            return (Integer)proxy.invokeOperation("removeMessages", limit, filter);
         }

         public boolean removeMessage(final long messageID) throws Exception
         {
            return (Boolean)proxy.invokeOperation("removeMessage", messageID);
         }

         public void resetMessageCounter() throws Exception
         {
            proxy.invokeOperation("resetMessageCounter");
         }

         public boolean sendMessageToDeadLetterAddress(final long messageID) throws Exception
         {
            return (Boolean)proxy.invokeOperation("sendMessageToDeadLetterAddress", messageID);
         }

         public int sendMessagesToDeadLetterAddress(final String filterStr) throws Exception
         {
            return (Integer)proxy.invokeOperation("sendMessagesToDeadLetterAddress", filterStr);
         }

         public void setDeadLetterAddress(final String deadLetterAddress) throws Exception
         {
            proxy.invokeOperation("setDeadLetterAddress", deadLetterAddress);
         }

         public void setExpiryAddress(final String expiryAddres) throws Exception
         {
            proxy.invokeOperation("setExpiryAddress", expiryAddres);
         }

         public void pause() throws Exception
         {
            proxy.invokeOperation("pause");
         }

         public void resume() throws Exception
         {
            proxy.invokeOperation("resume");
         }

         public boolean isPaused() throws Exception
         {
            return (Boolean)proxy.invokeOperation("isPaused");
         }

         public String listConsumersAsJSON() throws Exception
         {
            return (String)proxy.invokeOperation("listConsumersAsJSON");
         }

         @Override
         public Map<String, Map<String, Object>[]> listDeliveringMessages() throws Exception
         {
            // This map code could be done better,
            // however that's just to convert stuff for the test class, so I
            // am not going to spend a lot more time on it (Clebert)
            @SuppressWarnings("rawtypes")
            Map res = (Map)proxy.invokeOperation("listDeliveringMessages");

            @SuppressWarnings("rawtypes")
            Map response = new HashMap<String, Map<String, Object>[]>();

            for (Object key: res.keySet())
            {
               Object[] value = (Object[])res.get(key);


               Map<String, Object>[] results = new Map[value.length];
               for (int i = 0; i < value.length; i++)
               {
                  results[i] = (Map<String, Object>)value[i];
               }

               response.put(key, results);
            }

            return response;
         }

         @Override
         public String listDeliveringdMessagesAsJSON() throws Exception
         {
            return (String)proxy.invokeOperation("listDeliveringdMessagesAsJSON");
         }
      };
   }

   // Package protected ---------------------------------------------

   // Protected -----------------------------------------------------

   @Override
   protected void setUp() throws Exception
   {
      super.setUp();

      locator = HornetQClient.createServerLocatorWithoutHA(new TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY));
      ClientSessionFactory sf = locator.createSessionFactory();
      session = sf.createSession(false, true, true);
      session.start();
   }

   @Override
   protected void tearDown() throws Exception
   {
      if (session != null)
      {
         session.close();
      }

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

      session = null;

      super.tearDown();
   }

   // Private -------------------------------------------------------

   // Inner classes -------------------------------------------------

}
TOP

Related Classes of org.hornetq.tests.integration.management.QueueControlUsingCoreTest

TOP
Copyright © 2018 www.massapi.com. 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.