1717
1818import com .google .common .collect .Lists ;
1919import com .spectralogic .ds3client .Ds3Client ;
20+ import com .spectralogic .ds3client .Ds3ClientImpl ;
2021import com .spectralogic .ds3client .commands .GetObjectRequest ;
2122import com .spectralogic .ds3client .commands .GetObjectResponse ;
2223import com .spectralogic .ds3client .commands .PutObjectRequest ;
2324import com .spectralogic .ds3client .commands .spectrads3 .GetJobSpectraS3Request ;
2425import com .spectralogic .ds3client .commands .spectrads3 .GetJobSpectraS3Response ;
2526import com .spectralogic .ds3client .helpers .Ds3ClientHelpers ;
27+ import com .spectralogic .ds3client .helpers .FileObjectGetter ;
28+ import com .spectralogic .ds3client .helpers .FileObjectPutter ;
2629import com .spectralogic .ds3client .helpers .options .ReadJobOptions ;
2730import com .spectralogic .ds3client .integration .test .helpers .ABMTestHelper ;
31+ import com .spectralogic .ds3client .integration .test .helpers .Ds3ClientShim ;
2832import com .spectralogic .ds3client .integration .test .helpers .TempStorageIds ;
2933import com .spectralogic .ds3client .integration .test .helpers .TempStorageUtil ;
3034import com .spectralogic .ds3client .models .ChecksumType ;
3135import com .spectralogic .ds3client .models .Priority ;
3236import com .spectralogic .ds3client .models .bulk .Ds3Object ;
37+ import com .spectralogic .ds3client .models .bulk .PartialDs3Object ;
38+ import com .spectralogic .ds3client .models .common .Range ;
3339import com .spectralogic .ds3client .utils .ResourceUtils ;
40+ import org .apache .commons .io .FileUtils ;
3441import org .junit .AfterClass ;
3542import org .junit .BeforeClass ;
3643import org .junit .Test ;
3744import org .slf4j .Logger ;
3845import org .slf4j .LoggerFactory ;
3946
47+ import java .io .File ;
4048import java .io .IOException ;
49+ import java .io .InputStream ;
50+ import java .lang .reflect .InvocationTargetException ;
4151import java .net .URISyntaxException ;
4252import java .nio .channels .SeekableByteChannel ;
4353import java .nio .channels .WritableByteChannel ;
4454import java .nio .file .Files ;
4555import java .nio .file .Path ;
46- import java .util .UUID ;
56+ import java .nio .file .Paths ;
57+ import java .util .*;
4758
4859import static com .spectralogic .ds3client .integration .Util .RESOURCE_BASE_NAME ;
4960import static com .spectralogic .ds3client .integration .Util .deleteAllContents ;
5061import static org .hamcrest .Matchers .is ;
5162import static org .junit .Assert .assertThat ;
63+ import static org .junit .Assert .assertTrue ;
5264
5365public class GetJobManagement_Test {
5466
@@ -128,6 +140,75 @@ public void createReadJob() throws IOException, InterruptedException, URISyntaxE
128140 assertThat (jobSpectraS3Response .getStatusCode (), is (200 ));
129141 }
130142
143+ @ Test
144+ public void createReadJobWithBigFile () throws IOException , URISyntaxException , NoSuchMethodException , IllegalAccessException , InvocationTargetException {
145+ putBigFile ();
146+
147+ final String tempPathPrefix = null ;
148+ final Path tempDirectory = Files .createTempDirectory (Paths .get ("." ), tempPathPrefix );
149+
150+ try {
151+ final String DIR_NAME = "largeFiles/" ;
152+ final String FILE_NAME = "lesmis-copies.txt" ;
153+
154+ final Path objPath = ResourceUtils .loadFileResource (DIR_NAME + FILE_NAME );
155+ final long bookSize = Files .size (objPath );
156+ final Ds3Object obj = new Ds3Object (FILE_NAME , bookSize );
157+
158+ final Ds3ClientShim ds3ClientShim = new Ds3ClientShim ((Ds3ClientImpl )client );
159+
160+ final int maxNumBlockAllocationRetries = 1 ;
161+ final int maxNumObjectTransferAttempts = 3 ;
162+ final Ds3ClientHelpers ds3ClientHelpers = Ds3ClientHelpers .wrap (ds3ClientShim ,
163+ maxNumBlockAllocationRetries ,
164+ maxNumObjectTransferAttempts );
165+
166+ final Ds3ClientHelpers .Job readJob = ds3ClientHelpers .startReadJob (BUCKET_NAME , Arrays .asList (obj ));
167+
168+ final GetJobSpectraS3Response jobSpectraS3Response = ds3ClientShim
169+ .getJobSpectraS3 (new GetJobSpectraS3Request (readJob .getJobId ()));
170+
171+ assertThat (jobSpectraS3Response .getStatusCode (), is (200 ));
172+
173+ readJob .transfer (new FileObjectGetter (tempDirectory ));
174+
175+ final File originalFile = ResourceUtils .loadFileResource (DIR_NAME + FILE_NAME ).toFile ();
176+ final File fileCopiedFromBP = Paths .get (tempDirectory .toString (), FILE_NAME ).toFile ();
177+ assertTrue (FileUtils .contentEquals (originalFile , fileCopiedFromBP ));
178+
179+ } finally {
180+ FileUtils .deleteDirectory (tempDirectory .toFile ());
181+ }
182+ }
183+
184+ private void putBigFile () throws IOException , URISyntaxException {
185+ final String DIR_NAME = "largeFiles/" ;
186+ final String [] FILE_NAMES = new String [] { "lesmis-copies.txt" };
187+
188+ final Path dirPath = ResourceUtils .loadFileResource (DIR_NAME );
189+
190+ final List <String > bookTitles = new ArrayList <>();
191+ final List <Ds3Object > objects = new ArrayList <>();
192+ for (final String book : FILE_NAMES ) {
193+ final Path objPath = ResourceUtils .loadFileResource (DIR_NAME + book );
194+ final long bookSize = Files .size (objPath );
195+ final Ds3Object obj = new Ds3Object (book , bookSize );
196+
197+ bookTitles .add (book );
198+ objects .add (obj );
199+ }
200+
201+ final int maxNumBlockAllocationRetries = 1 ;
202+ final int maxNumObjectTransferAttempts = 3 ;
203+ final Ds3ClientHelpers ds3ClientHelpers = Ds3ClientHelpers .wrap (client ,
204+ maxNumBlockAllocationRetries ,
205+ maxNumObjectTransferAttempts );
206+
207+ final Ds3ClientHelpers .Job writeJob = ds3ClientHelpers .startWriteJob (BUCKET_NAME , objects );
208+ writeJob .transfer (new FileObjectPutter (dirPath ));
209+ }
210+
211+
131212 @ Test
132213 public void createReadJobWithPriorityOption () throws IOException ,
133214 InterruptedException , URISyntaxException {
@@ -165,4 +246,53 @@ public void createReadJobWithNameAndPriorityOptions() throws IOException,
165246 assertThat (jobSpectraS3Response .getMasterObjectListResult ().getName (), is ("test_job" ));
166247 assertThat (jobSpectraS3Response .getMasterObjectListResult ().getPriority (), is (Priority .LOW ));
167248 }
168- }
249+
250+ @ Test
251+ public void testPartialRetriesWithInjectedFailures () throws NoSuchMethodException , IllegalAccessException , InvocationTargetException , IOException , URISyntaxException {
252+ putBigFile ();
253+
254+ final String tempPathPrefix = null ;
255+ final Path tempDirectory = Files .createTempDirectory (Paths .get ("." ), tempPathPrefix );
256+
257+ try {
258+ final List <Ds3Object > filesToGet = new ArrayList <>();
259+
260+ final String DIR_NAME = "largeFiles/" ;
261+ final String FILE_NAME = "lesmis-copies.txt" ;
262+
263+ filesToGet .add (new PartialDs3Object (FILE_NAME , Range .byLength (0 , 100 )));
264+
265+ filesToGet .add (new PartialDs3Object (FILE_NAME , Range .byLength (100 , 100 )));
266+
267+ final Ds3ClientShim ds3ClientShim = new Ds3ClientShim ((Ds3ClientImpl ) client );
268+
269+ final int maxNumBlockAllocationRetries = 1 ;
270+ final int maxNumObjectTransferAttempts = 3 ;
271+ final Ds3ClientHelpers ds3ClientHelpers = Ds3ClientHelpers .wrap (ds3ClientShim ,
272+ maxNumBlockAllocationRetries ,
273+ maxNumObjectTransferAttempts );
274+
275+ final Ds3ClientHelpers .Job job = ds3ClientHelpers .startReadJob (BUCKET_NAME , filesToGet );
276+
277+ job .transfer (new FileObjectGetter (tempDirectory ));
278+
279+ try (final InputStream originalFileStream = Thread .currentThread ().getContextClassLoader ().getResourceAsStream (DIR_NAME + FILE_NAME )) {
280+ final byte [] first200Bytes = new byte [200 ];
281+ int numBytesRead = originalFileStream .read (first200Bytes , 0 , 200 );
282+
283+ assertThat (numBytesRead , is (200 ));
284+
285+ try (final InputStream fileReadFromBP = Files .newInputStream (Paths .get (tempDirectory .toString (), FILE_NAME ))) {
286+ final byte [] first200BytesFromBP = new byte [200 ];
287+
288+ numBytesRead = fileReadFromBP .read (first200BytesFromBP , 0 , 200 );
289+ assertThat (numBytesRead , is (200 ));
290+
291+ assertTrue (Arrays .equals (first200Bytes , first200BytesFromBP ));
292+ }
293+ }
294+ } finally {
295+ FileUtils .deleteDirectory (tempDirectory .toFile ());
296+ }
297+ }
298+ }
0 commit comments