more fixes for test cases in DefaultServletTest

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2022-09-27 11:01:56 +10:00
parent c6305ff36c
commit bed034c22d
4 changed files with 9 additions and 16 deletions

View File

@ -139,7 +139,7 @@ public class PrecompressedHttpContent implements HttpContent
@Override
public ByteBuffer getBuffer()
{
return _content.getBuffer();
return _precompressedContent.getBuffer();
}
@Override

View File

@ -21,6 +21,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
@ -230,7 +231,7 @@ public class CachedContentFactory implements HttpContent.ContentFactory
{
compressedContent = null;
Resource compressedResource = _factory.newResource(compressedPathInContext);
if (compressedResource.exists() && compressedResource.lastModified().isAfter(resource.lastModified()) &&
if (compressedResource.exists() && compressedResource.lastModified().compareTo(resource.lastModified()) >= 0 &&
compressedResource.length() < resource.length())
{
compressedContent = new CachedHttpContent(compressedPathInContext, compressedResource, null);
@ -271,12 +272,12 @@ public class CachedContentFactory implements HttpContent.ContentFactory
{
String compressedPathInContext = pathInContext + format.getExtension();
CachedHttpContent compressedContent = _cache.get(compressedPathInContext);
if (compressedContent != null && compressedContent.isValid() && compressedContent.getResource().lastModified().isAfter(resource.lastModified()))
if (compressedContent != null && compressedContent.isValid() && compressedContent.getResource().lastModified().compareTo(resource.lastModified()) >= 0)
compressedContents.put(format, compressedContent);
// Is there a precompressed resource?
Resource compressedResource = _factory.newResource(compressedPathInContext);
if (compressedResource.exists() && compressedResource.lastModified().isAfter(resource.lastModified()) &&
if (compressedResource.exists() && compressedResource.lastModified().compareTo(resource.lastModified()) >= 0 &&
compressedResource.length() < resource.length())
compressedContents.put(format,
new ResourceHttpContent(compressedResource, _mimeTypes.getMimeByExtension(compressedPathInContext)));
@ -452,7 +453,7 @@ public class CachedContentFactory implements HttpContent.ContentFactory
boolean isValid()
{
if (_lastModifiedValue == _resource.lastModified() && _contentLengthValue == _resource.length())
if (Objects.equals(_lastModifiedValue, _resource.lastModified()) && _contentLengthValue == _resource.length())
{
_lastAccessed = Instant.now();
return true;
@ -611,7 +612,8 @@ public class CachedContentFactory implements HttpContent.ContentFactory
public boolean isValid()
{
return _precompressedContent.isValid() && _content.isValid() && _content.getResource().lastModified().isBefore(_precompressedContent.getResource().lastModified());
return _precompressedContent.isValid() && _content.isValid() &&
_content.getResource().lastModified().compareTo(_precompressedContent.getResource().lastModified()) >= 0;
}
@Override

View File

@ -87,7 +87,7 @@ public class ResourceContentFactory implements ContentFactory
{
String compressedPathInContext = pathInContext + format.getExtension();
Resource compressedResource = _factory.newResource(compressedPathInContext);
if (compressedResource != null && compressedResource.exists() && compressedResource.lastModified().isAfter(resource.lastModified()) &&
if (compressedResource != null && compressedResource.exists() && compressedResource.lastModified().compareTo(resource.lastModified()) >= 0 &&
compressedResource.length() < resource.length())
compressedContents.put(format,
new ResourceHttpContent(compressedResource, _mimeTypes.getMimeByExtension(compressedPathInContext)));

View File

@ -358,7 +358,6 @@ public class DefaultServletTest
}
@Test
@Disabled // TODO
public void testListingProperUrlEncoding() throws Exception
{
ServletHolder defholder = context.addServlet(DefaultServlet.class, "/*");
@ -962,7 +961,6 @@ public class DefaultServletTest
* Ensure that oddball directory names are served with proper escaping
*/
@Test
@Disabled // TODO
public void testWelcomeRedirectDirWithQuestion() throws Exception
{
FS.ensureDirExists(docRoot);
@ -995,7 +993,6 @@ public class DefaultServletTest
* Ensure that oddball directory names are served with proper escaping
*/
@Test
@Disabled // TODO
public void testWelcomeRedirectDirWithSemicolon() throws Exception
{
FS.ensureDirExists(docRoot);
@ -1553,7 +1550,6 @@ public class DefaultServletTest
}
@Test
@Disabled // TODO
public void testGzip() throws Exception
{
FS.ensureDirExists(docRoot);
@ -1648,7 +1644,6 @@ public class DefaultServletTest
}
@Test
@Disabled // TODO
public void testCachedGzip() throws Exception
{
FS.ensureDirExists(docRoot);
@ -1731,7 +1726,6 @@ public class DefaultServletTest
}
@Test
@Disabled // TODO
public void testBrotli() throws Exception
{
createFile(docRoot.resolve("data0.txt"), "Hello Text 0");
@ -1819,7 +1813,6 @@ public class DefaultServletTest
}
@Test
@Disabled // TODO
public void testCachedBrotli() throws Exception
{
createFile(docRoot.resolve("data0.txt"), "Hello Text 0");
@ -1899,7 +1892,6 @@ public class DefaultServletTest
}
@Test
@Disabled // TODO
public void testDefaultBrotliOverGzip() throws Exception
{
createFile(docRoot.resolve("data0.txt"), "Hello Text 0");
@ -1936,7 +1928,6 @@ public class DefaultServletTest
}
@Test
@Disabled // TODO
public void testCustomCompressionFormats() throws Exception
{
createFile(docRoot.resolve("data0.txt"), "Hello Text 0");