Package org.serviceconnector.api

Examples of org.serviceconnector.api.SCMessage


   * Description: exchange message with cacheId, server reply without cacheExpirationTime<br>
   * Expectation: no caching of the message
   */
  @Test
  public void t01_cache() throws Exception {
    SCMessage request = new SCMessage(TestConstants.pangram);
    SCMessage response = null;
    sessionService1 = client.newSessionService(TestConstants.sesServiceName1);
    msgCallback1 = new MsgCallback(sessionService1);
    response = sessionService1.createSession(request, msgCallback1);
    request.setMessageInfo(TestConstants.cacheCmd);
    request.setData("cidNoCed");
View Full Code Here


   * Description: exchange message with cacheId, server reply with cacheExpirationTime + 1 hour, get message from cache<br>
   * Expectation: catching a cached message
   */
  @Test
  public void t02_cache() throws Exception {
    SCMessage request = new SCMessage();
    request.setCompressed(false);
    SCMessage response = null;
    sessionService1 = client.newSessionService(TestConstants.sesServiceName1);
    msgCallback1 = new MsgCallback(sessionService1);
    response = sessionService1.createSession(request, msgCallback1);
    request.setData("cacheFor1Hour");
    request.setCacheId("700");
    request.setMessageInfo(TestConstants.cacheCmd);
    response = sessionService1.execute(request);
    // inspect cache entry
    Map<String, String> inspectResponse = client.inspectCache(TestConstants.sesServiceName1, "700");
    Assert.assertEquals("success", inspectResponse.get("return"));
    Assert.assertEquals(SC_CACHE_ENTRY_STATE.LOADED.toString(), inspectResponse.get("cacheState"));
    Assert.assertEquals("700", inspectResponse.get("cacheId"));

    request.setData("cacheFor2Hour");
    response = sessionService1.execute(request);
    Assert.assertEquals("cacheFor1Hour", response.getData());
    // inspect cache entry
    inspectResponse = client.inspectCache(TestConstants.sesServiceName1, "700");
    Assert.assertEquals("success", inspectResponse.get("return"));
    Assert.assertEquals(SC_CACHE_ENTRY_STATE.LOADED.toString(), inspectResponse.get("cacheState"));
    Assert.assertEquals("700", inspectResponse.get("cacheId"));
View Full Code Here

   * Description: exchange message with cacheId, server reply with cacheExpirationTime + 2 seconds, let cached message expire<br>
   * Expectation: cached message expired
   */
  @Test
  public void t05_cache() throws Exception {
    SCMessage request = new SCMessage();
    request.setCompressed(false);
    SCMessage response = null;
    sessionService1 = client.newSessionService(TestConstants.sesServiceName1);
    msgCallback1 = new MsgCallback(sessionService1);
    response = sessionService1.createSession(request, msgCallback1);
    request.setData("cacheFor2Sec");
    request.setCacheId("700");
    request.setMessageInfo(TestConstants.cacheCmd);
    response = sessionService1.execute(request);
    Assert.assertEquals("cacheFor2Sec", response.getData());
    // wait until cache message expires
    Thread.sleep(4010);
    request.setData(TestConstants.pangram);
    response = sessionService1.execute(request);
    Assert.assertEquals(TestConstants.pangram, response.getData());
    sessionService1.deleteSession();
  }
View Full Code Here

   * In a second step insert a normal not expired cache message<br/>
   * Expectation: server cache message expired
   */
  @Test
  public void t06_cache() throws Exception {
    SCMessage request = new SCMessage();
    request.setCompressed(false);
    SCMessage response = null;
    sessionService1 = client.newSessionService(TestConstants.sesServiceName1);
    msgCallback1 = new MsgCallback(sessionService1);
    response = sessionService1.createSession(request, msgCallback1);
    // request expired server message, cache should still be empty
    request.setData("cacheExpired1Hour");
    request.setCacheId("700");
    request.setMessageInfo(TestConstants.cacheCmd);
    response = sessionService1.execute(request);
    Assert.assertEquals("cacheExpired1Hour", response.getData());
    // request valid server cache message, will be stored in cache
    request.setData("cacheFor1Hour");
    response = sessionService1.execute(request);
    Assert.assertEquals("cacheFor1Hour", response.getData());
    // request expired server message again, previous message should still remain in cache
    request.setData("cacheExpired1Hour");
    request.setCacheId("700");
    request.setMessageInfo(TestConstants.cacheCmd);
    response = sessionService1.execute(request);
View Full Code Here

   * Description: exchange large message with cacheId, server reply with cacheExpirationTime, part size 64KB<br>
   * Expectation: get large message from cache
   */
  @Test
  public void t07_cacheLargeMessage() throws Exception {
    SCMessage request = new SCMessage();
    request.setCompressed(false);
    request.setPartSize(1 << 16); // 64KB
    SCMessage response = null;
    sessionService1 = client.newSessionService(TestConstants.sesServiceName1);
    msgCallback1 = new MsgCallback(sessionService1);
    response = sessionService1.createSession(request, msgCallback1);
    String largeMessage = TestUtil.getLargeString();
    request.setData(largeMessage); // internal cache timeout on server one hour
    request.setCacheId("700");
    request.setMessageInfo(TestConstants.cacheCmd);
    response = sessionService1.execute(request);
    request.setData("cacheFor1Hour");
    response = sessionService1.execute(request);
    Assert.assertEquals(largeMessage, response.getData());
    // inspect cache entry
    Map<String, String> inspectResponse = client.inspectCache(TestConstants.sesServiceName1, "700");
    Assert.assertEquals("success", inspectResponse.get("return"));
    Assert.assertEquals(SC_CACHE_ENTRY_STATE.LOADED.toString(), inspectResponse.get("cacheState"));
    Assert.assertEquals("700", inspectResponse.get("cacheId"));
View Full Code Here

   * to the server is allowed.
   * Expectation: get large message from cache
   */
  @Test
  public void t07_2_cacheLargeMessage() throws Exception {
    SCMessage request = new SCMessage();
    request.setCompressed(false);
    SCMessage response = null;
    sessionService1 = client.newSessionService(TestConstants.sesServiceName1);
    msgCallback1 = new MsgCallback(sessionService1);
    response = sessionService1.createSession(request, msgCallback1);
    request.setPartSize(1 << 16); // 64KB
    Thread.sleep(1000);
    { // first time
      String largeMessage = TestUtil.getLargeString();
      request.setData(largeMessage); // internal cache timeout on server one hour
      request.setCacheId("700");
      request.setMessageInfo(TestConstants.cacheCmd);
      response = sessionService1.execute(request);
      Assert.assertEquals(largeMessage, response.getData());
      // inspect cache entry
      Map<String, String> inspectResponse = client.inspectCache(TestConstants.sesServiceName1, "700");
      Assert.assertEquals("success", inspectResponse.get("return"));
      Assert.assertEquals(SC_CACHE_ENTRY_STATE.LOADED.toString(), inspectResponse.get("cacheState"));
      Assert.assertEquals("700", inspectResponse.get("cacheId"));
      Assert.assertEquals("2", inspectResponse.get("cacheSize"));
    }
    Thread.sleep(1000);
    // next client calls, do not access srv, read from cache
    for (int i = 0; i < 10; i++) {
      String largeMessage = TestUtil.getLargeString();
      request.setData(largeMessage); // internal cache timeout on server one hour
      request.setCacheId("700");
      request.setMessageInfo(TestConstants.cacheCmd);
      response = sessionService1.execute(request);
      Assert.assertEquals(largeMessage, response.getData());
      Thread.sleep(1000);
    }
    sessionService1.deleteSession();
  }
View Full Code Here

   * Description: exchange large message with cacheId, server reply with cacheExpirationTime, part size 64KB<br>
   * Expectation: get large message from cache
   */
  @Test
  public void t07_3_cacheLargerMessage() throws Exception {
    SCMessage request = new SCMessage();
    request.setCompressed(false);
    request.setPartSize(1 << 16); // 64KB
    SCMessage response = null;
    sessionService1 = client.newSessionService(TestConstants.sesServiceName1);
    msgCallback1 = new MsgCallback(sessionService1);
    response = sessionService1.createSession(request, msgCallback1);
    String largeMessage = TestUtil.get10MBString();
    request.setData(largeMessage); // internal cache timeout on server one hour
    request.setCacheId("700");
    request.setMessageInfo(TestConstants.cacheCmd);
    response = sessionService1.execute(request);
    request.setData("cacheFor1Hour");
    response = sessionService1.execute(request);
    Assert.assertEquals(largeMessage, response.getData());
    // inspect cache entry
    Map<String, String> inspectResponse = client.inspectCache(TestConstants.sesServiceName1, "700");
    Assert.assertEquals("success", inspectResponse.get("return"));
    Assert.assertEquals(SC_CACHE_ENTRY_STATE.LOADED.toString(), inspectResponse.get("cacheState"));
    Assert.assertEquals("700", inspectResponse.get("cacheId"));
View Full Code Here

   * Description: exchange 10MB large message with cacheId, server reply with cacheExpirationTime, part size 64KB<br>
   * Expectation: get large message from cache
   */
  @Test
  public void t08_cache10MBLargeMessage() throws Exception {
    SCMessage request = new SCMessage();
    request.setCompressed(false);
    SCMessage response = null;
    request.setPartSize(1 << 16); // 64KB
    sessionService1 = client.newSessionService(TestConstants.sesServiceName1);
    msgCallback1 = new MsgCallback(sessionService1);
    response = sessionService1.createSession(request, msgCallback1);
    String largeMessage = TestUtil.get10MBString();
    request.setData(largeMessage); // internal cache timeout on server one hour
    request.setCacheId("700");
    request.setMessageInfo(TestConstants.cacheCmd);
    response = sessionService1.execute(request);
    // inspect cache entry
    Map<String, String> inspectResponse = client.inspectCache(TestConstants.sesServiceName1, "700");
    Assert.assertEquals("success", inspectResponse.get("return"));
    Assert.assertEquals(SC_CACHE_ENTRY_STATE.LOADED.toString(), inspectResponse.get("cacheState"));
    Assert.assertEquals("700", inspectResponse.get("cacheId"));
    Assert.assertEquals("52", inspectResponse.get("cacheSize"));
    request.setData("cacheFor1Hour");
    response = sessionService1.execute(request);
    Assert.assertEquals(largeMessage, response.getData());
    // inspect cache entry
    inspectResponse = client.inspectCache(TestConstants.sesServiceName1, "700");
    Assert.assertEquals("success", inspectResponse.get("return"));
    Assert.assertEquals(SC_CACHE_ENTRY_STATE.LOADED.toString(), inspectResponse.get("cacheState"));
    Assert.assertEquals("700", inspectResponse.get("cacheId"));
View Full Code Here

   * Description: exchange message with cacheId, server reply with cacheExpirationTime + 1 day<br>
   * Expectation: cached message stays
   */
  @Test
  public void t09_cacheFor1Day() throws Exception {
    SCMessage request = new SCMessage();
    request.setCompressed(false);
    SCMessage response = null;
    sessionService1 = client.newSessionService(TestConstants.sesServiceName1);
    msgCallback1 = new MsgCallback(sessionService1);
    response = sessionService1.createSession(request, msgCallback1);
    request.setData("cacheFor1Day");
    request.setCacheId("700");
    request.setMessageInfo(TestConstants.cacheCmd);
    response = sessionService1.execute(request);
    Assert.assertEquals("cacheFor1Day", response.getData());
    sessionService1.deleteSession();
  }
View Full Code Here

   * instances<br>
   * Expectation: get messages from cache
   */
  @Test
  public void t10_2ClientsGetDifferentCacheMessage() throws Exception {
    SCMessage request = new SCMessage();
    request.setCompressed(false);
    SCMessage response = null;
    // session service one stores "cacheFor1Hour" with cacheId 700
    sessionService1 = client.newSessionService(TestConstants.sesServiceName1);
    msgCallback1 = new MsgCallback(sessionService1);
    response = sessionService1.createSession(request, msgCallback1);
    request.setData("cacheFor1Hour");
    request.setCacheId("700");
    request.setMessageInfo(TestConstants.cacheCmd);
    response = sessionService1.execute(request);
    Assert.assertEquals("cacheFor1Hour", response.getData());

    // session service two stores "cacheFor2Hour" with cacheId 600
    SCSessionService sessionService2 = client.newSessionService(TestConstants.sesServiceName1);
    MsgCallback msgCallback2 = new MsgCallback(sessionService1);
    response = sessionService2.createSession(request, msgCallback2);
    request.setData("cacheFor2Hour");
    request.setCacheId("600");
    response = sessionService2.execute(request);
    Assert.assertEquals("cacheFor2Hour", response.getData());

    // session service one gets message with cacheId 700
    request.setData(TestConstants.pangram);
    request.setCacheId("700");
    request.setMessageInfo(TestConstants.cacheCmd);
    response = sessionService1.execute(request);
    Assert.assertEquals("cacheFor1Hour", response.getData());
    Assert.assertEquals("700", response.getCacheId());
    Assert.assertEquals("2", response.getCachePartNr());

    // session service two gets message with cacheId 600
    request.setData(TestConstants.pangram);
    request.setCacheId("600");
    request.setMessageInfo(TestConstants.cacheCmd);
    response = sessionService2.execute(request);
    Assert.assertEquals("cacheFor2Hour", response.getData());
    Assert.assertEquals("600", response.getCacheId());
    Assert.assertEquals("2", response.getCachePartNr());

    // session service one gets message with cacheId 600
    request.setData(TestConstants.pangram);
    request.setCacheId("600");
    request.setMessageInfo(TestConstants.cacheCmd);
    response = sessionService1.execute(request);
    Assert.assertEquals("cacheFor2Hour", response.getData());
    Assert.assertEquals("600", response.getCacheId());
    Assert.assertEquals("2", response.getCachePartNr());

    // session service two gets message with cacheId 700
    request.setData(TestConstants.pangram);
    request.setCacheId("700");
    request.setMessageInfo(TestConstants.cacheCmd);
    response = sessionService2.execute(request);
    Assert.assertEquals("cacheFor1Hour", response.getData());
    Assert.assertEquals("700", response.getCacheId());
    Assert.assertEquals("2", response.getCachePartNr());

    sessionService2.deleteSession();
    sessionService1.deleteSession();
  }
View Full Code Here

TOP

Related Classes of org.serviceconnector.api.SCMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.