Java Code Examples for org.apache.qpid.proton.amqp.Symbol#valueOf()

The following examples show how to use org.apache.qpid.proton.amqp.Symbol#valueOf() . 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 File: AmqpJmsMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testMessageAnnotationExistsUsingReceivedMessageWithMessageAnnotationsSection() {
    Symbol symbolKeyName = Symbol.valueOf("myTestSymbolName");
    String value = "myTestValue";

    Message message = Proton.message();

    Map<Symbol, Object> annotationsMap = new HashMap<Symbol, Object>();
    annotationsMap.put(symbolKeyName, value);
    message.setMessageAnnotations(new MessageAnnotations(annotationsMap));

    AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);

    assertTrue(amqpMessageFacade.messageAnnotationExists(symbolKeyName));
    assertFalse(amqpMessageFacade.messageAnnotationExists(Symbol.valueOf("otherName")));
}
 
Example 2
Source File: ArrayTypeCodecTest.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
private void doTestDecodeSymbolArrayType(int size) throws IOException {
    Symbol[] source = new Symbol[size];
    for (int i = 0; i < size; ++i) {
        source[i] = Symbol.valueOf("test->" + i);
    }

    encoder.writeArray(source);

    buffer.clear();

    Object result = decoder.readObject();
    assertNotNull(result);
    assertTrue(result.getClass().isArray());

    Symbol[] array = (Symbol[]) result;
    assertEquals(size, array.length);

    for (int i = 0; i < size; ++i) {
        assertEquals(source[i], array[i]);
    }
}
 
Example 3
Source File: SaslOutcomeMatcher.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
public SaslOutcomeMatcher()
{
    super(FrameType.SASL,
          ANY_CHANNEL,
          UnsignedLong.valueOf(0x0000000000000044L),
          Symbol.valueOf("amqp:sasl-outcome:list"));
}
 
Example 4
Source File: AmqpJmsBytesMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testCopyOfContentType() throws Exception {
    AmqpJmsBytesMessageFacade amqpBytesMessageFacade1 = createNewBytesMessageFacade();
    AmqpJmsBytesMessageFacade copy1 = amqpBytesMessageFacade1.copy();
    assertNull(copy1.getContentType());

    AmqpJmsBytesMessageFacade amqpBytesMessageFacade2 = createNewBytesMessageFacade();
    Symbol contentType = Symbol.valueOf("content-type");
    amqpBytesMessageFacade2.setContentType(contentType);

    AmqpJmsBytesMessageFacade copy2 = amqpBytesMessageFacade2.copy();
    assertEquals(contentType, copy2.getContentType());
}
 
Example 5
Source File: ProtonClientTest.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 20000)
public void testConnectionPropertiesSetNonDefaultWithoutProductVersion(TestContext context) throws Exception {
  Symbol clientCustomProp = Symbol.valueOf("custom-client-prop-key");
  String clientCustomPropValue = "custom-client-prop-value";

  Symbol serverCustomProp = Symbol.valueOf("custom-server-prop-key");
  String serverCustomPropValue = "custom-server-prop-value";

  LinkedHashMap<Symbol, Object> clientProps = new LinkedHashMap<Symbol, Object>();
  clientProps.put(clientCustomProp, clientCustomPropValue);

  LinkedHashMap<Symbol, Object> serverProps = new LinkedHashMap<Symbol, Object>();
  serverProps.put(serverCustomProp, serverCustomPropValue);

  final ConPropValidator serverExpectedPropsHandler = (c, props) -> {
    new ProductVersionConPropValidator(ProtonMetaDataSupportImpl.PRODUCT, ProtonMetaDataSupportImpl.VERSION)
        .validate(c, props);

    context.assertTrue(props.containsKey(clientCustomProp), "custom client prop not present");
    context.assertEquals(clientCustomPropValue, props.get(clientCustomProp), "unexpected custom client prop value");
  };

  final ConPropValidator clientExpectedPropsHandler = (c, props) -> {
    new ProductVersionConPropValidator(ProtonMetaDataSupportImpl.PRODUCT, ProtonMetaDataSupportImpl.VERSION)
        .validate(c, props);

    context.assertTrue(props.containsKey(serverCustomProp), "custom server prop not present");
    context.assertEquals(serverCustomPropValue, props.get(serverCustomProp), "unexpected custom server prop value");
  };

  doConnectionPropertiesTestImpl(context, true, clientProps, serverExpectedPropsHandler, serverProps,
      clientExpectedPropsHandler);
}
 
