Package org.jclouds.io

Examples of org.jclouds.io.PayloadSlicer


   public void testExecute() throws Exception {
      String container = "test-container";
      String blobName = "test-blob";
      long oneMB = 1048576L;
      AzureBlobClient client = createMock(AzureBlobClient.class);
      PayloadSlicer slicer = createMock(PayloadSlicer.class);
      MutableBlobMetadata metadata = new MutableBlobMetadataImpl();
      MutableContentMetadata contentMetadata = new BaseMutableContentMetadata();
      contentMetadata.setContentLength(MultipartUploadStrategy.MAX_BLOCK_SIZE * 3 + oneMB);
      metadata.setName(blobName);
      metadata.setContentMetadata(contentMetadata);
      Blob blob = new BlobImpl(metadata);
      Payload payload = new StringPayload("ABCD");
      payload.setContentMetadata(contentMetadata);
      blob.setPayload(payload);

      expect(slicer.slice(payload, 0, MultipartUploadStrategy.MAX_BLOCK_SIZE)).andReturn(payload);
      expect(slicer.slice(payload, MultipartUploadStrategy.MAX_BLOCK_SIZE, MultipartUploadStrategy.MAX_BLOCK_SIZE)).andReturn(payload);
      expect(slicer.slice(payload, MultipartUploadStrategy.MAX_BLOCK_SIZE * 2, MultipartUploadStrategy.MAX_BLOCK_SIZE)).andReturn(payload);
      expect(slicer.slice(payload, MultipartUploadStrategy.MAX_BLOCK_SIZE * 3, oneMB)).andReturn(payload);
      client.putBlock(eq(container), eq(blobName), anyObject(String.class), eq(payload));
      expectLastCall().times(4);
      expect(client.putBlockList(eq(container), eq(blobName), anyObject(List.class))).andReturn("Fake ETAG");

      AzureBlobBlockUploadStrategy strat = new AzureBlobBlockUploadStrategy(client, slicer);
View Full Code Here


@Test
public class BasePayloadSlicerTest {

   @Test
   public void testIterableSliceExpectedSingle() throws IOException {
      PayloadSlicer slicer = new BasePayloadSlicer();
      String contents = "aaaaaaaaaabbbbbbbbbbccccc";
      Payload payload = new InputStreamPayload(new ByteArrayInputStream(contents.getBytes(Charsets.US_ASCII)));

      Iterator<Payload> iter = slicer.slice(payload, 25).iterator();

      assertTrue(iter.hasNext(), "Not enough results");
      assertEquals(new String(ByteStreams.toByteArray(iter.next())), contents);
      assertFalse(iter.hasNext());
View Full Code Here

   }

   @Test
   public void testIterableSliceExpectedMulti() throws IOException {
      PayloadSlicer slicer = new BasePayloadSlicer();
      Payload payload = new InputStreamPayload(new ByteArrayInputStream("aaaaaaaaaabbbbbbbbbbccccc".getBytes(Charsets.US_ASCII)));

      Iterator<Payload> iter = slicer.slice(payload, 10).iterator();

      assertTrue(iter.hasNext(), "Not enough results");
      assertEquals(Strings2.toStringAndClose(iter.next().getInput()), "aaaaaaaaaa");
      assertTrue(iter.hasNext(), "Not enough results");
      assertEquals(Strings2.toStringAndClose(iter.next().getInput()), "bbbbbbbbbb");
View Full Code Here

   public void testExecute() throws Exception {
      String container = "test-container";
      String blobName = "test-blob";
      long oneMB = 1048576L;
      AzureBlobClient client = createMock(AzureBlobClient.class);
      PayloadSlicer slicer = createMock(PayloadSlicer.class);
      MutableBlobMetadata metadata = new MutableBlobMetadataImpl();
      MutableContentMetadata contentMetadata = new BaseMutableContentMetadata();
      contentMetadata.setContentLength(MultipartUploadStrategy.MAX_BLOCK_SIZE * 3 + oneMB);
      metadata.setName(blobName);
      metadata.setContentMetadata(contentMetadata);
      Blob blob = new BlobImpl(metadata);
      Payload payload = new StringPayload("ABCD");
      payload.setContentMetadata(contentMetadata);
      blob.setPayload(payload);

      expect(slicer.slice(payload, 0, MultipartUploadStrategy.MAX_BLOCK_SIZE)).andReturn(payload);
      expect(slicer.slice(payload, MultipartUploadStrategy.MAX_BLOCK_SIZE, MultipartUploadStrategy.MAX_BLOCK_SIZE)).andReturn(payload);
      expect(slicer.slice(payload, MultipartUploadStrategy.MAX_BLOCK_SIZE * 2, MultipartUploadStrategy.MAX_BLOCK_SIZE)).andReturn(payload);
      expect(slicer.slice(payload, MultipartUploadStrategy.MAX_BLOCK_SIZE * 3, oneMB)).andReturn(payload);
      client.putBlock(eq(container), eq(blobName), anyObject(String.class), eq(payload));
      expectLastCall().times(4);
      expect(client.putBlockList(eq(container), eq(blobName), anyObject(List.class))).andReturn("Fake ETAG");

      AzureBlobBlockUploadStrategy strat = new AzureBlobBlockUploadStrategy(client, slicer);
View Full Code Here

@Test
public class BasePayloadSlicerTest {

   @Test
   public void testIterableSliceExpectedSingle() throws IOException {
      PayloadSlicer slicer = new BasePayloadSlicer();
      String contents = "aaaaaaaaaabbbbbbbbbbccccc";
      Payload payload = new InputStreamPayload(new ByteArrayInputStream(contents.getBytes(Charsets.US_ASCII)));

      Iterator<Payload> iter = slicer.slice(payload, 25).iterator();

      assertTrue(iter.hasNext(), "Not enough results");
      assertEquals(Strings2.toStringAndClose(iter.next().openStream()), contents);
      assertFalse(iter.hasNext());
View Full Code Here

   }

   @Test
   public void testIterableSliceExpectedMulti() throws IOException {
      PayloadSlicer slicer = new BasePayloadSlicer();
      Payload payload = new InputStreamPayload(new ByteArrayInputStream("aaaaaaaaaabbbbbbbbbbccccc".getBytes(Charsets.US_ASCII)));

      Iterator<Payload> iter = slicer.slice(payload, 10).iterator();

      assertTrue(iter.hasNext(), "Not enough results");
      assertEquals(Strings2.toStringAndClose(iter.next().getInput()), "aaaaaaaaaa");
      assertTrue(iter.hasNext(), "Not enough results");
      assertEquals(Strings2.toStringAndClose(iter.next().getInput()), "bbbbbbbbbb");
View Full Code Here

   @Test
   public void testIterableSliceWithRepeatingByteSource() throws IOException {
      String content = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n"; /* 53 chars */
      byte[] contentBytes = content.getBytes(Charsets.UTF_8);
      ByteSource byteSource = ByteSources.repeatingArrayByteSource(contentBytes).slice(0, 1024);
      PayloadSlicer slicer = new BasePayloadSlicer();
      Payload payload = new ByteSourcePayload(byteSource);

      assertEquals(Iterables.size(slicer.slice(payload, 100)), 11);
      assertEquals(Iterables.size(slicer.slice(payload, 53)), 20);
   }
View Full Code Here

   public void testExecute() throws Exception {
      String container = "test-container";
      String blobName = "test-blob";
      long oneMB = 1048576L;
      AzureBlobClient client = createMock(AzureBlobClient.class);
      PayloadSlicer slicer = createMock(PayloadSlicer.class);
      MutableBlobMetadata metadata = new MutableBlobMetadataImpl();
      MutableContentMetadata contentMetadata = new BaseMutableContentMetadata();
      contentMetadata.setContentLength(MultipartUploadStrategy.MAX_BLOCK_SIZE * 3 + oneMB);
      metadata.setName(blobName);
      metadata.setContentMetadata(contentMetadata);
      Blob blob = new BlobImpl(metadata);
      ByteSource bytes = ByteSource.wrap("ABCD".getBytes(Charsets.UTF_8));
      Payload payload = Payloads.newByteSourcePayload(bytes);
      payload.setContentMetadata(contentMetadata);
      blob.setPayload(payload);

      expect(slicer.slice(payload, 0, MultipartUploadStrategy.MAX_BLOCK_SIZE)).andReturn(payload);
      expect(slicer.slice(payload, MultipartUploadStrategy.MAX_BLOCK_SIZE, MultipartUploadStrategy.MAX_BLOCK_SIZE)).andReturn(payload);
      expect(slicer.slice(payload, MultipartUploadStrategy.MAX_BLOCK_SIZE * 2, MultipartUploadStrategy.MAX_BLOCK_SIZE)).andReturn(payload);
      expect(slicer.slice(payload, MultipartUploadStrategy.MAX_BLOCK_SIZE * 3, oneMB)).andReturn(payload);
      client.putBlock(eq(container), eq(blobName), anyObject(String.class), eq(payload));
      expectLastCall().times(4);
      expect(client.putBlockList(eq(container), eq(blobName), EasyMock.<List<String>>anyObject())).andReturn("Fake ETAG");

      AzureBlobBlockUploadStrategy strat = new AzureBlobBlockUploadStrategy(client, slicer);
View Full Code Here

   public void testExceededContentLengthLimit() throws Exception {
      String container = "test-container";
      String blobName = "test-blob";

      AzureBlobClient client = createNiceMock(AzureBlobClient.class);
      PayloadSlicer slicer = createNiceMock(PayloadSlicer.class);

      MutableBlobMetadata metadata = new MutableBlobMetadataImpl();
      MutableContentMetadata contentMetadata = new BaseMutableContentMetadata();
      contentMetadata.setContentLength(MultipartUploadStrategy.MAX_BLOCK_SIZE * MultipartUploadStrategy.MAX_NUMBER_OF_BLOCKS + 1);
      metadata.setName(blobName);
View Full Code Here

TOP

Related Classes of org.jclouds.io.PayloadSlicer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.