Search in sources :

Example 1 with ByteArrayOutputStream

use of org.apache.activemq.util.ByteArrayOutputStream in project nifi by apache.

the class TestWaitNotifyProtocol method testNiFiVersionUpgrade.

/**
 * Test migration across NiFi version upgrade.
 * Old version of Wait/Notify processors use FlowFileAttributesSerializer for cache entries.
 * New version uses StringSerializer. WaitNotifyProtocol should be able to migrate old cache entries.
 */
@Test
public void testNiFiVersionUpgrade() throws Exception {
    doAnswer(successfulReplace).when(cache).replace(any(), any(), any());
    // Simulate old cache entry.
    final FlowFileAttributesSerializer attributesSerializer = new FlowFileAttributesSerializer();
    final Map<String, String> cachedAttributes = new HashMap<>();
    cachedAttributes.put("key1", "value1");
    cachedAttributes.put("key2", "value2");
    cachedAttributes.put("key3", "value3");
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    attributesSerializer.serialize(cachedAttributes, bos);
    final String signalId = "old-entry";
    cacheEntries.put(signalId, new AtomicCacheEntry<>(signalId, new String(bos.toByteArray(), StandardCharsets.UTF_8), 0L));
    final WaitNotifyProtocol protocol = new WaitNotifyProtocol(cache);
    final Signal signal = protocol.getSignal(signalId);
    assertEquals(1, signal.getCount(DEFAULT_COUNT_NAME));
    assertEquals("value1", signal.getAttributes().get("key1"));
    assertEquals("value2", signal.getAttributes().get("key2"));
    assertEquals("value3", signal.getAttributes().get("key3"));
    cacheEntries.put(signalId, new AtomicCacheEntry<>(signalId, "UNSUPPORTED_FORMAT", 0L));
    try {
        protocol.getSignal(signalId);
        fail("Should fail since cached value was not in expected format.");
    } catch (DeserializationException e) {
    }
}
Also used : Signal(org.apache.nifi.processors.standard.WaitNotifyProtocol.Signal) HashMap(java.util.HashMap) ByteArrayOutputStream(org.apache.activemq.util.ByteArrayOutputStream) DeserializationException(org.apache.nifi.distributed.cache.client.exception.DeserializationException) FlowFileAttributesSerializer(org.apache.nifi.processors.standard.util.FlowFileAttributesSerializer) Test(org.junit.Test)

Example 2 with ByteArrayOutputStream

use of org.apache.activemq.util.ByteArrayOutputStream in project activemq-artemis by apache.

the class ActiveMQTextMessageTest method setContent.

protected void setContent(Message message, String text) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dataOut = new DataOutputStream(baos);
    MarshallingSupport.writeUTF8(dataOut, text);
    dataOut.close();
    message.setContent(baos.toByteSequence());
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(org.apache.activemq.util.ByteArrayOutputStream)

Example 3 with ByteArrayOutputStream

use of org.apache.activemq.util.ByteArrayOutputStream in project activemq-artemis by apache.

the class MessageTestSupport method populateObject.