Example 6
Source File: SaslResponseMatcher.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
public SaslResponseMatcher()
{
    super(FrameType.SASL,
          ANY_CHANNEL,
          UnsignedLong.valueOf(0x0000000000000043L),
          Symbol.valueOf("amqp:sasl-response:list"));
}
 
Example 7
Source File: AttachMatcher.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
public AttachMatcher()
{
    super(FrameType.AMQP,
          ANY_CHANNEL,
          UnsignedLong.valueOf(0x0000000000000012L),
          Symbol.valueOf("amqp:attach:list"));
}
 
Example 8
Source File: MessageAnnotationsTypeCodecTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodeAndDecodeAnnoationsWithEmbeddedMaps() throws IOException {
    final Symbol SYMBOL_1 = Symbol.valueOf("x-opt-test1");
    final Symbol SYMBOL_2 = Symbol.valueOf("x-opt-test2");

    final String VALUE_1 = "string";
    final UnsignedInteger VALUE_2 = UnsignedInteger.valueOf(42);
    final UUID VALUE_3 = UUID.randomUUID();

    Map<String, Object> stringKeyedMap = new HashMap<>();
    stringKeyedMap.put("key1", VALUE_1);
    stringKeyedMap.put("key2", VALUE_2);
    stringKeyedMap.put("key3", VALUE_3);

    Map<Symbol, Object> symbolKeyedMap = new HashMap<>();
    symbolKeyedMap.put(Symbol.valueOf("key1"), VALUE_1);
    symbolKeyedMap.put(Symbol.valueOf("key2"), VALUE_2);
    symbolKeyedMap.put(Symbol.valueOf("key3"), VALUE_3);

    MessageAnnotations annotations = new MessageAnnotations(new HashMap<>());
    annotations.getValue().put(SYMBOL_1, stringKeyedMap);
    annotations.getValue().put(SYMBOL_2, symbolKeyedMap);

    encoder.writeObject(annotations);

    buffer.clear();

    final Object result = decoder.readObject();

    assertNotNull(result);
    assertTrue(result instanceof MessageAnnotations);

    MessageAnnotations readAnnotations = (MessageAnnotations) result;

    Map<Symbol, Object> resultMap = readAnnotations.getValue();

    assertEquals(annotations.getValue().size(), resultMap.size());
    assertEquals(resultMap.get(SYMBOL_1), stringKeyedMap);
    assertEquals(resultMap.get(SYMBOL_2), symbolKeyedMap);
}
 
Example 9
Source File: Benchmark.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
private void benchmarkSymbols() throws IOException {
    Symbol symbol1 = Symbol.valueOf("Symbol-1");
    Symbol symbol2 = Symbol.valueOf("Symbol-2");
    Symbol symbol3 = Symbol.valueOf("Symbol-3");

    resultSet.start();
    for (int i = 0; i < ITERATIONS; i++) {
        outputBuf.byteBuffer().clear();
        encoder.writeSymbol(symbol1);
        encoder.writeSymbol(symbol2);
        encoder.writeSymbol(symbol3);
    }
    resultSet.encodesComplete();

    CompositeReadableBuffer inputBuf = convertToComposite(outputBuf);
    decoder.setBuffer(inputBuf);

    resultSet.start();
    for (int i = 0; i < ITERATIONS; i++) {
        decoder.readSymbol();
        decoder.readSymbol();
        decoder.readSymbol();
        inputBuf.flip();
    }
    resultSet.decodesComplete();

    time("Symbol", resultSet);
}
 
