Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.txt text

Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,50 @@

import com.google.common.collect.Lists;
import com.spectralogic.ds3client.Ds3Client;
import com.spectralogic.ds3client.Ds3ClientImpl;
import com.spectralogic.ds3client.commands.GetObjectRequest;
import com.spectralogic.ds3client.commands.GetObjectResponse;
import com.spectralogic.ds3client.commands.PutObjectRequest;
import com.spectralogic.ds3client.commands.spectrads3.GetJobSpectraS3Request;
import com.spectralogic.ds3client.commands.spectrads3.GetJobSpectraS3Response;
import com.spectralogic.ds3client.helpers.Ds3ClientHelpers;
import com.spectralogic.ds3client.helpers.FileObjectGetter;
import com.spectralogic.ds3client.helpers.FileObjectPutter;
import com.spectralogic.ds3client.helpers.options.ReadJobOptions;
import com.spectralogic.ds3client.integration.test.helpers.ABMTestHelper;
import com.spectralogic.ds3client.integration.test.helpers.Ds3ClientShim;
import com.spectralogic.ds3client.integration.test.helpers.TempStorageIds;
import com.spectralogic.ds3client.integration.test.helpers.TempStorageUtil;
import com.spectralogic.ds3client.models.ChecksumType;
import com.spectralogic.ds3client.models.Priority;
import com.spectralogic.ds3client.models.bulk.Ds3Object;
import com.spectralogic.ds3client.models.bulk.PartialDs3Object;
import com.spectralogic.ds3client.models.common.Range;
import com.spectralogic.ds3client.utils.ResourceUtils;
import org.apache.commons.io.FileUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.URISyntaxException;
import java.nio.channels.SeekableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.UUID;
import java.nio.file.Paths;
import java.util.*;

import static com.spectralogic.ds3client.integration.Util.RESOURCE_BASE_NAME;
import static com.spectralogic.ds3client.integration.Util.deleteAllContents;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

public class GetJobManagement_Test {

Expand Down Expand Up @@ -128,6 +140,75 @@ public void createReadJob() throws IOException, InterruptedException, URISyntaxE
assertThat(jobSpectraS3Response.getStatusCode(), is(200));
}

@Test
public void createReadJobWithBigFile() throws IOException, URISyntaxException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
putBigFile();

final String tempPathPrefix = null;
final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix);

try {
final String DIR_NAME = "largeFiles/";
final String FILE_NAME = "lesmis-copies.txt";

final Path objPath = ResourceUtils.loadFileResource(DIR_NAME + FILE_NAME);
final long bookSize = Files.size(objPath);
final Ds3Object obj = new Ds3Object(FILE_NAME, bookSize);

final Ds3ClientShim ds3ClientShim = new Ds3ClientShim((Ds3ClientImpl)client);

final int maxNumBlockAllocationRetries = 1;
final int maxNumObjectTransferAttempts = 3;
final Ds3ClientHelpers ds3ClientHelpers = Ds3ClientHelpers.wrap(ds3ClientShim,
maxNumBlockAllocationRetries,
maxNumObjectTransferAttempts);

final Ds3ClientHelpers.Job readJob = ds3ClientHelpers.startReadJob(BUCKET_NAME, Arrays.asList(obj));

final GetJobSpectraS3Response jobSpectraS3Response = ds3ClientShim
.getJobSpectraS3(new GetJobSpectraS3Request(readJob.getJobId()));

assertThat(jobSpectraS3Response.getStatusCode(), is(200));

readJob.transfer(new FileObjectGetter(tempDirectory));

final File originalFile = ResourceUtils.loadFileResource(DIR_NAME + FILE_NAME).toFile();
final File fileCopiedFromBP = Paths.get(tempDirectory.toString(), FILE_NAME).toFile();
assertTrue(FileUtils.contentEquals(originalFile, fileCopiedFromBP));

} finally {
FileUtils.deleteDirectory(tempDirectory.toFile());
}
}

