Search in sources :

Example 1 with Payload

use of org.jclouds.io.Payload in project druid by druid-io.

the class CloudFilesByteSourceTest method openStreamTest.

@Test
public void openStreamTest() throws IOException {
    final String path = "path";
    CloudFilesObjectApiProxy objectApi = createMock(CloudFilesObjectApiProxy.class);
    CloudFilesObject cloudFilesObject = createMock(CloudFilesObject.class);
    Payload payload = createMock(Payload.class);
    InputStream stream = createMock(InputStream.class);
    expect(objectApi.get(path)).andReturn(cloudFilesObject);
    expect(cloudFilesObject.getPayload()).andReturn(payload);
    expect(payload.openStream()).andReturn(stream);
    payload.close();
    replayAll();
    CloudFilesByteSource byteSource = new CloudFilesByteSource(objectApi, path);
    assertEquals(stream, byteSource.openStream());
    byteSource.closeStream();
    verifyAll();
}
Also used : InputStream(java.io.InputStream) Payload(org.jclouds.io.Payload) Test(org.junit.Test)

Example 2 with Payload

use of org.jclouds.io.Payload in project druid by druid-io.

the class CloudFilesByteSourceTest method openStreamWithRecoverableErrorTest.

@Test()
public void openStreamWithRecoverableErrorTest() throws IOException {
    final String path = "path";
    CloudFilesObjectApiProxy objectApi = createMock(CloudFilesObjectApiProxy.class);
    CloudFilesObject cloudFilesObject = createMock(CloudFilesObject.class);
    Payload payload = createMock(Payload.class);
    InputStream stream = createMock(InputStream.class);
    expect(objectApi.get(path)).andReturn(cloudFilesObject);
    expect(cloudFilesObject.getPayload()).andReturn(payload);
    expect(payload.openStream()).andThrow(new IOException()).andReturn(stream);
    payload.close();
    replayAll();
    CloudFilesByteSource byteSource = new CloudFilesByteSource(objectApi, path);
    try {
        byteSource.openStream();
    } catch (Exception e) {
        assertEquals("Recoverable exception", e.getMessage());
    }
    assertEquals(stream, byteSource.openStream());
    byteSource.closeStream();
    verifyAll();
}
Also used : InputStream(java.io.InputStream) Payload(org.jclouds.io.Payload) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with Payload

use of org.jclouds.io.Payload in project druid by druid-io.

the class CloudFilesDataSegmentPusherTest method testPush.

@Test
public void testPush() throws Exception {
    ObjectApi objectApi = EasyMock.createStrictMock(ObjectApi.class);
    EasyMock.expect(objectApi.put(EasyMock.anyString(), EasyMock.<Payload>anyObject())).andReturn(null).atLeastOnce();
    EasyMock.replay(objectApi);
    CloudFilesApi api = EasyMock.createStrictMock(CloudFilesApi.class);
    EasyMock.expect(api.getObjectApi(EasyMock.anyString(), EasyMock.anyString())).andReturn(objectApi).atLeastOnce();
    EasyMock.replay(api);
    CloudFilesDataSegmentPusherConfig config = new CloudFilesDataSegmentPusherConfig();
    config.setRegion("region");
    config.setContainer("container");
    config.setBasePath("basePath");
    CloudFilesDataSegmentPusher pusher = new CloudFilesDataSegmentPusher(api, config, new DefaultObjectMapper());
    // Create a mock segment on disk
    File tmp = tempFolder.newFile("version.bin");
    final byte[] data = new byte[] { 0x0, 0x0, 0x0, 0x1 };
    Files.write(data, tmp);
    final long size = data.length;
    DataSegment segmentToPush = new DataSegment("foo", new Interval("2015/2016"), "0", Maps.<String, Object>newHashMap(), Lists.<String>newArrayList(), Lists.<String>newArrayList(), NoneShardSpec.instance(), 0, size);
    DataSegment segment = pusher.push(tempFolder.getRoot(), segmentToPush);
    Assert.assertEquals(segmentToPush.getSize(), segment.getSize());
    EasyMock.verify(api);
}
Also used : ObjectApi(org.jclouds.openstack.swift.v1.features.ObjectApi) Payload(org.jclouds.io.Payload) CloudFilesApi(org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) File(java.io.File) DataSegment(io.druid.timeline.DataSegment) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 4 with Payload

use of org.jclouds.io.Payload in project druid by druid-io.

