use of com.amazonaws.testutils.util.ConstantInputStream in project aws-sdk-android by aws-amplify.
the class S3InterruptIntegrationTest method testUploadInterrupts.
// Interrupting thread doesn't really abort the upload early UNLESS
// the content length is set
@Test
public void testUploadInterrupts() throws InterruptedException {
final InputStream is = new ConstantInputStream(DATA_SIZE, (byte) 'Z');
final ObjectMetadata omd = new ObjectMetadata();
omd.setContentLength(DATA_SIZE);
final PutObjectRequest req = new PutObjectRequest(TEST_BUCKET, "test", is, omd);
final Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
s3.putObject(req);
fail("PUT should have been aborted");
} catch (final AbortedException expected) {
// expected
}
}
});
t.start();
do {
t.join(2000);
if (t.isAlive()) {
t.interrupt();
debug("Upload thread interrupted");
} else {
debug("Upload thread joined");
}
} while (t.isAlive());
debug("Upload done");
}
use of com.amazonaws.testutils.util.ConstantInputStream in project aws-sdk-android by aws-amplify.
the class S3InterruptIntegrationTest method testUploadInterruptsViaFuture.
@Test
public void testUploadInterruptsViaFuture() throws InterruptedException {
final InputStream is = new ConstantInputStream(DATA_SIZE, (byte) 'Z');
final ObjectMetadata omd = new ObjectMetadata();
omd.setContentLength(DATA_SIZE);
final PutObjectRequest req = new PutObjectRequest(TEST_BUCKET, "test", is, omd);
final ExecutorService es = Executors.newSingleThreadExecutor();
final Boolean[] success = { null };
final Future<?> f = es.submit(new Runnable() {
@Override
public void run() {
try {
s3.putObject(req);
synchronized (success) {
success[0] = Boolean.FALSE;
}
return;
} catch (final AbortedException expected) {
// expected
}
synchronized (success) {
success[0] = Boolean.TRUE;
}
}
});
Thread.sleep(2000);
f.cancel(true);
while (success[0] == null) {
Thread.sleep(2000);
}
es.shutdownNow();
assertTrue("PUT via future should have been aborted", success[0].booleanValue());
debug("Upload via future done");
}
use of com.amazonaws.testutils.util.ConstantInputStream in project aws-sdk-android by aws-amplify.
the class S3InterruptIntegrationTest method testDownloadInterruptsViaFuture.
@Test
public void testDownloadInterruptsViaFuture() throws InterruptedException, IOException {
// Put an object to S3
final InputStream is = new ConstantInputStream(DATA_SIZE, (byte) 'Z');
final ObjectMetadata omd = new ObjectMetadata();
omd.setContentLength(DATA_SIZE);
final PutObjectRequest req = new PutObjectRequest(TEST_BUCKET, "test", is, omd);
s3.putObject(req);
final File destfile = CryptoTestUtils.generateRandomAsciiFile(0);
final ExecutorService es = Executors.newSingleThreadExecutor();
final Boolean[] success = { null };
final Future<?> f = es.submit(new Runnable() {
@Override
public void run() {
try {
final GetObjectRequest req = new GetObjectRequest(TEST_BUCKET, "test");
s3.getObject(req, destfile);
synchronized (success) {
success[0] = Boolean.FALSE;
}
return;
} catch (final AbortedException expected) {
}
synchronized (success) {
success[0] = Boolean.TRUE;
}
}
});
Thread.sleep(2000);
f.cancel(true);
while (success[0] == null) {
Thread.sleep(2000);
}
es.shutdownNow();
assertTrue("GET should have been aborted", success[0].booleanValue());
debug("Download via future done");
}
use of com.amazonaws.testutils.util.ConstantInputStream in project aws-sdk-android by aws-amplify.
the class S3InterruptIntegrationTest method testDownloadInterrupts.
@Test
public void testDownloadInterrupts() throws InterruptedException, IOException {
// Put an object to S3
final InputStream is = new ConstantInputStream(DATA_SIZE, (byte) 'Z');
final ObjectMetadata omd = new ObjectMetadata();
omd.setContentLength(DATA_SIZE);
final PutObjectRequest req = new PutObjectRequest(TEST_BUCKET, "test", is, omd);
s3.putObject(req);
final File destfile = CryptoTestUtils.generateRandomAsciiFile(0);
final Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
final GetObjectRequest req = new GetObjectRequest(TEST_BUCKET, "test");
s3.getObject(req, destfile);
fail("GET should have been aborted");
} catch (final AbortedException expected) {
}
}
});
t.start();
do {
t.join(2000);
if (t.isAlive()) {
t.interrupt();
debug("download thread interrupted");
} else {
debug("download thread joined");
}
} while (t.isAlive());
debug("Download done");
}
use of com.amazonaws.testutils.util.ConstantInputStream in project aws-sdk-android by aws-amplify.
the class S3SkipByteDigestIntegrationTest method testDigestWithSkippedBytes.
// https://github.com/aws/aws-sdk-java/issues/232
@Test
public void testDigestWithSkippedBytes() throws IOException {
if (DEBUG) {
debug("DATA_SIZE=" + DATA_SIZE);
}
final InputStream is = new ConstantInputStream(DATA_SIZE, (byte) 'Z');
final ObjectMetadata meta = new ObjectMetadata();
meta.setContentLength(DATA_SIZE);
s3.putObject(TEST_BUCKET, "key", is, meta);
{
// skip some random number of bytes
final S3Object object = s3.getObject(TEST_BUCKET, "key");
final InputStream content = object.getObjectContent();
final int n = rand.nextInt(DATA_SIZE);
if (DEBUG) {
debug("n=" + n);
}
content.skip(n);
IOUtils.toByteArray(content);
content.close();
}
{
// skip 0 bytes;
final S3Object object = s3.getObject(TEST_BUCKET, "key");
final InputStream content = object.getObjectContent();
final int n = 0;
if (DEBUG) {
debug("n=" + n);
}
content.skip(n);
IOUtils.toByteArray(content);
content.close();
}
{
// skip -1 bytes;
final S3Object object = s3.getObject(TEST_BUCKET, "key");
final InputStream content = object.getObjectContent();
final int n = -1;
if (DEBUG) {
debug("n=" + n);
}
content.skip(n);
IOUtils.toByteArray(content);
content.close();
}
{
// skip all bytes
final S3Object object = s3.getObject(TEST_BUCKET, "key");
final InputStream content = object.getObjectContent();
final int n = DATA_SIZE;
if (DEBUG) {
debug("n=" + n);
}
content.skip(n);
IOUtils.toByteArray(content);
content.close();
}
{
// skip more than all bytes
final S3Object object = s3.getObject(TEST_BUCKET, "key");
final InputStream content = object.getObjectContent();
final int n = DATA_SIZE + 100;
if (DEBUG) {
debug("n=" + n);
}
content.skip(n);
IOUtils.toByteArray(content);
content.close();
}
}
Aggregations