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();
}
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();
}
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);
}
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();
}
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);
}
}
Aggregations