Example 10
Source File: DataImplTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodeDecodeSymbolArrayUsingPutArray()
{
    Symbol symbol1 = Symbol.valueOf("testRoundtripSymbolArray1");
    Symbol symbol2 = Symbol.valueOf("testRoundtripSymbolArray2");

    Data data1 = new DataImpl();
    data1.putArray(false, Data.DataType.SYMBOL);
    data1.enter();
    data1.putSymbol(symbol1);
    data1.putSymbol(symbol2);
    data1.exit();

    Binary encoded = data1.encode();
    encoded.asByteBuffer();

    Data data2 = new DataImpl();
    data2.decode(encoded.asByteBuffer());

    assertEquals("unexpected array length", 2, data2.getArray());
    assertEquals("unexpected array length", Data.DataType.SYMBOL, data2.getArrayType());

    Object[] array = data2.getJavaArray();
    assertNotNull("Array should not be null", array);
    assertEquals("Expected a Symbol array", Symbol[].class, array.getClass());
    assertEquals("unexpected array length", 2, array.length);
    assertEquals("unexpected value", symbol1, array[0]);
    assertEquals("unexpected value", symbol2, array[1]);
}
 
Example 11
Source File: DispositionMatcher.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
public DispositionMatcher()
{
    super(FrameType.AMQP,
          ANY_CHANNEL,
          UnsignedLong.valueOf(0x0000000000000015L),
          Symbol.valueOf("amqp:disposition:list"));
}
 
Example 12
Source File: RejectedMatcher.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
public RejectedMatcherCore()
{
    super(UnsignedLong.valueOf(0x0000000000000025L),
          Symbol.valueOf("amqp:rejected:list"));
}
 
Example 13
Source File: TransactionalStateMatcher.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
public TransactionalStateMatcherCore()
{
    super(UnsignedLong.valueOf(0x0000000000000034L),
          Symbol.valueOf("amqp:transactional-state:list"));
}
 
Example 14
Source File: DeleteOnCloseMatcher.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
public DeleteOnCloseMatcherCore()
{
    super(UnsignedLong.valueOf(0x000000000000002bL),
          Symbol.valueOf("amqp:delete-on-close:list"));
}
 
Example 15
Source File: TransactionsIntegrationTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Test(timeout=20000)
public void testProducedMessagesAfterCommitOfSentMessagesFails() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        Connection connection = testFixture.establishConnecton(testPeer);
        connection.start();

        testPeer.expectBegin();
        testPeer.expectCoordinatorAttach();

        // First expect an unsettled 'declare' transfer to the txn coordinator, and
        // reply with a Declared disposition state containing the txnId.
        Binary txnId1 = new Binary(new byte[]{ (byte) 5, (byte) 6, (byte) 7, (byte) 8});
        testPeer.expectDeclare(txnId1);

        Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
        Queue queue = session.createQueue("myQueue");

        // Create a producer to use in provoking creation of the AMQP transaction
        testPeer.expectSenderAttach();
        MessageProducer producer = session.createProducer(queue);

        // Expect the message which was sent under the current transaction. Check it carries
        // TransactionalState with the above txnId but has no outcome. Respond with a
        // TransactionalState with Accepted outcome.
        TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
        messageMatcher.setHeadersMatcher(new MessageHeaderSectionMatcher(true));
        messageMatcher.setMessageAnnotationsMatcher(new MessageAnnotationsSectionMatcher(true));

        TransactionalStateMatcher stateMatcher = new TransactionalStateMatcher();
        stateMatcher.withTxnId(equalTo(txnId1));
        stateMatcher.withOutcome(nullValue());

        TransactionalState txState = new TransactionalState();
        txState.setTxnId(txnId1);
        txState.setOutcome(new Accepted());

        testPeer.expectTransfer(messageMatcher, stateMatcher, txState, true);

        producer.send(session.createMessage());

        // Expect an unsettled 'discharge' transfer to the txn coordinator containing the txnId,
        // and reply with rejected and settled disposition to indicate the commit failed
        Rejected commitFailure = new Rejected(new Error(Symbol.valueOf("failed"), "Unknown error"));
        testPeer.expectDischarge(txnId1, false, commitFailure);

        // Then expect an unsettled 'declare' transfer to the txn coordinator, and
        // reply with a declared disposition state containing the txnId.
        Binary txnId2 = new Binary(new byte[]{ (byte) 1, (byte) 2, (byte) 3, (byte) 4});
        testPeer.expectDeclare(txnId2);

        try {
            session.commit();
            fail("Commit operation should have failed.");
        } catch (TransactionRolledBackException jmsTxRb) {
        }

        // Expect the message which was sent under the current transaction. Check it carries
        // TransactionalState with the above txnId but has no outcome. Respond with a
        // TransactionalState with Accepted outcome.
        stateMatcher = new TransactionalStateMatcher();
        stateMatcher.withTxnId(equalTo(txnId2));
        stateMatcher.withOutcome(nullValue());

        txState = new TransactionalState();
        txState.setTxnId(txnId2);
        txState.setOutcome(new Accepted());

        testPeer.expectTransfer(messageMatcher, stateMatcher, txState, true);
        testPeer.expectDischarge(txnId2, true);

        producer.send(session.createMessage());

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example 16
Source File: DeclaredMatcher.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
public DeclaredMatcherCore()
{
    super(UnsignedLong.valueOf(0x0000000000000033L),
          Symbol.valueOf("amqp:declared:list"));
}
 
