Skip to content

Commit

Permalink
Fixing calculation of open-ended range size, adding tests for open-en…
Browse files Browse the repository at this point in the history
…ded and open-start ranges, updating other range ITs to not do duplicate requests
  • Loading branch information
escowles committed Aug 5, 2014
1 parent ae12d03 commit e8ad97c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
Expand Up @@ -95,8 +95,8 @@ protected Response getDatastreamContentResponse(final Datastream ds, final Strin
.header("Content-Range", contentRangeValue);
} else {
final long maxBufferSize = MAX_BUFFER_SIZE; // 10MB max buffer size?
final long rangeSize = range.size();
final long rangeStart = range.start();
final long rangeSize = range.size() == -1 ? contentSize - rangeStart : range.size();
final long remainingBytes = contentSize - rangeStart;
final long bufSize = rangeSize < remainingBytes ? rangeSize : remainingBytes;

Expand Down
Expand Up @@ -275,9 +275,9 @@ public void testRangeRequest() throws Exception {

final HttpGet method_test_get = new HttpGet(serverAddress + pid + "/ds1/fcr:content");
method_test_get.setHeader("Range", "bytes=1-3");
assertEquals(206, getStatus(method_test_get));

final HttpResponse response = client.execute(method_test_get);
assertEquals(206, response.getStatusLine().getStatusCode());
logger.debug("Returned from HTTP GET, now checking content...");
assertEquals("Got the wrong content back!", "arb",EntityUtils.toString(response.getEntity()));
assertEquals("bytes 1-3/20", response.getFirstHeader("Content-Range").getValue());
Expand All @@ -294,9 +294,9 @@ public void testRangeRequestWithSkipBytes() throws Exception {

final HttpGet method_test_get = new HttpGet(serverAddress + pid + "/ds1/fcr:content");
method_test_get.setHeader("Range", "bytes=1-21");
assertEquals(206, getStatus(method_test_get));

final HttpResponse response = client.execute(method_test_get);
assertEquals(206, response.getStatusLine().getStatusCode());
logger.debug("Returned from HTTP GET, now checking content...");
assertEquals("Got the wrong content back!", "arge marbles for ever",
EntityUtils.toString(response.getEntity()));
Expand All @@ -314,13 +314,51 @@ public void testRangeRequestBadRange() throws Exception {

final HttpGet method_test_get = new HttpGet(serverAddress + pid + "/ds1/fcr:content");
method_test_get.setHeader("Range", "bytes=50-100");
assertEquals(416, getStatus(method_test_get));

final HttpResponse response = client.execute(method_test_get);
assertEquals(416, response.getStatusLine().getStatusCode());
assertEquals("bytes 50-100/20", response.getFirstHeader("Content-Range").getValue());

}

@Test
public void testRangeRequestOpenEnded() throws Exception {
final String pid = getRandomUniquePid();
createObject(pid);

final HttpPost createDSMethod = postDSMethod(pid, "ds1", "marbles for everyone");
assertEquals(201, getStatus(createDSMethod));

final HttpGet method_test_get = new HttpGet(serverAddress + pid + "/ds1/fcr:content");
method_test_get.setHeader("Range", "bytes=2-");

final HttpResponse response = client.execute(method_test_get);
assertEquals(206, response.getStatusLine().getStatusCode());
logger.debug("Returned from HTTP GET, now checking content...");
assertEquals("Got the wrong content back!", "rbles for everyone",
EntityUtils.toString(response.getEntity()));
assertEquals("bytes 2-19/20", response.getFirstHeader("Content-Range").getValue());
}

@Test
public void testRangeRequestOpenStart() throws Exception {
final String pid = getRandomUniquePid();
createObject(pid);

final HttpPost createDSMethod = postDSMethod(pid, "ds1", "marbles for everyone");
assertEquals(201, getStatus(createDSMethod));

final HttpGet method_test_get = new HttpGet(serverAddress + pid + "/ds1/fcr:content");
method_test_get.setHeader("Range", "bytes=-2");

final HttpResponse response = client.execute(method_test_get);
assertEquals(206, response.getStatusLine().getStatusCode());
logger.debug("Returned from HTTP GET, now checking content...");
assertEquals("Got the wrong content back!", "mar",
EntityUtils.toString(response.getEntity()));
assertEquals("bytes 0-2/20", response.getFirstHeader("Content-Range").getValue());
}

@Test
public void testPostToExistingDS() throws Exception {
final String pid = getRandomUniquePid();
Expand Down

0 comments on commit e8ad97c

Please sign in to comment.