@Test public void testSourceDefaultRequestBehavior() { var source = new S3Source(client); var result = source.load(resourceId); assertThat(result).isNull(); verify(client).getObject(new GetObjectRequest(resourceId.getObjectId())); reset(client); var version = new S3Version("123", VersionType.ETAG); result = source.loadIfModified(resourceId, version); assertThat(result).isNull(); var request = new GetObjectRequest(resourceId.getObjectId()); request.setNonmatchingETagConstraints(Collections.singletonList(version.val())); verify(client).getObject(request); reset(client); version = new S3Version(new Date(), VersionType.LAST_MODIFIED); result = source.loadIfModified(resourceId, version); assertThat(result).isNull(); request = new GetObjectRequest(resourceId.getObjectId()); request.setModifiedSinceConstraint(version.val()); verify(client).getObject(request); reset(client); }
@Override public LoadedResource loadIfModified(S3ResourceId resourceId, SourceVersion version) { var objectId = resourceId.getObjectId(); var request = new GetObjectRequest(objectId); if (!version.isEmpty()) { var type = ((S3Version) version).getType(); if (type == VersionType.ETAG) { var val = version.<String>val(); request.setNonmatchingETagConstraints(Collections.singletonList(val)); } else if (type == VersionType.LAST_MODIFIED) { var val = version.<Date>val(); request.setModifiedSinceConstraint(val); } } var response = client.getObject(request); if (response != null) { SourceVersion resultVersion; var eTag = response.getObjectMetadata().getETag(); if (isNullOrEmpty(eTag)) { var lastModified = response.getObjectMetadata().getLastModified(); if (lastModified != null) { log.debug("Loaded Last-Modified version for {}: {}", objectId, eTag); resultVersion = new S3Version(lastModified, VersionType.LAST_MODIFIED); } else { log.debug("No resource version was found for {}", objectId); resultVersion = EMPTY; } } else { log.debug("Loaded ETag version for {}: {}", objectId, eTag); resultVersion = new S3Version(eTag, VersionType.ETAG); } return new LoadedResource(response.getObjectContent(), resultVersion, resourceId); } else { return null; } }
S3Source extends AbstractSource<S3ResourceId> implements NonListenableSource<S3ResourceId> { @Override public LoadedResource loadIfModified(S3ResourceId resourceId, SourceVersion version) { var objectId = resourceId.getObjectId(); var request = new GetObjectRequest(objectId); if (!version.isEmpty()) { var type = ((S3Version) version).getType(); if (type == VersionType.ETAG) { var val = version.<String>val(); request.setNonmatchingETagConstraints(Collections.singletonList(val)); } else if (type == VersionType.LAST_MODIFIED) { var val = version.<Date>val(); request.setModifiedSinceConstraint(val); } } var response = client.getObject(request); if (response != null) { SourceVersion resultVersion; var eTag = response.getObjectMetadata().getETag(); if (isNullOrEmpty(eTag)) { var lastModified = response.getObjectMetadata().getLastModified(); if (lastModified != null) { log.debug("Loaded Last-Modified version for {}: {}", objectId, eTag); resultVersion = new S3Version(lastModified, VersionType.LAST_MODIFIED); } else { log.debug("No resource version was found for {}", objectId); resultVersion = EMPTY; } } else { log.debug("Loaded ETag version for {}: {}", objectId, eTag); resultVersion = new S3Version(eTag, VersionType.ETAG); } return new LoadedResource(response.getObjectContent(), resultVersion, resourceId); } else { return null; } } }
S3Source extends AbstractSource<S3ResourceId> implements NonListenableSource<S3ResourceId> { @Override public LoadedResource loadIfModified(S3ResourceId resourceId, SourceVersion version) { var objectId = resourceId.getObjectId(); var request = new GetObjectRequest(objectId); if (!version.isEmpty()) { var type = ((S3Version) version).getType(); if (type == VersionType.ETAG) { var val = version.<String>val(); request.setNonmatchingETagConstraints(Collections.singletonList(val)); } else if (type == VersionType.LAST_MODIFIED) { var val = version.<Date>val(); request.setModifiedSinceConstraint(val); } } var response = client.getObject(request); if (response != null) { SourceVersion resultVersion; var eTag = response.getObjectMetadata().getETag(); if (isNullOrEmpty(eTag)) { var lastModified = response.getObjectMetadata().getLastModified(); if (lastModified != null) { log.debug("Loaded Last-Modified version for {}: {}", objectId, eTag); resultVersion = new S3Version(lastModified, VersionType.LAST_MODIFIED); } else { log.debug("No resource version was found for {}", objectId); resultVersion = EMPTY; } } else { log.debug("Loaded ETag version for {}: {}", objectId, eTag); resultVersion = new S3Version(eTag, VersionType.ETAG); } return new LoadedResource(response.getObjectContent(), resultVersion, resourceId); } else { return null; } } S3Source(AmazonS3 client); }
S3Source extends AbstractSource<S3ResourceId> implements NonListenableSource<S3ResourceId> { @Override public LoadedResource loadIfModified(S3ResourceId resourceId, SourceVersion version) { var objectId = resourceId.getObjectId(); var request = new GetObjectRequest(objectId); if (!version.isEmpty()) { var type = ((S3Version) version).getType(); if (type == VersionType.ETAG) { var val = version.<String>val(); request.setNonmatchingETagConstraints(Collections.singletonList(val)); } else if (type == VersionType.LAST_MODIFIED) { var val = version.<Date>val(); request.setModifiedSinceConstraint(val); } } var response = client.getObject(request); if (response != null) { SourceVersion resultVersion; var eTag = response.getObjectMetadata().getETag(); if (isNullOrEmpty(eTag)) { var lastModified = response.getObjectMetadata().getLastModified(); if (lastModified != null) { log.debug("Loaded Last-Modified version for {}: {}", objectId, eTag); resultVersion = new S3Version(lastModified, VersionType.LAST_MODIFIED); } else { log.debug("No resource version was found for {}", objectId); resultVersion = EMPTY; } } else { log.debug("Loaded ETag version for {}: {}", objectId, eTag); resultVersion = new S3Version(eTag, VersionType.ETAG); } return new LoadedResource(response.getObjectContent(), resultVersion, resourceId); } else { return null; } } S3Source(AmazonS3 client); @Override LoadedResource loadIfModified(S3ResourceId resourceId, SourceVersion version); @Override String describe(); }
S3Source extends AbstractSource<S3ResourceId> implements NonListenableSource<S3ResourceId> { @Override public LoadedResource loadIfModified(S3ResourceId resourceId, SourceVersion version) { var objectId = resourceId.getObjectId(); var request = new GetObjectRequest(objectId); if (!version.isEmpty()) { var type = ((S3Version) version).getType(); if (type == VersionType.ETAG) { var val = version.<String>val(); request.setNonmatchingETagConstraints(Collections.singletonList(val)); } else if (type == VersionType.LAST_MODIFIED) { var val = version.<Date>val(); request.setModifiedSinceConstraint(val); } } var response = client.getObject(request); if (response != null) { SourceVersion resultVersion; var eTag = response.getObjectMetadata().getETag(); if (isNullOrEmpty(eTag)) { var lastModified = response.getObjectMetadata().getLastModified(); if (lastModified != null) { log.debug("Loaded Last-Modified version for {}: {}", objectId, eTag); resultVersion = new S3Version(lastModified, VersionType.LAST_MODIFIED); } else { log.debug("No resource version was found for {}", objectId); resultVersion = EMPTY; } } else { log.debug("Loaded ETag version for {}: {}", objectId, eTag); resultVersion = new S3Version(eTag, VersionType.ETAG); } return new LoadedResource(response.getObjectContent(), resultVersion, resourceId); } else { return null; } } S3Source(AmazonS3 client); @Override LoadedResource loadIfModified(S3ResourceId resourceId, SourceVersion version); @Override String describe();  }