Java Code Examples for org.apache.activemq.artemis.api.core.SimpleString

The following examples show how to use org.apache.activemq.artemis.api.core.SimpleString. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: activemq-artemis   Source File: BridgeControlTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testNotifications() throws Exception {
   SimpleNotificationService.Listener notifListener = new SimpleNotificationService.Listener();
   BridgeControl bridgeControl = createBridgeControl(bridgeConfig.getName(), mbeanServer);

   server_0.getManagementService().addNotificationListener(notifListener);

   Assert.assertEquals(0, notifListener.getNotifications().size());

   bridgeControl.stop();

   Assert.assertEquals(1, notifListener.getNotifications().size());
   Notification notif = notifListener.getNotifications().get(0);
   Assert.assertEquals(CoreNotificationType.BRIDGE_STOPPED, notif.getType());
   Assert.assertEquals(bridgeControl.getName(), notif.getProperties().getSimpleStringProperty(new SimpleString("name")).toString());

   bridgeControl.start();

   Assert.assertEquals(2, notifListener.getNotifications().size());
   notif = notifListener.getNotifications().get(1);
   Assert.assertEquals(CoreNotificationType.BRIDGE_STARTED, notif.getType());
   Assert.assertEquals(bridgeControl.getName(), notif.getProperties().getSimpleStringProperty(new SimpleString("name")).toString());
}
 
Example 2
Source Project: activemq-artemis   Source File: MessageUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static Object getObjectProperty(final Message message, final String name) {
   final Object val;
   if (MessageUtil.JMSXGROUPID.equals(name)) {
      val = message.getGroupID();
   } else if (MessageUtil.JMSXGROUPSEQ.equals(name)) {
      val = message.getGroupSequence();
   } else if (MessageUtil.JMSXUSERID.equals(name)) {
      val = message.getValidatedUserID();
   } else {
      val = message.getObjectProperty(name);
   }
   if (val instanceof SimpleString) {
      return val.toString();
   }
   return val;
}
 
Example 3
Source Project: activemq-artemis   Source File: WildCardRoutingTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWildcardRoutingStarInMiddle() throws Exception {
   SimpleString addressAB = new SimpleString("a.b.c");
   SimpleString addressAC = new SimpleString("a.c");
   SimpleString address = new SimpleString("*.b.*");
   SimpleString queueName1 = new SimpleString("Q1");
   SimpleString queueName2 = new SimpleString("Q2");
   SimpleString queueName = new SimpleString("Q");
   clientSession.createQueue(new QueueConfiguration(queueName1).setAddress(addressAB).setDurable(false));
   clientSession.createQueue(new QueueConfiguration(queueName2).setAddress(addressAC).setDurable(false));
   clientSession.createQueue(new QueueConfiguration(queueName).setAddress(address).setDurable(false));
   ClientProducer producer = clientSession.createProducer(addressAB);
   ClientProducer producer2 = clientSession.createProducer(addressAC);
   ClientConsumer clientConsumer = clientSession.createConsumer(queueName);
   clientSession.start();
   producer.send(createTextMessage(clientSession, "m1"));
   producer2.send(createTextMessage(clientSession, "m2"));
   ClientMessage m = clientConsumer.receive(500);
   Assert.assertNotNull(m);
   Assert.assertEquals("m1", m.getBodyBuffer().readString());
   m.acknowledge();
   m = clientConsumer.receiveImmediate();
   Assert.assertNull(m);
}
 
Example 4
@Test
public void testProducerBlockWontGetTimeout() throws Exception {
   Connection connection = null;
   try {
      connection = factory.createConnection("admin", "password");
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Queue trash = session.createQueue("trash");
      final MessageProducer producer = session.createProducer(trash);
      producer.send(session.createTextMessage("foo"));
      Assert.assertNotNull(server.getPostOffice().getBinding(new SimpleString("trash")));
   } finally {
      if (connection != null) {
         connection.close();
      }
   }
}
 
