Exemplo n.º 1
0
    private void route(String consumerSource, String producerTarget, String routingKey, boolean succeed) throws Exception {
        AMQPContext ctx = new AMQPContext(AMQPContext.CLIENT);
        Connection conn = new Connection(ctx, host, port, false);
        conn.connect();
        Session s = conn.createSession(INBOUND_WINDOW, OUTBOUND_WINDOW);

        Consumer c = s.createConsumer(consumerSource, CONSUMER_LINK_CREDIT, QoS.AT_LEAST_ONCE, false, null);
        Producer p = s.createProducer(producerTarget, QoS.AT_LEAST_ONCE);
        AMQPMessage msg = msg();
        AmqpValue sentinel = new AmqpValue(new AMQPDouble(Math.random()));
        msg.setAmqpValue(sentinel);
        Properties props = new Properties();
        props.setSubject(new AMQPString(routingKey));
        msg.setProperties(props);
        p.send(msg);

        if (succeed) {
            AMQPMessage m = c.receive();
            assertNotNull(m);
            assertEquals(sentinel.getValue().getValueString(), m.getAmqpValue().getValue().getValueString());
            m.accept();
        } else {
            assertNull(get(c));
        }
        c.close();
        p.close();
        conn.close();
    }
Exemplo n.º 2
0
    public void testRedelivery() throws Exception {
        AMQPContext ctx = new AMQPContext(AMQPContext.CLIENT);
        Connection conn = new Connection(ctx, host, port, false);
        conn.connect();

        Session s = conn.createSession(INBOUND_WINDOW, OUTBOUND_WINDOW);
        Producer p = s.createProducer(QUEUE, QoS.AT_MOST_ONCE);
        p.send(msg());
        p.close();

        Consumer c = s.createConsumer(QUEUE, CONSUMER_LINK_CREDIT, QoS.AT_LEAST_ONCE, false, null);
        AMQPMessage m1 = c.receive();
        assertTrue(m1.getHeader().getFirstAcquirer().getValue());
        assertFalse(m1.isSettled());

        s.close();
        s = conn.createSession(INBOUND_WINDOW, OUTBOUND_WINDOW);
        c = s.createConsumer(QUEUE, CONSUMER_LINK_CREDIT, QoS.AT_LEAST_ONCE, false, null);
        AMQPMessage m2 = c.receive();
        m2.accept();

        assertTrue(compareMessageData(m1, m2));
        assertFalse(m2.getHeader().getFirstAcquirer().getValue());
        assertNull(get(c));
        conn.close();
    }
Exemplo n.º 3
0
 private void emptyQueue(String q) throws Exception {
     AMQPContext ctx = new AMQPContext(AMQPContext.CLIENT);
     Connection conn = new Connection(ctx, host, port, false);
     conn.connect();
     Session s = conn.createSession(INBOUND_WINDOW, OUTBOUND_WINDOW);
     Consumer c = s.createConsumer(q, CONSUMER_LINK_CREDIT, QoS.AT_MOST_ONCE, false, null);
     AMQPMessage m;
     while ((m = get(c)) != null);
     conn.close();
 }
Exemplo n.º 4
0
    public void testRoundTrip() throws Exception {
        AMQPContext ctx = new AMQPContext(AMQPContext.CLIENT);
        Connection conn = new Connection(ctx, host, port, false);
        conn.connect();

        Session s = conn.createSession(INBOUND_WINDOW, OUTBOUND_WINDOW);
        Producer p = s.createProducer(QUEUE, QoS.AT_LEAST_ONCE);
        p.send(msg());
        p.close(); // Settlement happens here
        Consumer c = s.createConsumer(QUEUE, CONSUMER_LINK_CREDIT, QoS.AT_LEAST_ONCE, false, null);
        AMQPMessage m = c.receive();
        m.accept();
        assertEquals(1, m.getData().size());
        assertEquals(data(), m.getData().get(0));
        conn.close();
    }
Exemplo n.º 5
0
    public void testReject() throws Exception {
        AMQPContext ctx = new AMQPContext(AMQPContext.CLIENT);
        Connection conn = new Connection(ctx, host, port, false);
        conn.connect();

        Session s = conn.createSession(INBOUND_WINDOW, OUTBOUND_WINDOW);
        Producer p = s.createProducer(QUEUE, QoS.AT_LEAST_ONCE);
        p.send(msg());
        p.close();

        Consumer c = s.createConsumer(QUEUE, CONSUMER_LINK_CREDIT, QoS.AT_LEAST_ONCE, false, null);
        AMQPMessage m = c.receive();
        m.reject();
        assertNull(get(c));
        conn.close();
    }
Exemplo n.º 6
0
 private void routeInvalidTarget(String producerTarget) throws Exception {
     AMQPContext ctx = new AMQPContext(AMQPContext.CLIENT);
     Connection conn = new Connection(ctx, host, port, false);
     conn.connect();
     Session s = conn.createSession(INBOUND_WINDOW, OUTBOUND_WINDOW);
     try {
         Producer p = s.createProducer(producerTarget, QoS.AT_LEAST_ONCE);
         p.close();
         fail("Target '" + producerTarget + "' should fail");
     }
     catch (Exception e) {
         // no-op
     }
     finally {
         conn.close();
     }
 }
