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) {
}
}
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());
}
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);
}
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);
}
Aggregations