Example 5
Source Project: activemq-artemis   Source File: MessagePropertyTest.java    License: Apache License 2.0 6 votes vote down vote up
private void receiveMessages() throws Exception {
   ClientSession session = sf.createSession(true, true);
   session.start();
   try (ClientConsumer consumer = session.createConsumer(ADDRESS)) {
      for (int i = 0; i < numMessages; i++) {
         ClientMessage message = consumer.receive(100);
         assertNotNull("Expecting a message " + i, message);
         assertMessageBody(i, message);
         assertEquals(i, message.getIntProperty("int").intValue());
         assertEquals((short) i, message.getShortProperty("short").shortValue());
         assertEquals((byte) i, message.getByteProperty("byte").byteValue());
         assertEquals(floatValue(i), message.getFloatProperty("float").floatValue(), 0.001);
         assertEquals(new SimpleString(Integer.toString(i)), message.getSimpleStringProperty(SIMPLE_STRING_KEY.toString()));
         assertEqualsByteArrays(byteArray(i), message.getBytesProperty("byte[]"));

         assertTrue(message.containsProperty("null-value"));
         assertEquals(message.getObjectProperty("null-value"), null);

         message.acknowledge();
      }
      assertNull("no more messages", consumer.receive(50));
   }
   session.commit();
}
 
Example 6
Source Project: activemq-artemis   Source File: EmbeddedJMSResource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get the Queue corresponding to a JMS Destination.
 * <p>
 * The full name of the JMS destination including the prefix should be provided - i.e. queue://myQueue
 * or topic://myTopic.  If the destination type prefix is not included in the destination name, a prefix
 * of "queue://" is assumed.
 *
 * @param destinationName the full name of the JMS Destination
 * @return the number of messages in the JMS Destination
 */
public Queue getDestinationQueue(String destinationName) {
   Queue queue = null;
   ActiveMQDestination destination = ActiveMQDestination.createDestination(destinationName, ActiveMQDestination.TYPE.QUEUE);
   String address = destination.getAddress();
   String name = destination.getName();
   if (destination.isQueue()) {
      queue = jmsServer.getActiveMQServer().locateQueue(destination.getSimpleAddress());
   } else {
      BindingQueryResult bindingQueryResult = null;
      try {
         bindingQueryResult = jmsServer.getActiveMQServer().bindingQuery(destination.getSimpleAddress());
      } catch (Exception ex) {
         log.error(String.format("getDestinationQueue( %s ) - bindingQuery for %s failed", destinationName, destination.getAddress()), ex);
         return null;
      }
      if (bindingQueryResult.isExists()) {
         List<SimpleString> queueNames = bindingQueryResult.getQueueNames();
         if (queueNames.size() > 0) {
            queue = jmsServer.getActiveMQServer().locateQueue(queueNames.get(0));
         }
      }
   }

   return queue;
}
 
Example 7
Source Project: activemq-artemis   Source File: PostOfficeImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public AddressInfo updateAddressInfo(SimpleString addressName,
                                     EnumSet<RoutingType> routingTypes) throws Exception {
   synchronized (this) {
      if (server.hasBrokerAddressPlugins()) {
         server.callBrokerAddressPlugins(plugin -> plugin.beforeUpdateAddress(addressName, routingTypes));
      }

      final AddressInfo address = addressManager.updateAddressInfo(addressName, routingTypes);
      if (server.hasBrokerAddressPlugins()) {
         server.callBrokerAddressPlugins(plugin -> plugin.afterUpdateAddress(address));
      }

      return address;
   }
}
 
Example 8
Source Project: activemq-artemis   Source File: QueueCommandTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteQueueWithConsumersFailsAndRemoveConsumersTrue() throws Exception {
   SimpleString queueName = new SimpleString("deleteQueue");

   CreateQueue command = new CreateQueue();
   command.setName(queueName.toString());
   command.setFilter("color='green'");
   command.setAutoCreateAddress(true);
   command.setMulticast(true);
   command.setAnycast(false);
   command.execute(new ActionContext());

   server.locateQueue(queueName).addConsumer(new DummyServerConsumer());

   DeleteQueue delete = new DeleteQueue();
   delete.setName(queueName.toString());
   delete.setRemoveConsumers(true);
   delete.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error)));
   checkExecutionPassed(command);
}
 