Exemplo n.º 7
0
 private void routeInvalidSource(String consumerSource) throws Exception {
     AMQPContext ctx = new AMQPContext(AMQPContext.CLIENT);
     Connection conn = new Connection(ctx, host, port, false);
     conn.connect();
     Session s = conn.createSession(INBOUND_WINDOW, OUTBOUND_WINDOW);
     try {
         Consumer c = s.createConsumer(consumerSource, CONSUMER_LINK_CREDIT, QoS.AT_LEAST_ONCE, false, null);
         c.close();
         fail("Source '" + consumerSource + "' should fail");
     }
     catch (Exception e) {
         // no-op
     }
     finally {
         conn.close();
     }
 }
Exemplo n.º 8
0
    private void decorationTest(DecorationProtocol d, Map<AMQPString, AMQPType> map) throws Exception {
        AMQPContext ctx = new AMQPContext(AMQPContext.CLIENT);
        Connection conn = new Connection(ctx, host, port, false);
        conn.connect();
        Session s = conn.createSession(INBOUND_WINDOW, OUTBOUND_WINDOW);
        Producer p = s.createProducer(QUEUE, QoS.AT_LEAST_ONCE);
        AMQPMessage msg = msg();

        d.decorateMessage(msg, map);
        p.send(msg);
        p.close();
        Consumer c = s.createConsumer(QUEUE, CONSUMER_LINK_CREDIT, QoS.AT_LEAST_ONCE, false, null);
        AMQPMessage recvMsg = c.receive();
        recvMsg.accept();

        compareMaps(map, d.getDecoration(recvMsg));
        conn.close();
    }
Exemplo n.º 9
0
    public void fragmentation(long FrameSize, int PayloadSize)
            throws UnsupportedProtocolVersionException, AMQPException, AuthenticationException, IOException {
        AMQPContext ctx = new AMQPContext(AMQPContext.CLIENT);
        Connection conn = new Connection(ctx, host, port, false);
        conn.setMaxFrameSize(FrameSize);
        conn.connect();
        Session s = conn.createSession(INBOUND_WINDOW, OUTBOUND_WINDOW);

        Producer p = s.createProducer(QUEUE, QoS.AT_LEAST_ONCE);
        AMQPMessage msg = new AMQPMessage();
        msg.addData(new Data(new byte [PayloadSize]));
        p.send(msg);
        p.close();

        Consumer c = s.createConsumer(QUEUE, CONSUMER_LINK_CREDIT, QoS.AT_LEAST_ONCE, false, null);
        AMQPMessage m = c.receive();
        m.accept();
        c.close();
        assertEquals(PayloadSize, m.getData().get(0).getValue().length);
        conn.close();
    }
Exemplo n.º 10
0
    public void testDataTypes() throws Exception {
        AMQPContext ctx = new AMQPContext(AMQPContext.CLIENT);
        Connection conn = new Connection(ctx, host, port, false);
        conn.connect();

        Session s = conn.createSession(INBOUND_WINDOW, OUTBOUND_WINDOW);
        Producer p = s.createProducer(QUEUE, QoS.AT_LEAST_ONCE);
        AMQPMessage msg = new AMQPMessage();

        List<AMQPType> al = new ArrayList<AMQPType>();
        al.add(new AMQPBoolean(true));
        al.add(new AMQPByte(Byte.MAX_VALUE));
        al.add(new AMQPChar(Character.CURRENCY_SYMBOL));
        al.add(new AMQPDecimal64(BigDecimal.TEN));
        al.add(new AMQPDouble(Double.NaN));
        al.add(new AMQPInt(Integer.MIN_VALUE));
        al.add(new AMQPNull());
        al.add(new AMQPString("\uFFF9"));
        al.add(new AMQPSymbol(new String(new char[256])));
        al.add(new AMQPTimestamp(Long.MAX_VALUE));
        al.add(new AMQPUuid(System.currentTimeMillis(), Long.MIN_VALUE));
        al.add(new AMQPUnsignedShort(0));
        al.add(new AMQPArray(AMQPBoolean.FALSE.getCode(), new AMQPBoolean[]{}));
        al.add(new AmqpSequence(new ArrayList<AMQPType>()));
        AmqpSequence seq = new AmqpSequence(al);
        AmqpValue val = new AmqpValue(seq);
        msg.setAmqpValue(val);

        p.send(msg);
        p.close();
        Consumer c = s.createConsumer(QUEUE, CONSUMER_LINK_CREDIT, QoS.AT_LEAST_ONCE, false, null);
        AMQPMessage recvMsg = c.receive();
        recvMsg.accept();

        assertEquals(val.getValue().getValueString(), recvMsg.getAmqpValue().getValue().getValueString());
        conn.close();
    }