Example 17
Source File: ProducerIntegrationTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
private void doSendingMessageSetsJMSDeliveryTimeTestImpl(boolean deliveryDelay) throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        // add connection capability to indicate server support for DELAYED-DELIVERY
        Connection connection = testFixture.establishConnecton(testPeer, new Symbol[]{ DELAYED_DELIVERY });

        testPeer.expectBegin();
        testPeer.expectSenderAttach();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        String queueName = "myQueue";
        Queue queue = session.createQueue(queueName);
        MessageProducer producer = session.createProducer(queue);

        int delay = 0;
        if (deliveryDelay) {
            delay = 123456;
            producer.setDeliveryDelay(delay);
        }

        // Create matcher to expect the DeliveryTime to be set to a value
        // representing 'now' [+ delivery-delay], within a upper delta for execution time.
        long deliveryTimeLower = System.currentTimeMillis();
        long deliveryTimeUpper = deliveryTimeLower + delay + 3000;
        Matcher<Long> inRange = both(greaterThanOrEqualTo(deliveryTimeLower)).and(lessThanOrEqualTo(deliveryTimeUpper));
        Symbol DELIVERY_TIME = Symbol.valueOf("x-opt-delivery-time");

        String text = "myMessage";
        TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
        messageMatcher.setHeadersMatcher(new MessageHeaderSectionMatcher(true));
        MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
        if (deliveryDelay) {
            msgAnnotationsMatcher.withEntry(DELIVERY_TIME, inRange);
        }
        messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);
        messageMatcher.setPropertiesMatcher(new MessagePropertiesSectionMatcher(true));
        messageMatcher.setMessageContentMatcher(new EncodedAmqpValueMatcher(text));
        testPeer.expectTransfer(messageMatcher);

        Message message = session.createTextMessage(text);

        producer.send(message);

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);

        if (!deliveryDelay) {
            assertFalse("Message should not have delivery time annotation",
                    msgAnnotationsMatcher.keyExistsInReceivedAnnotations(DELIVERY_TIME));
        }

        assertThat(message.getJMSDeliveryTime(), inRange);
    }
}
 
Example 18
Source File: DeleteOnNoLinksMatcher.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
public DeleteOnNoLinksMatcherCore()
{
    super(UnsignedLong.valueOf(0x000000000000002cL),
          Symbol.valueOf("amqp:delete-on-no-links:list"));
}
 