@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    Message info = (Message) object;
    info.setProducerId(createProducerId("ProducerId:1"));
    info.setDestination(createActiveMQDestination("Destination:2"));
    info.setTransactionId(createTransactionId("TransactionId:3"));
    info.setOriginalDestination(createActiveMQDestination("OriginalDestination:4"));
    info.setMessageId(createMessageId("MessageId:5"));
    info.setOriginalTransactionId(createTransactionId("OriginalTransactionId:6"));
    info.setGroupID("GroupID:7");
    info.setGroupSequence(1);
    info.setCorrelationId("CorrelationId:8");
    info.setPersistent(true);
    info.setExpiration(1);
    info.setPriority((byte) 1);
    info.setReplyTo(createActiveMQDestination("ReplyTo:9"));
    info.setTimestamp(2);
    info.setType("Type:10");
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dataOut = new DataOutputStream(baos);
        MarshallingSupport.writeUTF8(dataOut, "Content:11");
        dataOut.close();
        info.setContent(baos.toByteSequence());
    }
    {
        Map<String, Object> map = new HashMap<>();
        map.put("MarshalledProperties", 12);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream os = new DataOutputStream(baos);
        MarshallingSupport.marshalPrimitiveMap(map, os);
        os.close();
        info.setMarshalledProperties(baos.toByteSequence());
    }
    info.setDataStructure(createDataStructure("DataStructure:13"));
    info.setTargetConsumerId(createConsumerId("TargetConsumerId:14"));
    info.setCompressed(false);
    info.setRedeliveryCounter(2);
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:15");
        }
        info.setBrokerPath(value);
    }
    info.setArrival(3);
    info.setUserID("UserID:16");
    info.setRecievedByDFBridge(true);
}
Also used : Message(org.apache.activemq.command.Message) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(org.apache.activemq.util.ByteArrayOutputStream) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with ByteArrayOutputStream

use of org.apache.activemq.util.ByteArrayOutputStream in project activemq-artemis by apache.

the class MessageTestSupport method populateObject.

@Override
protected void populateObject(Object object) throws Exception {
    super.populateObject(object);
    Message info = (Message) object;
    info.setProducerId(createProducerId("ProducerId:1"));
    info.setDestination(createActiveMQDestination("Destination:2"));
    info.setTransactionId(createTransactionId("TransactionId:3"));
    info.setOriginalDestination(createActiveMQDestination("OriginalDestination:4"));
    info.setMessageId(createMessageId("MessageId:5"));
    info.setOriginalTransactionId(createTransactionId("OriginalTransactionId:6"));
    info.setGroupID("GroupID:7");
    info.setGroupSequence(1);
    info.setCorrelationId("CorrelationId:8");
    info.setPersistent(true);
    info.setExpiration(1);
    info.setPriority((byte) 1);
    info.setReplyTo(createActiveMQDestination("ReplyTo:9"));
    info.setTimestamp(2);
    info.setType("Type:10");
    {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dataOut = new DataOutputStream(baos);
        MarshallingSupport.writeUTF8(dataOut, "Content:11");
        dataOut.close();
        info.setContent(baos.toByteSequence());
    }
    {
        Map<String, Object> map = new HashMap<>();
        map.put("MarshalledProperties", 12);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream os = new DataOutputStream(baos);
        MarshallingSupport.marshalPrimitiveMap(map, os);
        os.close();
        info.setMarshalledProperties(baos.toByteSequence());
    }
    info.setDataStructure(createDataStructure("DataStructure:13"));
    info.setTargetConsumerId(createConsumerId("TargetConsumerId:14"));
    info.setCompressed(false);
    info.setRedeliveryCounter(2);
    {
        BrokerId[] value = new BrokerId[2];
        for (int i = 0; i < 2; i++) {
            value[i] = createBrokerId("BrokerPath:15");
        }
        info.setBrokerPath(value);
    }
    info.setArrival(3);
    info.setUserID("UserID:16");
    info.setRecievedByDFBridge(true);
    info.setDroppable(false);
}
Also used : Message(org.apache.activemq.command.Message) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(org.apache.activemq.util.ByteArrayOutputStream) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ByteArrayOutputStream (org.apache.activemq.util.ByteArrayOutputStream)4 DataOutputStream (java.io.DataOutputStream)3 HashMap (java.util.HashMap)3 Map (java.util.Map)2 Message (org.apache.activemq.command.Message)2 DeserializationException (org.apache.nifi.distributed.cache.client.exception.DeserializationException)1 Signal (org.apache.nifi.processors.standard.WaitNotifyProtocol.Signal)1 FlowFileAttributesSerializer (org.apache.nifi.processors.standard.util.FlowFileAttributesSerializer)1 Test (org.junit.Test)1