Skip to content

Commit 03e56ff

Browse files
author
Denver
committed
Merge pull request #139 from rpmoore/empty_object
Empty object
2 parents dcaaaa5 + 0deeaf3 commit 03e56ff

File tree

4 files changed

+57
-14
lines changed

4 files changed

+57
-14
lines changed

ds3-sdk-integration/src/test/java/com/spectralogic/ds3client/integration/Regression_Test.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@
55
import com.spectralogic.ds3client.Ds3Client;
66
import com.spectralogic.ds3client.commands.CancelJobRequest;
77
import com.spectralogic.ds3client.commands.CancelJobResponse;
8+
import com.spectralogic.ds3client.commands.GetAvailableJobChunksRequest;
89
import com.spectralogic.ds3client.helpers.Ds3ClientHelpers;
910
import com.spectralogic.ds3client.models.Contents;
1011
import com.spectralogic.ds3client.models.bulk.Ds3Object;
12+
import com.spectralogic.ds3client.networking.FailedRequestException;
1113
import com.spectralogic.ds3client.serializer.XmlProcessingException;
1214
import org.junit.AfterClass;
1315
import org.junit.BeforeClass;
1416
import org.junit.Test;
1517

1618
import java.io.IOException;
19+
import java.nio.channels.SeekableByteChannel;
1720
import java.security.SignatureException;
21+
import java.util.Collections;
1822
import java.util.List;
1923

2024
import org.slf4j.Logger;
2125
import org.slf4j.LoggerFactory;
2226

23-
import static org.junit.Assert.assertEquals;
24-
import static org.junit.Assert.assertTrue;
27+
import static org.hamcrest.CoreMatchers.is;
28+
import static org.hamcrest.CoreMatchers.notNullValue;
29+
import static org.junit.Assert.*;
2530

2631
public class Regression_Test {
2732

@@ -205,4 +210,40 @@ public void testPrefixForNestedDirectories() throws IOException, SignatureExcept
205210
Util.deleteAllContents(client, bucketName);
206211
}
207212
}
213+
214+
@Test
215+
public void emptyObjectTest() throws IOException, SignatureException, XmlProcessingException {
216+
Util.assumeVersion1_2(client);
217+
final String bucketName = "emptyObject";
218+
final List<Ds3Object> objects = Collections.singletonList(new Ds3Object("obj1.txt", 0));
219+
220+
try {
221+
222+
final Ds3ClientHelpers helpers = Ds3ClientHelpers.wrap(client);
223+
224+
helpers.ensureBucketExists(bucketName);
225+
226+
final Ds3ClientHelpers.Job job = helpers.startWriteJob(bucketName, objects);
227+
228+
assertThat(job, is(notNullValue()));
229+
230+
try {
231+
client.getAvailableJobChunks(new GetAvailableJobChunksRequest(job.getJobId()));
232+
fail();
233+
} catch(final FailedRequestException e) {
234+
assertThat(e.getStatusCode(), is(404)); // this returns 410 in bp 3.0
235+
}
236+
237+
job.transfer(new Ds3ClientHelpers.ObjectChannelBuilder() {
238+
@Override
239+
public SeekableByteChannel buildChannel(final String key) throws IOException {
240+
fail("This call should never be hit");
241+
return new NullChannel();
242+
}
243+
});
244+
} finally {
245+
Util.deleteAllContents(client, bucketName);
246+
}
247+
248+
}
208249
}

ds3-sdk/src/main/java/com/spectralogic/ds3client/helpers/JobImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,17 @@ public JobImpl(final Ds3Client client, final MasterObjectList masterObjectList)
3333

3434
@Override
3535
public UUID getJobId() {
36+
if (this.masterObjectList == null) {
37+
return null;
38+
}
3639
return this.masterObjectList.getJobId();
3740
}
3841

3942
@Override
4043
public String getBucketName() {
44+
if (this.masterObjectList == null) {
45+
return null;
46+
}
4147
return this.masterObjectList.getBucketName();
4248
}
4349

ds3-sdk/src/main/java/com/spectralogic/ds3client/helpers/WriteJobImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public WriteJobImpl(
4747
final Ds3Client client,
4848
final MasterObjectList masterObjectList) {
4949
super(client, masterObjectList);
50-
if (masterObjectList == null) {
51-
LOG.info("An empty job was created");
50+
if (this.masterObjectList == null || this.masterObjectList.getObjects() == null) {
51+
LOG.info("Job has no data to transfer");
5252
this.filteredChunks = null;
5353
this.partTracker = null;
5454
} else {
@@ -86,8 +86,8 @@ public void removeObjectCompletedListener(final ObjectCompletedListener listener
8686
public void transfer(final ObjectChannelBuilder channelBuilder)
8787
throws SignatureException, IOException, XmlProcessingException {
8888
LOG.debug("Starting job transfer");
89-
if (masterObjectList == null) {
90-
LOG.info("There is nothing to transfer");
89+
if (this.masterObjectList == null || this.masterObjectList.getObjects() == null) {
90+
LOG.info("There is nothing to transfer for job" + ((this.getJobId() == null) ? "" : " " + this.getJobId().toString()));
9191
return;
9292
}
9393
try (final JobState jobState = new JobState(channelBuilder, filteredChunks, partTracker, ImmutableMap.<String, ImmutableMultimap<BulkObject,Range>>of())) {

ds3-sdk/src/main/java/com/spectralogic/ds3client/serializer/XmlOutput.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
2323
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
2424
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
25-
import com.spectralogic.ds3client.BulkCommand;
2625
import com.spectralogic.ds3client.models.bulk.Ds3ObjectList;
2726

2827
import java.io.IOException;
@@ -44,21 +43,18 @@ public class XmlOutput {
4443
module.setDefaultUseWrapper(false);
4544
mapper = new XmlMapper(module);
4645
final SimpleFilterProvider filterProvider = new SimpleFilterProvider().setFailOnUnknownId(false);
47-
mapper.setFilters(filterProvider);
46+
mapper.setFilterProvider(filterProvider);
4847
if (isProductionBuild()) {
4948
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
5049
} else {
51-
LOG.info("Non-production build: Asserting on Deserializing invalid XML elements in responses.");
50+
LOG.info("Non-production build: Asserting on de-serializing unknown elements and attributes in XML response payloads.");
5251
}
5352
}
5453

5554
protected static boolean isProductionBuild() {
5655
String productionBuild = System.getenv(PRODUCTION_BUILD);
5756
if (productionBuild != null) {
58-
if (productionBuild.equals("true")) {
59-
return true;
60-
}
61-
return false;
57+
return productionBuild.equals("true");
6258
}
6359

6460
final Properties props = new Properties();
@@ -74,7 +70,7 @@ protected static boolean isProductionBuild() {
7470
return true;
7571
}
7672
else {
77-
LOG.error("Unknown productionBuild value[" + productionBuild + "]. Defaulting to fail for unknown XML elements.");
73+
LOG.error("Unknown productionBuild value[" + productionBuild + "]. Defaulting to false for unknown XML elements.");
7874
}
7975
} catch (final IOException e) {
8076
LOG.error("Failed to load property file: ", e);

0 commit comments

Comments
 (0)