Example #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");
    }
  }
 @Test
 public void setDeleteAt() throws IOException, DateParseException {
   expectStatusCode(202, false);
   prepareMetadata();
   final Date date = DateUtils.parseDate("Mon, 03 Sep 2001 05:40:33 GMT");
   object.setDeleteAt(date);
   verifyHeaderValue(Long.toString(date.getTime() / 1000), X_DELETE_AT, "POST");
 }
 @Override
 public Object handle(
     GenerationConfiguration configuration,
     Object generatedObject,
     GenerationContext contextForExpression) {
   this.handleConfiguration = configuration;
   this.handleGeneratedObject = generatedObject;
   handleContextForExpression = contextForExpression;
   return Long.valueOf(1L);
 }
 protected void prepareBytes(byte[] bytes, String md5) {
   expectStatusCode(200, false);
   prepareHeader(
       response,
       AbstractDownloadObjectCommand.ETAG,
       md5 == null ? DigestUtils.md5Hex(bytes) : md5);
   prepareHeader(
       response, AbstractDownloadObjectCommand.CONTENT_LENGTH, Long.toString(bytes.length));
   httpEntity = new ByteArrayEntity(bytes);
   new NonStrictExpectations() {
     {
       response.getEntity();
       result = httpEntity;
     }
   };
 }
  protected void testTempUrl(final String method, final LocalTime localTime) {
    final String password = "******";
    final long todayInMS = 1369581129861L;
    final long oneDayInSeconds = 86400L;
    final long tomorrowInSeconds = todayInMS / 1000 + oneDayInSeconds;

    final AbstractStoredObject object = createStoredObjectForTempURL(password);
    // Make sure that a fixed date is used
    useFixedDateForToday(todayInMS);
    // Check whether the secure URL contains the right signature and expiry date
    final String secureUrl;
    if (method.equals("GET")) {
      secureUrl = object.getTempGetUrl(oneDayInSeconds);
    } else {
      secureUrl = object.getTempPutUrl(oneDayInSeconds);
    }
    assertTrue(
        "Does not contain the timestamp of 'tomorrow'",
        secureUrl.contains(Long.toString(tomorrowInSeconds)));
    String plainText = method + "\n" + tomorrowInSeconds + "\n/internal/path/alpha/some-image.jpg";
    String signature = HashSignature.getSignature(password, plainText);
    assertTrue("The signature of the secure URL", secureUrl.contains(signature));
  }
 @CustomFieldSerializer(fieldName = "fieldCustomSerializable")
 public SFSDataWrapper customSerializeCustomField(Long value) {
   return new SFSDataWrapper(SFSDataType.INT, value.intValue());
 }
 @CustomFieldDeserializer(fieldName = "fieldCustomSerializable")
 public Long customDeserializeCustomField(SFSDataWrapper wrapper) {
   return Long.valueOf((Integer) wrapper.getObject());
 }