SCClient clientToSc0 = new SCClient(TestConstants.HOST, TestConstants.PORT_SC0_TCP, ConnectionType.NETTY_TCP);
clientToSc0.attach();
SCSessionService sessionSrvToSC0 = clientToSc0.newSessionService(TestConstants.sesServiceName1);
// 3: load data to cache (cid=700) on SC0
SCMessage request = new SCMessage();
request.setData("cacheFor1Hour_managedData");
request.setCacheId("700");
request.setMessageInfo(TestConstants.cacheCmd);
sessionSrvToSC0.createSession(new SCMessage(), new SessionMsgCallback(sessionSrvToSC0));
sessionSrvToSC0.execute(request);
// 4: start cache guardian - publish 3 large appendix
SCSubscribeMessage subMsg = new SCSubscribeMessage();
subMsg.setMask(TestConstants.mask);
subMsg.setSessionInfo(TestConstants.publish3LargeAppendixMsgCmd);
subMsg.setData("700");
clientToSc0.startCacheGuardian(TestConstants.cacheGuardian1, subMsg, cacheGuardianCbk);
// 5: verify callback retrieval - 3 appendix within 10sec
cacheGuardianCbk.waitForAppendMessage(3, 10);
// 6: verify data is in cache on SC0
Map<String, String> inspectResponse = clientToSc0.inspectCache("700");
this.checkCacheInspectString(inspectResponse, "success", SC_CACHE_ENTRY_STATE.LOADED, "700", "3",
"700/0/0=0&700/1/0=1&700/2/0=1&700/3/0=1&", TestConstants.cacheGuardian1);
// 7: start cache guardian over top level (cascaded) SC - doing nothing
subMsg.setSessionInfo(TestConstants.doNothingCmd);
guardianClient.startCacheGuardian(TestConstants.cacheGuardian1, subMsg, cacheGuardianCbk);
// 8: stop cache guardian over SC0 - cached managed data should stay
clientToSc0.stopCacheGuardian();
// 9: verify data is still in cache on SC0
inspectResponse = clientToSc0.inspectCache("700");
this.checkCacheInspectString(inspectResponse, "success", SC_CACHE_ENTRY_STATE.LOADED, "700", "3",
"700/0/0=0&700/1/0=1&700/2/0=1&700/3/0=1&", TestConstants.cacheGuardian1);
// 10: verify data is NOT in top level cache
inspectResponse = this.mgmtClient.inspectCache("700");
this.checkCacheInspectString(inspectResponse, "notfound", SC_CACHE_ENTRY_STATE.UNDEFINDED, "700", "", "", "");
// 11: reconnect client to top level (cascaded) SC - read data from cache
this.sessionClient.attach();
sessionService1 = sessionClient.newSessionService(TestConstants.sesServiceName1);
sessionService1.createSession(new SCMessage(), new SessionMsgCallback(sessionService1));
SCMessage response = sessionService1.execute(request);
// 12: verify data is correct
this.checkAppendices(response, 3);
// 13: verify data is now in top level cache