Example 19
Source File: SessionTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Test
public void testCapabilities() throws Exception
{
    final Symbol clientOfferedCap = Symbol.valueOf("clientOfferedCapability");
    final Symbol clientDesiredCap = Symbol.valueOf("clientDesiredCapability");
    final Symbol serverOfferedCap = Symbol.valueOf("serverOfferedCapability");
    final Symbol serverDesiredCap = Symbol.valueOf("serverDesiredCapability");

    Symbol[] clientOfferedCapabilities = new Symbol[] { clientOfferedCap };
    Symbol[] clientDesiredCapabilities = new Symbol[] { clientDesiredCap };

    Symbol[] serverOfferedCapabilities = new Symbol[] { serverOfferedCap };
    Symbol[] serverDesiredCapabilities = new Symbol[] { serverDesiredCap };

    LOGGER.fine(bold("======== About to create transports"));

    getClient().transport = Proton.transport();
    ProtocolTracerEnabler.setProtocolTracer(getClient().transport, TestLoggingHelper.CLIENT_PREFIX);

    getServer().transport = Proton.transport();
    ProtocolTracerEnabler.setProtocolTracer(getServer().transport, "            " + TestLoggingHelper.SERVER_PREFIX);

    doOutputInputCycle();

    getClient().connection = Proton.connection();
    getClient().transport.bind(getClient().connection);

    getServer().connection = Proton.connection();
    getServer().transport.bind(getServer().connection);

    LOGGER.fine(bold("======== About to open connections"));
    getClient().connection.open();
    getServer().connection.open();

    doOutputInputCycle();

    LOGGER.fine(bold("======== About to open sessions"));
    getClient().session = getClient().connection.session();

    // Set the client session capabilities
    getClient().session.setOfferedCapabilities(clientOfferedCapabilities);
    getClient().session.setDesiredCapabilities(clientDesiredCapabilities);

    getClient().session.open();

    pumpClientToServer();

    getServer().session = getServer().connection.sessionHead(of(UNINITIALIZED), of(ACTIVE));
    assertEndpointState(getServer().session, UNINITIALIZED, ACTIVE);

    // Set the server session capabilities
    getServer().session.setOfferedCapabilities(serverOfferedCapabilities);
    getServer().session.setDesiredCapabilities(serverDesiredCapabilities);

    getServer().session.open();
    assertEndpointState(getServer().session, ACTIVE, ACTIVE);

    pumpServerToClient();

    // Verify server side got the clients session capabilities as expected
    Symbol[] serverRemoteOfferedCapabilities = getServer().session.getRemoteOfferedCapabilities();
    assertNotNull("Server had no remote offered capabilities", serverRemoteOfferedCapabilities);
    assertEquals("Server remote offered capabilities not expected size", 1, serverRemoteOfferedCapabilities.length);
    assertTrue("Server remote offered capabilities lack expected value: " + clientOfferedCap, Arrays.asList(serverRemoteOfferedCapabilities).contains(clientOfferedCap));

    Symbol[] serverRemoteDesiredCapabilities = getServer().session.getRemoteDesiredCapabilities();
    assertNotNull("Server had no remote desired capabilities", serverRemoteDesiredCapabilities);
    assertEquals("Server remote desired capabilities not expected size", 1, serverRemoteDesiredCapabilities.length);
    assertTrue("Server remote desired capabilities lack expected value: " + clientDesiredCap, Arrays.asList(serverRemoteDesiredCapabilities).contains(clientDesiredCap));

    // Verify the client side got the servers session capabilities as expected
    Symbol[]  clientRemoteOfferedCapabilities = getClient().session.getRemoteOfferedCapabilities();
    assertNotNull("Client had no remote offered capabilities", clientRemoteOfferedCapabilities);
    assertEquals("Client remote offered capabilities not expected size", 1, clientRemoteOfferedCapabilities.length);
    assertTrue("Client remote offered capabilities lack expected value: " + serverOfferedCap, Arrays.asList(clientRemoteOfferedCapabilities).contains(serverOfferedCap));

    Symbol[]  clientRemoteDesiredCapabilities = getClient().session.getRemoteDesiredCapabilities();
    assertNotNull("Client had no remote desired capabilities", clientRemoteDesiredCapabilities);
    assertEquals("Client remote desired capabilities not expected size", 1, clientRemoteDesiredCapabilities.length);
    assertTrue("Client remote desired capabilities lack expected value: " + serverDesiredCap, Arrays.asList(clientRemoteDesiredCapabilities).contains(serverDesiredCap));
}
 
Example 20
Source File: ProtonClientTest.java    From vertx-proton with Apache License 2.0 3 votes vote down vote up
@Test(timeout = 20000)
public void testNotSettingDesiredAndOfferedCapabilitiesRetainsAnonRelay(TestContext context) throws Exception {

  Symbol foo = Symbol.valueOf("foo");


  doTestCapabilities(context, null, new Symbol[] { foo },
                     new Symbol[] { foo }, null, false);

  doTestCapabilities(context, null, new Symbol[] { foo },
                     new Symbol[] { foo }, null, true);

}