private void putBigFile() throws IOException, URISyntaxException {
final String DIR_NAME = "largeFiles/";
final String[] FILE_NAMES = new String[] { "lesmis-copies.txt" };

final Path dirPath = ResourceUtils.loadFileResource(DIR_NAME);

final List<String> bookTitles = new ArrayList<>();
final List<Ds3Object> objects = new ArrayList<>();
for (final String book : FILE_NAMES) {
final Path objPath = ResourceUtils.loadFileResource(DIR_NAME + book);
final long bookSize = Files.size(objPath);
final Ds3Object obj = new Ds3Object(book, bookSize);

bookTitles.add(book);
objects.add(obj);
}

final int maxNumBlockAllocationRetries = 1;
final int maxNumObjectTransferAttempts = 3;
final Ds3ClientHelpers ds3ClientHelpers = Ds3ClientHelpers.wrap(client,
maxNumBlockAllocationRetries,
maxNumObjectTransferAttempts);

final Ds3ClientHelpers.Job writeJob = ds3ClientHelpers.startWriteJob(BUCKET_NAME, objects);
writeJob.transfer(new FileObjectPutter(dirPath));
}


@Test
public void createReadJobWithPriorityOption() throws IOException,
InterruptedException, URISyntaxException {
Expand Down Expand Up @@ -165,4 +246,53 @@ public void createReadJobWithNameAndPriorityOptions() throws IOException,
assertThat(jobSpectraS3Response.getMasterObjectListResult().getName(), is("test_job"));
assertThat(jobSpectraS3Response.getMasterObjectListResult().getPriority(), is(Priority.LOW));
}
}

@Test
public void testPartialRetriesWithInjectedFailures() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException, URISyntaxException {
putBigFile();

final String tempPathPrefix = null;
final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix);

try {
final List<Ds3Object> filesToGet = new ArrayList<>();

final String DIR_NAME = "largeFiles/";
final String FILE_NAME = "lesmis-copies.txt";

filesToGet.add(new PartialDs3Object(FILE_NAME, Range.byLength(0, 100)));

filesToGet.add(new PartialDs3Object(FILE_NAME, Range.byLength(100, 100)));

final Ds3ClientShim ds3ClientShim = new Ds3ClientShim((Ds3ClientImpl) client);

final int maxNumBlockAllocationRetries = 1;
final int maxNumObjectTransferAttempts = 3;
final Ds3ClientHelpers ds3ClientHelpers = Ds3ClientHelpers.wrap(ds3ClientShim,
maxNumBlockAllocationRetries,
maxNumObjectTransferAttempts);

final Ds3ClientHelpers.Job job = ds3ClientHelpers.startReadJob(BUCKET_NAME, filesToGet);

job.transfer(new FileObjectGetter(tempDirectory));

try (final InputStream originalFileStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(DIR_NAME + FILE_NAME)) {
final byte[] first200Bytes = new byte[200];
int numBytesRead = originalFileStream.read(first200Bytes, 0, 200);

assertThat(numBytesRead, is(200));

try (final InputStream fileReadFromBP = Files.newInputStream(Paths.get(tempDirectory.toString(), FILE_NAME))) {
final byte[] first200BytesFromBP = new byte[200];

numBytesRead = fileReadFromBP.read(first200BytesFromBP, 0, 200);
assertThat(numBytesRead, is(200));

assertTrue(Arrays.equals(first200Bytes, first200BytesFromBP));
}
}
} finally {
FileUtils.deleteDirectory(tempDirectory.toFile());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@
import com.spectralogic.ds3client.integration.test.helpers.TempStorageUtil;
import com.spectralogic.ds3client.models.*;
import com.spectralogic.ds3client.models.bulk.Ds3Object;
import com.spectralogic.ds3client.networking.ConnectionDetails;
import com.spectralogic.ds3client.networking.FailedRequestException;
import com.spectralogic.ds3client.networking.NetworkClient;
import com.spectralogic.ds3client.networking.NetworkClientImpl;
import com.spectralogic.ds3client.utils.ByteArraySeekableByteChannel;
import com.spectralogic.ds3client.utils.ResourceUtils;
import org.apache.commons.io.FileUtils;
Expand All @@ -45,7 +42,6 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.nio.channels.SeekableByteChannel;
Expand All @@ -56,6 +52,7 @@
import java.util.Date;
import java.util.List;
import java.util.UUID;
import com.spectralogic.ds3client.integration.test.helpers.Ds3ClientShim;

import static com.spectralogic.ds3client.integration.Util.RESOURCE_BASE_NAME;
import static com.spectralogic.ds3client.integration.Util.deleteAllContents;
Expand Down Expand Up @@ -907,53 +904,6 @@ public void objectCompleted(final String name) {
}
}

