GetQos gq = new GetQos(glob);
for (int i=0; i<10; i++) {
MsgUnit[] msgs = con.getCached(gk, gq);
assertEquals(this.synchronousCache.toXml(""), 1, msgs.length);
GetReturnQos grq = new GetReturnQos(glob, msgs[0].getQos());
assertEquals("", 1, this.synchronousCache.getNumQueriesCached());
log.info("Accessed xmlBlaster message with content '" + new String(msgs[0].getContent()) +
"' and status=" + grq.getState());
}
sendErase(publishOidArr[0]);
assertEquals("", 0, this.synchronousCache.getNumQueriesCached());
sendErase(publishOidArr[2]);
}
catch (XmlBlasterException e) {
log.severe("testCachedAccess() failed: " + e.getMessage());
fail(e.getMessage());
}
assertEquals("Unexpected update arrived", 0, this.updateInterceptor.waitOnUpdate(1000L, 0));
}
{
log.info("Entering testCachedAccess with updated MsgUnit ...");
try {
PublishReturnQos publishReturnQos = publishMsg(publishOidArr[0], contentArr[0]);
GetKey gk = new GetKey(glob, publishOidArr[0]);
GetQos gq = new GetQos(glob);
for (int i=0; i<5; i++) {
MsgUnit[] msgs = con.getCached(gk, gq);
GetReturnQos grq = new GetReturnQos(glob, msgs[0].getQos());
assertEquals(this.synchronousCache.toXml(""), 1, msgs.length);
assertEquals("", 1, this.synchronousCache.getNumQueriesCached());
assertEquals("", publishReturnQos.getRcvTimestamp(), grq.getRcvTimestamp());
assertEquals("", contentArr[0], msgs[0].getContentStr());
log.info("Accessed xmlBlaster message with content '" + new String(msgs[0].getContent()) +
"' and status=" + grq.getState() + " rcv=" + grq.getRcvTimestamp());
}
// Now publish again an check if cache is updated
String contentNew = contentArr[0]+"-NEW";
publishReturnQos = publishMsg(publishOidArr[0], contentNew);
try { Thread.sleep(200L); } catch( InterruptedException i) {} // Wait 200 milli seconds, until all updates are processed ...
for (int i=0; i<5; i++) {
MsgUnit[] msgs = con.getCached(gk, gq);
GetReturnQos grq = new GetReturnQos(glob, msgs[0].getQos());
assertEquals(this.synchronousCache.toXml(""), 1, msgs.length);
assertEquals("", 1, this.synchronousCache.getNumQueriesCached());
assertEquals("", publishReturnQos.getRcvTimestamp().getTimestamp(), grq.getRcvTimestamp().getTimestamp());
assertEquals("", publishReturnQos.getKeyOid(), msgs[0].getKeyOid());
assertEquals("", contentNew, msgs[0].getContentStr());
log.info("Accessed xmlBlaster message with content '" + new String(msgs[0].getContent()) +
"' and status=" + grq.getState() + " rcv=" + grq.getRcvTimestamp());
}
sendErase(publishOidArr[0]);
assertEquals("", 0, this.synchronousCache.getNumQueriesCached());
}
catch (XmlBlasterException e) {
log.severe("testCachedAccess() failed: " + e.getMessage());
fail(e.getMessage());
}
assertEquals("Unexpected update arrived", 0, this.updateInterceptor.waitOnUpdate(1000L, 0));
}
{
log.info("Entering testCachedAccess with XPATH ...");
try {
PublishReturnQos publishReturnQos0 = publishMsg(publishOidArr[0], contentArr[0]);
PublishReturnQos publishReturnQos1 = publishMsg(publishOidArr[1], contentArr[1]);
publishMsg(publishOidArr[2], contentArr[2]);
try { Thread.sleep(200L); } catch( InterruptedException i) {} // Wait 200 milli seconds, until all updates are processed ...
// This should match [0] and [1] msg:
GetKey gk = new GetKey(glob, "//key[starts-with(@oid,'oid-')]", Constants.XPATH);
GetQos gq = new GetQos(glob);
for (int i=0; i<10; i++) {
MsgUnit[] msgs = con.getCached(gk, gq);
assertEquals("", 2, msgs.length);
GetReturnQos grq0 = new GetReturnQos(glob, msgs[0].getQos());
GetReturnQos grq1 = new GetReturnQos(glob, msgs[1].getQos());
assertEquals(this.synchronousCache.toXml(""), 2, msgs.length);
assertEquals(this.synchronousCache.toXml(""), 1, this.synchronousCache.getNumQueriesCached());
log.info(" publishReturnQos0.getRcvTimestamp()=" + publishReturnQos0.getRcvTimestamp() +
" publishReturnQos1.getRcvTimestamp()=" + publishReturnQos1.getRcvTimestamp() +
" grq0.getRcvTimestamp()=" + grq0.getRcvTimestamp() +
" grq1.getRcvTimestamp()=" + grq1.getRcvTimestamp());
assertTrue("", publishReturnQos0.getRcvTimestamp().equals(grq0.getRcvTimestamp()) ||
publishReturnQos0.getRcvTimestamp().equals(grq1.getRcvTimestamp()));
assertTrue("", publishReturnQos1.getRcvTimestamp().equals(grq0.getRcvTimestamp()) ||
publishReturnQos1.getRcvTimestamp().equals(grq1.getRcvTimestamp()));
assertTrue("", !grq0.getRcvTimestamp().equals(grq1.getRcvTimestamp()));
assertEquals("", 2, msgs.length);
log.info("Accessed " + msgs.length + " xmlBlaster messages with content '" +
new String(msgs[0].getContent()) +
"' and '" + new String(msgs[1].getContent()) + "' and status=" + grq0.getState());
}