try {
byte[] content = "this is the content".getBytes();
PublishKey key = new PublishKey(glob, "someKey");
PublishQosServer publishQosServer = new PublishQosServer(glob, "<qos><persistent/></qos>");
MsgQosData msgQosData = publishQosServer.getData();
((MsgQosSaxFactory)glob.getMsgQosFactory()).sendRemainingLife(false); // so we can compare the toXml() directly
// populate it
String state = Constants.STATE_EXPIRED;
msgQosData.setState(state);
msgQosData.setSubscriptionId("someId");
msgQosData.setPersistent(true);
msgQosData.setForceUpdate(false);
msgQosData.setReadonly(true);
msgQosData.setSender(new SessionName(glob, "somebody"));
msgQosData.setRedeliver(4);
msgQosData.setQueueSize(1000L);
msgQosData.setQueueIndex(500L);
//msgQosData.addRouteInfo(null);
//msgQosData.dirtyRead(null);//NodeId
msgQosData.setPriority(PriorityEnum.LOW4_PRIORITY);
msgQosData.setFromPersistenceStore(true);
msgQosData.setLifeTime(4000L);
msgQosData.setRemainingLifeStatic(6000L);
MsgUnit msgUnit = new MsgUnit(key.toXml(), content, msgQosData.toXml());
log.fine("Testing" + msgQosData.toXml());
SessionName receiver = new SessionName(glob, "receiver1");
String subscriptionId = "subid";
int redeliverCounter = 2;
boolean updateOneway = true;
org.xmlBlaster.engine.ServerScope global = new org.xmlBlaster.engine.ServerScope();
MsgUnitWrapper msgWrapper = new MsgUnitWrapper(glob, msgUnit, queue.getStorageId());
MsgQueueUpdateEntry entry = new MsgQueueUpdateEntry(global, msgWrapper, queue.getStorageId(),
receiver, subscriptionId, updateOneway);
entry.incrRedeliverCounter();
entry.incrRedeliverCounter();
queue.put(entry, false);
I_QueueEntry returnEntry = queue.peek();
boolean isUpdate = (returnEntry instanceof MsgQueueUpdateEntry);
assertTrue("updateEntry: the return value is not an update ", isUpdate);
MsgQueueUpdateEntry updateEntry = (MsgQueueUpdateEntry)returnEntry;
assertEquals("The subscriptionId of the entry is different ", subscriptionId, updateEntry.getSubscriptionId());
assertEquals("The state of the entry is different ", state, updateEntry.getState());
assertEquals("The redeliverCounter of the entry is different ", redeliverCounter, updateEntry.getRedeliverCounter());
assertEquals("The priority of the entry is different ", entry.getPriority(), updateEntry.getPriority());
assertEquals("The oneway of the entry is different ", updateOneway, updateEntry.updateOneway());
assertEquals("The persistent of the entry is different ", entry.isPersistent(), updateEntry.isPersistent());
assertEquals("The receiver of the entry is different ", entry.getReceiver().toString(), updateEntry.getReceiver().toString());
assertEquals("The uniqueId of the entry is different ", entry.getUniqueId(), updateEntry.getUniqueId());
assertEquals("The msgUnitWrapperUniqueId of the entry is different ", entry.getMsgUnitWrapperUniqueId(), updateEntry.getMsgUnitWrapperUniqueId());
assertEquals("The topic oid of the entry is different ", entry.getKeyOid(), updateEntry.getKeyOid());
assertEquals("The topic oid of the entry is different ", entry.getStorageId().getId(), updateEntry.getStorageId().getId());
log.info("SUCCESS: MsgQueueUpdateEntry: Persistent fields are read as expected");
MsgUnit retMsgUnit = null;
try {
retMsgUnit = updateEntry.getMsgUnit();
}
catch (Throwable e) { // Should not happen for RAM queue
log.severe("Lookup failed, probably engine.Global has no Requestbroker, wi ignore the problem: " + e.getMessage());
e.printStackTrace();
return;
}
MsgQosData retMsgQosData = updateEntry.getMsgQosData();
log.fine("Received" + retMsgQosData.toXml());
// check message unit:
assertEquals("The key of the message unit is different ", key.getOid(), retMsgUnit.getKeyData().getOid());
assertEquals("The content of the message unit is different ", new String(retMsgUnit.getContent()), new String(content));
//assertEquals("The qos of the message unit is different ", retMsgUnit.getQosData().isPersistent(), publishQosServer.isPersistent());
//assertEquals("The qos of the message unit is different OLD="+oldXml+" NEW="+newXml, oldXml, newXml);
assertEquals("msgQosData check failure: getSubscriptionId ", msgQosData.getSubscriptionId(), retMsgQosData.getSubscriptionId());
// assertEquals("msgQosData check failure: getPersistent ", msgQosData.getPersistent(), retMsgQosData.getPersistent());
// assertEquals("msgQosData check failure: getForceUpdate ", msgQosData.getForceUpdate(), retMsgQosData.getForceUpdate());
// assertEquals("msgQosData check failure: getReadOnly ", msgQosData.getReadOnly(), retMsgQosData.getReadOnly());
assertEquals("msgQosData check failure: getSender ", msgQosData.getSender().toString(), retMsgQosData.getSender().toString());
assertEquals("msgQosData check failure: getRedeliver ", msgQosData.getRedeliver(), retMsgQosData.getRedeliver());
assertEquals("msgQosData check failure: getQueueSize ", msgQosData.getQueueSize(), retMsgQosData.getQueueSize());
assertEquals("msgQosData check failure: getQueueIndex ", msgQosData.getQueueIndex(), retMsgQosData.getQueueIndex());
assertEquals("msgQosData check failure: getPriority ", msgQosData.getPriority().getInt(), retMsgQosData.getPriority().getInt());
// assertEquals("msgQosData check failure: getFromPersistentStore ", msgQosData.getFromPersistentStore(), retMsgQosData.getFromPersistentStore());
assertEquals("msgQosData check failure: getLifeTime ", msgQosData.getLifeTime(), retMsgQosData.getLifeTime());
//assertEquals("msgQosData check failure: getRemainingLifeStatic ", msgQosData.getRemainingLifeStatic(), retMsgQosData.getRemainingLifeStatic());
assertEquals("msgQosData check failure: receiver", receiver, updateEntry.getReceiver());
queue.removeRandom(returnEntry); //just for cleaning up