private static class Ds3ClientShim extends Ds3ClientImpl {
private static Method getNetClientMethod = null;

int numRetries = 0;

static {
try {
getNetClientMethod = Ds3ClientImpl.class.getDeclaredMethod("getNetClient");
} catch (final NoSuchMethodException e) {
fail("Could not find Ds3ClientImpl method getNetClient.");
}

getNetClientMethod.setAccessible(true);
}

public Ds3ClientShim(final NetworkClient netClient) {
super(netClient);
}

public Ds3ClientShim(final Ds3ClientImpl ds3ClientImpl) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
this((NetworkClient)getNetClientMethod.invoke(ds3ClientImpl));
}

@Override
public PutObjectResponse putObject(final PutObjectRequest request) throws IOException {
if(numRetries++ >= 1) {
return super.putObject(request);
}

throw new Ds3NoMoreRetriesException(1);
}

@Override
public Ds3Client newForNode(final JobNode node) {
final ConnectionDetails newConnectionDetails;
try {
newConnectionDetails = ((NetworkClient)getNetClientMethod.invoke(this)).getConnectionDetails();
final NetworkClient newNetClient = new NetworkClientImpl(newConnectionDetails);
return new Ds3ClientShim(newNetClient);
} catch (final IllegalAccessException | InvocationTargetException e) {
fail("Failure trying to create Ds3Client used in verifying putObject retries: " + e.getMessage());
}

return null;
}
}

private interface ObjectTransferExceptionHandler {
boolean handleException(final Throwable t);
}
Expand All @@ -975,4 +925,4 @@ public boolean handleException(final Throwable t) {
}
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* ****************************************************************************
* Copyright 2014-2016 Spectra Logic Corporation. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* ****************************************************************************
*/

package com.spectralogic.ds3client.integration.test.helpers;

import com.spectralogic.ds3client.Ds3Client;
import com.spectralogic.ds3client.Ds3ClientImpl;
import com.spectralogic.ds3client.commands.GetObjectRequest;
import com.spectralogic.ds3client.commands.GetObjectResponse;
import com.spectralogic.ds3client.commands.PutObjectRequest;
import com.spectralogic.ds3client.commands.PutObjectResponse;
import com.spectralogic.ds3client.exceptions.Ds3NoMoreRetriesException;
import com.spectralogic.ds3client.models.JobNode;
import com.spectralogic.ds3client.networking.ConnectionDetails;
import com.spectralogic.ds3client.networking.NetworkClient;
import com.spectralogic.ds3client.networking.NetworkClientImpl;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import static org.junit.Assert.fail;

public class Ds3ClientShim extends Ds3ClientImpl {
private static Method getNetClientMethod = null;

int numRetries = 0;

static {
try {
getNetClientMethod = Ds3ClientImpl.class.getDeclaredMethod("getNetClient");
} catch (final NoSuchMethodException e) {
fail("Could not find Ds3ClientImpl method getNetClient.");
}

getNetClientMethod.setAccessible(true);
}

public Ds3ClientShim(final NetworkClient netClient) {
super(netClient);
}

public Ds3ClientShim(final Ds3ClientImpl ds3ClientImpl) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
this((NetworkClient)getNetClientMethod.invoke(ds3ClientImpl));
}

@Override
public PutObjectResponse putObject(final PutObjectRequest request) throws IOException {
if (numRetries++ >= 1) {
return super.putObject(request);
}

throw new Ds3NoMoreRetriesException(1);
}

@Override
public GetObjectResponse getObject(final GetObjectRequest request) throws IOException {
if (numRetries++ >= 1) {
return super.getObject(request);
}

throw new Ds3NoMoreRetriesException(1);
}

@Override
public Ds3Client newForNode(final JobNode node) {
final ConnectionDetails newConnectionDetails;
try {
newConnectionDetails = ((NetworkClient)getNetClientMethod.invoke(this)).getConnectionDetails();
final NetworkClient newNetClient = new NetworkClientImpl(newConnectionDetails);
return new Ds3ClientShim(newNetClient);
} catch (final IllegalAccessException | InvocationTargetException e) {
fail("Failure trying to create Ds3Client used in verifying putObject retries: " + e.getMessage());
}

return null;
}
}
Loading