the class CloudFilesObjectApiProxyTest method getTest.

@Test
public void getTest() {
    final String path = "path";
    final String region = "region";
    final String container = "container";
    CloudFilesApi cloudFilesApi = createMock(CloudFilesApi.class);
    ObjectApi objectApi = createMock(ObjectApi.class);
    SwiftObject swiftObject = createMock(SwiftObject.class);
    Payload payload = createMock(Payload.class);
    expect(cloudFilesApi.getObjectApi(region, container)).andReturn(objectApi);
    expect(objectApi.get(path)).andReturn(swiftObject);
    expect(swiftObject.getPayload()).andReturn(payload);
    replayAll();
    CloudFilesObjectApiProxy cfoApiProxy = new CloudFilesObjectApiProxy(cloudFilesApi, region, container);
    CloudFilesObject cloudFilesObject = cfoApiProxy.get(path);
    assertEquals(cloudFilesObject.getPayload(), payload);
    assertEquals(cloudFilesObject.getRegion(), region);
    assertEquals(cloudFilesObject.getContainer(), container);
    assertEquals(cloudFilesObject.getPath(), path);
    verifyAll();
}
Also used : ObjectApi(org.jclouds.openstack.swift.v1.features.ObjectApi) SwiftObject(org.jclouds.openstack.swift.v1.domain.SwiftObject) CloudFilesApi(org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi) Payload(org.jclouds.io.Payload) Test(org.junit.Test)

Example 5 with Payload

use of org.jclouds.io.Payload in project camel by apache.

the class JcloudsBlobStoreProducer method process.

@Override
public void process(Exchange exchange) throws Exception {
    String container = getContainerName(exchange);
    String blobName = getBlobName(exchange);
    String operation = getOperation(exchange);
    List blobNames = getBlobNameList(exchange);
    if (LOG.isTraceEnabled()) {
        LOG.trace("Processing {} operation on '{}'", operation, container + "/" + blobName);
    }
    if (JcloudsConstants.GET.equals(operation)) {
        exchange.getOut().setBody(JcloudsBlobStoreHelper.readBlob(blobStore, container, blobName));
    } else if (JcloudsConstants.COUNT_BLOBS.equals(operation)) {
        exchange.getOut().setBody(JcloudsBlobStoreHelper.countBlob(blobStore, container));
    } else if (JcloudsConstants.REMOVE_BLOB.equals(operation)) {
        JcloudsBlobStoreHelper.removeBlob(blobStore, container, blobName);
    } else if (JcloudsConstants.CLEAR_CONTAINER.equals(operation)) {
        JcloudsBlobStoreHelper.clearContainer(blobStore, container);
    } else if (JcloudsConstants.DELETE_CONTAINER.equals(operation)) {
        JcloudsBlobStoreHelper.deleteContainer(blobStore, container);
    } else if (JcloudsConstants.CONTAINER_EXISTS.equals(operation)) {
        exchange.getOut().setBody(JcloudsBlobStoreHelper.containerExists(blobStore, container));
    } else if (JcloudsConstants.REMOVE_BLOBS.equals(operation)) {
        JcloudsBlobStoreHelper.removeBlobs(blobStore, container, blobNames);
    } else {
        Payload body = exchange.getIn().getBody(Payload.class);
        JcloudsBlobStoreHelper.writeBlob(blobStore, container, blobName, body);
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) Payload(org.jclouds.io.Payload)

Aggregations

Payload (org.jclouds.io.Payload)13 Test (org.junit.Test)7 InputStream (java.io.InputStream)4 SwiftObject (org.jclouds.openstack.swift.v1.domain.SwiftObject)4 IOException (java.io.IOException)3 ObjectApi (org.jclouds.openstack.swift.v1.features.ObjectApi)3 CloudFilesApi (org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi)3 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)1 DataSegment (io.druid.timeline.DataSegment)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 FallbackConverter (org.apache.camel.FallbackConverter)1 TypeConverter (org.apache.camel.TypeConverter)1 GenericFile (org.apache.camel.component.file.GenericFile)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 Blob (org.jclouds.blobstore.domain.Blob)1 HdfsPayload (org.jclouds.examples.blobstore.hdfs.io.payloads.HdfsPayload)1 GetOptions (org.jclouds.http.options.GetOptions)1 ByteSourcePayload (org.jclouds.io.payloads.ByteSourcePayload)1