Example 9
@Test
public void testBooleanProperty() throws Exception {
   Boolean val = RandomUtil.randomBoolean();
   props.putBooleanProperty(key, val);

   Assert.assertEquals(val, props.getBooleanProperty(key));
   Assert.assertEquals(new SimpleString(Boolean.toString(val)), props.getSimpleStringProperty(key));

   props.putSimpleStringProperty(key, new SimpleString(Boolean.toString(val)));
   Assert.assertEquals(val, props.getBooleanProperty(key));

   try {
      props.putByteProperty(key, RandomUtil.randomByte());
      props.getBooleanProperty(key);
      Assert.fail();
   } catch (ActiveMQPropertyConversionException e) {
   }

   Assert.assertFalse(props.getBooleanProperty(unknownKey));
}
 
Example 10
Source Project: activemq-artemis   Source File: QueueControlImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String getUser() {
   if (AuditLogger.isEnabled()) {
      AuditLogger.getUser(queue);
   }
   checkStarted();

   clearIO();
   try {
      SimpleString user = queue.getUser();
      return user == null ? null : user.toString();
   } finally {
      blockOnIO();
   }
}
 
Example 11
Source Project: activemq-artemis   Source File: ExpiryAddressTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicSend() throws Exception {
   SimpleString ea = new SimpleString("EA");
   SimpleString adSend = new SimpleString("a1");
   SimpleString qName = new SimpleString("q1");
   SimpleString eq = new SimpleString("EA1");
   AddressSettings addressSettings = new AddressSettings().setExpiryAddress(ea);
   server.getAddressSettingsRepository().addMatch("#", addressSettings);
   clientSession.createQueue(new QueueConfiguration(eq).setAddress(ea).setDurable(false));
   clientSession.createQueue(new QueueConfiguration(qName).setAddress(adSend).setDurable(false));

   ClientProducer producer = clientSession.createProducer(adSend);
   ClientMessage clientMessage = createTextMessage(clientSession, "heyho!");
   clientMessage.setExpiration(System.currentTimeMillis());
   producer.send(clientMessage);

   clientSession.start();
   ClientConsumer clientConsumer = clientSession.createConsumer(qName);
   ClientMessage m = clientConsumer.receiveImmediate();
   Assert.assertNull(m);
   m = clientConsumer.receiveImmediate();
   Assert.assertNull(m);
   clientConsumer.close();
   clientConsumer = clientSession.createConsumer(eq);
   m = clientConsumer.receive(500);
   Assert.assertNotNull(m);
   Assert.assertEquals(qName.toString(), m.getStringProperty(Message.HDR_ORIGINAL_QUEUE));
   Assert.assertEquals(adSend.toString(), m.getStringProperty(Message.HDR_ORIGINAL_ADDRESS));
   Assert.assertNotNull(m);
   Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
   m.acknowledge();
}
 
Example 12
Source Project: activemq-artemis   Source File: AMQPSessionCallback.java    License: Apache License 2.0 5 votes vote down vote up
public void createSharedDurableQueue(SimpleString address,
                                     RoutingType routingType,
                                     SimpleString queueName,
                                     SimpleString filter) throws Exception {
   try {
      serverSession.createSharedQueue(new QueueConfiguration(queueName).setAddress(address).setRoutingType(routingType).setFilterString(filter));
   } catch (ActiveMQQueueExistsException alreadyExists) {
      // nothing to be done.. just ignore it. if you have many consumers all doing the same another one probably already done it
   } catch (ActiveMQSecurityException se) {
      throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.securityErrorCreatingConsumer(se.getMessage());
   }
}
 
Example 13
Source Project: activemq-artemis   Source File: ActiveMQSession.java    License: Apache License 2.0 5 votes vote down vote up
public void deleteTemporaryTopic(final ActiveMQDestination tempTopic) throws JMSException {
   if (!tempTopic.isTemporary()) {
      throw new InvalidDestinationException("Not a temporary topic " + tempTopic);
   }

   try {
      AddressQuery response = session.addressQuery(tempTopic.getSimpleAddress());

      if (!response.isExists()) {
         throw new InvalidDestinationException("Cannot delete temporary topic " + tempTopic.getName() +
                                                  " does not exist");
      }

      if (response.getQueueNames().size() > 1) {
         throw new IllegalStateException("Cannot delete temporary topic " + tempTopic.getName() +
                                            " since it has subscribers");
      }

      SimpleString address = tempTopic.getSimpleAddress();

      session.deleteQueue(address);

      connection.removeTemporaryQueue(address);
   } catch (ActiveMQException e) {
      throw JMSExceptionHelper.convertFromActiveMQException(e);
   }
}
 
