@Override
 public void resetCounters() {
   super.resetCounters();
   for (String key : selectorCounts.keySet()) {
     selectorCounts.put(key, new AtomicInteger(0));
   }
 }
Пример #2
0
  @Before
  public void setUp() {
    // Set up connection to the broker
    try {
      Map<String, Object> connectionParams = new HashMap<String, Object>();

      connectionParams.put(
          org.hornetq.integration.transports.netty.TransportConstants.HOST_PROP_NAME, "localhost");
      connectionParams.put(
          org.hornetq.integration.transports.netty.TransportConstants.PORT_PROP_NAME, 5445);

      TransportConfiguration transport =
          new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParams);

      hornetQConnectionFactory = new HornetQConnectionFactory(false, transport);

      connection = hornetQConnectionFactory.createConnection();
      connection.start();

      session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 private MapMessage newMapMessage(Map<String, Object> body) throws JMSException {
   MapMessage message = new MapMessageImpl();
   for (String key : body.keySet()) {
     Object value = body.get(key);
     message.setObject(key, value);
   }
   return message;
 }
    @Override
    protected Message createMessage(int i) throws Exception {
      TextMessage msg = createTextMessage(this.session, "Message-" + i);
      if (selectors.size() > 0) {
        String value = getRandomKey();
        msg.setStringProperty("SYMBOL", value);
        AtomicInteger currentCount = selectorCounts.get(value);
        currentCount.incrementAndGet();
      }

      return msg;
    }
  public static void setAllProperties(Message jmsMessage, Map propertyTable) throws JMSException {

    if (jmsMessage == null || propertyTable == null) {
      return;
    }
    Iterator iter = propertyTable.entrySet().iterator();
    while (iter.hasNext()) {
      Map.Entry entry = (Map.Entry) iter.next();
      Object name = entry.getKey();
      Object value = entry.getValue();
      if (name instanceof String) {
        setProperty((String) name, value, jmsMessage);
      }
    }
  }
  @Test
  public void shouldSetHeaderOnlyMapPropertyAnnotation() throws Exception {
    String xml =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
            + "<testMethodHeaderOnly>\n" //
            + "    <arg0>foo</arg0>\n" //
            + "</testMethodHeaderOnly>\n";
    when(message.getText()).thenReturn(xml);
    when(message.getPropertyNames()).thenReturn(new StringTokenizer("arg1[A] arg1[B] arg1[C]"));
    when(message.getStringProperty("arg1[A]")).thenReturn("one");
    when(message.getStringProperty("arg1[B]")).thenReturn("two");
    when(message.getStringProperty("arg1[C]")).thenReturn("three");

    XmlMessageDecoder<TestInterfaceHeaderOnlyMap> decoder =
        XmlMessageDecoder.of(TestInterfaceHeaderOnlyMap.class, implMap);

    decoder.onMessage(message);

    Map<String, String> map = new HashMap<String, String>();
    map.put("A", "one");
    map.put("B", "two");
    map.put("C", "three");
    verify(implMap).testMethodHeaderOnly("foo", map);
  }
 public int getCountForProperty(String key) {
   return selectorCounts.get(key).get();
 }
 public void addMessageProperty(String value) {
   if (!this.selectors.contains(value)) {
     selectors.add(value);
     selectorCounts.put(value, new AtomicInteger(0));
   }
 }