示例#1
0
  // @Test(timeout=120000)
  public void checkForIDRepeats() throws Exception {
    final int iterations = 2500;
    long repeats = 0;
    logTestStart();
    // Run a few thousand iterations and check for repeats
    Set<Long> observed = new HashSet<Long>(iterations * 2);
    BOSHClientConfig cfg = session.getBOSHClientConfig();
    for (int i = 0; i < iterations; i++) {
      // Initiate a new session
      BOSHClient sess = BOSHClient.create(cfg);
      sess.send(ComposableBody.builder().build());
      StubConnection conn = cm.awaitConnection();
      AbstractBody req = conn.getRequest().getBody();
      String rid = req.getAttribute(Attributes.RID);
      if (!observed.add(Long.valueOf(rid))) {
        repeats++;
      }

      conn.closeConnection();
      sess.close();
    }
    LOG.info("Repeated initial RID " + repeats + " time(s)");
    if (repeats >= 2) {
      fail("Initial RID repeated " + repeats + " times in " + iterations + " iterations");
    }
  }
示例#2
0
  /**
   * If the connection manager did not specify a 'maxpause' attribute at the start of the session
   * then the client MUST NOT send a 'pause' attribute during the session.
   *
   * @param idx message number (zero-based)
   * @param request message to validate
   */
  private void validateSubsequentPause(final int idx, final Node request, final Node previous) {
    AbstractBody scr = sessionCreationResponse.get();
    if (scr == null) {
      // Not checking this
      return;
    }

    try {
      // Check the current node:
      AttrPause pause =
          AttrPause.createFromString(request.getBody().getAttribute(Attributes.PAUSE));
      if (pause != null) {
        AttrMaxPause maxPause =
            AttrMaxPause.createFromString(scr.getAttribute(Attributes.MAXPAUSE));
        assertNotNull(
            "Request #"
                + idx
                + " can only use pause when "
                + "advertized in session creation response",
            maxPause);
        assertTrue(pause.intValue() < maxPause.intValue());
      }

      // Check the previous node
      AttrPause prevPause =
          AttrPause.createFromString(previous.getBody().getAttribute(Attributes.PAUSE));
      if (prevPause != null) {
        long delta = request.getTime() - previous.getTime();
        if (delta > prevPause.getInMilliseconds()) {
          fail(
              "Request #"
                  + idx
                  + " was sent too late relative to "
                  + "the previous pause message (delta="
                  + delta
                  + ", pause="
                  + prevPause.getInMilliseconds()
                  + ")");
        }
      }
    } catch (BOSHException boshx) {
      fail("Could not parse pause/maxpause: " + boshx.getMessage());
    }
  }
示例#3
0
 static CMSessionParams fromSessionInit(AbstractBody req, AbstractBody resp)
     throws BOSHException, InterruptedException {
   AttrAck aAck = AttrAck.createFromString(resp.getAttribute(Attributes.ACK));
   boolean acking =
       aAck != null && ((String) aAck.getValue()).equals(req.getAttribute(Attributes.RID));
   return new CMSessionParams(
       AttrSessionID.createFromString(getRequiredAttribute(resp, Attributes.SID)),
       AttrWait.createFromString(getRequiredAttribute(resp, Attributes.WAIT)),
       AttrVersion.createFromString(resp.getAttribute(Attributes.VER)),
       AttrPolling.createFromString(resp.getAttribute(Attributes.POLLING)),
       AttrInactivity.createFromString(resp.getAttribute(Attributes.INACTIVITY)),
       AttrRequests.createFromString(resp.getAttribute(Attributes.REQUESTS)),
       AttrHold.createFromString(resp.getAttribute(Attributes.HOLD)),
       AttrAccept.createFromString(resp.getAttribute(Attributes.ACCEPT)),
       AttrMaxPause.createFromString(resp.getAttribute(Attributes.MAXPAUSE)),
       aAck,
       AttrCharsets.createFromString(resp.getAttribute(Attributes.CHARSETS)),
       acking);
 }
示例#4
0
 private static String getRequiredAttribute(AbstractBody body, BodyQName name)
     throws BOSHException {
   String attrStr = body.getAttribute(name);
   if (attrStr != null) {
     return attrStr;
   }
   throw new BOSHException(
       "Connection Manager session creation response did not include required '"
           + name.getLocalPart()
           + "' attribute");
 }
示例#5
0
 /**
  * The <body/> element of the first request SHOULD possess the following attributes (they SHOULD
  * NOT be included in any other requests except as specified under Adding Streams To A Session):
  * "to", "xml:lang", "ver", "wait", "hold".
  *
  * @param message number (zero-based)
  * @param request request message
  * @param previous previous request message
  */
 private void validateRequestHeaders(final int idx, final Node request, final Node previous) {
   AbstractBody body = request.getBody();
   if (previous == null) {
     // session creation request
     assertNotNull(
         "to attribute not present in request #" + idx, body.getAttribute(Attributes.TO));
     assertNotNull(
         "xml:lang attribute not present in request #" + idx,
         body.getAttribute(Attributes.XML_LANG));
     assertNotNull(
         "ver attribute not present in request #" + idx, body.getAttribute(Attributes.VER));
     assertNotNull(
         "wait attribute not present in request #" + idx, body.getAttribute(Attributes.WAIT));
     assertNotNull(
         "hold attribute not present in request #" + idx, body.getAttribute(Attributes.HOLD));
   } else {
     // subsequent request
     assertNull("to attribute was present in request #" + idx, body.getAttribute(Attributes.TO));
     assertNull(
         "xml:lang attribute was present in request #" + idx,
         body.getAttribute(Attributes.XML_LANG));
     assertNull("ver attribute was present in request #" + idx, body.getAttribute(Attributes.VER));
     assertNull(
         "wait attribute was present in request #" + idx, body.getAttribute(Attributes.WAIT));
     assertNull(
         "hold attribute was present in request #" + idx, body.getAttribute(Attributes.HOLD));
   }
 }