Example 14
Source Project: activemq-artemis   Source File: QueueImpl.java    License: Apache License 2.0 5 votes vote down vote up
private void createExpiryResources() throws Exception {
   AddressSettings addressSettings = server.getAddressSettingsRepository().getMatch(getAddress().toString());
   if (addressSettings.isAutoCreateExpiryResources() && !getAddress().equals(addressSettings.getExpiryAddress())) {
      if (addressSettings.getExpiryAddress() != null && addressSettings.getExpiryAddress().length() != 0) {
         SimpleString expiryQueueName = addressSettings.getExpiryQueuePrefix().concat(getAddress()).concat(addressSettings.getExpiryQueueSuffix());
         SimpleString expiryFilter = new SimpleString(String.format("%s = '%s'", Message.HDR_ORIGINAL_ADDRESS, getAddress()));
         server.createQueue(new QueueConfiguration(expiryQueueName).setAddress(addressSettings.getExpiryAddress()).setFilterString(expiryFilter).setAutoCreated(true).setAutoCreateAddress(true), true);
      }
   }
}
 
Example 15
Source Project: activemq-artemis   Source File: BridgeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testInjectedTransformer() throws Exception {
   final SimpleString ADDRESS = new SimpleString("myAddress");
   final SimpleString QUEUE = new SimpleString("myQueue");
   final String BRIDGE = "myBridge";

   ServiceRegistryImpl serviceRegistry = new ServiceRegistryImpl();
   Transformer transformer = new Transformer() {
      @Override
      public Message transform(Message message) {
         return null;
      }
   };

   serviceRegistry.addBridgeTransformer(BRIDGE, transformer);
   Configuration config = createDefaultInVMConfig().addConnectorConfiguration("in-vm", new TransportConfiguration(INVM_CONNECTOR_FACTORY));
   ActiveMQServer server = addServer(new ActiveMQServerImpl(config, null, null, null, serviceRegistry));
   server.start();
   server.waitForActivation(100, TimeUnit.MILLISECONDS);
   server.createQueue(new QueueConfiguration(QUEUE).setAddress(ADDRESS).setRoutingType(RoutingType.ANYCAST).setDurable(false));
   List<String> connectors = new ArrayList<>();
   connectors.add("in-vm");
   server.deployBridge(new BridgeConfiguration().setName(BRIDGE).setQueueName(QUEUE.toString()).setForwardingAddress(ADDRESS.toString()).setStaticConnectors(connectors));
   Bridge bridge = server.getClusterManager().getBridges().get(BRIDGE);
   assertNotNull(bridge);
   assertEquals(transformer, ((BridgeImpl) bridge).getTransformer());
}
 
Example 16
Source Project: activemq-artemis   Source File: ClientSessionImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a <em>non-temporary</em> queue <em>non-durable</em> queue.
 *
 * @param address      the queue will be bound to this address
 * @param routingType the delivery mode for this queue, MULTICAST or ANYCAST
 * @param queueName    the name of the queue
 * @throws ActiveMQException in an exception occurs while creating the queue
 */
@Deprecated
@Override
public void createQueue(String address, RoutingType routingType, String queueName) throws ActiveMQException {
   internalCreateQueue(SimpleString.toSimpleString(address),
                       SimpleString.toSimpleString(queueName),
                       false,
                       false,
                       new QueueAttributes()
                               .setRoutingType(routingType)
                               .setFilterString(null)
                               .setDurable(false)
                               .setPurgeOnNoConsumers(ActiveMQDefaultConfiguration.getDefaultPurgeOnNoConsumers())
                               .setMaxConsumers(ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers()));
}
 
Example 17
Source Project: activemq-artemis   Source File: AbstractFederationStream.java    License: Apache License 2.0 5 votes vote down vote up
public AbstractFederationStream(final ActiveMQServer server, final Federation federation, final String name, final FederationStreamConfiguration config,
                                final FederationConnection connection) {
   this.server = server;
   this.federation = federation;
   Objects.requireNonNull(config.getName());
   this.name = SimpleString.toSimpleString(config.getName());
   this.config = config;
   this.connection = connection != null ? connection : new FederationConnection(server.getConfiguration(), name, config.getConnectionConfiguration());
}
 
Example 18
Source Project: activemq-artemis   Source File: ActiveMQTextMessage.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setText(final String text) throws JMSException {
   checkWrite();

   if (text != null) {
      this.text = new SimpleString(text);
   } else {
      this.text = null;
   }

   writeBodyText(message.getBodyBuffer(), this.text);
}
 
Example 19
@Override
public int getEncodeSize(Message record) {
   AMQPLargeMessage msgEncode = (AMQPLargeMessage) record;
   ByteBuf buf = msgEncode.getSavedEncodeBuffer();

   try {
      int encodeSize = DataConstants.SIZE_BYTE + DataConstants.SIZE_INT + DataConstants.SIZE_LONG + DataConstants.SIZE_LONG + SimpleString.sizeofNullableString(record.getAddressSimpleString()) + DataConstants.SIZE_BOOLEAN + buf.writerIndex();

      TypedProperties properties = ((AMQPMessage) record).getExtraProperties();

      return encodeSize + (properties != null ? properties.getEncodeSize() : 0);
   } finally {
      msgEncode.releaseEncodedBuffer();
   }
}
 
Example 20
Source Project: activemq-artemis   Source File: ExpireTestOnRestartTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {
   super.setUp();
   server = createServer(true);
   AddressSettings setting = new AddressSettings().setExpiryAddress(SimpleString.toSimpleString("exp")).setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE).setPageSizeBytes(100 * 1024).setMaxSizeBytes(200 * 1024);
   server.getConfiguration().setJournalSyncNonTransactional(false);
   server.getConfiguration().setMessageExpiryScanPeriod(-1);
   server.getConfiguration().setJournalSyncTransactional(false);
   server.getAddressSettingsRepository().addMatch("#", setting);
   server.start();
}
 
Example 21
Source Project: activemq-artemis   Source File: WildCardRoutingTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWildcardRoutingWithHashMultiLengthAddresses() throws Exception {
   SimpleString addressAB = new SimpleString("a.b.c.f");
   SimpleString addressAC = new SimpleString("a.c.f");
   SimpleString address = new SimpleString("a.#.f");
   SimpleString queueName1 = new SimpleString("Q1");
   SimpleString queueName2 = new SimpleString("Q2");
   SimpleString queueName = new SimpleString("Q");
   clientSession.createQueue(new QueueConfiguration(queueName1).setAddress(addressAB).setDurable(false));
   clientSession.createQueue(new QueueConfiguration(queueName2).setAddress(addressAC).setDurable(false));
   clientSession.createQueue(new QueueConfiguration(queueName).setAddress(address).setDurable(false));
   ClientProducer producer = clientSession.createProducer(addressAB);
   ClientProducer producer2 = clientSession.createProducer(addressAC);
   ClientConsumer clientConsumer = clientSession.createConsumer(queueName);
   clientSession.start();
   producer.send(createTextMessage(clientSession, "m1"));
   producer2.send(createTextMessage(clientSession, "m2"));
   ClientMessage m = clientConsumer.receive(500);
   Assert.assertNotNull(m);
   Assert.assertEquals("m1", m.getBodyBuffer().readString());
   m.acknowledge();
   m = clientConsumer.receive(500);
   Assert.assertNotNull(m);
   Assert.assertEquals("m2", m.getBodyBuffer().readString());
   m.acknowledge();
   m = clientConsumer.receiveImmediate();
   Assert.assertNull(m);
}
 
Example 22
Source Project: activemq-artemis   Source File: AMQPSessionCallbackTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test that the AMQPSessionCallback grants no credit when the computation results in negative credit
 */
@Test
public void testOfferProducerWithAddressDoesNotGrantNegativeCredit() throws Exception {
   // Mock returns to get at the runnable that grants credit.
   Mockito.when(manager.getServer()).thenReturn(server);
   Mockito.when(server.getPagingManager()).thenReturn(pagingManager);
   Mockito.when(pagingManager.getPageStore(any(SimpleString.class))).thenReturn(pagingStore);

   // Capture credit runnable and invoke to trigger credit top off
   ArgumentCaptor<Runnable> argument = ArgumentCaptor.forClass(Runnable.class);
   AMQPSessionCallback session = new AMQPSessionCallback(protonSPI, manager, connection, transportConnection, executor, operationContext);

   // Credit is at threshold
   Mockito.when(receiver.getCredit()).thenReturn(AMQP_LOW_CREDITS_DEFAULT);

   session.flow(new SimpleString("test"), ProtonServerReceiverContext.createCreditRunnable(1, AMQP_LOW_CREDITS_DEFAULT, receiver, connection));

   // Run the credit refill code.
   Mockito.verify(pagingStore).checkMemory(argument.capture());
   assertNotNull(argument.getValue());
   argument.getValue().run();

   // Ensure we aren't looking at remote credit as that gives us the wrong view of what credit is at the broker
   Mockito.verify(receiver, never()).getRemoteCredit();

   // Credit runnable should not grant what would be negative credit here
   Mockito.verify(receiver, never()).flow(anyInt());
}
 
Example 23
Source Project: activemq-artemis   Source File: DeadLetterAddressTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicSendToMultipleQueues() throws Exception {
   SimpleString dla = new SimpleString("DLA");
   SimpleString qName = new SimpleString("q1");
   AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1).setDeadLetterAddress(dla);
   server.getAddressSettingsRepository().addMatch(qName.toString(), addressSettings);
   SimpleString dlq = new SimpleString("DLQ1");
   SimpleString dlq2 = new SimpleString("DLQ2");
   clientSession.createQueue(new QueueConfiguration(dlq).setAddress(dla).setDurable(false));
   clientSession.createQueue(new QueueConfiguration(dlq2).setAddress(dla).setDurable(false));
   clientSession.createQueue(new QueueConfiguration(qName).setDurable(false));
   ClientProducer producer = clientSession.createProducer(qName);
   producer.send(createTextMessage(clientSession, "heyho!"));
   clientSession.start();
   ClientConsumer clientConsumer = clientSession.createConsumer(qName);
   ClientMessage m = clientConsumer.receive(500);
   m.acknowledge();
   Assert.assertNotNull(m);
   Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
   // force a cancel
   clientSession.rollback();
   m = clientConsumer.receiveImmediate();
   Assert.assertNull(m);
   clientConsumer.close();
   clientConsumer = clientSession.createConsumer(dlq);
   m = clientConsumer.receive(500);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
   clientConsumer.close();
   clientConsumer = clientSession.createConsumer(dlq2);
   m = clientConsumer.receive(500);
   Assert.assertNotNull(m);
   m.acknowledge();
   Assert.assertEquals(m.getBodyBuffer().readString(), "heyho!");
   clientConsumer.close();
}
 
Example 24
Source Project: activemq-artemis   Source File: BindingsImplTest.java    License: Apache License 2.0 5 votes vote down vote up
private void internalTest(final boolean route) throws Exception {
   final FakeBinding fake = new FakeBinding(new SimpleString("a"));

   final Bindings bind = new BindingsImpl(null, null);
   bind.addBinding(fake);
   bind.addBinding(new FakeBinding(new SimpleString("a")));
   bind.addBinding(new FakeBinding(new SimpleString("a")));

   Thread t = new Thread() {
      @Override
      public void run() {
         try {
            bind.removeBinding(fake);
         } catch (Exception e) {
            e.printStackTrace();
         }
      }
   };

   Queue queue = new FakeQueue(new SimpleString("a"));
   t.start();

   for (int i = 0; i < 100; i++) {
      if (route) {
         bind.route(new CoreMessage(i, 100), new RoutingContextImpl(new FakeTransaction()));
      } else {
         bind.redistribute(new CoreMessage(i, 100), queue, new RoutingContextImpl(new FakeTransaction()));
      }
   }
}
 
Example 25
Source Project: activemq-artemis   Source File: SimpleStringTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testContains() {
   SimpleString simpleString = new SimpleString("abcdefghijklmnopqrst");
   Assert.assertFalse(simpleString.contains('.'));
   Assert.assertFalse(simpleString.contains('%'));
   Assert.assertFalse(simpleString.contains('8'));
   Assert.assertFalse(simpleString.contains('.'));
   Assert.assertTrue(simpleString.contains('a'));
   Assert.assertTrue(simpleString.contains('b'));
   Assert.assertTrue(simpleString.contains('c'));
   Assert.assertTrue(simpleString.contains('d'));
   Assert.assertTrue(simpleString.contains('e'));
   Assert.assertTrue(simpleString.contains('f'));
   Assert.assertTrue(simpleString.contains('g'));
   Assert.assertTrue(simpleString.contains('h'));
   Assert.assertTrue(simpleString.contains('i'));
   Assert.assertTrue(simpleString.contains('j'));
   Assert.assertTrue(simpleString.contains('k'));
   Assert.assertTrue(simpleString.contains('l'));
   Assert.assertTrue(simpleString.contains('m'));
   Assert.assertTrue(simpleString.contains('n'));
   Assert.assertTrue(simpleString.contains('o'));
   Assert.assertTrue(simpleString.contains('p'));
   Assert.assertTrue(simpleString.contains('q'));
   Assert.assertTrue(simpleString.contains('r'));
   Assert.assertTrue(simpleString.contains('s'));
   Assert.assertTrue(simpleString.contains('t'));
}
 
Example 26
Source Project: activemq-artemis   Source File: QueueControlTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testListScheduledMessagesAsJSON() throws Exception {
   long delay = 2000;
   SimpleString address = RandomUtil.randomSimpleString();
   SimpleString queue = RandomUtil.randomSimpleString();
   int intValue = RandomUtil.randomInt();
   session.createQueue(new QueueConfiguration(queue).setAddress(address).setDurable(durable));

   QueueControl queueControl = createManagementControl(address, queue);

   ClientProducer producer = session.createProducer(address);
   ClientMessage message = session.createMessage(false);
   message.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, System.currentTimeMillis() + delay);
   message.putIntProperty(new SimpleString("key"), intValue);
   producer.send(message);
   // unscheduled message
   producer.send(session.createMessage(durable));

   String jsonString = queueControl.listScheduledMessagesAsJSON();
   Assert.assertNotNull(jsonString);
   JsonArray array = JsonUtil.readJsonArray(jsonString);
   Assert.assertEquals(1, array.size());
   int i = Integer.parseInt(array.getJsonObject(0).get("key").toString().replaceAll("\"", ""));
   Assert.assertEquals(intValue, i);

   Thread.sleep(delay + 500);

   jsonString = queueControl.listScheduledMessagesAsJSON();
   Assert.assertNotNull(jsonString);
   array = JsonUtil.readJsonArray(jsonString);
   Assert.assertEquals(0, array.size());

   consumeMessages(2, session, queue);

   session.deleteQueue(queue);
}
 
Example 27
Source Project: activemq-artemis   Source File: SimpleStringTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testEquals() throws Exception {
   Assert.assertFalse(new SimpleString("abcdef").equals(new Object()));

   Assert.assertFalse(new SimpleString("abcef").equals(null));

   Assert.assertEquals(new SimpleString("abcdef"), new SimpleString("abcdef"));

   Assert.assertFalse(new SimpleString("abcdef").equals(new SimpleString("abggcdef")));
   Assert.assertFalse(new SimpleString("abcdef").equals(new SimpleString("ghijkl")));
}
 
Example 28
Source Project: activemq-artemis   Source File: SendAckFailTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void storeDuplicateIDTransactional(long txID,
                                          SimpleString address,
                                          byte[] duplID,
                                          long recordID) throws Exception {
   manager.storeDuplicateIDTransactional(txID, address, duplID, recordID);
}
 
Example 29
Source Project: activemq-artemis   Source File: ActiveMQMapMessage.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public short getShort(final String name) throws JMSException {
   try {
      return map.getShortProperty(new SimpleString(name));
   } catch (ActiveMQPropertyConversionException e) {
      throw new MessageFormatException(e.getMessage());
   }
}
 
Example 30
Source Project: activemq-artemis   Source File: ServerJMSMapMessage.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean getBoolean(final String name) throws JMSException {
   try {
      return map.getBooleanProperty(new SimpleString(name));
   } catch (ActiveMQPropertyConversionException e) {
      throw new MessageFormatException(e.getMessage());
   }
}